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 QQUICKPATH_H |
5 | #define QQUICKPATH_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 <private/qtquickglobal_p.h> |
19 | |
20 | QT_REQUIRE_CONFIG(quick_path); |
21 | |
22 | #include <qqml.h> |
23 | |
24 | #include <private/qqmlnullablevalue_p.h> |
25 | #include <private/qbezier_p.h> |
26 | #include <private/qtquickglobal_p.h> |
27 | |
28 | #include <QtCore/QObject> |
29 | #include <QtCore/QHash> |
30 | #include <QtGui/QPainterPath> |
31 | #include <QtGui/QFont> |
32 | |
33 | QT_BEGIN_NAMESPACE |
34 | |
35 | class QQuickCurve; |
36 | struct QQuickPathData |
37 | { |
38 | int index; |
39 | QPointF endPoint; |
40 | QList<QQuickCurve*> curves; |
41 | }; |
42 | |
43 | class Q_QUICK_PRIVATE_EXPORT QQuickPathElement : public QObject |
44 | { |
45 | Q_OBJECT |
46 | QML_ANONYMOUS |
47 | QML_ADDED_IN_VERSION(2, 0) |
48 | public: |
49 | QQuickPathElement(QObject *parent=nullptr) : QObject(parent) {} |
50 | Q_SIGNALS: |
51 | void changed(); |
52 | }; |
53 | |
54 | class Q_QUICK_PRIVATE_EXPORT QQuickPathAttribute : public QQuickPathElement |
55 | { |
56 | Q_OBJECT |
57 | |
58 | Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged FINAL) |
59 | Q_PROPERTY(qreal value READ value WRITE setValue NOTIFY valueChanged FINAL) |
60 | QML_NAMED_ELEMENT(PathAttribute) |
61 | QML_ADDED_IN_VERSION(2, 0) |
62 | public: |
63 | QQuickPathAttribute(QObject *parent=nullptr) : QQuickPathElement(parent) {} |
64 | |
65 | |
66 | QString name() const; |
67 | void setName(const QString &name); |
68 | |
69 | qreal value() const; |
70 | void setValue(qreal value); |
71 | |
72 | Q_SIGNALS: |
73 | void nameChanged(); |
74 | void valueChanged(); |
75 | |
76 | private: |
77 | QString _name; |
78 | qreal _value = 0; |
79 | }; |
80 | |
81 | class Q_QUICK_PRIVATE_EXPORT QQuickCurve : public QQuickPathElement |
82 | { |
83 | Q_OBJECT |
84 | |
85 | Q_PROPERTY(qreal x READ x WRITE setX NOTIFY xChanged FINAL) |
86 | Q_PROPERTY(qreal y READ y WRITE setY NOTIFY yChanged FINAL) |
87 | Q_PROPERTY(qreal relativeX READ relativeX WRITE setRelativeX NOTIFY relativeXChanged FINAL) |
88 | Q_PROPERTY(qreal relativeY READ relativeY WRITE setRelativeY NOTIFY relativeYChanged FINAL) |
89 | QML_ANONYMOUS |
90 | QML_ADDED_IN_VERSION(2, 0) |
91 | public: |
92 | QQuickCurve(QObject *parent=nullptr) : QQuickPathElement(parent) {} |
93 | |
94 | qreal x() const; |
95 | void setX(qreal x); |
96 | bool hasX(); |
97 | |
98 | qreal y() const; |
99 | void setY(qreal y); |
100 | bool hasY(); |
101 | |
102 | qreal relativeX() const; |
103 | void setRelativeX(qreal x); |
104 | bool hasRelativeX(); |
105 | |
106 | qreal relativeY() const; |
107 | void setRelativeY(qreal y); |
108 | bool hasRelativeY(); |
109 | |
110 | virtual void addToPath(QPainterPath &, const QQuickPathData &) {} |
111 | |
112 | Q_SIGNALS: |
113 | void xChanged(); |
114 | void yChanged(); |
115 | void relativeXChanged(); |
116 | void relativeYChanged(); |
117 | |
118 | private: |
119 | QQmlNullableValue<qreal> _x; |
120 | QQmlNullableValue<qreal> _y; |
121 | QQmlNullableValue<qreal> _relativeX; |
122 | QQmlNullableValue<qreal> _relativeY; |
123 | }; |
124 | |
125 | class Q_QUICK_PRIVATE_EXPORT QQuickPathLine : public QQuickCurve |
126 | { |
127 | Q_OBJECT |
128 | QML_NAMED_ELEMENT(PathLine) |
129 | QML_ADDED_IN_VERSION(2, 0) |
130 | public: |
131 | QQuickPathLine(QObject *parent=nullptr) : QQuickCurve(parent) {} |
132 | |
133 | void addToPath(QPainterPath &path, const QQuickPathData &) override; |
134 | }; |
135 | |
136 | class Q_QUICK_PRIVATE_EXPORT QQuickPathMove : public QQuickCurve |
137 | { |
138 | Q_OBJECT |
139 | QML_NAMED_ELEMENT(PathMove) |
140 | QML_ADDED_IN_VERSION(2, 9) |
141 | public: |
142 | QQuickPathMove(QObject *parent=nullptr) : QQuickCurve(parent) {} |
143 | |
144 | void addToPath(QPainterPath &path, const QQuickPathData &) override; |
145 | }; |
146 | |
147 | class Q_QUICK_PRIVATE_EXPORT QQuickPathQuad : public QQuickCurve |
148 | { |
149 | Q_OBJECT |
150 | |
151 | Q_PROPERTY(qreal controlX READ controlX WRITE setControlX NOTIFY controlXChanged FINAL) |
152 | Q_PROPERTY(qreal controlY READ controlY WRITE setControlY NOTIFY controlYChanged FINAL) |
153 | Q_PROPERTY(qreal relativeControlX READ relativeControlX WRITE setRelativeControlX NOTIFY relativeControlXChanged FINAL) |
154 | Q_PROPERTY(qreal relativeControlY READ relativeControlY WRITE setRelativeControlY NOTIFY relativeControlYChanged FINAL) |
155 | |
156 | QML_NAMED_ELEMENT(PathQuad) |
157 | QML_ADDED_IN_VERSION(2, 0) |
158 | public: |
159 | QQuickPathQuad(QObject *parent=nullptr) : QQuickCurve(parent) {} |
160 | |
161 | qreal controlX() const; |
162 | void setControlX(qreal x); |
163 | |
164 | qreal controlY() const; |
165 | void setControlY(qreal y); |
166 | |
167 | qreal relativeControlX() const; |
168 | void setRelativeControlX(qreal x); |
169 | bool hasRelativeControlX(); |
170 | |
171 | qreal relativeControlY() const; |
172 | void setRelativeControlY(qreal y); |
173 | bool hasRelativeControlY(); |
174 | |
175 | void addToPath(QPainterPath &path, const QQuickPathData &) override; |
176 | |
177 | Q_SIGNALS: |
178 | void controlXChanged(); |
179 | void controlYChanged(); |
180 | void relativeControlXChanged(); |
181 | void relativeControlYChanged(); |
182 | |
183 | private: |
184 | qreal _controlX = 0; |
185 | qreal _controlY = 0; |
186 | QQmlNullableValue<qreal> _relativeControlX; |
187 | QQmlNullableValue<qreal> _relativeControlY; |
188 | }; |
189 | |
190 | class Q_QUICK_PRIVATE_EXPORT QQuickPathCubic : public QQuickCurve |
191 | { |
192 | Q_OBJECT |
193 | |
194 | Q_PROPERTY(qreal control1X READ control1X WRITE setControl1X NOTIFY control1XChanged FINAL) |
195 | Q_PROPERTY(qreal control1Y READ control1Y WRITE setControl1Y NOTIFY control1YChanged FINAL) |
196 | Q_PROPERTY(qreal control2X READ control2X WRITE setControl2X NOTIFY control2XChanged FINAL) |
197 | Q_PROPERTY(qreal control2Y READ control2Y WRITE setControl2Y NOTIFY control2YChanged FINAL) |
198 | Q_PROPERTY(qreal relativeControl1X READ relativeControl1X WRITE setRelativeControl1X NOTIFY relativeControl1XChanged FINAL) |
199 | Q_PROPERTY(qreal relativeControl1Y READ relativeControl1Y WRITE setRelativeControl1Y NOTIFY relativeControl1YChanged FINAL) |
200 | Q_PROPERTY(qreal relativeControl2X READ relativeControl2X WRITE setRelativeControl2X NOTIFY relativeControl2XChanged FINAL) |
201 | Q_PROPERTY(qreal relativeControl2Y READ relativeControl2Y WRITE setRelativeControl2Y NOTIFY relativeControl2YChanged FINAL) |
202 | QML_NAMED_ELEMENT(PathCubic) |
203 | QML_ADDED_IN_VERSION(2, 0) |
204 | public: |
205 | QQuickPathCubic(QObject *parent=nullptr) : QQuickCurve(parent) {} |
206 | |
207 | qreal control1X() const; |
208 | void setControl1X(qreal x); |
209 | |
210 | qreal control1Y() const; |
211 | void setControl1Y(qreal y); |
212 | |
213 | qreal control2X() const; |
214 | void setControl2X(qreal x); |
215 | |
216 | qreal control2Y() const; |
217 | void setControl2Y(qreal y); |
218 | |
219 | qreal relativeControl1X() const; |
220 | void setRelativeControl1X(qreal x); |
221 | bool hasRelativeControl1X(); |
222 | |
223 | qreal relativeControl1Y() const; |
224 | void setRelativeControl1Y(qreal y); |
225 | bool hasRelativeControl1Y(); |
226 | |
227 | qreal relativeControl2X() const; |
228 | void setRelativeControl2X(qreal x); |
229 | bool hasRelativeControl2X(); |
230 | |
231 | qreal relativeControl2Y() const; |
232 | void setRelativeControl2Y(qreal y); |
233 | bool hasRelativeControl2Y(); |
234 | |
235 | void addToPath(QPainterPath &path, const QQuickPathData &) override; |
236 | |
237 | Q_SIGNALS: |
238 | void control1XChanged(); |
239 | void control1YChanged(); |
240 | void control2XChanged(); |
241 | void control2YChanged(); |
242 | void relativeControl1XChanged(); |
243 | void relativeControl1YChanged(); |
244 | void relativeControl2XChanged(); |
245 | void relativeControl2YChanged(); |
246 | |
247 | private: |
248 | qreal _control1X = 0; |
249 | qreal _control1Y = 0; |
250 | qreal _control2X = 0; |
251 | qreal _control2Y = 0; |
252 | QQmlNullableValue<qreal> _relativeControl1X; |
253 | QQmlNullableValue<qreal> _relativeControl1Y; |
254 | QQmlNullableValue<qreal> _relativeControl2X; |
255 | QQmlNullableValue<qreal> _relativeControl2Y; |
256 | }; |
257 | |
258 | class Q_QUICK_PRIVATE_EXPORT QQuickPathCatmullRomCurve : public QQuickCurve |
259 | { |
260 | Q_OBJECT |
261 | QML_NAMED_ELEMENT(PathCurve) |
262 | QML_ADDED_IN_VERSION(2, 0) |
263 | public: |
264 | QQuickPathCatmullRomCurve(QObject *parent=nullptr) : QQuickCurve(parent) {} |
265 | |
266 | void addToPath(QPainterPath &path, const QQuickPathData &) override; |
267 | }; |
268 | |
269 | class Q_QUICK_PRIVATE_EXPORT QQuickPathArc : public QQuickCurve |
270 | { |
271 | Q_OBJECT |
272 | Q_PROPERTY(qreal radiusX READ radiusX WRITE setRadiusX NOTIFY radiusXChanged FINAL) |
273 | Q_PROPERTY(qreal radiusY READ radiusY WRITE setRadiusY NOTIFY radiusYChanged FINAL) |
274 | Q_PROPERTY(bool useLargeArc READ useLargeArc WRITE setUseLargeArc NOTIFY useLargeArcChanged FINAL) |
275 | Q_PROPERTY(ArcDirection direction READ direction WRITE setDirection NOTIFY directionChanged FINAL) |
276 | Q_PROPERTY(qreal xAxisRotation READ xAxisRotation WRITE setXAxisRotation NOTIFY xAxisRotationChanged REVISION(2, 9) FINAL) |
277 | QML_NAMED_ELEMENT(PathArc) |
278 | QML_ADDED_IN_VERSION(2, 0) |
279 | |
280 | public: |
281 | QQuickPathArc(QObject *parent=nullptr) |
282 | : QQuickCurve(parent) {} |
283 | |
284 | enum ArcDirection { Clockwise, Counterclockwise }; |
285 | Q_ENUM(ArcDirection) |
286 | |
287 | qreal radiusX() const; |
288 | void setRadiusX(qreal); |
289 | |
290 | qreal radiusY() const; |
291 | void setRadiusY(qreal); |
292 | |
293 | bool useLargeArc() const; |
294 | void setUseLargeArc(bool); |
295 | |
296 | ArcDirection direction() const; |
297 | void setDirection(ArcDirection direction); |
298 | |
299 | qreal xAxisRotation() const; |
300 | void setXAxisRotation(qreal rotation); |
301 | |
302 | void addToPath(QPainterPath &path, const QQuickPathData &) override; |
303 | |
304 | Q_SIGNALS: |
305 | void radiusXChanged(); |
306 | void radiusYChanged(); |
307 | void useLargeArcChanged(); |
308 | void directionChanged(); |
309 | Q_REVISION(2, 9) void xAxisRotationChanged(); |
310 | |
311 | private: |
312 | qreal _radiusX = 0; |
313 | qreal _radiusY = 0; |
314 | bool _useLargeArc = false; |
315 | ArcDirection _direction = Clockwise; |
316 | qreal _xAxisRotation = 0; |
317 | }; |
318 | |
319 | class Q_QUICK_PRIVATE_EXPORT QQuickPathAngleArc : public QQuickCurve |
320 | { |
321 | Q_OBJECT |
322 | Q_PROPERTY(qreal centerX READ centerX WRITE setCenterX NOTIFY centerXChanged FINAL) |
323 | Q_PROPERTY(qreal centerY READ centerY WRITE setCenterY NOTIFY centerYChanged FINAL) |
324 | Q_PROPERTY(qreal radiusX READ radiusX WRITE setRadiusX NOTIFY radiusXChanged FINAL) |
325 | Q_PROPERTY(qreal radiusY READ radiusY WRITE setRadiusY NOTIFY radiusYChanged FINAL) |
326 | Q_PROPERTY(qreal startAngle READ startAngle WRITE setStartAngle NOTIFY startAngleChanged FINAL) |
327 | Q_PROPERTY(qreal sweepAngle READ sweepAngle WRITE setSweepAngle NOTIFY sweepAngleChanged FINAL) |
328 | Q_PROPERTY(bool moveToStart READ moveToStart WRITE setMoveToStart NOTIFY moveToStartChanged FINAL) |
329 | |
330 | QML_NAMED_ELEMENT(PathAngleArc) |
331 | QML_ADDED_IN_VERSION(2, 11) |
332 | |
333 | public: |
334 | QQuickPathAngleArc(QObject *parent=nullptr) |
335 | : QQuickCurve(parent) {} |
336 | |
337 | qreal centerX() const; |
338 | void setCenterX(qreal); |
339 | |
340 | qreal centerY() const; |
341 | void setCenterY(qreal); |
342 | |
343 | qreal radiusX() const; |
344 | void setRadiusX(qreal); |
345 | |
346 | qreal radiusY() const; |
347 | void setRadiusY(qreal); |
348 | |
349 | qreal startAngle() const; |
350 | void setStartAngle(qreal); |
351 | |
352 | qreal sweepAngle() const; |
353 | void setSweepAngle(qreal); |
354 | |
355 | bool moveToStart() const; |
356 | void setMoveToStart(bool); |
357 | |
358 | void addToPath(QPainterPath &path, const QQuickPathData &) override; |
359 | |
360 | Q_SIGNALS: |
361 | void centerXChanged(); |
362 | void centerYChanged(); |
363 | void radiusXChanged(); |
364 | void radiusYChanged(); |
365 | void startAngleChanged(); |
366 | void sweepAngleChanged(); |
367 | void moveToStartChanged(); |
368 | |
369 | private: |
370 | qreal _centerX = 0; |
371 | qreal _centerY = 0; |
372 | qreal _radiusX = 0; |
373 | qreal _radiusY = 0; |
374 | qreal _startAngle = 0; |
375 | qreal _sweepAngle = 0; |
376 | bool _moveToStart = true; |
377 | }; |
378 | |
379 | class Q_QUICK_PRIVATE_EXPORT QQuickPathSvg : public QQuickCurve |
380 | { |
381 | Q_OBJECT |
382 | Q_PROPERTY(QString path READ path WRITE setPath NOTIFY pathChanged FINAL) |
383 | QML_NAMED_ELEMENT(PathSvg) |
384 | QML_ADDED_IN_VERSION(2, 0) |
385 | public: |
386 | QQuickPathSvg(QObject *parent=nullptr) : QQuickCurve(parent) {} |
387 | |
388 | QString path() const; |
389 | void setPath(const QString &path); |
390 | |
391 | void addToPath(QPainterPath &path, const QQuickPathData &) override; |
392 | |
393 | Q_SIGNALS: |
394 | void pathChanged(); |
395 | |
396 | private: |
397 | QString _path; |
398 | }; |
399 | |
400 | class Q_QUICK_PRIVATE_EXPORT QQuickPathPercent : public QQuickPathElement |
401 | { |
402 | Q_OBJECT |
403 | Q_PROPERTY(qreal value READ value WRITE setValue NOTIFY valueChanged FINAL) |
404 | QML_NAMED_ELEMENT(PathPercent) |
405 | QML_ADDED_IN_VERSION(2, 0) |
406 | public: |
407 | QQuickPathPercent(QObject *parent=nullptr) : QQuickPathElement(parent) {} |
408 | |
409 | qreal value() const; |
410 | void setValue(qreal value); |
411 | |
412 | Q_SIGNALS: |
413 | void valueChanged(); |
414 | |
415 | private: |
416 | qreal _value = 0; |
417 | }; |
418 | |
419 | class Q_QUICK_PRIVATE_EXPORT QQuickPathPolyline : public QQuickCurve |
420 | { |
421 | Q_OBJECT |
422 | Q_PROPERTY(QPointF start READ start NOTIFY startChanged FINAL) |
423 | Q_PROPERTY(QVariant path READ path WRITE setPath NOTIFY pathChanged FINAL) |
424 | QML_NAMED_ELEMENT(PathPolyline) |
425 | QML_ADDED_IN_VERSION(2, 14) |
426 | public: |
427 | QQuickPathPolyline(QObject *parent=nullptr); |
428 | |
429 | QVariant path() const; |
430 | void setPath(const QVariant &path); |
431 | void setPath(const QVector<QPointF> &path); |
432 | QPointF start() const; |
433 | void addToPath(QPainterPath &path, const QQuickPathData &data) override; |
434 | |
435 | Q_SIGNALS: |
436 | void pathChanged(); |
437 | void startChanged(); |
438 | |
439 | private: |
440 | QVector<QPointF> m_path; |
441 | }; |
442 | |
443 | class Q_QUICK_PRIVATE_EXPORT QQuickPathMultiline : public QQuickCurve |
444 | { |
445 | Q_OBJECT |
446 | Q_PROPERTY(QPointF start READ start NOTIFY startChanged FINAL) |
447 | Q_PROPERTY(QVariant paths READ paths WRITE setPaths NOTIFY pathsChanged FINAL) |
448 | QML_NAMED_ELEMENT(PathMultiline) |
449 | QML_ADDED_IN_VERSION(2, 14) |
450 | public: |
451 | QQuickPathMultiline(QObject *parent=nullptr); |
452 | |
453 | QVariant paths() const; |
454 | void setPaths(const QVariant &paths); |
455 | void setPaths(const QVector<QVector<QPointF>> &paths); |
456 | QPointF start() const; |
457 | void addToPath(QPainterPath &path, const QQuickPathData &) override; |
458 | |
459 | Q_SIGNALS: |
460 | void pathsChanged(); |
461 | void startChanged(); |
462 | |
463 | private: |
464 | QPointF absolute(const QPointF &relative) const; |
465 | |
466 | QVector<QVector<QPointF>> m_paths; |
467 | }; |
468 | |
469 | struct QQuickCachedBezier |
470 | { |
471 | QQuickCachedBezier() {} |
472 | QBezier bezier; |
473 | int element; |
474 | qreal bezLength; |
475 | qreal currLength; |
476 | qreal p; |
477 | bool isValid = false; |
478 | }; |
479 | |
480 | class QQuickPathPrivate; |
481 | class Q_QUICK_PRIVATE_EXPORT QQuickPath : public QObject, public QQmlParserStatus |
482 | { |
483 | Q_OBJECT |
484 | |
485 | Q_INTERFACES(QQmlParserStatus) |
486 | Q_PROPERTY(QQmlListProperty<QQuickPathElement> pathElements READ pathElements FINAL) |
487 | Q_PROPERTY(qreal startX READ startX WRITE setStartX NOTIFY startXChanged FINAL) |
488 | Q_PROPERTY(qreal startY READ startY WRITE setStartY NOTIFY startYChanged FINAL) |
489 | Q_PROPERTY(bool closed READ isClosed NOTIFY changed FINAL) |
490 | Q_PROPERTY(bool simplify READ simplify WRITE setSimplify NOTIFY simplifyChanged REVISION(6, 6) FINAL) |
491 | Q_PROPERTY(QSizeF scale READ scale WRITE setScale NOTIFY scaleChanged REVISION(2, 14)) |
492 | Q_CLASSINFO("DefaultProperty" , "pathElements" ) |
493 | QML_NAMED_ELEMENT(Path) |
494 | QML_ADDED_IN_VERSION(2, 0) |
495 | public: |
496 | QQuickPath(QObject *parent=nullptr); |
497 | ~QQuickPath() override; |
498 | |
499 | QQmlListProperty<QQuickPathElement> pathElements(); |
500 | |
501 | qreal startX() const; |
502 | void setStartX(qreal x); |
503 | bool hasStartX() const; |
504 | |
505 | qreal startY() const; |
506 | void setStartY(qreal y); |
507 | bool hasStartY() const; |
508 | |
509 | bool isClosed() const; |
510 | |
511 | QPainterPath path() const; |
512 | QStringList attributes() const; |
513 | qreal attributeAt(const QString &, qreal) const; |
514 | Q_REVISION(2, 14) Q_INVOKABLE QPointF pointAtPercent(qreal t) const; |
515 | QPointF sequentialPointAt(qreal p, qreal *angle = nullptr) const; |
516 | void invalidateSequentialHistory() const; |
517 | |
518 | QSizeF scale() const; |
519 | void setScale(const QSizeF &scale); |
520 | |
521 | bool simplify() const; |
522 | void setSimplify(bool s); |
523 | |
524 | Q_SIGNALS: |
525 | void changed(); |
526 | void startXChanged(); |
527 | void startYChanged(); |
528 | Q_REVISION(6, 6) void simplifyChanged(); |
529 | Q_REVISION(2, 14) void scaleChanged(); |
530 | |
531 | protected: |
532 | QQuickPath(QQuickPathPrivate &dd, QObject *parent = nullptr); |
533 | void componentComplete() override; |
534 | void classBegin() override; |
535 | void disconnectPathElements(); |
536 | void connectPathElements(); |
537 | void gatherAttributes(); |
538 | |
539 | // pathElements property |
540 | static QQuickPathElement *pathElements_at(QQmlListProperty<QQuickPathElement> *, qsizetype); |
541 | static void pathElements_append(QQmlListProperty<QQuickPathElement> *, QQuickPathElement *); |
542 | static qsizetype pathElements_count(QQmlListProperty<QQuickPathElement> *); |
543 | static void pathElements_clear(QQmlListProperty<QQuickPathElement> *); |
544 | |
545 | private Q_SLOTS: |
546 | void processPath(); |
547 | |
548 | private: |
549 | struct AttributePoint { |
550 | AttributePoint() {} |
551 | AttributePoint(const AttributePoint &other) |
552 | : percent(other.percent), scale(other.scale), origpercent(other.origpercent), values(other.values) {} |
553 | AttributePoint &operator=(const AttributePoint &other) { |
554 | percent = other.percent; scale = other.scale; origpercent = other.origpercent; values = other.values; return *this; |
555 | } |
556 | qreal percent = 0; //massaged percent along the painter path |
557 | qreal scale = 1; |
558 | qreal origpercent = 0; //'real' percent along the painter path |
559 | QHash<QString, qreal> values; |
560 | }; |
561 | |
562 | void interpolate(int idx, const QString &name, qreal value); |
563 | void endpoint(const QString &name); |
564 | void createPointCache() const; |
565 | |
566 | static void interpolate(QList<AttributePoint> &points, int idx, const QString &name, qreal value); |
567 | static void endpoint(QList<AttributePoint> &attributePoints, const QString &name); |
568 | static QPointF forwardsPointAt(const QPainterPath &path, const qreal &pathLength, const QList<AttributePoint> &attributePoints, QQuickCachedBezier &prevBez, qreal p, qreal *angle = nullptr); |
569 | static QPointF backwardsPointAt(const QPainterPath &path, const qreal &pathLength, const QList<AttributePoint> &attributePoints, QQuickCachedBezier &prevBez, qreal p, qreal *angle = nullptr); |
570 | |
571 | private: |
572 | Q_DISABLE_COPY(QQuickPath) |
573 | Q_DECLARE_PRIVATE(QQuickPath) |
574 | friend class QQuickPathAnimationUpdater; |
575 | |
576 | public: |
577 | QPainterPath createPath(const QPointF &startPoint, const QPointF &endPoint, const QStringList &attributes, qreal &pathLength, QList<AttributePoint> &attributePoints, bool *closed = nullptr); |
578 | QPainterPath createShapePath(const QPointF &startPoint, const QPointF &endPoint, qreal &pathLength, bool *closed = nullptr); |
579 | static QPointF sequentialPointAt(const QPainterPath &path, const qreal &pathLength, const QList<AttributePoint> &attributePoints, QQuickCachedBezier &prevBez, qreal p, qreal *angle = nullptr); |
580 | }; |
581 | |
582 | class Q_QUICK_PRIVATE_EXPORT QQuickPathText : public QQuickPathElement |
583 | { |
584 | Q_OBJECT |
585 | Q_PROPERTY(qreal x READ x WRITE setX NOTIFY xChanged FINAL) |
586 | Q_PROPERTY(qreal y READ y WRITE setY NOTIFY yChanged FINAL) |
587 | Q_PROPERTY(qreal width READ width NOTIFY changed FINAL) |
588 | Q_PROPERTY(qreal height READ height NOTIFY changed FINAL) |
589 | Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged FINAL) |
590 | Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged FINAL) |
591 | QML_NAMED_ELEMENT(PathText) |
592 | QML_ADDED_IN_VERSION(2, 15) |
593 | public: |
594 | QQuickPathText(QObject *parent=nullptr) : QQuickPathElement(parent) |
595 | { |
596 | connect(sender: this, signal: &QQuickPathText::xChanged, context: this, slot: &QQuickPathElement::changed); |
597 | connect(sender: this, signal: &QQuickPathText::yChanged, context: this, slot: &QQuickPathElement::changed); |
598 | connect(sender: this, signal: &QQuickPathText::textChanged, context: this, slot: &QQuickPathElement::changed); |
599 | connect(sender: this, signal: &QQuickPathText::fontChanged, context: this, slot: &QQuickPathElement::changed); |
600 | |
601 | connect(sender: this, signal: &QQuickPathElement::changed, context: this, slot: &QQuickPathText::invalidate); |
602 | } |
603 | |
604 | void addToPath(QPainterPath &path); |
605 | |
606 | qreal x() const { return _x; } |
607 | qreal y() const { return _y; } |
608 | QString text() const { return _text; } |
609 | QFont font() const { return _font; } |
610 | |
611 | void setX(qreal x) |
612 | { |
613 | if (qFuzzyCompare(p1: _x, p2: x)) |
614 | return; |
615 | |
616 | _x = x; |
617 | Q_EMIT xChanged(); |
618 | } |
619 | |
620 | void setY(qreal y) |
621 | { |
622 | if (qFuzzyCompare(p1: _y, p2: y)) |
623 | return; |
624 | |
625 | _y = y; |
626 | Q_EMIT yChanged(); |
627 | } |
628 | |
629 | void setText(const QString &text) |
630 | { |
631 | if (text == _text) |
632 | return; |
633 | |
634 | _text = text; |
635 | Q_EMIT textChanged(); |
636 | } |
637 | |
638 | void setFont(const QFont &font) |
639 | { |
640 | if (font == _font) |
641 | return; |
642 | |
643 | _font = font; |
644 | Q_EMIT fontChanged(); |
645 | } |
646 | |
647 | qreal width() const |
648 | { |
649 | updatePath(); |
650 | return _path.boundingRect().width(); |
651 | } |
652 | |
653 | qreal height() const |
654 | { |
655 | updatePath(); |
656 | return _path.boundingRect().height(); |
657 | } |
658 | |
659 | Q_SIGNALS: |
660 | void xChanged(); |
661 | void yChanged(); |
662 | void textChanged(); |
663 | void fontChanged(); |
664 | |
665 | private Q_SLOTS: |
666 | void invalidate() |
667 | { |
668 | _path.clear(); |
669 | } |
670 | |
671 | private: |
672 | void updatePath() const; |
673 | |
674 | QString _text; |
675 | qreal _x = qreal(0.0); |
676 | qreal _y = qreal(0.0); |
677 | QFont _font; |
678 | |
679 | mutable QPainterPath _path; |
680 | }; |
681 | |
682 | QT_END_NAMESPACE |
683 | |
684 | QML_DECLARE_TYPE(QQuickPathElement) |
685 | QML_DECLARE_TYPE(QQuickPathAttribute) |
686 | QML_DECLARE_TYPE(QQuickCurve) |
687 | QML_DECLARE_TYPE(QQuickPathLine) |
688 | QML_DECLARE_TYPE(QQuickPathMove) |
689 | QML_DECLARE_TYPE(QQuickPathQuad) |
690 | QML_DECLARE_TYPE(QQuickPathCubic) |
691 | QML_DECLARE_TYPE(QQuickPathCatmullRomCurve) |
692 | QML_DECLARE_TYPE(QQuickPathArc) |
693 | QML_DECLARE_TYPE(QQuickPathAngleArc) |
694 | QML_DECLARE_TYPE(QQuickPathSvg) |
695 | QML_DECLARE_TYPE(QQuickPathPercent) |
696 | QML_DECLARE_TYPE(QQuickPathPolyline) |
697 | QML_DECLARE_TYPE(QQuickPath) |
698 | QML_DECLARE_TYPE(QQuickPathText) |
699 | |
700 | #endif // QQUICKPATH_H |
701 | |