1 |
|
2 |
|
3 #ifndef OBJECTCHARM_H_ |
|
4 #define OBJECTCHARM_H_ |
|
5 |
|
6 #include <QObject> |
|
7 |
|
8 class QGraphicsObject; |
|
9 class QGraphicsScene; |
|
10 class QGraphicsItem; |
|
11 |
|
12 namespace GVA { |
|
13 |
|
14 // ------------------------------- |
|
15 |
|
16 /*! |
|
17 * Base class for object "charms". Charms set an event filter on a particular |
|
18 * object and perform some action in response to the events sent to the object. |
|
19 * ObjectCharms automatically destroy themselves when the target object is |
|
20 * destroyed. |
|
21 */ |
|
22 class ObjectCharm : public QObject { |
|
23 Q_OBJECT |
|
24 public: |
|
25 ObjectCharm(QObject *object); |
|
26 |
|
27 private slots: |
|
28 virtual void onObjectDestroyed(); |
|
29 |
|
30 protected: |
|
31 QObject *m_object; |
|
32 }; |
|
33 |
|
34 // ------------------------------- |
|
35 |
|
36 /*! |
|
37 * This class emits a signal when the user clicks outside of the given graphics object. |
|
38 */ |
|
39 class ExternalEventCharm : public ObjectCharm { |
|
40 Q_OBJECT |
|
41 public: |
|
42 ExternalEventCharm(QGraphicsObject *object); |
|
43 |
|
44 signals: |
|
45 /*! This signal is emitted when the user clicks outside of the object. |
|
46 * \param type The Qt event type. |
|
47 * \param name The Qt event name. |
|
48 * \param description The Qt event description. |
|
49 */ |
|
50 void externalMouseEvent( |
|
51 int type, |
|
52 const QString & name, |
|
53 const QString & description); |
|
54 private: |
|
55 void checkForExternalEvent(QObject * o, QEvent * e); |
|
56 void emitExternalEvent(QEvent * e); |
|
57 bool eventFilter(QObject *object, QEvent *event); |
|
58 QGraphicsScene *scene(); |
|
59 }; |
|
60 |
|
61 // ------------------------------- |
|
62 |
|
63 /*! |
|
64 * This class draws a circle in response to mouse click events on the given object. Intended |
|
65 * for testing purposes only. |
|
66 */ |
|
67 class TouchCircleCharm : public ObjectCharm { |
|
68 Q_OBJECT |
|
69 public: |
|
70 TouchCircleCharm(QObject *object, QGraphicsItem *parent = 0); |
|
71 ~TouchCircleCharm(); |
|
72 |
|
73 private slots: |
|
74 void onTimer(); |
|
75 |
|
76 private: |
|
77 bool eventFilter(QObject *object, QEvent *event); |
|
78 |
|
79 class QGraphicsEllipseItem * m_item; |
|
80 class QTimer * m_timer; |
|
81 }; |
|
82 |
|
83 } |
|
84 |
|
85 #endif /* OBJECTCHARM_H_ */ |
|