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 QQUICKSHAPE_P_H
5#define QQUICKSHAPE_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 <QtQuickShapes/private/qquickshapesglobal_p.h>
19#include <QtQuick/qquickitem.h>
20
21#include <private/qtquickglobal_p.h>
22#include <private/qquickpath_p_p.h>
23#include <private/qquickrectangle_p.h>
24
25QT_BEGIN_NAMESPACE
26
27class QQuickShapePathPrivate;
28class QQuickShapePrivate;
29
30void Q_QUICKSHAPES_PRIVATE_EXPORT QQuickShapes_initializeModule();
31
32class Q_QUICKSHAPES_PRIVATE_EXPORT QQuickShapesModule
33{
34public:
35 static void defineModule();
36};
37
38class Q_QUICKSHAPES_PRIVATE_EXPORT QQuickShapeGradient : public QQuickGradient
39{
40 Q_OBJECT
41 Q_PROPERTY(SpreadMode spread READ spread WRITE setSpread NOTIFY spreadChanged FINAL)
42 Q_CLASSINFO("DefaultProperty", "stops")
43
44 QML_NAMED_ELEMENT(ShapeGradient)
45 QML_ADDED_IN_VERSION(1, 0)
46 QML_UNCREATABLE("ShapeGradient is an abstract base class.");
47
48public:
49 enum SpreadMode {
50 PadSpread,
51 ReflectSpread,
52 RepeatSpread
53 };
54 Q_ENUM(SpreadMode)
55
56 QQuickShapeGradient(QObject *parent = nullptr);
57
58 SpreadMode spread() const;
59 void setSpread(SpreadMode mode);
60
61Q_SIGNALS:
62 void spreadChanged();
63
64private:
65 SpreadMode m_spread;
66};
67
68class Q_QUICKSHAPES_PRIVATE_EXPORT QQuickShapeLinearGradient : public QQuickShapeGradient
69{
70 Q_OBJECT
71 Q_PROPERTY(qreal x1 READ x1 WRITE setX1 NOTIFY x1Changed FINAL)
72 Q_PROPERTY(qreal y1 READ y1 WRITE setY1 NOTIFY y1Changed FINAL)
73 Q_PROPERTY(qreal x2 READ x2 WRITE setX2 NOTIFY x2Changed FINAL)
74 Q_PROPERTY(qreal y2 READ y2 WRITE setY2 NOTIFY y2Changed FINAL)
75 Q_CLASSINFO("DefaultProperty", "stops")
76 QML_NAMED_ELEMENT(LinearGradient)
77 QML_ADDED_IN_VERSION(1, 0)
78
79public:
80 QQuickShapeLinearGradient(QObject *parent = nullptr);
81
82 qreal x1() const;
83 void setX1(qreal v);
84 qreal y1() const;
85 void setY1(qreal v);
86 qreal x2() const;
87 void setX2(qreal v);
88 qreal y2() const;
89 void setY2(qreal v);
90
91Q_SIGNALS:
92 void x1Changed();
93 void y1Changed();
94 void x2Changed();
95 void y2Changed();
96
97private:
98 QPointF m_start;
99 QPointF m_end;
100};
101
102class Q_QUICKSHAPES_PRIVATE_EXPORT QQuickShapeRadialGradient : public QQuickShapeGradient
103{
104 Q_OBJECT
105 Q_PROPERTY(qreal centerX READ centerX WRITE setCenterX NOTIFY centerXChanged FINAL)
106 Q_PROPERTY(qreal centerY READ centerY WRITE setCenterY NOTIFY centerYChanged FINAL)
107 Q_PROPERTY(qreal centerRadius READ centerRadius WRITE setCenterRadius NOTIFY centerRadiusChanged FINAL)
108 Q_PROPERTY(qreal focalX READ focalX WRITE setFocalX NOTIFY focalXChanged FINAL)
109 Q_PROPERTY(qreal focalY READ focalY WRITE setFocalY NOTIFY focalYChanged FINAL)
110 Q_PROPERTY(qreal focalRadius READ focalRadius WRITE setFocalRadius NOTIFY focalRadiusChanged FINAL)
111 Q_CLASSINFO("DefaultProperty", "stops")
112 QML_NAMED_ELEMENT(RadialGradient)
113 QML_ADDED_IN_VERSION(1, 0)
114
115public:
116 QQuickShapeRadialGradient(QObject *parent = nullptr);
117
118 qreal centerX() const;
119 void setCenterX(qreal v);
120
121 qreal centerY() const;
122 void setCenterY(qreal v);
123
124 qreal centerRadius() const;
125 void setCenterRadius(qreal v);
126
127 qreal focalX() const;
128 void setFocalX(qreal v);
129
130 qreal focalY() const;
131 void setFocalY(qreal v);
132
133 qreal focalRadius() const;
134 void setFocalRadius(qreal v);
135
136Q_SIGNALS:
137 void centerXChanged();
138 void centerYChanged();
139 void focalXChanged();
140 void focalYChanged();
141 void centerRadiusChanged();
142 void focalRadiusChanged();
143
144private:
145 QPointF m_centerPoint;
146 QPointF m_focalPoint;
147 qreal m_centerRadius = 0;
148 qreal m_focalRadius = 0;
149};
150
151class Q_QUICKSHAPES_PRIVATE_EXPORT QQuickShapeConicalGradient : public QQuickShapeGradient
152{
153 Q_OBJECT
154 Q_PROPERTY(qreal centerX READ centerX WRITE setCenterX NOTIFY centerXChanged FINAL)
155 Q_PROPERTY(qreal centerY READ centerY WRITE setCenterY NOTIFY centerYChanged FINAL)
156 Q_PROPERTY(qreal angle READ angle WRITE setAngle NOTIFY angleChanged FINAL)
157 Q_CLASSINFO("DefaultProperty", "stops")
158 QML_NAMED_ELEMENT(ConicalGradient)
159 QML_ADDED_IN_VERSION(1, 0)
160
161public:
162 QQuickShapeConicalGradient(QObject *parent = nullptr);
163
164 qreal centerX() const;
165 void setCenterX(qreal v);
166
167 qreal centerY() const;
168 void setCenterY(qreal v);
169
170 qreal angle() const;
171 void setAngle(qreal v);
172
173Q_SIGNALS:
174 void centerXChanged();
175 void centerYChanged();
176 void angleChanged();
177
178private:
179 QPointF m_centerPoint;
180 qreal m_angle = 0;
181};
182
183class Q_QUICKSHAPES_PRIVATE_EXPORT QQuickShapePath : public QQuickPath
184{
185 Q_OBJECT
186
187 Q_PROPERTY(QColor strokeColor READ strokeColor WRITE setStrokeColor NOTIFY strokeColorChanged FINAL)
188 Q_PROPERTY(qreal strokeWidth READ strokeWidth WRITE setStrokeWidth NOTIFY strokeWidthChanged FINAL)
189 Q_PROPERTY(QColor fillColor READ fillColor WRITE setFillColor NOTIFY fillColorChanged FINAL)
190 Q_PROPERTY(FillRule fillRule READ fillRule WRITE setFillRule NOTIFY fillRuleChanged FINAL)
191 Q_PROPERTY(JoinStyle joinStyle READ joinStyle WRITE setJoinStyle NOTIFY joinStyleChanged FINAL)
192 Q_PROPERTY(int miterLimit READ miterLimit WRITE setMiterLimit NOTIFY miterLimitChanged FINAL)
193 Q_PROPERTY(CapStyle capStyle READ capStyle WRITE setCapStyle NOTIFY capStyleChanged FINAL)
194 Q_PROPERTY(StrokeStyle strokeStyle READ strokeStyle WRITE setStrokeStyle NOTIFY strokeStyleChanged FINAL)
195 Q_PROPERTY(qreal dashOffset READ dashOffset WRITE setDashOffset NOTIFY dashOffsetChanged FINAL)
196 Q_PROPERTY(QVector<qreal> dashPattern READ dashPattern WRITE setDashPattern NOTIFY dashPatternChanged FINAL)
197 Q_PROPERTY(QQuickShapeGradient *fillGradient READ fillGradient WRITE setFillGradient RESET resetFillGradient FINAL)
198 Q_PROPERTY(QSizeF scale READ scale WRITE setScale NOTIFY scaleChanged REVISION(1, 14) FINAL)
199 QML_NAMED_ELEMENT(ShapePath)
200 QML_ADDED_IN_VERSION(1, 0)
201
202public:
203 enum FillRule {
204 OddEvenFill = Qt::OddEvenFill,
205 WindingFill = Qt::WindingFill
206 };
207 Q_ENUM(FillRule)
208
209 enum JoinStyle {
210 MiterJoin = Qt::MiterJoin,
211 BevelJoin = Qt::BevelJoin,
212 RoundJoin = Qt::RoundJoin
213 };
214 Q_ENUM(JoinStyle)
215
216 enum CapStyle {
217 FlatCap = Qt::FlatCap,
218 SquareCap = Qt::SquareCap,
219 RoundCap = Qt::RoundCap
220 };
221 Q_ENUM(CapStyle)
222
223 enum StrokeStyle {
224 SolidLine = Qt::SolidLine,
225 DashLine = Qt::DashLine
226 };
227 Q_ENUM(StrokeStyle)
228
229 QQuickShapePath(QObject *parent = nullptr);
230 ~QQuickShapePath();
231
232 QColor strokeColor() const;
233 void setStrokeColor(const QColor &color);
234
235 qreal strokeWidth() const;
236 void setStrokeWidth(qreal w);
237
238 QColor fillColor() const;
239 void setFillColor(const QColor &color);
240
241 FillRule fillRule() const;
242 void setFillRule(FillRule fillRule);
243
244 JoinStyle joinStyle() const;
245 void setJoinStyle(JoinStyle style);
246
247 int miterLimit() const;
248 void setMiterLimit(int limit);
249
250 CapStyle capStyle() const;
251 void setCapStyle(CapStyle style);
252
253 StrokeStyle strokeStyle() const;
254 void setStrokeStyle(StrokeStyle style);
255
256 qreal dashOffset() const;
257 void setDashOffset(qreal offset);
258
259 QVector<qreal> dashPattern() const;
260 void setDashPattern(const QVector<qreal> &array);
261
262 QQuickShapeGradient *fillGradient() const;
263 void setFillGradient(QQuickShapeGradient *gradient);
264 void resetFillGradient();
265
266Q_SIGNALS:
267 void shapePathChanged();
268 void strokeColorChanged();
269 void strokeWidthChanged();
270 void fillColorChanged();
271 void fillRuleChanged();
272 void joinStyleChanged();
273 void miterLimitChanged();
274 void capStyleChanged();
275 void strokeStyleChanged();
276 void dashOffsetChanged();
277 void dashPatternChanged();
278
279private:
280 Q_DISABLE_COPY(QQuickShapePath)
281 Q_DECLARE_PRIVATE(QQuickShapePath)
282 Q_PRIVATE_SLOT(d_func(), void _q_fillGradientChanged())
283};
284
285class Q_QUICKSHAPES_PRIVATE_EXPORT QQuickShape : public QQuickItem
286{
287 Q_OBJECT
288 Q_PROPERTY(RendererType rendererType READ rendererType NOTIFY rendererChanged FINAL)
289 Q_PROPERTY(bool asynchronous READ asynchronous WRITE setAsynchronous NOTIFY asynchronousChanged FINAL)
290 Q_PROPERTY(bool vendorExtensionsEnabled READ vendorExtensionsEnabled WRITE setVendorExtensionsEnabled NOTIFY vendorExtensionsEnabledChanged FINAL)
291 Q_PROPERTY(RendererType preferredRendererType READ preferredRendererType
292 WRITE setPreferredRendererType NOTIFY preferredRendererTypeChanged REVISION(6, 6) FINAL)
293 Q_PROPERTY(Status status READ status NOTIFY statusChanged FINAL)
294 Q_PROPERTY(ContainsMode containsMode READ containsMode WRITE setContainsMode NOTIFY containsModeChanged REVISION(1, 11) FINAL)
295 Q_PROPERTY(QRectF boundingRect READ boundingRect NOTIFY boundingRectChanged REVISION(6, 6) FINAL)
296
297 Q_PROPERTY(QQmlListProperty<QObject> data READ data)
298 Q_CLASSINFO("DefaultProperty", "data")
299 QML_NAMED_ELEMENT(Shape)
300 QML_ADDED_IN_VERSION(1, 0)
301
302public:
303 enum RendererType {
304 UnknownRenderer,
305 GeometryRenderer,
306 NvprRenderer,
307 SoftwareRenderer,
308 CurveRenderer
309 };
310 Q_ENUM(RendererType)
311
312 enum Status {
313 Null,
314 Ready,
315 Processing
316 };
317 Q_ENUM(Status)
318
319 enum ContainsMode {
320 BoundingRectContains,
321 FillContains
322 };
323 Q_ENUM(ContainsMode)
324
325 QQuickShape(QQuickItem *parent = nullptr);
326 ~QQuickShape();
327
328 RendererType rendererType() const;
329
330 bool asynchronous() const;
331 void setAsynchronous(bool async);
332
333 Q_REVISION(6, 6) RendererType preferredRendererType() const;
334 Q_REVISION(6, 6) void setPreferredRendererType(RendererType preferredType);
335
336 Q_REVISION(6, 6) QRectF boundingRect() const override;
337
338 bool vendorExtensionsEnabled() const;
339 void setVendorExtensionsEnabled(bool enable);
340
341 Status status() const;
342
343 ContainsMode containsMode() const;
344 void setContainsMode(ContainsMode containsMode);
345
346 bool contains(const QPointF &point) const override;
347
348 QQmlListProperty<QObject> data();
349
350protected:
351 QSGNode *updatePaintNode(QSGNode *node, UpdatePaintNodeData *) override;
352 void updatePolish() override;
353 void itemChange(ItemChange change, const ItemChangeData &data) override;
354 void componentComplete() override;
355 void classBegin() override;
356
357Q_SIGNALS:
358 void rendererChanged();
359 void asynchronousChanged();
360 void vendorExtensionsEnabledChanged();
361 void statusChanged();
362 Q_REVISION(6, 6) void preferredRendererTypeChanged();
363 Q_REVISION(6, 6) void boundingRectChanged();
364 Q_REVISION(1, 11) void containsModeChanged();
365
366private:
367 Q_DISABLE_COPY(QQuickShape)
368 Q_DECLARE_PRIVATE(QQuickShape)
369 Q_PRIVATE_SLOT(d_func(), void _q_shapePathChanged())
370};
371
372QT_END_NAMESPACE
373
374QML_DECLARE_TYPE(QQuickShape)
375
376#endif // QQUICKSHAPE_P_H
377

source code of qtdeclarative/src/quickshapes/qquickshape_p.h