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
427 QML_NAMED_ELEMENT(PathRectangle)
428 QML_ADDED_IN_VERSION(6, 8)
429public:
430 QQuickPathRectangle(QObject *parent = nullptr) : QQuickCurve(parent) {}
431
432 qreal width() const;
433 void setWidth(qreal width);
434
435 qreal height() const;
436 void setHeight(qreal height);
437
438 qreal strokeAdjustment() const;
439 void setStrokeAdjustment(qreal newStrokeAdjustment);
440
441 qreal radius() const;
442 void setRadius(qreal newRadius);
443
444 qreal topLeftRadius() const { return cornerRadius(Qt::TopLeftCorner); }
445 void setTopLeftRadius(qreal radius) { setCornerRadius(Qt::TopLeftCorner, radius); }
446 void resetTopLeftRadius() { resetCornerRadius(Qt::TopLeftCorner); }
447
448 qreal topRightRadius() const { return cornerRadius(Qt::TopRightCorner); }
449 void setTopRightRadius(qreal radius) { setCornerRadius(Qt::TopRightCorner, radius); }
450 void resetTopRightRadius() { resetCornerRadius(Qt::TopRightCorner); }
451
452 qreal bottomLeftRadius() const { return cornerRadius(Qt::BottomLeftCorner); }
453 void setBottomLeftRadius(qreal radius) { setCornerRadius(Qt::BottomLeftCorner, radius); }
454 void resetBottomLeftRadius() { resetCornerRadius(Qt::BottomLeftCorner); }
455
456 qreal bottomRightRadius() const { return cornerRadius(Qt::BottomRightCorner); }
457 void setBottomRightRadius(qreal radius) { setCornerRadius(Qt::BottomRightCorner, radius); }
458 void resetBottomRightRadius() { resetCornerRadius(Qt::BottomRightCorner); }
459
460 qreal cornerRadius(Qt::Corner corner) const;
461 void setCornerRadius(Qt::Corner corner, qreal newCornerRadius);
462 void resetCornerRadius(Qt::Corner corner);
463
464 bool hasBevel() const;
465 void setBevel(bool bevel);
466
467 bool hasTopLeftBevel() const { return cornerBevel(Qt::TopLeftCorner); }
468 void setTopLeftBevel(bool bevel) { setCornerBevel(Qt::TopLeftCorner, bevel); }
469 void resetTopLeftBevel() { resetCornerBevel(Qt::TopLeftCorner); }
470
471 bool hasTopRightBevel() const { return cornerBevel(Qt::TopRightCorner); }
472 void setTopRightBevel(bool bevel) { setCornerBevel(Qt::TopRightCorner, bevel); }
473 void resetTopRightBevel() { resetCornerBevel(Qt::TopRightCorner); }
474
475 bool hasBottomLeftBevel() const { return cornerBevel(Qt::BottomLeftCorner); }
476 void setBottomLeftBevel(bool bevel) { setCornerBevel(Qt::BottomLeftCorner, bevel); }
477 void resetBottomLeftBevel() { resetCornerBevel(Qt::BottomLeftCorner); }
478
479 bool hasBottomRightBevel() const { return cornerBevel(Qt::BottomRightCorner); }
480 void setBottomRightBevel(bool bevel) { setCornerBevel(Qt::BottomRightCorner, bevel); }
481 void resetBottomRightBevel() { resetCornerBevel(Qt::BottomRightCorner); }
482
483 bool cornerBevel(Qt::Corner corner) const;
484 void setCornerBevel(Qt::Corner corner, bool newCornerBevel);
485 void resetCornerBevel(Qt::Corner corner);
486
487 void addToPath(QPainterPath &path, const QQuickPathData &) override;
488
489Q_SIGNALS:
490 void widthChanged();
491 void heightChanged();
492 void strokeAdjustmentChanged();
493 void radiusChanged();
494 void topLeftRadiusChanged();
495 void topRightRadiusChanged();
496 void bottomLeftRadiusChanged();
497 void bottomRightRadiusChanged();
498 Q_REVISION(6, 10) void bevelChanged();
499 Q_REVISION(6, 10) void topLeftBevelChanged();
500 Q_REVISION(6, 10) void topRightBevelChanged();
501 Q_REVISION(6, 10) void bottomLeftBevelChanged();
502 Q_REVISION(6, 10) void bottomRightBevelChanged();
503
504private:
505 void emitCornerRadiusChanged(Qt::Corner corner);
506 void emitCornerBevelChanged(Qt::Corner corner);
507
508 qreal _width = 0;
509 qreal _height = 0;
510 qreal _strokeAdjustment = 0;
511 struct ExtraData
512 {
513 ExtraData() {
514 std::fill_n(cornerRadii, 4, 0);
515 cornerProperties = 0;
516 }
517 qreal radius = 0;
518 qreal cornerRadii[4];
519 unsigned cornerProperties :9;
520 inline bool isRadiusSet(Qt::Corner corner) {
521 return cornerProperties & (1 << corner);
522 };
523 inline bool isBevelSet(Qt::Corner corner) {
524 return cornerProperties & (1 << (corner + 4));
525 };
526 };
527 QLazilyAllocated<ExtraData> _extra;
528};
529
530class Q_QUICK_EXPORT QQuickPathPercent : public QQuickPathElement
531{
532 Q_OBJECT
533 Q_PROPERTY(qreal value READ value WRITE setValue NOTIFY valueChanged)
534 QML_NAMED_ELEMENT(PathPercent)
535 QML_ADDED_IN_VERSION(2, 0)
536public:
537 QQuickPathPercent(QObject *parent=nullptr) : QQuickPathElement(parent) {}
538
539 qreal value() const;
540 void setValue(qreal value);
541
542Q_SIGNALS:
543 void valueChanged();
544
545private:
546 qreal _value = 0;
547};
548
549class Q_QUICK_EXPORT QQuickPathPolyline : public QQuickCurve
550{
551 Q_OBJECT
552 Q_PROPERTY(QPointF start READ start NOTIFY startChanged)
553 Q_PROPERTY(QVariant path READ path WRITE setPath NOTIFY pathChanged)
554 QML_NAMED_ELEMENT(PathPolyline)
555 QML_ADDED_IN_VERSION(2, 14)
556public:
557 QQuickPathPolyline(QObject *parent=nullptr);
558
559 QVariant path() const;
560 void setPath(const QVariant &path);
561 void setPath(const QVector<QPointF> &path);
562 QPointF start() const;
563 void addToPath(QPainterPath &path, const QQuickPathData &data) override;
564
565Q_SIGNALS:
566 void pathChanged();
567 void startChanged();
568
569private:
570 QVector<QPointF> m_path;
571};
572
573class Q_QUICK_EXPORT QQuickPathMultiline : public QQuickCurve
574{
575 Q_OBJECT
576 Q_PROPERTY(QPointF start READ start NOTIFY startChanged)
577 Q_PROPERTY(QVariant paths READ paths WRITE setPaths NOTIFY pathsChanged)
578 QML_NAMED_ELEMENT(PathMultiline)
579 QML_ADDED_IN_VERSION(2, 14)
580public:
581 QQuickPathMultiline(QObject *parent=nullptr);
582
583 QVariant paths() const;
584 void setPaths(const QVariant &paths);
585 void setPaths(const QVector<QVector<QPointF>> &paths);
586 QPointF start() const;
587 void addToPath(QPainterPath &path, const QQuickPathData &) override;
588
589Q_SIGNALS:
590 void pathsChanged();
591 void startChanged();
592
593private:
594 QPointF absolute(const QPointF &relative) const;
595
596 QVector<QVector<QPointF>> m_paths;
597};
598
609
610class QQuickPathPrivate;
611class Q_QUICK_EXPORT QQuickPath : public QObject, public QQmlParserStatus
612{
613 Q_OBJECT
614
615 Q_INTERFACES(QQmlParserStatus)
616 Q_PROPERTY(QQmlListProperty<QQuickPathElement> pathElements READ pathElements)
617 Q_PROPERTY(qreal startX READ startX WRITE setStartX NOTIFY startXChanged)
618 Q_PROPERTY(qreal startY READ startY WRITE setStartY NOTIFY startYChanged)
619 Q_PROPERTY(bool closed READ isClosed NOTIFY changed)
620 Q_PROPERTY(bool simplify READ simplify WRITE setSimplify NOTIFY simplifyChanged REVISION(6, 6) FINAL)
621 Q_PROPERTY(QSizeF scale READ scale WRITE setScale NOTIFY scaleChanged REVISION(2, 14))
622 Q_PROPERTY(bool asynchronous READ isAsynchronous WRITE setAsynchronous NOTIFY asynchronousChanged REVISION(6, 9))
623 Q_CLASSINFO("DefaultProperty", "pathElements")
624 QML_NAMED_ELEMENT(Path)
625 QML_ADDED_IN_VERSION(2, 0)
626public:
627 QQuickPath(QObject *parent=nullptr);
628 ~QQuickPath() override;
629
630 QQmlListProperty<QQuickPathElement> pathElements();
631
632 qreal startX() const;
633 void setStartX(qreal x);
634 bool hasStartX() const;
635
636 qreal startY() const;
637 void setStartY(qreal y);
638 bool hasStartY() const;
639
640 bool isClosed() const;
641
642 QPainterPath path() const;
643 void setPath(const QPainterPath &path);
644
645 QStringList attributes() const;
646 qreal attributeAt(const QString &, qreal) const;
647 Q_REVISION(2, 14) Q_INVOKABLE QPointF pointAtPercent(qreal t) const;
648 QPointF sequentialPointAt(qreal p, qreal *angle = nullptr) const;
649 void invalidateSequentialHistory() const;
650
651 QSizeF scale() const;
652 void setScale(const QSizeF &scale);
653
654 bool simplify() const;
655 void setSimplify(bool s);
656
657 bool isAsynchronous() const;
658 void setAsynchronous(bool a);
659
660public Q_SLOTS:
661 // This is public in order to allow types from DesignHelpers to create and add path
662 // elements and process the path once at the end rather than after each element.
663 void processPath();
664
665Q_SIGNALS:
666 void changed();
667 void startXChanged();
668 void startYChanged();
669 Q_REVISION(6, 6) void simplifyChanged();
670 Q_REVISION(2, 14) void scaleChanged();
671 Q_REVISION(6, 9) void asynchronousChanged();
672
673protected:
674 QQuickPath(QQuickPathPrivate &dd, QObject *parent = nullptr);
675 void componentComplete() override;
676 void classBegin() override;
677 void disconnectPathElements();
678 void connectPathElements();
679 void gatherAttributes();
680
681 // pathElements property
682 static QQuickPathElement *pathElements_at(QQmlListProperty<QQuickPathElement> *, qsizetype);
683 static void pathElements_append(QQmlListProperty<QQuickPathElement> *, QQuickPathElement *);
684 static qsizetype pathElements_count(QQmlListProperty<QQuickPathElement> *);
685 static void pathElements_clear(QQmlListProperty<QQuickPathElement> *);
686 static void pathElements_replace(
687 QQmlListProperty<QQuickPathElement> *, qsizetype, QQuickPathElement *);
688 static void pathElements_removeLast(QQmlListProperty<QQuickPathElement> *);
689
690private:
691 struct AttributePoint {
692 AttributePoint() {}
693 AttributePoint(const AttributePoint &other)
694 : percent(other.percent), scale(other.scale), origpercent(other.origpercent), values(other.values) {}
695 AttributePoint &operator=(const AttributePoint &other) {
696 percent = other.percent; scale = other.scale; origpercent = other.origpercent; values = other.values; return *this;
697 }
698 qreal percent = 0; //massaged percent along the painter path
699 qreal scale = 1;
700 qreal origpercent = 0; //'real' percent along the painter path
701 QHash<QString, qreal> values;
702 };
703
704 void doProcessPath();
705 void interpolate(int idx, const QString &name, qreal value);
706 void endpoint(const QString &name);
707 void createPointCache() const;
708
709 static void interpolate(QList<AttributePoint> &points, int idx, const QString &name, qreal value);
710 static void endpoint(QList<AttributePoint> &attributePoints, const QString &name);
711 static QPointF forwardsPointAt(const QPainterPath &path, const qreal &pathLength, const QList<AttributePoint> &attributePoints, QQuickCachedBezier &prevBez, qreal p, qreal *angle = nullptr);
712 static QPointF backwardsPointAt(const QPainterPath &path, const qreal &pathLength, const QList<AttributePoint> &attributePoints, QQuickCachedBezier &prevBez, qreal p, qreal *angle = nullptr);
713
714private:
715 Q_DISABLE_COPY(QQuickPath)
716 Q_DECLARE_PRIVATE(QQuickPath)
717 friend class QQuickPathAnimationUpdater;
718
719public:
720 QPainterPath createPath(const QPointF &startPoint, const QPointF &endPoint, const QStringList &attributes, qreal &pathLength, QList<AttributePoint> &attributePoints, bool *closed = nullptr);
721 QPainterPath createShapePath(const QPointF &startPoint, const QPointF &endPoint, qreal &pathLength, bool *closed = nullptr);
722 static QPointF sequentialPointAt(const QPainterPath &path, const qreal &pathLength, const QList<AttributePoint> &attributePoints, QQuickCachedBezier &prevBez, qreal p, qreal *angle = nullptr);
723};
724
725class Q_QUICK_EXPORT QQuickPathText : public QQuickPathElement
726{
727 Q_OBJECT
728 Q_PROPERTY(qreal x READ x WRITE setX NOTIFY xChanged)
729 Q_PROPERTY(qreal y READ y WRITE setY NOTIFY yChanged)
730 Q_PROPERTY(qreal width READ width NOTIFY changed)
731 Q_PROPERTY(qreal height READ height NOTIFY changed)
732 Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
733 Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged)
734 QML_NAMED_ELEMENT(PathText)
735 QML_ADDED_IN_VERSION(2, 15)
736public:
737 QQuickPathText(QObject *parent=nullptr) : QQuickPathElement(parent)
738 {
739 connect(this, &QQuickPathText::xChanged, this, &QQuickPathElement::changed);
740 connect(this, &QQuickPathText::yChanged, this, &QQuickPathElement::changed);
741 connect(this, &QQuickPathText::textChanged, this, &QQuickPathElement::changed);
742 connect(this, &QQuickPathText::fontChanged, this, &QQuickPathElement::changed);
743
744 connect(this, &QQuickPathElement::changed, this, &QQuickPathText::invalidate);
745 }
746
747 void addToPath(QPainterPath &path);
748
749 qreal x() const { return _x; }
750 qreal y() const { return _y; }
751 QString text() const { return _text; }
752 QFont font() const { return _font; }
753
754 void setX(qreal x)
755 {
756 if (qFuzzyCompare(_x, x))
757 return;
758
759 _x = x;
760 Q_EMIT xChanged();
761 }
762
763 void setY(qreal y)
764 {
765 if (qFuzzyCompare(_y, y))
766 return;
767
768 _y = y;
769 Q_EMIT yChanged();
770 }
771
772 void setText(const QString &text)
773 {
774 if (text == _text)
775 return;
776
777 _text = text;
778 Q_EMIT textChanged();
779 }
780
781 void setFont(const QFont &font)
782 {
783 if (font == _font)
784 return;
785
786 _font = font;
787 Q_EMIT fontChanged();
788 }
789
790 qreal width() const
791 {
792 updatePath();
793 return _path.boundingRect().width();
794 }
795
796 qreal height() const
797 {
798 updatePath();
799 return _path.boundingRect().height();
800 }
801
802Q_SIGNALS:
803 void xChanged();
804 void yChanged();
805 void textChanged();
806 void fontChanged();
807
808private Q_SLOTS:
809 void invalidate()
810 {
811 _path.clear();
812 }
813
814private:
815 void updatePath() const;
816
817 QString _text;
818 qreal _x = qreal(0.0);
819 qreal _y = qreal(0.0);
820 QFont _font;
821
822 mutable QPainterPath _path;
823};
824
825QT_END_NAMESPACE
826
827#endif // QQUICKPATH_H
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