NCL Composer  0.1.5
 All Classes Functions Variables Pages
qnlygraphicsregion.h
1 /*
2  * Copyright 2011 TeleMidia/PUC-Rio.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library. If not, see
16  * <http://www.gnu.org/licenses/>.
17  */
18 #ifndef QNLYGRAPHICSREGION_H
19 #define QNLYGRAPHICSREGION_H
20 
21 #include <QGraphicsItem>
22 #include <QWidget>
23 #include <QObject>
24 #include <QPainterPath>
25 #include <QSizeF>
26 #include <QActionGroup>
27 #include <QAction>
28 #include <QMenu>
29 #include <QGraphicsSceneContextMenuEvent>
30 #include <QRectF>
31 #include <QPointF>
32 #include <QGraphicsScene>
33 #include <QPainter>
34 #include <QStyleOptionGraphicsItem>
35 #include <QLineEdit>
36 #include <QTextDocument>
37 #include <QKeyEvent>
38 #include <QGraphicsSceneMouseEvent>
39 
40 #include "qnlygraphicsregionbase.h"
41 
43 
44 #define ROUND_DOUBLE(x) x<0.0?x=0.0:(x>100.0?x=0.0:x)
45 
46 class QnlyGraphicsRegion : public QObject, public QGraphicsItem
47 {
48  Q_OBJECT
49  Q_INTERFACES(QGraphicsItem)
50 
51 public:
52  QnlyGraphicsRegion(QMenu* switchMenu, QnlyGraphicsRegion* parent = 0);
53 
54  virtual ~QnlyGraphicsRegion();
55 
56  enum QnlyResizeType {
57  Top,
58  TopRight,
59  Right,
60  BottomRight,
61  Bottom,
62  BottomLeft,
63  Left,
64  TopLeft,
65  };
66 
67  bool isMoving() const;
68 
69  void setMoving(bool moving);
70 
71  bool isResizing() const;
72 
73  void setParent(QnlyGraphicsRegion* region);
74 
75  void setResizing(bool resizing);
76 
77  bool isSelected() const;
78 
79  void setSelected(bool selected);
80 
81  bool isPainted() const;
82 
83  void setPainted(bool painted);
84 
85  bool hasChanged() const;
86 
87  void setChanged(bool changed);
88 
89  bool isValidated() const;
90 
91  void setValidated(bool validated);
92 
93  QString getId() const;
94 
95  void setId(const QString &id);
96 
97  QString getUid() const;
98 
99  void setUid(const QString &uid);
100 
101  QString getTitle() const;
102 
103  void setTitle(const QString &title);
104 
105  QString getColor() const;
106 
107  void setColor(const QString &color);
108 
109  int getzIndex() const;
110 
111  void setzIndex(int zindex);
112 
113  qreal getzIndexTop() const;
114 
115  qreal getTop() const;
116 
117  qreal getMoveTop() const;
118 
119  qreal getPressTop() const;
120 
121  qreal getResizeTop() const;
122 
123  qreal getRelativeTop() const;
124 
125  void setRelativeTop(qreal relativeTop);
126 
127  qreal getLeft() const;
128 
129  qreal getMoveLeft() const;
130 
131  qreal getPressLeft() const;
132 
133  qreal getResizeLeft() const;
134 
135  qreal getRelativeLeft() const;
136 
137  void setRelativeLeft(qreal relativeLeft);
138 
139  qreal getRight() const;
140 
141  qreal getRelativeRight() const;
142 
143  void setRelativeRight(qreal relativeRight);
144 
145  qreal getBottom() const;
146 
147  qreal getRelativeBottom() const;
148 
149  void setRelativeBottom(qreal relativeBottom);
150 
151  qreal getWidth() const;
152 
153  qreal getPressWidth() const;
154 
155  qreal getResizeWidth() const;
156 
157  qreal getRelativeWidth() const;
158 
159  void setRelativeWidth(qreal relativeWidth);
160 
161  qreal getHeight() const;
162 
163  qreal getPressHeight() const;
164 
165  qreal getResizeHeight() const;
166 
167  qreal getRelativeHeight() const;
168 
169  void setRelativeHeight(qreal relativeHeight);
170 
171  QnlyResizeType getResizeType() const;
172 
173  void adjust(bool repaint = true);
174 
175  void addRegion(QnlyGraphicsRegion* region);
176 
177  void removeRegion(QnlyGraphicsRegion* region);
178 
179  void hideRegion(QnlyGraphicsRegion* region);
180 
181  void updateActionText(QnlyGraphicsRegion *region);
182 
183  void updateCursor(QGraphicsSceneMouseEvent* event);
184 
185  void setGridAction(QAction* action);
186 
187 signals:
188  void regionAdditionRequested(QnlyGraphicsRegion* parent);
189 
190  void regionSelectionRequested(QnlyGraphicsRegion* region);
191 
192  void regionDeletionRequested(QnlyGraphicsRegion* region);
193 
194  void regionChangeRequested(QnlyGraphicsRegion* region,
195  QMap<QString, QString> attributes);
196 
197  void dragMediaOverRegion(QString mediaid, QnlyGraphicsRegion *region);
198 
199  void regionbasePerformed();
200 
201 protected:
202  void setTop(qreal top);
203 
204  void setMoveTop(qreal moveTop);
205 
206  void setPressTop(qreal pressTop);
207 
208  void setResizeTop(qreal resizeTop);
209 
210  void setLeft(qreal left);
211 
212  void setMoveLeft(qreal moveLeft);
213 
214  void setPressLeft(qreal pressLeft);
215 
216  void setResizeLeft(qreal resizeLeft);
217 
218  void setRight(qreal right);
219 
220  void setBottom(qreal bottom);
221 
222  void setWidth(qreal width);
223 
224  void setPressWidth(qreal pressWidth);
225 
226  void setResizeWidth(qreal resizeWidth);
227 
228  void setHeight(qreal height);
229 
230  void setPressHeight(qreal pressHeight);
231 
232  void setResizeHeight(qreal resizeHeight);
233 
234  void setzIndexTop(qreal zindexTop);
235 
236  void setResizeType(const QnlyResizeType &resizeType);
237 
238  virtual void move(QGraphicsSceneMouseEvent* event);
239 
240  virtual void resize(QGraphicsSceneMouseEvent* event);
241 
242  virtual QPainterPath shape() const;
243 
244  virtual QRectF boundingRect() const;
245 
246  virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
247 
248  virtual void mouseMoveEvent(QGraphicsSceneMouseEvent* event);
249 
250  virtual void mousePressEvent(QGraphicsSceneMouseEvent* event);
251 
252  virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent* event);
253 
254  virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent* event);
255 
256  void keyReleaseEvent(QKeyEvent * event);
257 
258  void keyPressEvent(QKeyEvent * event);
259 
260  void dragEnterEvent(QGraphicsSceneDragDropEvent *event);
261 
262  void dropEvent(QGraphicsSceneDragDropEvent *event);
263 
264 protected slots:
265  void performShow(QAction* action);
266 
267  void performRegion();
268 
269  void performHide();
270 
271  void performDelete();
272 
273  void performExport();
274 
275 private:
276  void createActions();
277 
278  void createMenus();
279 
280  void createConnections();
281 
282  bool moving;
283 
284  bool resizing;
285 
286  bool selected;
287 
288  bool validated;
289 
290  bool painted;
291 
292  bool changed;
293 
294  qreal top;
295 
296  qreal moveTop;
297 
298  qreal pressTop;
299 
300  qreal resizeTop;
301 
302  qreal relativeTop;
303 
304  qreal left;
305 
306  qreal moveLeft;
307 
308  qreal pressLeft;
309 
310  qreal resizeLeft;
311 
312  qreal relativeLeft;
313 
314  qreal right;
315 
316  qreal relativeRight;
317 
318  qreal bottom;
319 
320  qreal relativeBottom;
321 
322  qreal width;
323 
324  qreal pressWidth;
325 
326  qreal resizeWidth;
327 
328  qreal relativeWidth;
329 
330  qreal height;
331 
332  qreal pressHeight;
333 
334  qreal resizeHeight;
335 
336  qreal relativeHeight;
337 
338  qreal zindex;
339 
340  qreal zindexTop;
341 
342  QMenu* viewMenu;
343 
344  QMenu* insertMenu;
345 
346  QMenu* showMenu;
347 
348  QMenu* arrangeMenu;
349 
350  QMenu* switchMenu;
351 
352  QMenu* contextMenu;
353 
354  QAction* helpAction;
355 
356  QAction* undoAction;
357 
358  QAction* redoAction;
359 
360  QAction* cutAction;
361 
362  QAction* copyAction;
363 
364  QAction* pasteAction;
365 
366  QAction* deleteAction;
367 
368  QAction* zoominAction;
369 
370  QAction* zoomoutAction;
371 
372  QAction* zoomresetAction;
373 
374  QAction* hideAction;
375 
376  QAction* fullscreenAction;
377 
378  QAction* exportAction;
379 
380  QAction* regionAction;
381 
382  QAction* regionbaseAction;
383 
384  QAction* bringfrontAction;
385 
386  QAction* bringforwardAction;
387 
388  QAction* sendbackwardAction;
389 
390  QAction* sendbackAction;
391 
392  QAction* propertiesAction;
393 
394  QAction* gridAction;
395 
396  QString id;
397 
398  QString uid;
399 
400  QString title;
401 
402  QString color;
403 
404  QnlyResizeType resizeType;
405 
406  QActionGroup* regionActionGroup;
407 
408  QMap<QString, QAction*> regionActions;
409 
410  QMap<QString, QnlyGraphicsRegion*> regions;
411 };
412 
413 #endif // QNLYGRAPHICSREGION_H