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
qquickpathinterpolator.cpp
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
6
7#include "qquickpath_p.h"
8
10
11/*!
12 \qmltype PathInterpolator
13 \nativetype QQuickPathInterpolator
14 \inqmlmodule QtQuick
15 \ingroup qtquick-animation-control
16 \brief Specifies how to manually animate along a path.
17
18 PathInterpolator provides \c x, \c y, and \c angle information for a particular \c progress
19 along a path.
20
21 In the following example, we animate a green rectangle along a bezier path.
22
23 \snippet qml/pathinterpolator.qml 0
24*/
25
26QQuickPathInterpolator::QQuickPathInterpolator(QObject *parent) :
27 QObject(parent), _path(nullptr), _x(0), _y(0), _angle(0), _progress(0)
28{
29}
30
31/*!
32 \qmlproperty Path QtQuick::PathInterpolator::path
33 This property holds the path to interpolate.
34
35 For more information on defining a path see the \l Path documentation.
36*/
37QQuickPath *QQuickPathInterpolator::path() const
38{
39 return _path;
40}
41
42void QQuickPathInterpolator::setPath(QQuickPath *path)
43{
44 if (_path == path)
45 return;
46 if (_path)
47 disconnect(_path, SIGNAL(changed()), this, SLOT(_q_pathUpdated()));
48 _path = path;
49 connect(_path, SIGNAL(changed()), this, SLOT(_q_pathUpdated()));
50 emit pathChanged();
51}
52
53/*!
54 \qmlproperty real QtQuick::PathInterpolator::progress
55 This property holds the current progress along the path.
56
57 Typical usage of PathInterpolator is to set the progress
58 (often via a NumberAnimation), and read the corresponding
59 values for x, y, and angle (often via bindings to these values).
60
61 Progress ranges from 0.0 to 1.0.
62*/
63qreal QQuickPathInterpolator::progress() const
64{
65 return _progress;
66}
67
68void QQuickPathInterpolator::setProgress(qreal progress)
69{
70 progress = qMin(qMax(progress, (qreal)0.0), (qreal)1.0);
71
72 if (progress == _progress)
73 return;
74 _progress = progress;
75 emit progressChanged();
76 _q_pathUpdated();
77}
78
79/*!
80 \qmlproperty real QtQuick::PathInterpolator::x
81 \qmlproperty real QtQuick::PathInterpolator::y
82
83 These properties hold the position of the path at \l progress.
84*/
85qreal QQuickPathInterpolator::x() const
86{
87 return _x;
88}
89
90qreal QQuickPathInterpolator::y() const
91{
92 return _y;
93}
94
95/*!
96 \qmlproperty real QtQuick::PathInterpolator::angle
97
98 This property holds the angle of the path tangent at \l progress.
99
100 Angles are reported clockwise, with zero degrees at the 3 o'clock position.
101*/
102qreal QQuickPathInterpolator::angle() const
103{
104 return _angle;
105}
106
107void QQuickPathInterpolator::_q_pathUpdated()
108{
109 if (! _path)
110 return;
111
112 qreal angle = 0;
113 const QPointF pt = _path->sequentialPointAt(_progress, &angle);
114
115 if (_x != pt.x()) {
116 _x = pt.x();
117 emit xChanged();
118 }
119
120 if (_y != pt.y()) {
121 _y = pt.y();
122 emit yChanged();
123 }
124
125 //convert to clockwise
126 angle = qreal(360) - angle;
127 if (qFuzzyCompare(angle, qreal(360)))
128 angle = qreal(0);
129
130 if (angle != _angle) {
131 _angle = angle;
132 emit angleChanged();
133 }
134}
135
136QT_END_NAMESPACE
137
138#include "moc_qquickpathinterpolator_p.cpp"