1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtQuick module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QQUICKSHAPE_P_H
41#define QQUICKSHAPE_P_H
42
43//
44// W A R N I N G
45// -------------
46//
47// This file is not part of the Qt API. It exists purely as an
48// implementation detail. This header file may change from version to
49// version without notice, or even be removed.
50//
51// We mean it.
52//
53
54#include <QtQuickShapes/private/qquickshapesglobal_p.h>
55#include <QtQuick/qquickitem.h>
56
57#include <private/qtquickglobal_p.h>
58#include <private/qquickpath_p_p.h>
59#include <private/qquickrectangle_p.h>
60
61QT_BEGIN_NAMESPACE
62
63class QQuickShapePathPrivate;
64class QQuickShapePrivate;
65
66class Q_QUICKSHAPES_PRIVATE_EXPORT QQuickShapesModule
67{
68public:
69 static void defineModule();
70};
71
72class Q_QUICKSHAPES_PRIVATE_EXPORT QQuickShapeGradient : public QQuickGradient
73{
74 Q_OBJECT
75 Q_PROPERTY(SpreadMode spread READ spread WRITE setSpread NOTIFY spreadChanged)
76 Q_CLASSINFO("DefaultProperty", "stops")
77
78 QML_NAMED_ELEMENT(ShapeGradient)
79 QML_UNCREATABLE("ShapeGradient is an abstract base class.");
80
81public:
82 enum SpreadMode {
83 PadSpread,
84 RepeatSpread,
85 ReflectSpread
86 };
87 Q_ENUM(SpreadMode)
88
89 QQuickShapeGradient(QObject *parent = nullptr);
90
91 SpreadMode spread() const;
92 void setSpread(SpreadMode mode);
93
94signals:
95 void spreadChanged();
96
97private:
98 SpreadMode m_spread;
99};
100
101class Q_QUICKSHAPES_PRIVATE_EXPORT QQuickShapeLinearGradient : public QQuickShapeGradient
102{
103 Q_OBJECT
104 Q_PROPERTY(qreal x1 READ x1 WRITE setX1 NOTIFY x1Changed)
105 Q_PROPERTY(qreal y1 READ y1 WRITE setY1 NOTIFY y1Changed)
106 Q_PROPERTY(qreal x2 READ x2 WRITE setX2 NOTIFY x2Changed)
107 Q_PROPERTY(qreal y2 READ y2 WRITE setY2 NOTIFY y2Changed)
108 Q_CLASSINFO("DefaultProperty", "stops")
109 QML_NAMED_ELEMENT(LinearGradient)
110
111public:
112 QQuickShapeLinearGradient(QObject *parent = nullptr);
113
114 qreal x1() const;
115 void setX1(qreal v);
116 qreal y1() const;
117 void setY1(qreal v);
118 qreal x2() const;
119 void setX2(qreal v);
120 qreal y2() const;
121 void setY2(qreal v);
122
123signals:
124 void x1Changed();
125 void y1Changed();
126 void x2Changed();
127 void y2Changed();
128
129private:
130 QPointF m_start;
131 QPointF m_end;
132};
133
134class Q_QUICKSHAPES_PRIVATE_EXPORT QQuickShapeRadialGradient : public QQuickShapeGradient
135{
136 Q_OBJECT
137 Q_PROPERTY(qreal centerX READ centerX WRITE setCenterX NOTIFY centerXChanged)
138 Q_PROPERTY(qreal centerY READ centerY WRITE setCenterY NOTIFY centerYChanged)
139 Q_PROPERTY(qreal centerRadius READ centerRadius WRITE setCenterRadius NOTIFY centerRadiusChanged)
140 Q_PROPERTY(qreal focalX READ focalX WRITE setFocalX NOTIFY focalXChanged)
141 Q_PROPERTY(qreal focalY READ focalY WRITE setFocalY NOTIFY focalYChanged)
142 Q_PROPERTY(qreal focalRadius READ focalRadius WRITE setFocalRadius NOTIFY focalRadiusChanged)
143 Q_CLASSINFO("DefaultProperty", "stops")
144 QML_NAMED_ELEMENT(RadialGradient)
145
146public:
147 QQuickShapeRadialGradient(QObject *parent = nullptr);
148
149 qreal centerX() const;
150 void setCenterX(qreal v);
151
152 qreal centerY() const;
153 void setCenterY(qreal v);
154
155 qreal centerRadius() const;
156 void setCenterRadius(qreal v);
157
158 qreal focalX() const;
159 void setFocalX(qreal v);
160
161 qreal focalY() const;
162 void setFocalY(qreal v);
163
164 qreal focalRadius() const;
165 void setFocalRadius(qreal v);
166
167signals:
168 void centerXChanged();
169 void centerYChanged();
170 void focalXChanged();
171 void focalYChanged();
172 void centerRadiusChanged();
173 void focalRadiusChanged();
174
175private:
176 QPointF m_centerPoint;
177 QPointF m_focalPoint;
178 qreal m_centerRadius = 0;
179 qreal m_focalRadius = 0;
180};
181
182class Q_QUICKSHAPES_PRIVATE_EXPORT QQuickShapeConicalGradient : public QQuickShapeGradient
183{
184 Q_OBJECT
185 Q_PROPERTY(qreal centerX READ centerX WRITE setCenterX NOTIFY centerXChanged)
186 Q_PROPERTY(qreal centerY READ centerY WRITE setCenterY NOTIFY centerYChanged)
187 Q_PROPERTY(qreal angle READ angle WRITE setAngle NOTIFY angleChanged)
188 Q_CLASSINFO("DefaultProperty", "stops")
189 QML_NAMED_ELEMENT(ConicalGradient)
190
191public:
192 QQuickShapeConicalGradient(QObject *parent = nullptr);
193
194 qreal centerX() const;
195 void setCenterX(qreal v);
196
197 qreal centerY() const;
198 void setCenterY(qreal v);
199
200 qreal angle() const;
201 void setAngle(qreal v);
202
203signals:
204 void centerXChanged();
205 void centerYChanged();
206 void angleChanged();
207
208private:
209 QPointF m_centerPoint;
210 qreal m_angle = 0;
211};
212
213class Q_QUICKSHAPES_PRIVATE_EXPORT QQuickShapePath : public QQuickPath
214{
215 Q_OBJECT
216
217 Q_PROPERTY(QColor strokeColor READ strokeColor WRITE setStrokeColor NOTIFY strokeColorChanged)
218 Q_PROPERTY(qreal strokeWidth READ strokeWidth WRITE setStrokeWidth NOTIFY strokeWidthChanged)
219 Q_PROPERTY(QColor fillColor READ fillColor WRITE setFillColor NOTIFY fillColorChanged)
220 Q_PROPERTY(FillRule fillRule READ fillRule WRITE setFillRule NOTIFY fillRuleChanged)
221 Q_PROPERTY(JoinStyle joinStyle READ joinStyle WRITE setJoinStyle NOTIFY joinStyleChanged)
222 Q_PROPERTY(int miterLimit READ miterLimit WRITE setMiterLimit NOTIFY miterLimitChanged)
223 Q_PROPERTY(CapStyle capStyle READ capStyle WRITE setCapStyle NOTIFY capStyleChanged)
224 Q_PROPERTY(StrokeStyle strokeStyle READ strokeStyle WRITE setStrokeStyle NOTIFY strokeStyleChanged)
225 Q_PROPERTY(qreal dashOffset READ dashOffset WRITE setDashOffset NOTIFY dashOffsetChanged)
226 Q_PROPERTY(QVector<qreal> dashPattern READ dashPattern WRITE setDashPattern NOTIFY dashPatternChanged)
227 Q_PROPERTY(QQuickShapeGradient *fillGradient READ fillGradient WRITE setFillGradient RESET resetFillGradient)
228 Q_PROPERTY(QSizeF scale READ scale WRITE setScale NOTIFY scaleChanged REVISION 14)
229 QML_NAMED_ELEMENT(ShapePath)
230
231public:
232 enum FillRule {
233 OddEvenFill = Qt::OddEvenFill,
234 WindingFill = Qt::WindingFill
235 };
236 Q_ENUM(FillRule)
237
238 enum JoinStyle {
239 MiterJoin = Qt::MiterJoin,
240 BevelJoin = Qt::BevelJoin,
241 RoundJoin = Qt::RoundJoin
242 };
243 Q_ENUM(JoinStyle)
244
245 enum CapStyle {
246 FlatCap = Qt::FlatCap,
247 SquareCap = Qt::SquareCap,
248 RoundCap = Qt::RoundCap
249 };
250 Q_ENUM(CapStyle)
251
252 enum StrokeStyle {
253 SolidLine = Qt::SolidLine,
254 DashLine = Qt::DashLine
255 };
256 Q_ENUM(StrokeStyle)
257
258 QQuickShapePath(QObject *parent = nullptr);
259 ~QQuickShapePath();
260
261 QColor strokeColor() const;
262 void setStrokeColor(const QColor &color);
263
264 qreal strokeWidth() const;
265 void setStrokeWidth(qreal w);
266
267 QColor fillColor() const;
268 void setFillColor(const QColor &color);
269
270 FillRule fillRule() const;
271 void setFillRule(FillRule fillRule);
272
273 JoinStyle joinStyle() const;
274 void setJoinStyle(JoinStyle style);
275
276 int miterLimit() const;
277 void setMiterLimit(int limit);
278
279 CapStyle capStyle() const;
280 void setCapStyle(CapStyle style);
281
282 StrokeStyle strokeStyle() const;
283 void setStrokeStyle(StrokeStyle style);
284
285 qreal dashOffset() const;
286 void setDashOffset(qreal offset);
287
288 QVector<qreal> dashPattern() const;
289 void setDashPattern(const QVector<qreal> &array);
290
291 QQuickShapeGradient *fillGradient() const;
292 void setFillGradient(QQuickShapeGradient *gradient);
293 void resetFillGradient();
294
295Q_SIGNALS:
296 void shapePathChanged();
297 void strokeColorChanged();
298 void strokeWidthChanged();
299 void fillColorChanged();
300 void fillRuleChanged();
301 void joinStyleChanged();
302 void miterLimitChanged();
303 void capStyleChanged();
304 void strokeStyleChanged();
305 void dashOffsetChanged();
306 void dashPatternChanged();
307
308private:
309 Q_DISABLE_COPY(QQuickShapePath)
310 Q_DECLARE_PRIVATE(QQuickShapePath)
311 Q_PRIVATE_SLOT(d_func(), void _q_fillGradientChanged())
312};
313
314class Q_QUICKSHAPES_PRIVATE_EXPORT QQuickShape : public QQuickItem
315{
316 Q_OBJECT
317 Q_PROPERTY(RendererType rendererType READ rendererType NOTIFY rendererChanged)
318 Q_PROPERTY(bool asynchronous READ asynchronous WRITE setAsynchronous NOTIFY asynchronousChanged)
319 Q_PROPERTY(bool vendorExtensionsEnabled READ vendorExtensionsEnabled WRITE setVendorExtensionsEnabled NOTIFY vendorExtensionsEnabledChanged)
320 Q_PROPERTY(Status status READ status NOTIFY statusChanged)
321 Q_PROPERTY(ContainsMode containsMode READ containsMode WRITE setContainsMode NOTIFY containsModeChanged REVISION 11)
322 Q_PROPERTY(QQmlListProperty<QObject> data READ data)
323 Q_CLASSINFO("DefaultProperty", "data")
324 QML_NAMED_ELEMENT(Shape)
325
326public:
327 enum RendererType {
328 UnknownRenderer,
329 GeometryRenderer,
330 NvprRenderer,
331 SoftwareRenderer
332 };
333 Q_ENUM(RendererType)
334
335 enum Status {
336 Null,
337 Ready,
338 Processing
339 };
340 Q_ENUM(Status)
341
342 enum ContainsMode {
343 BoundingRectContains,
344 FillContains
345 };
346 Q_ENUM(ContainsMode)
347
348 QQuickShape(QQuickItem *parent = nullptr);
349 ~QQuickShape();
350
351 RendererType rendererType() const;
352
353 bool asynchronous() const;
354 void setAsynchronous(bool async);
355
356 bool vendorExtensionsEnabled() const;
357 void setVendorExtensionsEnabled(bool enable);
358
359 Status status() const;
360
361 ContainsMode containsMode() const;
362 void setContainsMode(ContainsMode containsMode);
363
364 bool contains(const QPointF &point) const override;
365
366 QQmlListProperty<QObject> data();
367
368protected:
369 QSGNode *updatePaintNode(QSGNode *node, UpdatePaintNodeData *) override;
370 void updatePolish() override;
371 void itemChange(ItemChange change, const ItemChangeData &data) override;
372 void componentComplete() override;
373 void classBegin() override;
374
375Q_SIGNALS:
376 void rendererChanged();
377 void asynchronousChanged();
378 void vendorExtensionsEnabledChanged();
379 void statusChanged();
380 Q_REVISION(11) void containsModeChanged();
381
382private:
383 Q_DISABLE_COPY(QQuickShape)
384 Q_DECLARE_PRIVATE(QQuickShape)
385 Q_PRIVATE_SLOT(d_func(), void _q_shapePathChanged())
386};
387
388QT_END_NAMESPACE
389
390QML_DECLARE_TYPE(QQuickShape)
391
392#endif // QQUICKSHAPE_P_H
393

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