1 | // Copyright (C) 2016 The Qt Company Ltd. |
---|---|
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #ifndef QQUICKRECTANGLE_P_H |
5 | #define QQUICKRECTANGLE_P_H |
6 | |
7 | // |
8 | // W A R N I N G |
9 | // ------------- |
10 | // |
11 | // This file is not part of the Qt API. It exists purely as an |
12 | // implementation detail. This header file may change from version to |
13 | // version without notice, or even be removed. |
14 | // |
15 | // We mean it. |
16 | // |
17 | |
18 | #include "qquickitem.h" |
19 | |
20 | #include <QtGui/qbrush.h> |
21 | |
22 | #include <private/qtquickglobal_p.h> |
23 | |
24 | QT_BEGIN_NAMESPACE |
25 | |
26 | class Q_QUICK_PRIVATE_EXPORT QQuickPen : public QObject |
27 | { |
28 | Q_OBJECT |
29 | |
30 | Q_PROPERTY(qreal width READ width WRITE setWidth NOTIFY widthChanged FINAL) |
31 | Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged FINAL) |
32 | Q_PROPERTY(bool pixelAligned READ pixelAligned WRITE setPixelAligned NOTIFY pixelAlignedChanged FINAL) |
33 | QML_ANONYMOUS |
34 | QML_ADDED_IN_VERSION(2, 0) |
35 | public: |
36 | QQuickPen(QObject *parent=nullptr); |
37 | |
38 | qreal width() const; |
39 | void setWidth(qreal w); |
40 | |
41 | QColor color() const; |
42 | void setColor(const QColor &c); |
43 | |
44 | bool pixelAligned() const; |
45 | void setPixelAligned(bool aligned); |
46 | |
47 | bool isValid() const; |
48 | |
49 | Q_SIGNALS: |
50 | void widthChanged(); |
51 | void colorChanged(); |
52 | void pixelAlignedChanged(); |
53 | |
54 | private: |
55 | qreal m_width; |
56 | QColor m_color; |
57 | bool m_aligned : 1; |
58 | bool m_valid : 1; |
59 | }; |
60 | |
61 | class Q_QUICK_PRIVATE_EXPORT QQuickGradientStop : public QObject |
62 | { |
63 | Q_OBJECT |
64 | |
65 | Q_PROPERTY(qreal position READ position WRITE setPosition FINAL) |
66 | Q_PROPERTY(QColor color READ color WRITE setColor FINAL) |
67 | QML_NAMED_ELEMENT(GradientStop) |
68 | QML_ADDED_IN_VERSION(2, 0) |
69 | |
70 | public: |
71 | QQuickGradientStop(QObject *parent=nullptr); |
72 | |
73 | qreal position() const; |
74 | void setPosition(qreal position); |
75 | |
76 | QColor color() const; |
77 | void setColor(const QColor &color); |
78 | |
79 | private: |
80 | void updateGradient(); |
81 | |
82 | private: |
83 | qreal m_position; |
84 | QColor m_color; |
85 | }; |
86 | |
87 | class Q_QUICK_PRIVATE_EXPORT QQuickGradient : public QObject |
88 | { |
89 | Q_OBJECT |
90 | |
91 | Q_PROPERTY(QQmlListProperty<QQuickGradientStop> stops READ stops FINAL) |
92 | Q_PROPERTY(Orientation orientation READ orientation WRITE setOrientation NOTIFY orientationChanged REVISION(2, 12) FINAL) |
93 | Q_CLASSINFO("DefaultProperty", "stops") |
94 | QML_NAMED_ELEMENT(Gradient) |
95 | QML_ADDED_IN_VERSION(2, 0) |
96 | QML_EXTENDED_NAMESPACE(QGradient) |
97 | |
98 | public: |
99 | QQuickGradient(QObject *parent=nullptr); |
100 | ~QQuickGradient() override; |
101 | |
102 | enum Orientation { Vertical = Qt::Vertical, |
103 | Horizontal = Qt::Horizontal }; |
104 | Q_ENUM(Orientation) |
105 | |
106 | QQmlListProperty<QQuickGradientStop> stops(); |
107 | |
108 | Orientation orientation() const { return m_orientation; } |
109 | void setOrientation(Orientation orientation); |
110 | |
111 | QGradientStops gradientStops() const; |
112 | |
113 | Q_SIGNALS: |
114 | void updated(); |
115 | void orientationChanged(); |
116 | |
117 | private: |
118 | void doUpdate(); |
119 | |
120 | private: |
121 | QList<QQuickGradientStop *> m_stops; |
122 | Orientation m_orientation = Vertical; |
123 | friend class QQuickRectangle; |
124 | friend class QQuickGradientStop; |
125 | }; |
126 | |
127 | class QQuickRectanglePrivate; |
128 | class Q_QUICK_PRIVATE_EXPORT QQuickRectangle : public QQuickItem |
129 | { |
130 | Q_OBJECT |
131 | |
132 | Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) |
133 | Q_PROPERTY(QJSValue gradient READ gradient WRITE setGradient RESET resetGradient FINAL) |
134 | Q_PROPERTY(QQuickPen * border READ border CONSTANT FINAL) |
135 | Q_PROPERTY(qreal radius READ radius WRITE setRadius NOTIFY radiusChanged FINAL) |
136 | QML_NAMED_ELEMENT(Rectangle) |
137 | QML_ADDED_IN_VERSION(2, 0) |
138 | public: |
139 | QQuickRectangle(QQuickItem *parent=nullptr); |
140 | |
141 | QColor color() const; |
142 | void setColor(const QColor &); |
143 | |
144 | QQuickPen *border(); |
145 | |
146 | QJSValue gradient() const; |
147 | void setGradient(const QJSValue &gradient); |
148 | void resetGradient(); |
149 | |
150 | qreal radius() const; |
151 | void setRadius(qreal radius); |
152 | |
153 | Q_SIGNALS: |
154 | void colorChanged(); |
155 | void radiusChanged(); |
156 | |
157 | protected: |
158 | QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *) override; |
159 | |
160 | private Q_SLOTS: |
161 | void doUpdate(); |
162 | |
163 | private: |
164 | Q_DISABLE_COPY(QQuickRectangle) |
165 | Q_DECLARE_PRIVATE(QQuickRectangle) |
166 | }; |
167 | |
168 | QT_END_NAMESPACE |
169 | |
170 | QML_DECLARE_TYPE(QQuickPen) |
171 | QML_DECLARE_TYPE(QQuickGradientStop) |
172 | QML_DECLARE_TYPE(QQuickGradient) |
173 | QML_DECLARE_TYPE(QQuickRectangle) |
174 | |
175 | #endif // QQUICKRECTANGLE_P_H |
176 |