Schim
gtext.h
Go to the documentation of this file.
1 #ifndef GTEXT_H
3 #define GTEXT_H
4 
5 #include "gobject.h"
6 
7 #include "model/text.h"
8 
9 class GDisplayText;
10 
24 class GText : public GObject
25 {
26  Q_OBJECT
27 public:
28  explicit GText(Text *obj = new Text);
29  ~GText();
30 
31  // GETTERS
32  Text *get() override;
33  const Text *get() const override;
34  bool isInEditMode() const;
35 
36  // OBJECT EDITING
37  void setEditMode(bool edit);
38  void reloadFromModel() override;
39  void applyToModel() override;
40 
41 signals:
42  void focusOut();
43 
44 protected:
45  // EVENTS
46  QVariant itemChange(GraphicsItemChange change, const QVariant &value) override;
51  void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) override;
53  void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override;
55  void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override;
56  void timerEvent(QTimerEvent *event) override;
57  void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override;
58 
59 private slots:
60  void onContextEdit();
61  void onFocusOut();
62 
63 private:
64  // OVERRIDE QGraphicsItem
65  QPainterPath shape() const override;
66  QRectF boundingRect() const override;
67  void paint(QPainter*, const QStyleOptionGraphicsItem*, QWidget*) override;
68 
69  // ATTRIBUTES
70  GDisplayText *displayItem;
71 };
72 
76 class GDisplayText : public QGraphicsTextItem
77 {
78  Q_OBJECT
79 protected:
80  // EVENTS
81  void focusOutEvent(QFocusEvent *event) override;
82  void keyPressEvent(QKeyEvent *event) override;
83 
84 signals:
90  void focusOut();
91 
92 public:
93  // OVERRIDE QGraphicsItem
94  void setParentItem(GText *parent);
95  GText *parentItem();
96 protected:
97  void paint(QPainter*, const QStyleOptionGraphicsItem*, QWidget*) override;
98 
99 private:
100  friend class GText;
101 };
102 
103 #endif // GTEXT_H
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) override
GCompositeObject * parentItem() const
Return the parent item cast to a GObject*.
A helper item for GText that displays its textual content.
Definition: gtext.h:76
A graphical text object that wraps a Text.
Definition: gtext.h:24
Object * obj
The object that is being wrapped.
Definition: gobject.h:177
The base class of all objects represented in a graphical scene.
Definition: gobject.h:24
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override
void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override
void reloadFromModel() override
Update the graphical representation to match the object from the model.
void applyToModel() override
Apply changes to the underlying model object.
A visual text object.
Definition: text.h:17