arenasceneelement.cpp
Go to the documentation of this file.
1 #include "arenasceneelement.h"
2 
3 #include "../model/arenaelement.h"
4 #include "../model/arenaelementtype.h"
5 
6 #include "arenascene.h"
7 
8 #include <QDebug>
9 #include <QMimeData>
10 #include <QDrag>
11 #include <QPixmap>
12 #include <QCursor>
13 #include <QGraphicsSceneMouseEvent>
14 #include <QPainter>
15 #include <QStyleOptionGraphicsItem>
16 
18  : m_element(element)
19 {
20  setPixmap(element->type()->pixmap());
21  m_isEditorSample = false;
22  setFlag(QGraphicsItem::ItemIsMovable, true);
23  setFlag(QGraphicsItem::ItemIsSelectable, true);
24 
25  connect(element, SIGNAL(posChanged(ArenaElement*, QPoint)),
26  SLOT(slotPosChanged(ArenaElement*, QPoint)));
27  connect(element, SIGNAL(rotationChanged(ArenaElement*, int)),
28  SLOT(slotRotationChanged(ArenaElement*, int)));
29 
30  //setTransformOriginPoint(pixmap().width() / 2.0, pixmap().width() / 2.0);
31 
32 #if 0
33  switch (element->type()->type())
34  {
36  //setTransformOriginPoint(-42.5, 12.5);
37  break;
41  setTransformOriginPoint(pixmap().width() / 2.0, pixmap().width() / 2.0);
42  break;
43  }
44 #endif
45 
46  slotPosChanged(element, element->pos());
47  slotRotationChanged(element, element->rotation());
48 }
49 
51 {
53  setOffset(gridOffset());
54 }
55 
57 {
58  if (m_isEditorSample)
59  return QPointF(0, 0);
60 
61  // Offset of the pixmap before the rotation is performed!
62  QPointF offset(-pixmap().width() / 2.0, -pixmap().height() / 2.0);
63 
64  switch(m_element->type()->type())
65  {
67  offset += QPointF(0, -CELL_SIZE / 2);
68  break;
72  break;
73  }
74 
75  return offset;
76 }
77 
79 {
80  setOffset(gridOffset());
81  setRotation(rotation);
82 }
83 
84 void ArenaSceneElement::mousePressEvent(QGraphicsSceneMouseEvent *event)
85 {
86  if (m_isEditorSample)
87  {
88  QMimeData *data = new QMimeData;
89  data->setData("type", m_element->type()->name().toLatin1());
90  data->setData("rotation", QString::number(m_element->rotation()).toLatin1());
91  QDrag *drag = new QDrag(event->widget());
92  drag->setMimeData(data);
93  drag->start();
94 
95  setCursor(Qt::OpenHandCursor);
96  }
97 
98  // Z value 1 is used to put the item being moved on top
99  setZValue(1);
100  event->accept();
101  QGraphicsPixmapItem::mousePressEvent(event);
102 }
103 
105 {
106  Q_ASSERT(element == m_element);
107 
108  QPointF newPos = ArenaScene::gridToScene(pos + element->itemOffset());
109  setPos(newPos);
110 }
Item freely movable within a grid point.
Type type() const
ArenaElementType const * type() const
Definition: arenaelement.h:43
void slotRotationChanged(ArenaElement *element, int rotation)
QPixmap pixmap() const
void mousePressEvent(QGraphicsSceneMouseEvent *event)
void setIsEditorSample(bool isEditorSample)
ArenaElement * element() const
ArenaSceneElement(ArenaElement *element)
QPointF itemOffset() const
Returns the item&#39;s offset from the grid point with 0 <= x,y <= 1 ( (0,0) is bottom left) ...
Definition: arenaelement.h:55
const int CELL_SIZE
Definition: arenascene.h:15
int rotation() const
Returns the rotation in degrees.
Definition: arenaelement.h:26
void slotPosChanged(ArenaElement *element, QPoint pos)
QPoint pos() const
Returns the position in arena coordinates.
Definition: arenaelement.h:22
ArenaElement * m_element
static QPointF gridToScene(QPointF gridPos)
Definition: arenascene.cpp:50
Item that can be mounted to a wall element.
QString name() const


hector_nist_arena_designer
Author(s): Stefan Kohlbrecher , Johannes Simon
autogenerated on Fri Aug 21 2020 10:45:27