5 #include "../model/arena.h" 6 #include "../model/arenaelement.h" 7 #include "../model/arenaelementtype.h" 17 , m_lastDragFinished(true)
18 , m_autoRotateWalls(false)
25 qreal diffX = b.x() - a.x();
26 qreal diffY = b.y() - a.y();
27 return diffX*diffX + diffY*diffY;
34 QPointF top = gridPos - QPointF(0, halfItemSize);
35 QPointF bottom = gridPos + QPointF(0, halfItemSize);
36 QPointF left = gridPos - QPointF(halfItemSize, 0);
37 QPointF right = gridPos + QPointF(halfItemSize, 0);
44 qreal minDist = qMin(distTop, qMin(distBottom, qMin(distLeft, distRight)));
46 if (minDist == distTop)
48 if (minDist == distRight)
50 if (minDist == distBottom)
59 QPointF top = gridPos + QPointF(
ITEM_SIZE / 2.0, 0.0);
61 QPointF left = gridPos + QPointF(0.0,
ITEM_SIZE / 2.0);
69 qreal minDist = qMin(distTop, qMin(distBottom, qMin(distLeft, distRight)));
71 if (minDist == distTop)
73 if (minDist == distRight)
75 if (minDist == distBottom)
83 startDrag(QList<ArenaSceneElement*>() << sceneElement);
98 sceneElements.first()->element()->isItem()));
105 foreach (QGraphicsItem *item,
m_scene->selectedItems())
106 item->setSelected(
false);
113 Q_ASSERT(sceneElement);
115 sceneElement->setSelected(
true);
154 QPointF newPos = origPos + gridMouseOffset;
155 qDebug() <<
"origPos:" << origPos;
156 dragTo(activeElement, newPos);
164 dragTo(activeElement, to);
198 painter->setBrush(QBrush(0xE0E0E0));
199 painter->setPen(0xE0E0E0);
200 painter->drawEllipse(gridPos, r, r);
QMap< ArenaSceneElement *, QPointF > m_origPositions
qreal squaredDistance(const QPointF &a, const QPointF &b)
void removeElement(ArenaElement *element)
bool operationInProgress() const
void setItemOffset(const QPointF &offset)
See itemOffset()
void draw(QPainter *painter, const QRectF &rect)
static QPoint sceneToGrid(QPointF scenePos)
bool isItem() const
Convenience method returning true iff. this is an item element (freely movable)
void dragTo(const QPointF &to)
void setSnapToGrid(bool snap)
ArenaElement * element() const
void dragBy(const QPointF &by)
QPointF getRotationSnapPoint(const QPointF &scenePos)
void setRotation(int rotation)
Sets the rotation in degrees.
ArenaElement * addElement(const QString &elementType)
Creates and adds an element of type elementType.
void setPos(QPoint pos)
Sets the position in arena coordinates.
int getSnapRotation(const QPointF &scenePos)
static QPointF sceneToGridF(QPointF scenePos)
static QPointF nearestGridPoint(QPointF scenePos)
ArenaController(Arena *arena, ArenaScene *scene)
void startInsertion(const QString &elementType, const QPointF &pos)
QPointF m_totalMouseOffset
QList< ArenaSceneElement * > m_activeElements
SceneElement currently being manipulated through this controller.
ArenaSceneElement * sceneElementFor(ArenaElement *element)
bool isWall() const
Convenience method returning true iff. this is a wall element.
bool m_lastDragFinished
True iff. endDrag() has been called after last startDrag()
void startDrag(ArenaSceneElement *sceneElement)
void setAutoRotateWalls(bool autoRotate)