Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qquickpath_p.h
Go to the documentation of this file.
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// Qt-Security score:significant reason:default
4
5#ifndef QQUICKPATH_H
6#define QQUICKPATH_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <private/qtquickglobal_p.h>
20
22
23#include <qqml.h>
24
25#include <private/qqmlnullablevalue_p.h>
26#include <private/qlazilyallocated_p.h>
27#include <private/qbezier_p.h>
28#include <private/qtquickglobal_p.h>
29
30#include <QtCore/QObject>
31#include <QtCore/QDebug>
32#include <QtCore/QHash>
33#include <QtGui/QPainterPath>
34#include <QtGui/QFont>
35
37
38class QQuickCurve;
39class QQuickCurvePrivate;
40
47
48class Q_QUICK_EXPORT QQuickPathElement : public QObject
49{
50 Q_OBJECT
51 QML_ANONYMOUS
52 QML_ADDED_IN_VERSION(2, 0)
53public:
54 QQuickPathElement(QObject *parent=nullptr) : QObject(parent) {}
55Q_SIGNALS:
56 void changed();
57};
58
59class Q_QUICK_EXPORT QQuickPathAttribute : public QQuickPathElement
60{
61 Q_OBJECT
62
63 Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
64 Q_PROPERTY(qreal value READ value WRITE setValue NOTIFY valueChanged)
65 QML_NAMED_ELEMENT(PathAttribute)
66 QML_ADDED_IN_VERSION(2, 0)
67public:
68 QQuickPathAttribute(QObject *parent=nullptr) : QQuickPathElement(parent) {}
69
70
71 QString name() const;
72 void setName(const QString &name);
73
74 qreal value() const;
75 void setValue(qreal value);
76
77Q_SIGNALS:
78 void nameChanged();
79 void valueChanged();
80
81private:
82 QString _name;
83 qreal _value = 0;
84};
85
86class Q_QUICK_EXPORT QQuickCurve : public QQuickPathElement
87{
88 Q_OBJECT
89
90 Q_PROPERTY(qreal x READ x WRITE setX NOTIFY xChanged)
91 Q_PROPERTY(qreal y READ y WRITE setY NOTIFY yChanged)
92 Q_PROPERTY(qreal relativeX READ relativeX WRITE setRelativeX NOTIFY relativeXChanged)
93 Q_PROPERTY(qreal relativeY READ relativeY WRITE setRelativeY NOTIFY relativeYChanged)
94 QML_ANONYMOUS
95 QML_ADDED_IN_VERSION(2, 0)
96public:
97 QQuickCurve(QObject *parent=nullptr) : QQuickPathElement(parent) {}
98
99 qreal x() const;
100 void setX(qreal x);
101 bool hasX();
102
103 qreal y() const;
104 void setY(qreal y);
105 bool hasY();
106
107 qreal relativeX() const;
108 void setRelativeX(qreal x);
109 bool hasRelativeX();
110
111 qreal relativeY() const;
112 void setRelativeY(qreal y);
113 bool hasRelativeY();
114
115 virtual void addToPath(QPainterPath &, const QQuickPathData &) {}
116
117Q_SIGNALS:
118 void xChanged();
119 void yChanged();
120 void relativeXChanged();
121 void relativeYChanged();
122
123private:
124#ifndef QT_NO_DEBUG_STREAM
125 friend Q_QUICK_EXPORT QDebug operator<<(QDebug debug, const QQuickCurve *curve);
126#endif
127
128 QQmlNullableValue<qreal> _x;
129 QQmlNullableValue<qreal> _y;
130 QQmlNullableValue<qreal> _relativeX;
131 QQmlNullableValue<qreal> _relativeY;
132};
133
134class Q_QUICK_EXPORT QQuickPathLine : public QQuickCurve
135{
136 Q_OBJECT
137 QML_NAMED_ELEMENT(PathLine)
138 QML_ADDED_IN_VERSION(2, 0)
139public:
140 QQuickPathLine(QObject *parent=nullptr) : QQuickCurve(parent) {}
141
142 void addToPath(QPainterPath &path, const QQuickPathData &) override;
143};
144
145class Q_QUICK_EXPORT QQuickPathMove : public QQuickCurve
146{
147 Q_OBJECT
148 QML_NAMED_ELEMENT(PathMove)
149 QML_ADDED_IN_VERSION(2, 9)
150public:
151 QQuickPathMove(QObject *parent=nullptr) : QQuickCurve(parent) {}
152
153 void addToPath(QPainterPath &path, const QQuickPathData &) override;
154};
155
156class Q_QUICK_EXPORT QQuickPathQuad : public QQuickCurve
157{
158 Q_OBJECT
159
160 Q_PROPERTY(qreal controlX READ controlX WRITE setControlX NOTIFY controlXChanged)
161 Q_PROPERTY(qreal controlY READ controlY WRITE setControlY NOTIFY controlYChanged)
162 Q_PROPERTY(qreal relativeControlX READ relativeControlX WRITE setRelativeControlX NOTIFY relativeControlXChanged)
163 Q_PROPERTY(qreal relativeControlY READ relativeControlY WRITE setRelativeControlY NOTIFY relativeControlYChanged)
164
165 QML_NAMED_ELEMENT(PathQuad)
166 QML_ADDED_IN_VERSION(2, 0)
167public:
168 QQuickPathQuad(QObject *parent=nullptr) : QQuickCurve(parent) {}
169
170 qreal controlX() const;
171 void setControlX(qreal x);
172
173 qreal controlY() const;
174 void setControlY(qreal y);
175
176 qreal relativeControlX() const;
177 void setRelativeControlX(qreal x);
178 bool hasRelativeControlX();
179
180 qreal relativeControlY() const;
181 void setRelativeControlY(qreal y);
182 bool hasRelativeControlY();
183
184 void addToPath(QPainterPath &path, const QQuickPathData &) override;
185
186Q_SIGNALS:
187 void controlXChanged();
188 void controlYChanged();
189 void relativeControlXChanged();
190 void relativeControlYChanged();
191
192private:
193 qreal _controlX = 0;
194 qreal _controlY = 0;
195 QQmlNullableValue<qreal> _relativeControlX;
196 QQmlNullableValue<qreal> _relativeControlY;
197};
198
199class Q_QUICK_EXPORT QQuickPathCubic : public QQuickCurve
200{
201 Q_OBJECT
202
203 Q_PROPERTY(qreal control1X READ control1X WRITE setControl1X NOTIFY control1XChanged)
204 Q_PROPERTY(qreal control1Y READ control1Y WRITE setControl1Y NOTIFY control1YChanged)
205 Q_PROPERTY(qreal control2X READ control2X WRITE setControl2X NOTIFY control2XChanged)
206 Q_PROPERTY(qreal control2Y READ control2Y WRITE setControl2Y NOTIFY control2YChanged)
207 Q_PROPERTY(qreal relativeControl1X READ relativeControl1X WRITE setRelativeControl1X NOTIFY relativeControl1XChanged)
208 Q_PROPERTY(qreal relativeControl1Y READ relativeControl1Y WRITE setRelativeControl1Y NOTIFY relativeControl1YChanged)
209 Q_PROPERTY(qreal relativeControl2X READ relativeControl2X WRITE setRelativeControl2X NOTIFY relativeControl2XChanged)
210 Q_PROPERTY(qreal relativeControl2Y READ relativeControl2Y WRITE setRelativeControl2Y NOTIFY relativeControl2YChanged)
211 QML_NAMED_ELEMENT(PathCubic)
212 QML_ADDED_IN_VERSION(2, 0)
213public:
214 QQuickPathCubic(QObject *parent=nullptr) : QQuickCurve(parent) {}
215
216 qreal control1X() const;
217 void setControl1X(qreal x);
218
219 qreal control1Y() const;
220 void setControl1Y(qreal y);
221
222 qreal control2X() const;
223 void setControl2X(qreal x);
224
225 qreal control2Y() const;
226 void setControl2Y(qreal y);
227
228 qreal relativeControl1X() const;
229 void setRelativeControl1X(qreal x);
230 bool hasRelativeControl1X();
231
232 qreal relativeControl1Y() const;
233 void setRelativeControl1Y(qreal y);
234 bool hasRelativeControl1Y();
235
236 qreal relativeControl2X() const;
237 void setRelativeControl2X(qreal x);
238 bool hasRelativeControl2X();
239
240 qreal relativeControl2Y() const;
241 void setRelativeControl2Y(qreal y);
242 bool hasRelativeControl2Y();
243
244 void addToPath(QPainterPath &path, const QQuickPathData &) override;
245
246Q_SIGNALS:
247 void control1XChanged();
248 void control1YChanged();
249 void control2XChanged();
250 void control2YChanged();
251 void relativeControl1XChanged();
252 void relativeControl1YChanged();
253 void relativeControl2XChanged();
254 void relativeControl2YChanged();
255
256private:
257 qreal _control1X = 0;
258 qreal _control1Y = 0;
259 qreal _control2X = 0;
260 qreal _control2Y = 0;
261 QQmlNullableValue<qreal> _relativeControl1X;
262 QQmlNullableValue<qreal> _relativeControl1Y;
263 QQmlNullableValue<qreal> _relativeControl2X;
264 QQmlNullableValue<qreal> _relativeControl2Y;
265};
266
267class Q_QUICK_EXPORT QQuickPathCatmullRomCurve : public QQuickCurve
268{
269 Q_OBJECT
270 QML_NAMED_ELEMENT(PathCurve)
271 QML_ADDED_IN_VERSION(2, 0)
272public:
273 QQuickPathCatmullRomCurve(QObject *parent=nullptr) : QQuickCurve(parent) {}
274
275 void addToPath(QPainterPath &path, const QQuickPathData &) override;
276};
277
278class Q_QUICK_EXPORT QQuickPathArc : public QQuickCurve
279{
280 Q_OBJECT
281 Q_PROPERTY(qreal radiusX READ radiusX WRITE setRadiusX NOTIFY radiusXChanged)
282 Q_PROPERTY(qreal radiusY READ radiusY WRITE setRadiusY NOTIFY radiusYChanged)
283 Q_PROPERTY(bool useLargeArc READ useLargeArc WRITE setUseLargeArc NOTIFY useLargeArcChanged)
284 Q_PROPERTY(ArcDirection direction READ direction WRITE setDirection NOTIFY directionChanged)
285 Q_PROPERTY(qreal xAxisRotation READ xAxisRotation WRITE setXAxisRotation NOTIFY xAxisRotationChanged REVISION(2, 9))
286 QML_NAMED_ELEMENT(PathArc)
287 QML_ADDED_IN_VERSION(2, 0)
288
289public:
290 QQuickPathArc(QObject *parent=nullptr)
291 : QQuickCurve(parent) {}
292
293 enum ArcDirection { Clockwise, Counterclockwise };
294 Q_ENUM(ArcDirection)
295
296 qreal radiusX() const;
297 void setRadiusX(qreal);
298
299 qreal radiusY() const;
300 void setRadiusY(qreal);
301
302 bool useLargeArc() const;
303 void setUseLargeArc(bool);
304
305 ArcDirection direction() const;
306 void setDirection(ArcDirection direction);
307
308 qreal xAxisRotation() const;
309 void setXAxisRotation(qreal rotation);
310
311 void addToPath(QPainterPath &path, const QQuickPathData &) override;
312
313Q_SIGNALS:
314 void radiusXChanged();
315 void radiusYChanged();
316 void useLargeArcChanged();
317 void directionChanged();
318 Q_REVISION(2, 9) void xAxisRotationChanged();
319
320private:
321 qreal _radiusX = 0;
322 qreal _radiusY = 0;
323 bool _useLargeArc = false;
324 ArcDirection _direction = Clockwise;
325 qreal _xAxisRotation = 0;
326};
327
328class Q_QUICK_EXPORT QQuickPathAngleArc : public QQuickCurve
329{
330 Q_OBJECT
331 Q_PROPERTY(qreal centerX READ centerX WRITE setCenterX NOTIFY centerXChanged)
332 Q_PROPERTY(qreal centerY READ centerY WRITE setCenterY NOTIFY centerYChanged)
333 Q_PROPERTY(qreal radiusX READ radiusX WRITE setRadiusX NOTIFY radiusXChanged)
334 Q_PROPERTY(qreal radiusY READ radiusY WRITE setRadiusY NOTIFY radiusYChanged)
335 Q_PROPERTY(qreal startAngle READ startAngle WRITE setStartAngle NOTIFY startAngleChanged)
336 Q_PROPERTY(qreal sweepAngle READ sweepAngle WRITE setSweepAngle NOTIFY sweepAngleChanged)
337 Q_PROPERTY(bool moveToStart READ moveToStart WRITE setMoveToStart NOTIFY moveToStartChanged)
338
339 QML_NAMED_ELEMENT(PathAngleArc)
340 QML_ADDED_IN_VERSION(2, 11)
341
342public:
343 QQuickPathAngleArc(QObject *parent=nullptr)
344 : QQuickCurve(parent) {}
345
346 qreal centerX() const;
347 void setCenterX(qreal);
348
349 qreal centerY() const;
350 void setCenterY(qreal);
351
352 qreal radiusX() const;
353 void setRadiusX(qreal);
354
355 qreal radiusY() const;
356 void setRadiusY(qreal);
357
358 qreal startAngle() const;
359 void setStartAngle(qreal);
360
361 qreal sweepAngle() const;
362 void setSweepAngle(qreal);
363
364 bool moveToStart() const;
365 void setMoveToStart(bool);
366
367 void addToPath(QPainterPath &path, const QQuickPathData &) override;
368
369Q_SIGNALS:
370 void centerXChanged();
371 void centerYChanged();
372 void radiusXChanged();
373 void radiusYChanged();
374 void startAngleChanged();
375 void sweepAngleChanged();
376 void moveToStartChanged();
377
378private:
379 qreal _centerX = 0;
380 qreal _centerY = 0;
381 qreal _radiusX = 0;
382 qreal _radiusY = 0;
383 qreal _startAngle = 0;
384 qreal _sweepAngle = 0;
385 bool _moveToStart = true;
386};
387
388class Q_QUICK_EXPORT QQuickPathSvg : public QQuickCurve
389{
390 Q_OBJECT
391 Q_PROPERTY(QString path READ path WRITE setPath NOTIFY pathChanged)
392 QML_NAMED_ELEMENT(PathSvg)
393 QML_ADDED_IN_VERSION(2, 0)
394public:
395 QQuickPathSvg(QObject *parent=nullptr) : QQuickCurve(parent) {}
396
397 QString path() const;
398 void setPath(const QString &path);
399
400 void addToPath(QPainterPath &path, const QQuickPathData &) override;
401
402Q_SIGNALS:
403 void pathChanged();
404
405private:
406 QString _path;
407};
408
409class Q_QUICK_EXPORT QQuickPathRectangle : public QQuickCurve
410{
411 Q_OBJECT
412
413 Q_PROPERTY(qreal width READ width WRITE setWidth NOTIFY widthChanged FINAL)
414 Q_PROPERTY(qreal height READ height WRITE setHeight NOTIFY heightChanged FINAL)
415 Q_PROPERTY(qreal strokeAdjustment READ strokeAdjustment WRITE setStrokeAdjustment NOTIFY strokeAdjustmentChanged FINAL)
416 Q_PROPERTY(qreal radius READ radius WRITE setRadius NOTIFY radiusChanged FINAL)
417 Q_PROPERTY(qreal topLeftRadius READ topLeftRadius WRITE setTopLeftRadius RESET resetTopLeftRadius NOTIFY topLeftRadiusChanged FINAL)
418 Q_PROPERTY(qreal topRightRadius READ topRightRadius WRITE setTopRightRadius NOTIFY topRightRadiusChanged RESET resetTopRightRadius FINAL)
419 Q_PROPERTY(qreal bottomLeftRadius READ bottomLeftRadius WRITE setBottomLeftRadius NOTIFY bottomLeftRadiusChanged RESET resetBottomLeftRadius FINAL)
420 Q_PROPERTY(qreal bottomRightRadius READ bottomRightRadius WRITE setBottomRightRadius NOTIFY bottomRightRadiusChanged RESET resetBottomRightRadius FINAL)
421 Q_PROPERTY(bool bevel READ hasBevel WRITE setBevel NOTIFY bevelChanged FINAL REVISION(6, 10))
422 Q_PROPERTY(bool topLeftBevel READ hasTopLeftBevel WRITE setTopLeftBevel NOTIFY topLeftBevelChanged RESET resetTopLeftBevel FINAL REVISION(6, 10))
423 Q_PROPERTY(bool topRightBevel READ hasTopRightBevel WRITE setTopRightBevel NOTIFY topRightBevelChanged RESET resetTopRightBevel FINAL REVISION(6, 10))
424 Q_PROPERTY(bool bottomLeftBevel READ hasBottomLeftBevel WRITE setBottomLeftBevel NOTIFY bottomLeftBevelChanged RESET resetBottomLeftBevel FINAL REVISION(6, 10))
425 Q_PROPERTY(bool bottomRightBevel READ hasBottomRightBevel WRITE setBottomRightBevel NOTIFY bottomRightBevelChanged RESET resetBottomRightBevel FINAL REVISION(6, 10))
426 Q_PROPERTY(CornerShape cornerShape READ cornerShape WRITE setCornerShape NOTIFY
427 cornerShapeChanged REVISION(6, 13))
428 Q_PROPERTY(CornerShape topLeftCornerShape READ topLeftCornerShape WRITE setTopLeftCornerShape
429 RESET resetTopLeftCornerShape NOTIFY topLeftCornerShapeChanged REVISION(6,
430 13))
431 Q_PROPERTY(CornerShape topRightCornerShape READ topRightCornerShape WRITE setTopRightCornerShape
432 RESET resetTopRightCornerShape NOTIFY topRightCornerShapeChanged
433 REVISION(6, 13))
434 Q_PROPERTY(CornerShape bottomLeftCornerShape READ bottomLeftCornerShape WRITE
435 setBottomLeftCornerShape RESET resetBottomLeftCornerShape NOTIFY
436 bottomLeftCornerShapeChanged REVISION(6, 13))
437 Q_PROPERTY(CornerShape bottomRightCornerShape READ bottomRightCornerShape WRITE
438 setBottomRightCornerShape RESET resetBottomRightCornerShape NOTIFY
439 bottomRightCornerShapeChanged REVISION(6, 13))
441 QML_NAMED_ELEMENT(PathRectangle)
442 QML_ADDED_IN_VERSION(6, 8)
443public:
444 enum CornerShape { Rounded, Bevel, Squircle };
445 Q_ENUM(CornerShape)
446
447 QQuickPathRectangle(QObject *parent = nullptr) : QQuickCurve(parent) {}
448
449 qreal width() const;
450 void setWidth(qreal width);
451
452 qreal height() const;
453 void setHeight(qreal height);
455 qreal strokeAdjustment() const;
456 void setStrokeAdjustment(qreal newStrokeAdjustment);
457
458 qreal radius() const;
459 void setRadius(qreal newRadius);
461 qreal topLeftRadius() const { return cornerRadius(Qt::TopLeftCorner); }
462 void setTopLeftRadius(qreal radius) { setCornerRadius(Qt::TopLeftCorner, radius); }
463 void resetTopLeftRadius() { resetCornerRadius(Qt::TopLeftCorner); }
465 qreal topRightRadius() const { return cornerRadius(Qt::TopRightCorner); }
466 void setTopRightRadius(qreal radius) { setCornerRadius(Qt::TopRightCorner, radius); }
467 void resetTopRightRadius() { resetCornerRadius(Qt::TopRightCorner); }
469 qreal bottomLeftRadius() const { return cornerRadius(Qt::BottomLeftCorner); }
470 void setBottomLeftRadius(qreal radius) { setCornerRadius(Qt::BottomLeftCorner, radius); }
471 void resetBottomLeftRadius() { resetCornerRadius(Qt::BottomLeftCorner); }
472
473 qreal bottomRightRadius() const { return cornerRadius(Qt::BottomRightCorner); }
474 void setBottomRightRadius(qreal radius) { setCornerRadius(Qt::BottomRightCorner, radius); }
475 void resetBottomRightRadius() { resetCornerRadius(Qt::BottomRightCorner); }
476
477 qreal cornerRadius(Qt::Corner corner) const;
478 void setCornerRadius(Qt::Corner corner, qreal newCornerRadius);
479 void resetCornerRadius(Qt::Corner corner);
480
481 bool hasBevel() const;
482 void setBevel(bool bevel);
484 bool hasTopLeftBevel() const { return cornerBevel(Qt::TopLeftCorner); }
485 void setTopLeftBevel(bool bevel) { setCornerBevel(Qt::TopLeftCorner, bevel); }
486 void resetTopLeftBevel() { resetCornerBevel(Qt::TopLeftCorner); }
488 bool hasTopRightBevel() const { return cornerBevel(Qt::TopRightCorner); }
489 void setTopRightBevel(bool bevel) { setCornerBevel(Qt::TopRightCorner, bevel); }
490 void resetTopRightBevel() { resetCornerBevel(Qt::TopRightCorner); }
492 bool hasBottomLeftBevel() const { return cornerBevel(Qt::BottomLeftCorner); }
493 void setBottomLeftBevel(bool bevel) { setCornerBevel(Qt::BottomLeftCorner, bevel); }
494 void resetBottomLeftBevel() { resetCornerBevel(Qt::BottomLeftCorner); }
495
496 bool hasBottomRightBevel() const { return cornerBevel(Qt::BottomRightCorner); }
497 void setBottomRightBevel(bool bevel) { setCornerBevel(Qt::BottomRightCorner, bevel); }
498 void resetBottomRightBevel() { resetCornerBevel(Qt::BottomRightCorner); }
499
500 bool cornerBevel(Qt::Corner corner) const;
501 void setCornerBevel(Qt::Corner corner, bool newCornerBevel);
502 void resetCornerBevel(Qt::Corner corner);
503
504 CornerShape cornerShape() const;
505 void setCornerShape(CornerShape shape);
507 CornerShape topLeftCornerShape() const { return cornerShape(Qt::TopLeftCorner); }
508 void setTopLeftCornerShape(CornerShape shape) { setCornerShape(Qt::TopLeftCorner, shape); }
509 void resetTopLeftCornerShape() { resetCornerShape(Qt::TopLeftCorner); }
510
511 CornerShape topRightCornerShape() const { return cornerShape(Qt::TopRightCorner); }
512 void setTopRightCornerShape(CornerShape shape) { setCornerShape(Qt::TopRightCorner, shape); }
513 void resetTopRightCornerShape() { resetCornerShape(Qt::TopRightCorner); }
514
515 CornerShape bottomLeftCornerShape() const { return cornerShape(Qt::BottomLeftCorner); }
516 void setBottomLeftCornerShape(CornerShape shape)
517 {
518 setCornerShape(Qt::BottomLeftCorner, shape);
519 }
520 void resetBottomLeftCornerShape() { resetCornerShape(Qt::BottomLeftCorner); }
521
522 CornerShape bottomRightCornerShape() const { return cornerShape(Qt::BottomRightCorner); }
523 void setBottomRightCornerShape(CornerShape shape)
524 {
525 setCornerShape(Qt::BottomRightCorner, shape);
526 }
527 void resetBottomRightCornerShape() { resetCornerShape(Qt::BottomRightCorner); }
528
529 CornerShape cornerShape(Qt::Corner corner) const;
530 void setCornerShape(Qt::Corner corner, CornerShape newCornerShape);
531 void resetCornerShape(Qt::Corner corner);
533 void addToPath(QPainterPath &path, const QQuickPathData &) override;
535Q_SIGNALS:
536 void widthChanged();
537 void heightChanged();
538 void strokeAdjustmentChanged();
539 void radiusChanged();
540 void topLeftRadiusChanged();
541 void topRightRadiusChanged();
542 void bottomLeftRadiusChanged();
543 void bottomRightRadiusChanged();
544 Q_REVISION(6, 10) void bevelChanged();
545 Q_REVISION(6, 10) void topLeftBevelChanged();
546 Q_REVISION(6, 10) void topRightBevelChanged();
547 Q_REVISION(6, 10) void bottomLeftBevelChanged();
548 Q_REVISION(6, 10) void bottomRightBevelChanged();
549 Q_REVISION(6, 13) void cornerShapeChanged();
550 Q_REVISION(6, 13) void topLeftCornerShapeChanged();
551 Q_REVISION(6, 13) void topRightCornerShapeChanged();
552 Q_REVISION(6, 13) void bottomLeftCornerShapeChanged();
553 Q_REVISION(6, 13) void bottomRightCornerShapeChanged();
554
555private:
556 void emitCornerRadiusChanged(Qt::Corner corner);
557 void emitCornerShapeChanged(Qt::Corner corner, bool oldBevel);
558
559 qreal _width = 0;
560 qreal _height = 0;
561 qreal _strokeAdjustment = 0;
562 struct ExtraData
564 qreal radius = 0;
565 CornerShape shape = Rounded;
567 struct IndividualCornerData
568 {
569 IndividualCornerData() : shape(Rounded), isRadiusSet(0), isShapeSet(0) { }
570 qreal radius = 0;
571 unsigned shape : 4;
572 unsigned isRadiusSet : 1;
573 unsigned isShapeSet : 1;
574 };
575
576 IndividualCornerData cornerData[4];
577 inline bool isRadiusSet(Qt::Corner corner) {
578 return cornerData[corner].isRadiusSet;
579 };
580 inline bool isShapeSet(Qt::Corner corner)
581 {
582 return cornerData[corner].isShapeSet;
583 };
584 };
585 QLazilyAllocated<ExtraData> _extra;
586};
587
588class Q_QUICK_EXPORT QQuickPathPercent : public QQuickPathElement
589{
590 Q_OBJECT
591 Q_PROPERTY(qreal value READ value WRITE setValue NOTIFY valueChanged)
592 QML_NAMED_ELEMENT(PathPercent)
593 QML_ADDED_IN_VERSION(2, 0)
594public:
595 QQuickPathPercent(QObject *parent=nullptr) : QQuickPathElement(parent) {}
596
597 qreal value() const;
598 void setValue(qreal value);
599
600Q_SIGNALS:
601 void valueChanged();
602
603private:
604 qreal _value = 0;
605};
606
607class Q_QUICK_EXPORT QQuickPathPolyline : public QQuickCurve
608{
609 Q_OBJECT
610 Q_PROPERTY(QPointF start READ start NOTIFY startChanged)
611 Q_PROPERTY(QVariant path READ path WRITE setPath NOTIFY pathChanged)
612 QML_NAMED_ELEMENT(PathPolyline)
613 QML_ADDED_IN_VERSION(2, 14)
614public:
615 QQuickPathPolyline(QObject *parent=nullptr);
616
617 QVariant path() const;
618 void setPath(const QVariant &path);
619 void setPath(const QList<QPointF> &path);
620 QPointF start() const;
621 void addToPath(QPainterPath &path, const QQuickPathData &data) override;
622
623Q_SIGNALS:
624 void pathChanged();
625 void startChanged();
626
627private:
628 QList<QPointF> m_path;
629};
630
631class Q_QUICK_EXPORT QQuickPathMultiline : public QQuickCurve
632{
633 Q_OBJECT
634 Q_PROPERTY(QPointF start READ start NOTIFY startChanged)
635 Q_PROPERTY(QVariant paths READ paths WRITE setPaths NOTIFY pathsChanged)
636 QML_NAMED_ELEMENT(PathMultiline)
637 QML_ADDED_IN_VERSION(2, 14)
638public:
639 QQuickPathMultiline(QObject *parent=nullptr);
640
641 QVariant paths() const;
642 void setPaths(const QVariant &paths);
643 void setPaths(const QList<QList<QPointF>> &paths);
644 QPointF start() const;
645 void addToPath(QPainterPath &path, const QQuickPathData &) override;
646
647Q_SIGNALS:
648 void pathsChanged();
649 void startChanged();
650
651private:
652 QPointF absolute(const QPointF &relative) const;
653
654 QList<QList<QPointF>> m_paths;
655};
656
667
668class QQuickPathPrivate;
669class Q_QUICK_EXPORT QQuickPath : public QObject, public QQmlParserStatus
670{
671 Q_OBJECT
672
673 Q_INTERFACES(QQmlParserStatus)
674 Q_PROPERTY(QQmlListProperty<QQuickPathElement> pathElements READ pathElements)
675 Q_PROPERTY(qreal startX READ startX WRITE setStartX NOTIFY startXChanged)
676 Q_PROPERTY(qreal startY READ startY WRITE setStartY NOTIFY startYChanged)
677 Q_PROPERTY(bool closed READ isClosed NOTIFY changed)
678 Q_PROPERTY(bool simplify READ simplify WRITE setSimplify NOTIFY simplifyChanged REVISION(6, 6) FINAL)
679 Q_PROPERTY(QSizeF scale READ scale WRITE setScale NOTIFY scaleChanged VIRTUAL REVISION(2, 14))
680 Q_PROPERTY(bool asynchronous READ isAsynchronous WRITE setAsynchronous NOTIFY asynchronousChanged REVISION(6, 9))
681 Q_CLASSINFO("DefaultProperty", "pathElements")
682 QML_NAMED_ELEMENT(Path)
683 QML_ADDED_IN_VERSION(2, 0)
684public:
685 QQuickPath(QObject *parent=nullptr);
686 ~QQuickPath() override;
687
688 QQmlListProperty<QQuickPathElement> pathElements();
689
690 qreal startX() const;
691 void setStartX(qreal x);
692 bool hasStartX() const;
693
694 qreal startY() const;
695 void setStartY(qreal y);
696 bool hasStartY() const;
697
698 bool isClosed() const;
699
700 QPainterPath path() const;
701 void setPath(const QPainterPath &path);
702
703 QStringList attributes() const;
704 qreal attributeAt(const QString &, qreal) const;
705 Q_REVISION(2, 14) Q_INVOKABLE QPointF pointAtPercent(qreal t) const;
706 QPointF sequentialPointAt(qreal p, qreal *angle = nullptr) const;
707 void invalidateSequentialHistory() const;
708
709 QSizeF scale() const;
710 void setScale(const QSizeF &scale);
711
712 bool simplify() const;
713 void setSimplify(bool s);
714
715 bool isAsynchronous() const;
716 void setAsynchronous(bool a);
717
718public Q_SLOTS:
719 // This is public in order to allow types from DesignHelpers to create and add path
720 // elements and process the path once at the end rather than after each element.
721 void processPath();
722
723Q_SIGNALS:
724 void changed();
725 void startXChanged();
726 void startYChanged();
727 Q_REVISION(6, 6) void simplifyChanged();
728 Q_REVISION(2, 14) void scaleChanged();
729 Q_REVISION(6, 9) void asynchronousChanged();
730
731protected:
732 QQuickPath(QQuickPathPrivate &dd, QObject *parent = nullptr);
733 void componentComplete() override;
734 void classBegin() override;
735 void disconnectPathElements();
736 void connectPathElements();
737 void gatherAttributes();
738
739 // pathElements property
740 static QQuickPathElement *pathElements_at(QQmlListProperty<QQuickPathElement> *, qsizetype);
741 static void pathElements_append(QQmlListProperty<QQuickPathElement> *, QQuickPathElement *);
742 static qsizetype pathElements_count(QQmlListProperty<QQuickPathElement> *);
743 static void pathElements_clear(QQmlListProperty<QQuickPathElement> *);
744 static void pathElements_replace(
745 QQmlListProperty<QQuickPathElement> *, qsizetype, QQuickPathElement *);
746 static void pathElements_removeLast(QQmlListProperty<QQuickPathElement> *);
747
748private:
749 struct AttributePoint {
750 AttributePoint() {}
751 AttributePoint(const AttributePoint &other)
752 : percent(other.percent), scale(other.scale), origpercent(other.origpercent), values(other.values) {}
753 AttributePoint &operator=(const AttributePoint &other) {
754 percent = other.percent; scale = other.scale; origpercent = other.origpercent; values = other.values; return *this;
755 }
756 qreal percent = 0; //massaged percent along the painter path
757 qreal scale = 1;
758 qreal origpercent = 0; //'real' percent along the painter path
759 QHash<QString, qreal> values;
760 };
761
762 void doProcessPath();
763 void interpolate(int idx, const QString &name, qreal value);
764 void endpoint(const QString &name);
765 void createPointCache() const;
766
767 static void interpolate(QList<AttributePoint> &points, int idx, const QString &name, qreal value);
768 static void endpoint(QList<AttributePoint> &attributePoints, const QString &name);
769 static QPointF forwardsPointAt(const QPainterPath &path, const qreal &pathLength, const QList<AttributePoint> &attributePoints, QQuickCachedBezier &prevBez, qreal p, qreal *angle = nullptr);
770 static QPointF backwardsPointAt(const QPainterPath &path, const qreal &pathLength, const QList<AttributePoint> &attributePoints, QQuickCachedBezier &prevBez, qreal p, qreal *angle = nullptr);
771
772private:
773 Q_DISABLE_COPY(QQuickPath)
774 Q_DECLARE_PRIVATE(QQuickPath)
775 friend class QQuickPathAnimationUpdater;
776
777public:
778 QPainterPath createPath(const QPointF &startPoint, const QPointF &endPoint, const QStringList &attributes, qreal &pathLength, QList<AttributePoint> &attributePoints, bool *closed = nullptr);
779 QPainterPath createShapePath(const QPointF &startPoint, const QPointF &endPoint, qreal &pathLength, bool *closed = nullptr);
780 static QPointF sequentialPointAt(const QPainterPath &path, const qreal &pathLength, const QList<AttributePoint> &attributePoints, QQuickCachedBezier &prevBez, qreal p, qreal *angle = nullptr);
781};
782
783class Q_QUICK_EXPORT QQuickPathText : public QQuickPathElement
784{
785 Q_OBJECT
786 Q_PROPERTY(qreal x READ x WRITE setX NOTIFY xChanged)
787 Q_PROPERTY(qreal y READ y WRITE setY NOTIFY yChanged)
788 Q_PROPERTY(qreal width READ width NOTIFY changed)
789 Q_PROPERTY(qreal height READ height NOTIFY changed)
790 Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
791 Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged)
792 QML_NAMED_ELEMENT(PathText)
793 QML_ADDED_IN_VERSION(2, 15)
794public:
795 QQuickPathText(QObject *parent=nullptr) : QQuickPathElement(parent)
796 {
797 connect(this, &QQuickPathText::xChanged, this, &QQuickPathElement::changed);
798 connect(this, &QQuickPathText::yChanged, this, &QQuickPathElement::changed);
799 connect(this, &QQuickPathText::textChanged, this, &QQuickPathElement::changed);
800 connect(this, &QQuickPathText::fontChanged, this, &QQuickPathElement::changed);
801
802 connect(this, &QQuickPathElement::changed, this, &QQuickPathText::invalidate);
803 }
804
805 void addToPath(QPainterPath &path);
806
807 qreal x() const { return _x; }
808 qreal y() const { return _y; }
809 QString text() const { return _text; }
810 QFont font() const { return _font; }
811
812 void setX(qreal x)
813 {
814 if (qFuzzyCompare(_x, x))
815 return;
816
817 _x = x;
818 Q_EMIT xChanged();
819 }
820
821 void setY(qreal y)
822 {
823 if (qFuzzyCompare(_y, y))
824 return;
825
826 _y = y;
827 Q_EMIT yChanged();
828 }
829
830 void setText(const QString &text)
831 {
832 if (text == _text)
833 return;
834
835 _text = text;
836 Q_EMIT textChanged();
837 }
838
839 void setFont(const QFont &font)
840 {
841 if (font == _font)
842 return;
843
844 _font = font;
845 Q_EMIT fontChanged();
846 }
847
848 qreal width() const
849 {
850 updatePath();
851 return _path.boundingRect().width();
852 }
853
854 qreal height() const
855 {
856 updatePath();
857 return _path.boundingRect().height();
858 }
859
860Q_SIGNALS:
861 void xChanged();
862 void yChanged();
863 void textChanged();
864 void fontChanged();
865
866private Q_SLOTS:
867 void invalidate()
868 {
869 _path.clear();
870 }
871
872private:
873 void updatePath() const;
874
875 QString _text;
876 qreal _x = qreal(0.0);
877 qreal _y = qreal(0.0);
878 QFont _font;
879
880 mutable QPainterPath _path;
881};
882
883QT_END_NAMESPACE
884
885#endif // QQUICKPATH_H
\qmltype PathAttribute \nativetype QQuickPathAttribute \inqmlmodule QtQuick
\qmltype PathQuad \nativetype QQuickPathQuad \inqmlmodule QtQuick
Combined button and popup list for selecting options.
QDebug operator<<(QDebug debug, const QQuickCurve *curve)
static qreal slopeAt(qreal t, qreal a, qreal b, qreal c, qreal d)
static QQuickPathPrivate * privatePath(QObject *object)
static int segmentCount(const QPainterPath &path, qreal pathLength)
QPointF positionForCurve(const QQuickPathData &data, const QPointF &prevPoint)
\qmltype PathLine \nativetype QQuickPathLine \inqmlmodule QtQuick
QPointF previousPathPosition(const QPainterPath &path)
\qmltype PathCurve \nativetype QQuickPathCatmullRomCurve \inqmlmodule QtQuick
static QBezier nextBezier(const QPainterPath &path, int *current, qreal *bezLength, bool reverse=false)
static void scalePath(QPainterPath &path, const QSizeF &scale)
QT_REQUIRE_CONFIG(quick_path)
QList< QQuickCurve * > curves