NCL Composer  0.1.5
 All Classes Functions Variables Pages
qncggraphicsentity.h
1 #ifndef QNCGGRAPHICSENTITY_H
2 #define QNCGGRAPHICSENTITY_H
3 
4 #include <QGraphicsItem>
5 #include <QGraphicsScene>
6 #include <QPainter>
7 #include <QPainterPath>
8 #include <QGraphicsSceneMouseEvent>
9 #include <QGraphicsSceneHoverEvent>
10 #include <QObject>
11 #include <QCursor>
12 
13 #include <QDebug>
14 
15 #include "qncg.h"
16 
17 typedef Qncg::EntityType QncgEntityType;
18 typedef Qncg::ResizeType QncgResizeType;
19 
20 class QncgGraphicsEntity :public QObject, public QGraphicsItem
21 {
22  Q_OBJECT
23 
24 public:
26 
27  virtual ~QncgGraphicsEntity();
28 
29  void setMoveable(bool moveable);
30 
31  bool isMoveable() const;
32 
33  void setSelectable(bool selected);
34 
35  bool isSelectable() const;
36 
37  void setResizable(bool resizable);
38 
39  bool isResizable() const;
40 
41  void setMoving(bool moving);
42 
43  bool isMoving() const;
44 
45  void setResizing(bool resizing);
46 
47  bool isResizing() const;
48 
49  void setSelected(bool selected);
50 
51  bool isSelected() const;
52 
53  qreal getTop() const;
54 
55  void setTop(qreal top);
56 
57  qreal getMoveTop() const;
58 
59  void setMoveTop(qreal moveTop);
60 
61  qreal getPressTop() const;
62 
63  void setPressTop(qreal pressTop);
64 
65  qreal getResizeTop() const;
66 
67  void setResizeTop(qreal resizeTop);
68 
69  qreal getLeft() const;
70 
71  void setLeft(qreal left);
72 
73  qreal getMoveLeft() const;
74 
75  void setMoveLeft(qreal moveLeft);
76 
77  qreal getPressLeft() const;
78 
79  void setPressLeft(qreal pressLeft);
80 
81  qreal getResizeLeft() const;
82 
83  void setResizeLeft(qreal resizeLeft);
84 
85  qreal getWidth() const;
86 
87  void setWidth(qreal width);
88 
89  qreal getPressWidth() const;
90 
91  void setPressWidth(qreal pressWidth);
92 
93  qreal getResizeWidth() const;
94 
95  void setResizeWidth(qreal resizeWidth);
96 
97  qreal getHeight() const;
98 
99  void setHeight(qreal height);
100 
101  qreal getPressHeight() const;
102 
103  void setPressHeight(qreal pressHeight);
104 
105  qreal getResizeHeight() const;
106 
107  void setResizeHeight(qreal resizeHeight);
108 
109  int getzIndex() const;
110 
111  void setzIndex(int zindex);
112 
113  QncgResizeType getncgResize() const;
114 
115  void setncgResize(QncgResizeType resizeType);
116 
117  QncgEntityType getncgType() const;
118 
119  void setncgType(QncgEntityType entityType);
120 
121  QncgGraphicsEntity* getncgGraphicsParent() const;
122 
123  void setncgGraphicsParent(QncgGraphicsEntity* parent);
124 
125  QVector<QncgGraphicsEntity*> getncgGraphicsEntities();
126 
127  void addncgGraphicsEntity(QncgGraphicsEntity* entity);
128 
129  void removencgGraphicsEntity(QncgGraphicsEntity* entity);
130 
131  virtual void adjust(bool avoidCollision = false) = 0;
132 
133 signals:
134  void entityAboutToChange(QMap<QString, QString> properties);
135 
136  void entityChanged();
137 
138  void entitySelected();
139 
140 protected:
141  virtual void draw(QPainter* painter) = 0;
142 
143  virtual void delineate(QPainterPath* painter) const = 0;
144 
145  virtual void move(QGraphicsSceneMouseEvent* event) = 0;
146 
147  virtual void resize(QGraphicsSceneMouseEvent* event) = 0;
148 
149  virtual QPainterPath shape() const;
150 
151  virtual QRectF boundingRect() const;
152 
153  virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
154 
155  virtual void mouseMoveEvent(QGraphicsSceneMouseEvent* event);
156 
157  virtual void mousePressEvent(QGraphicsSceneMouseEvent* event);
158 
159  virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent*event);
160 
161  virtual void hoverMoveEvent(QGraphicsSceneHoverEvent* event);
162 
163 private:
164  bool moveable;
165 
166  bool selectable;
167 
168  bool resizable;
169 
170  bool moving;
171 
172  bool resizing;
173 
174  bool selected;
175 
176  qreal top;
177 
178  qreal moveTop;
179 
180  qreal pressTop;
181 
182  qreal resizeTop;
183 
184  qreal left;
185 
186  qreal moveLeft;
187 
188  qreal pressLeft;
189 
190  qreal resizeLeft;
191 
192  qreal width;
193 
194  qreal pressWidth;
195 
196  qreal resizeWidth;
197 
198  qreal height;
199 
200  qreal pressHeight;
201 
202  qreal resizeHeight;
203 
204  int zindex;
205 
206  QncgEntityType entityType;
207 
208  QncgResizeType resizeType;
209 
210  QncgGraphicsEntity* parent;
211 
212  QVector<QncgGraphicsEntity*> entities;
213 };
214 
215 #endif // QNCGGRAPHICSENTITY_H