Debian Codegraph @

utils/fgqcanvas/fgcanvaselement.h

raw symbols SCIP
1 //
2 // Copyright (C) 2017 James Turner [email protected]
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License as
6 // published by the Free Software Foundation; either version 2 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful, but
10 // WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
18 #ifndef FGCANVASELEMENT_H
19 #define FGCANVASELEMENT_H
20
21 #include <QObject>
22 #include <QTransform>
23 #include <QColor>
24 #include <QVariant>
25
26 #include <vector>
27
28 class LocalProp;
29 class FGCanvasPaintContext;
30 class FGCanvasGroup;
31 class CanvasItem;
32 class QQuickItem;
33 class CanvasConnection;
34
35 /**
36 * Coordinate reference frame (eg. "clip" property)
37 */
38 enum class ReferenceFrame
39 {
40 GLOBAL, ///< Global coordinates
41 PARENT, ///< Coordinates relative to parent coordinate frame
42 LOCAL ///< Coordinates relative to local coordinates (parent
43 /// coordinates with local transformations applied)
44 };
45
46 class FGCanvasElement : public QObject
47 {
48 Q_OBJECT
49 public:
50 explicit FGCanvasElement(FGCanvasGroup* pr, LocalProp* prop);
51
52 void paint(FGCanvasPaintContext* context) const;
53
54 QTransform combinedTransform() const;
55
56 bool isVisible() const;
57
58 int zIndex() const;
59
60 const FGCanvasGroup* parentGroup() const;
61
62 const FGCanvasGroup* rootGroup() const;
63
64 CanvasConnection* connection() const;
65
66 static bool isStyleProperty(QByteArray name);
67
68 LocalProp* property() const;
69
70 void setHighlighted(bool hilighted);
71 bool isHighlighted() const;
72
73 virtual CanvasItem* quickItem() const;
74
75 virtual CanvasItem* createQuickItem(QQuickItem* parent);
76
77 void requestPolish();
78
79 void polish();
80
81 virtual void dumpElement() = 0;
82 protected:
83
84 virtual void doPaint(FGCanvasPaintContext* context) const;
85 virtual void doPolish();
86
87 virtual bool onChildAdded(LocalProp* prop);
88 virtual bool onChildRemoved(LocalProp* prop);
89
90 virtual void doDestroy();
91
92 const LocalProp* _propertyRoot;
93 const FGCanvasGroup* _parent;
94
95 QColor fillColor() const;
96
97 QColor parseColorValue(QVariant value) const;
98
99 virtual void markStyleDirty();
100
101 QVariant getCascadedStyle(const char* name, QVariant defaultValue = QVariant()) const;
102
103 private slots:
104 void onPropDestroyed();
105
106 private:
107
108 void onCenterChanged(QVariant value);
109
110 void markTransformsDirty();
111
112 void markZIndexDirty(QVariant value);
113
114 void onVisibleChanged(QVariant value);
115
116 void markClipDirty();
117 void markSVGIDDirty(QVariant value);
118
119 private:
120 friend class FGCanvasGroup;
121
122 bool _polishRequired = false;
123 bool _visible = true;
124 bool _highlighted = false;
125
126 mutable bool _transformsDirty = true;
127 mutable bool _styleDirty = true;
128
129 mutable QTransform _combinedTransform;
130
131 QPointF _center;
132
133 mutable QColor _fillColor;
134 int _zIndex = 0;
135 QByteArray _svgElementId;
136
137 mutable bool _clipDirty = true;
138 mutable bool _hasClip = false;
139 mutable QRectF _clipRect;
140 mutable ReferenceFrame _clipFrame = ReferenceFrame::GLOBAL;
141
142 void parseCSSClip(QByteArray value);
143 double parseCSSValue(QByteArray value) const;
144 };
145
146 using FGCanvasElementVec = std::vector<FGCanvasElement*>;
147
148 #endif // FGCANVASELEMENT_H