| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 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 |
|
| 37 |
|
| 38 |
enum class ReferenceFrame |
| 39 |
{ |
| 40 |
GLOBAL, |
| 41 |
PARENT, |
| 42 |
LOCAL |
| 43 |
|
| 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 |