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