Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/quick/items/qquickitemanimation.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
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 | #include "qquickitemanimation_p.h" | - | ||||||||||||||||||||||||
41 | #include "qquickitemanimation_p_p.h" | - | ||||||||||||||||||||||||
42 | #include "qquickstateoperations_p.h" | - | ||||||||||||||||||||||||
43 | - | |||||||||||||||||||||||||
44 | #include <private/qqmlproperty_p.h> | - | ||||||||||||||||||||||||
45 | #if QT_CONFIG(quick_path) | - | ||||||||||||||||||||||||
46 | #include <private/qquickpath_p.h> | - | ||||||||||||||||||||||||
47 | #endif | - | ||||||||||||||||||||||||
48 | #include "private/qparallelanimationgroupjob_p.h" | - | ||||||||||||||||||||||||
49 | #include "private/qsequentialanimationgroupjob_p.h" | - | ||||||||||||||||||||||||
50 | - | |||||||||||||||||||||||||
51 | #include <QtCore/qmath.h> | - | ||||||||||||||||||||||||
52 | #include <QtGui/qtransform.h> | - | ||||||||||||||||||||||||
53 | #include <QtQml/qqmlinfo.h> | - | ||||||||||||||||||||||||
54 | - | |||||||||||||||||||||||||
55 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||||||||
56 | - | |||||||||||||||||||||||||
57 | /*! | - | ||||||||||||||||||||||||
58 | \qmltype ParentAnimation | - | ||||||||||||||||||||||||
59 | \instantiates QQuickParentAnimation | - | ||||||||||||||||||||||||
60 | \inqmlmodule QtQuick | - | ||||||||||||||||||||||||
61 | \ingroup qtquick-animation-properties | - | ||||||||||||||||||||||||
62 | \since 5.0 | - | ||||||||||||||||||||||||
63 | \inherits Animation | - | ||||||||||||||||||||||||
64 | \brief Animates changes in parent values. | - | ||||||||||||||||||||||||
65 | - | |||||||||||||||||||||||||
66 | ParentAnimation is used to animate a parent change for an \l Item. | - | ||||||||||||||||||||||||
67 | - | |||||||||||||||||||||||||
68 | For example, the following ParentChange changes \c blueRect to become | - | ||||||||||||||||||||||||
69 | a child of \c redRect when it is clicked. The inclusion of the | - | ||||||||||||||||||||||||
70 | ParentAnimation, which defines a NumberAnimation to be applied during | - | ||||||||||||||||||||||||
71 | the transition, ensures the item animates smoothly as it moves to | - | ||||||||||||||||||||||||
72 | its new parent: | - | ||||||||||||||||||||||||
73 | - | |||||||||||||||||||||||||
74 | \snippet qml/parentanimation.qml 0 | - | ||||||||||||||||||||||||
75 | - | |||||||||||||||||||||||||
76 | A ParentAnimation can contain any number of animations. These animations will | - | ||||||||||||||||||||||||
77 | be run in parallel; to run them sequentially, define them within a | - | ||||||||||||||||||||||||
78 | SequentialAnimation. | - | ||||||||||||||||||||||||
79 | - | |||||||||||||||||||||||||
80 | In some cases, such as when reparenting between items with clipping enabled, it is useful | - | ||||||||||||||||||||||||
81 | to animate the parent change via another item that does not have clipping | - | ||||||||||||||||||||||||
82 | enabled. Such an item can be set using the \l via property. | - | ||||||||||||||||||||||||
83 | - | |||||||||||||||||||||||||
84 | ParentAnimation is typically used within a \l Transition in conjunction | - | ||||||||||||||||||||||||
85 | with a ParentChange. When used in this manner, it animates any | - | ||||||||||||||||||||||||
86 | ParentChange that has occurred during the state change. This can be | - | ||||||||||||||||||||||||
87 | overridden by setting a specific target item using the \l target property. | - | ||||||||||||||||||||||||
88 | - | |||||||||||||||||||||||||
89 | \sa {Animation and Transitions in Qt Quick}, {Qt Quick Examples - Animation} | - | ||||||||||||||||||||||||
90 | */ | - | ||||||||||||||||||||||||
91 | QQuickParentAnimation::QQuickParentAnimation(QObject *parent) | - | ||||||||||||||||||||||||
92 | : QQuickAnimationGroup(*(new QQuickParentAnimationPrivate), parent) | - | ||||||||||||||||||||||||
93 | { | - | ||||||||||||||||||||||||
94 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||||||||
95 | - | |||||||||||||||||||||||||
96 | QQuickParentAnimation::~QQuickParentAnimation() | - | ||||||||||||||||||||||||
97 | { | - | ||||||||||||||||||||||||
98 | } | - | ||||||||||||||||||||||||
99 | - | |||||||||||||||||||||||||
100 | /*! | - | ||||||||||||||||||||||||
101 | \qmlproperty Item QtQuick::ParentAnimation::target | - | ||||||||||||||||||||||||
102 | The item to reparent. | - | ||||||||||||||||||||||||
103 | - | |||||||||||||||||||||||||
104 | When used in a transition, if no target is specified, all | - | ||||||||||||||||||||||||
105 | ParentChange occurrences are animated by the ParentAnimation. | - | ||||||||||||||||||||||||
106 | */ | - | ||||||||||||||||||||||||
107 | QQuickItem *QQuickParentAnimation::target() const | - | ||||||||||||||||||||||||
108 | { | - | ||||||||||||||||||||||||
109 | Q_D(const QQuickParentAnimation); | - | ||||||||||||||||||||||||
110 | return d->target; never executed: return d->target; | 0 | ||||||||||||||||||||||||
111 | } | - | ||||||||||||||||||||||||
112 | - | |||||||||||||||||||||||||
113 | void QQuickParentAnimation::setTargetObject(QQuickItem *target) | - | ||||||||||||||||||||||||
114 | { | - | ||||||||||||||||||||||||
115 | Q_D(QQuickParentAnimation); | - | ||||||||||||||||||||||||
116 | if (target == d->target)
| 0-2 | ||||||||||||||||||||||||
117 | return; never executed: return; | 0 | ||||||||||||||||||||||||
118 | - | |||||||||||||||||||||||||
119 | d->target = target; | - | ||||||||||||||||||||||||
120 | emit targetChanged(); | - | ||||||||||||||||||||||||
121 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||||||||
122 | - | |||||||||||||||||||||||||
123 | /*! | - | ||||||||||||||||||||||||
124 | \qmlproperty Item QtQuick::ParentAnimation::newParent | - | ||||||||||||||||||||||||
125 | The new parent to animate to. | - | ||||||||||||||||||||||||
126 | - | |||||||||||||||||||||||||
127 | If the ParentAnimation is defined within a \l Transition, | - | ||||||||||||||||||||||||
128 | this value defaults to the value defined in the end state of the | - | ||||||||||||||||||||||||
129 | \l Transition. | - | ||||||||||||||||||||||||
130 | */ | - | ||||||||||||||||||||||||
131 | QQuickItem *QQuickParentAnimation::newParent() const | - | ||||||||||||||||||||||||
132 | { | - | ||||||||||||||||||||||||
133 | Q_D(const QQuickParentAnimation); | - | ||||||||||||||||||||||||
134 | return d->newParent; never executed: return d->newParent; | 0 | ||||||||||||||||||||||||
135 | } | - | ||||||||||||||||||||||||
136 | - | |||||||||||||||||||||||||
137 | void QQuickParentAnimation::setNewParent(QQuickItem *newParent) | - | ||||||||||||||||||||||||
138 | { | - | ||||||||||||||||||||||||
139 | Q_D(QQuickParentAnimation); | - | ||||||||||||||||||||||||
140 | if (newParent == d->newParent)
| 0 | ||||||||||||||||||||||||
141 | return; never executed: return; | 0 | ||||||||||||||||||||||||
142 | - | |||||||||||||||||||||||||
143 | d->newParent = newParent; | - | ||||||||||||||||||||||||
144 | emit newParentChanged(); | - | ||||||||||||||||||||||||
145 | } never executed: end of block | 0 | ||||||||||||||||||||||||
146 | - | |||||||||||||||||||||||||
147 | /*! | - | ||||||||||||||||||||||||
148 | \qmlproperty Item QtQuick::ParentAnimation::via | - | ||||||||||||||||||||||||
149 | The item to reparent via. This provides a way to do an unclipped animation | - | ||||||||||||||||||||||||
150 | when both the old parent and new parent are clipped. | - | ||||||||||||||||||||||||
151 | - | |||||||||||||||||||||||||
152 | \qml | - | ||||||||||||||||||||||||
153 | ParentAnimation { | - | ||||||||||||||||||||||||
154 | target: myItem | - | ||||||||||||||||||||||||
155 | via: topLevelItem | - | ||||||||||||||||||||||||
156 | // ... | - | ||||||||||||||||||||||||
157 | } | - | ||||||||||||||||||||||||
158 | \endqml | - | ||||||||||||||||||||||||
159 | - | |||||||||||||||||||||||||
160 | \note This only works when the ParentAnimation is used in a \l Transition | - | ||||||||||||||||||||||||
161 | in conjunction with a ParentChange. | - | ||||||||||||||||||||||||
162 | */ | - | ||||||||||||||||||||||||
163 | QQuickItem *QQuickParentAnimation::via() const | - | ||||||||||||||||||||||||
164 | { | - | ||||||||||||||||||||||||
165 | Q_D(const QQuickParentAnimation); | - | ||||||||||||||||||||||||
166 | return d->via; never executed: return d->via; | 0 | ||||||||||||||||||||||||
167 | } | - | ||||||||||||||||||||||||
168 | - | |||||||||||||||||||||||||
169 | void QQuickParentAnimation::setVia(QQuickItem *via) | - | ||||||||||||||||||||||||
170 | { | - | ||||||||||||||||||||||||
171 | Q_D(QQuickParentAnimation); | - | ||||||||||||||||||||||||
172 | if (via == d->via)
| 0-2 | ||||||||||||||||||||||||
173 | return; never executed: return; | 0 | ||||||||||||||||||||||||
174 | - | |||||||||||||||||||||||||
175 | d->via = via; | - | ||||||||||||||||||||||||
176 | emit viaChanged(); | - | ||||||||||||||||||||||||
177 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||||||||
178 | - | |||||||||||||||||||||||||
179 | //### mirrors same-named function in QQuickItem | - | ||||||||||||||||||||||||
180 | QPointF QQuickParentAnimationPrivate::computeTransformOrigin(QQuickItem::TransformOrigin origin, qreal width, qreal height) const | - | ||||||||||||||||||||||||
181 | { | - | ||||||||||||||||||||||||
182 | switch (origin) { | - | ||||||||||||||||||||||||
183 | default: never executed: default: | 0 | ||||||||||||||||||||||||
184 | case QQuickItem::TopLeft: never executed: case QQuickItem::TopLeft: | 0 | ||||||||||||||||||||||||
185 | return QPointF(0, 0); never executed: return QPointF(0, 0); | 0 | ||||||||||||||||||||||||
186 | case QQuickItem::Top: never executed: case QQuickItem::Top: | 0 | ||||||||||||||||||||||||
187 | return QPointF(width / 2., 0); never executed: return QPointF(width / 2., 0); | 0 | ||||||||||||||||||||||||
188 | case QQuickItem::TopRight: never executed: case QQuickItem::TopRight: | 0 | ||||||||||||||||||||||||
189 | return QPointF(width, 0); never executed: return QPointF(width, 0); | 0 | ||||||||||||||||||||||||
190 | case QQuickItem::Left: never executed: case QQuickItem::Left: | 0 | ||||||||||||||||||||||||
191 | return QPointF(0, height / 2.); never executed: return QPointF(0, height / 2.); | 0 | ||||||||||||||||||||||||
192 | case QQuickItem::Center: executed 2 times by 1 test: case QQuickItem::Center: Executed by:
| 2 | ||||||||||||||||||||||||
193 | return QPointF(width / 2., height / 2.); executed 2 times by 1 test: return QPointF(width / 2., height / 2.); Executed by:
| 2 | ||||||||||||||||||||||||
194 | case QQuickItem::Right: never executed: case QQuickItem::Right: | 0 | ||||||||||||||||||||||||
195 | return QPointF(width, height / 2.); never executed: return QPointF(width, height / 2.); | 0 | ||||||||||||||||||||||||
196 | case QQuickItem::BottomLeft: never executed: case QQuickItem::BottomLeft: | 0 | ||||||||||||||||||||||||
197 | return QPointF(0, height); never executed: return QPointF(0, height); | 0 | ||||||||||||||||||||||||
198 | case QQuickItem::Bottom: never executed: case QQuickItem::Bottom: | 0 | ||||||||||||||||||||||||
199 | return QPointF(width / 2., height); never executed: return QPointF(width / 2., height); | 0 | ||||||||||||||||||||||||
200 | case QQuickItem::BottomRight: never executed: case QQuickItem::BottomRight: | 0 | ||||||||||||||||||||||||
201 | return QPointF(width, height); never executed: return QPointF(width, height); | 0 | ||||||||||||||||||||||||
202 | } | - | ||||||||||||||||||||||||
203 | } | - | ||||||||||||||||||||||||
204 | - | |||||||||||||||||||||||||
205 | struct QQuickParentAnimationData : public QAbstractAnimationAction | - | ||||||||||||||||||||||||
206 | { | - | ||||||||||||||||||||||||
207 | QQuickParentAnimationData() : reverse(false) {} executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||||||||||||||
208 | ~QQuickParentAnimationData() { qDeleteAll(pc); } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||||||||||||||
209 | - | |||||||||||||||||||||||||
210 | QQuickStateActions actions; | - | ||||||||||||||||||||||||
211 | //### reverse should probably apply on a per-action basis | - | ||||||||||||||||||||||||
212 | bool reverse; | - | ||||||||||||||||||||||||
213 | QList<QQuickParentChange *> pc; | - | ||||||||||||||||||||||||
214 | void doAction() override | - | ||||||||||||||||||||||||
215 | { | - | ||||||||||||||||||||||||
216 | for (int ii = 0; ii < actions.count(); ++ii) {
| 4 | ||||||||||||||||||||||||
217 | const QQuickStateAction &action = actions.at(ii); | - | ||||||||||||||||||||||||
218 | if (reverse)
| 0-4 | ||||||||||||||||||||||||
219 | action.event->reverse(); never executed: action.event->reverse(); | 0 | ||||||||||||||||||||||||
220 | else | - | ||||||||||||||||||||||||
221 | action.event->execute(); executed 4 times by 1 test: action.event->execute(); Executed by:
| 4 | ||||||||||||||||||||||||
222 | } | - | ||||||||||||||||||||||||
223 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||||||||||||||
224 | }; | - | ||||||||||||||||||||||||
225 | - | |||||||||||||||||||||||||
226 | QAbstractAnimationJob* QQuickParentAnimation::transition(QQuickStateActions &actions, | - | ||||||||||||||||||||||||
227 | QQmlProperties &modified, | - | ||||||||||||||||||||||||
228 | TransitionDirection direction, | - | ||||||||||||||||||||||||
229 | QObject *defaultTarget) | - | ||||||||||||||||||||||||
230 | { | - | ||||||||||||||||||||||||
231 | Q_D(QQuickParentAnimation); | - | ||||||||||||||||||||||||
232 | - | |||||||||||||||||||||||||
233 | QQuickParentAnimationData *data = new QQuickParentAnimationData; | - | ||||||||||||||||||||||||
234 | QQuickParentAnimationData *viaData = new QQuickParentAnimationData; | - | ||||||||||||||||||||||||
235 | - | |||||||||||||||||||||||||
236 | bool hasExplicit = false; | - | ||||||||||||||||||||||||
237 | if (d->target && d->newParent) {
| 0-2 | ||||||||||||||||||||||||
238 | data->reverse = false; | - | ||||||||||||||||||||||||
239 | QQuickStateAction myAction; | - | ||||||||||||||||||||||||
240 | QQuickParentChange *pc = new QQuickParentChange; | - | ||||||||||||||||||||||||
241 | pc->setObject(d->target); | - | ||||||||||||||||||||||||
242 | pc->setParent(d->newParent); | - | ||||||||||||||||||||||||
243 | myAction.event = pc; | - | ||||||||||||||||||||||||
244 | data->pc << pc; | - | ||||||||||||||||||||||||
245 | data->actions << myAction; | - | ||||||||||||||||||||||||
246 | hasExplicit = true; | - | ||||||||||||||||||||||||
247 | if (d->via) {
| 0 | ||||||||||||||||||||||||
248 | viaData->reverse = false; | - | ||||||||||||||||||||||||
249 | QQuickStateAction myVAction; | - | ||||||||||||||||||||||||
250 | QQuickParentChange *vpc = new QQuickParentChange; | - | ||||||||||||||||||||||||
251 | vpc->setObject(d->target); | - | ||||||||||||||||||||||||
252 | vpc->setParent(d->via); | - | ||||||||||||||||||||||||
253 | myVAction.event = vpc; | - | ||||||||||||||||||||||||
254 | viaData->pc << vpc; | - | ||||||||||||||||||||||||
255 | viaData->actions << myVAction; | - | ||||||||||||||||||||||||
256 | } never executed: end of block | 0 | ||||||||||||||||||||||||
257 | //### once actions have concept of modified, | - | ||||||||||||||||||||||||
258 | // loop to match appropriate ParentChanges and mark as modified | - | ||||||||||||||||||||||||
259 | } never executed: end of block | 0 | ||||||||||||||||||||||||
260 | - | |||||||||||||||||||||||||
261 | if (!hasExplicit)
| 0-2 | ||||||||||||||||||||||||
262 | for (int i = 0; i < actions.size(); ++i) {
| 2 | ||||||||||||||||||||||||
263 | QQuickStateAction &action = actions[i]; | - | ||||||||||||||||||||||||
264 | if (action.event && action.event->type() == QQuickStateActionEvent::ParentChange
| 0-2 | ||||||||||||||||||||||||
265 | && (!d->target || static_cast<QQuickParentChange*>(action.event)->object() == d->target)) {
| 0-2 | ||||||||||||||||||||||||
266 | - | |||||||||||||||||||||||||
267 | QQuickParentChange *pc = static_cast<QQuickParentChange*>(action.event); | - | ||||||||||||||||||||||||
268 | QQuickStateAction myAction = action; | - | ||||||||||||||||||||||||
269 | data->reverse = action.reverseEvent; | - | ||||||||||||||||||||||||
270 | - | |||||||||||||||||||||||||
271 | //### this logic differs from PropertyAnimation | - | ||||||||||||||||||||||||
272 | // (probably a result of modified vs. done) | - | ||||||||||||||||||||||||
273 | if (d->newParent) {
| 0-2 | ||||||||||||||||||||||||
274 | QQuickParentChange *epc = new QQuickParentChange; | - | ||||||||||||||||||||||||
275 | epc->setObject(static_cast<QQuickParentChange*>(action.event)->object()); | - | ||||||||||||||||||||||||
276 | epc->setParent(d->newParent); | - | ||||||||||||||||||||||||
277 | myAction.event = epc; | - | ||||||||||||||||||||||||
278 | data->pc << epc; | - | ||||||||||||||||||||||||
279 | data->actions << myAction; | - | ||||||||||||||||||||||||
280 | pc = epc; | - | ||||||||||||||||||||||||
281 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
282 | action.actionDone = true; | - | ||||||||||||||||||||||||
283 | data->actions << myAction; | - | ||||||||||||||||||||||||
284 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||||||||
285 | - | |||||||||||||||||||||||||
286 | if (d->via) {
| 0-2 | ||||||||||||||||||||||||
287 | viaData->reverse = false; | - | ||||||||||||||||||||||||
288 | QQuickStateAction myAction; | - | ||||||||||||||||||||||||
289 | QQuickParentChange *vpc = new QQuickParentChange; | - | ||||||||||||||||||||||||
290 | vpc->setObject(pc->object()); | - | ||||||||||||||||||||||||
291 | vpc->setParent(d->via); | - | ||||||||||||||||||||||||
292 | myAction.event = vpc; | - | ||||||||||||||||||||||||
293 | viaData->pc << vpc; | - | ||||||||||||||||||||||||
294 | viaData->actions << myAction; | - | ||||||||||||||||||||||||
295 | QQuickStateAction dummyAction; | - | ||||||||||||||||||||||||
296 | QQuickStateAction &xAction = pc->xIsSet() && i < actions.size()-1 ? actions[++i] : dummyAction;
| 0-2 | ||||||||||||||||||||||||
297 | QQuickStateAction &yAction = pc->yIsSet() && i < actions.size()-1 ? actions[++i] : dummyAction;
| 0-2 | ||||||||||||||||||||||||
298 | QQuickStateAction &sAction = pc->scaleIsSet() && i < actions.size()-1 ? actions[++i] : dummyAction;
| 0-2 | ||||||||||||||||||||||||
299 | QQuickStateAction &rAction = pc->rotationIsSet() && i < actions.size()-1 ? actions[++i] : dummyAction;
| 0-2 | ||||||||||||||||||||||||
300 | QQuickItem *target = pc->object(); | - | ||||||||||||||||||||||||
301 | QQuickItem *targetParent = action.reverseEvent ? pc->originalParent() : pc->parent();
| 0-2 | ||||||||||||||||||||||||
302 | - | |||||||||||||||||||||||||
303 | //### this mirrors the logic in QQuickParentChange. | - | ||||||||||||||||||||||||
304 | bool ok; | - | ||||||||||||||||||||||||
305 | const QTransform &transform = targetParent->itemTransform(d->via, &ok); | - | ||||||||||||||||||||||||
306 | if (transform.type() >= QTransform::TxShear || !ok) {
| 0-2 | ||||||||||||||||||||||||
307 | qmlWarning(this) << QQuickParentAnimation::tr("Unable to preserve appearance under complex transform"); | - | ||||||||||||||||||||||||
308 | ok = false; | - | ||||||||||||||||||||||||
309 | } never executed: end of block | 0 | ||||||||||||||||||||||||
310 | - | |||||||||||||||||||||||||
311 | qreal scale = 1; | - | ||||||||||||||||||||||||
312 | qreal rotation = 0; | - | ||||||||||||||||||||||||
313 | bool isRotate = (transform.type() == QTransform::TxRotate) || (transform.m11() < 0);
| 0-2 | ||||||||||||||||||||||||
314 | if (ok && !isRotate) {
| 0-2 | ||||||||||||||||||||||||
315 | if (transform.m11() == transform.m22())
| 0 | ||||||||||||||||||||||||
316 | scale = transform.m11(); never executed: scale = transform.m11(); | 0 | ||||||||||||||||||||||||
317 | else { | - | ||||||||||||||||||||||||
318 | qmlWarning(this) << QQuickParentAnimation::tr("Unable to preserve appearance under non-uniform scale"); | - | ||||||||||||||||||||||||
319 | ok = false; | - | ||||||||||||||||||||||||
320 | } never executed: end of block | 0 | ||||||||||||||||||||||||
321 | } else if (ok && isRotate) {
| 0-2 | ||||||||||||||||||||||||
322 | if (transform.m11() == transform.m22())
| 0-2 | ||||||||||||||||||||||||
323 | scale = qSqrt(transform.m11()*transform.m11() + transform.m12()*transform.m12()); executed 2 times by 1 test: scale = qSqrt(transform.m11()*transform.m11() + transform.m12()*transform.m12()); Executed by:
| 2 | ||||||||||||||||||||||||
324 | else { | - | ||||||||||||||||||||||||
325 | qmlWarning(this) << QQuickParentAnimation::tr("Unable to preserve appearance under non-uniform scale"); | - | ||||||||||||||||||||||||
326 | ok = false; | - | ||||||||||||||||||||||||
327 | } never executed: end of block | 0 | ||||||||||||||||||||||||
328 | - | |||||||||||||||||||||||||
329 | if (scale != 0)
| 0-2 | ||||||||||||||||||||||||
330 | rotation = qRadiansToDegrees(qAtan2(transform.m12() / scale, transform.m11() / scale)); executed 2 times by 1 test: rotation = qRadiansToDegrees(qAtan2(transform.m12() / scale, transform.m11() / scale)); Executed by:
| 2 | ||||||||||||||||||||||||
331 | else { | - | ||||||||||||||||||||||||
332 | qmlWarning(this) << QQuickParentAnimation::tr("Unable to preserve appearance under scale of 0"); | - | ||||||||||||||||||||||||
333 | ok = false; | - | ||||||||||||||||||||||||
334 | } never executed: end of block | 0 | ||||||||||||||||||||||||
335 | } | - | ||||||||||||||||||||||||
336 | - | |||||||||||||||||||||||||
337 | const QPointF &point = transform.map(QPointF(xAction.toValue.toReal(),yAction.toValue.toReal())); | - | ||||||||||||||||||||||||
338 | qreal x = point.x(); | - | ||||||||||||||||||||||||
339 | qreal y = point.y(); | - | ||||||||||||||||||||||||
340 | if (ok && target->transformOrigin() != QQuickItem::TopLeft) {
| 0-2 | ||||||||||||||||||||||||
341 | qreal w = target->width(); | - | ||||||||||||||||||||||||
342 | qreal h = target->height(); | - | ||||||||||||||||||||||||
343 | if (pc->widthIsSet() && i < actions.size() - 1)
| 0-2 | ||||||||||||||||||||||||
344 | w = actions.at(++i).toValue.toReal(); executed 2 times by 1 test: w = actions.at(++i).toValue.toReal(); Executed by:
| 2 | ||||||||||||||||||||||||
345 | if (pc->heightIsSet() && i < actions.size() - 1)
| 0-2 | ||||||||||||||||||||||||
346 | h = actions.at(++i).toValue.toReal(); never executed: h = actions.at(++i).toValue.toReal(); | 0 | ||||||||||||||||||||||||
347 | const QPointF &transformOrigin | - | ||||||||||||||||||||||||
348 | = d->computeTransformOrigin(target->transformOrigin(), w,h); | - | ||||||||||||||||||||||||
349 | qreal tempxt = transformOrigin.x(); | - | ||||||||||||||||||||||||
350 | qreal tempyt = transformOrigin.y(); | - | ||||||||||||||||||||||||
351 | QTransform t; | - | ||||||||||||||||||||||||
352 | t.translate(-tempxt, -tempyt); | - | ||||||||||||||||||||||||
353 | t.rotate(rotation); | - | ||||||||||||||||||||||||
354 | t.scale(scale, scale); | - | ||||||||||||||||||||||||
355 | t.translate(tempxt, tempyt); | - | ||||||||||||||||||||||||
356 | const QPointF &offset = t.map(QPointF(0,0)); | - | ||||||||||||||||||||||||
357 | x += offset.x(); | - | ||||||||||||||||||||||||
358 | y += offset.y(); | - | ||||||||||||||||||||||||
359 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||||||||
360 | - | |||||||||||||||||||||||||
361 | if (ok) {
| 0-2 | ||||||||||||||||||||||||
362 | //qDebug() << x << y << rotation << scale; | - | ||||||||||||||||||||||||
363 | xAction.toValue = x; | - | ||||||||||||||||||||||||
364 | yAction.toValue = y; | - | ||||||||||||||||||||||||
365 | sAction.toValue = sAction.toValue.toReal() * scale; | - | ||||||||||||||||||||||||
366 | rAction.toValue = rAction.toValue.toReal() + rotation; | - | ||||||||||||||||||||||||
367 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||||||||
368 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||||||||
369 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||||||||
370 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||||||||
371 | - | |||||||||||||||||||||||||
372 | if (data->actions.count()) {
| 0-2 | ||||||||||||||||||||||||
373 | QSequentialAnimationGroupJob *topLevelGroup = new QSequentialAnimationGroupJob; | - | ||||||||||||||||||||||||
374 | QActionAnimation *viaAction = d->via ? new QActionAnimation : nullptr;
| 0-2 | ||||||||||||||||||||||||
375 | QActionAnimation *targetAction = new QActionAnimation; | - | ||||||||||||||||||||||||
376 | //we'll assume the common case by far is to have children, and always create ag | - | ||||||||||||||||||||||||
377 | QParallelAnimationGroupJob *ag = new QParallelAnimationGroupJob; | - | ||||||||||||||||||||||||
378 | - | |||||||||||||||||||||||||
379 | if (d->via)
| 0-2 | ||||||||||||||||||||||||
380 | viaAction->setAnimAction(viaData); executed 2 times by 1 test: viaAction->setAnimAction(viaData); Executed by:
| 2 | ||||||||||||||||||||||||
381 | targetAction->setAnimAction(data); | - | ||||||||||||||||||||||||
382 | - | |||||||||||||||||||||||||
383 | //take care of any child animations | - | ||||||||||||||||||||||||
384 | bool valid = d->defaultProperty.isValid(); | - | ||||||||||||||||||||||||
385 | QAbstractAnimationJob* anim; | - | ||||||||||||||||||||||||
386 | for (int ii = 0; ii < d->animations.count(); ++ii) {
| 2 | ||||||||||||||||||||||||
387 | if (valid)
| 0-2 | ||||||||||||||||||||||||
388 | d->animations.at(ii)->setDefaultTarget(d->defaultProperty); never executed: d->animations.at(ii)->setDefaultTarget(d->defaultProperty); | 0 | ||||||||||||||||||||||||
389 | anim = d->animations.at(ii)->transition(actions, modified, direction, defaultTarget); | - | ||||||||||||||||||||||||
390 | if (anim)
| 0-2 | ||||||||||||||||||||||||
391 | ag->appendAnimation(anim); executed 2 times by 1 test: ag->appendAnimation(anim); Executed by:
| 2 | ||||||||||||||||||||||||
392 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||||||||
393 | - | |||||||||||||||||||||||||
394 | //TODO: simplify/clarify logic | - | ||||||||||||||||||||||||
395 | bool forwards = direction == QQuickAbstractAnimation::Forward; | - | ||||||||||||||||||||||||
396 | if (forwards) {
| 0-2 | ||||||||||||||||||||||||
397 | topLevelGroup->appendAnimation(d->via ? viaAction : targetAction); | - | ||||||||||||||||||||||||
398 | topLevelGroup->appendAnimation(ag); | - | ||||||||||||||||||||||||
399 | if (d->via)
| 0-2 | ||||||||||||||||||||||||
400 | topLevelGroup->appendAnimation(targetAction); executed 2 times by 1 test: topLevelGroup->appendAnimation(targetAction); Executed by:
| 2 | ||||||||||||||||||||||||
401 | } else { executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||||||||
402 | if (d->via)
| 0 | ||||||||||||||||||||||||
403 | topLevelGroup->appendAnimation(targetAction); never executed: topLevelGroup->appendAnimation(targetAction); | 0 | ||||||||||||||||||||||||
404 | topLevelGroup->appendAnimation(ag); | - | ||||||||||||||||||||||||
405 | topLevelGroup->appendAnimation(d->via ? viaAction : targetAction); | - | ||||||||||||||||||||||||
406 | } never executed: end of block | 0 | ||||||||||||||||||||||||
407 | return initInstance(topLevelGroup); executed 2 times by 1 test: return initInstance(topLevelGroup); Executed by:
| 2 | ||||||||||||||||||||||||
408 | } else { | - | ||||||||||||||||||||||||
409 | delete data; | - | ||||||||||||||||||||||||
410 | delete viaData; | - | ||||||||||||||||||||||||
411 | } never executed: end of block | 0 | ||||||||||||||||||||||||
412 | return nullptr; never executed: return nullptr; | 0 | ||||||||||||||||||||||||
413 | } | - | ||||||||||||||||||||||||
414 | - | |||||||||||||||||||||||||
415 | /*! | - | ||||||||||||||||||||||||
416 | \qmltype AnchorAnimation | - | ||||||||||||||||||||||||
417 | \instantiates QQuickAnchorAnimation | - | ||||||||||||||||||||||||
418 | \inqmlmodule QtQuick | - | ||||||||||||||||||||||||
419 | \ingroup qtquick-animation-properties | - | ||||||||||||||||||||||||
420 | \inherits Animation | - | ||||||||||||||||||||||||
421 | \brief Animates changes in anchor values. | - | ||||||||||||||||||||||||
422 | - | |||||||||||||||||||||||||
423 | AnchorAnimation is used to animate an anchor change. | - | ||||||||||||||||||||||||
424 | - | |||||||||||||||||||||||||
425 | In the following snippet we animate the addition of a right anchor to a \l Rectangle: | - | ||||||||||||||||||||||||
426 | - | |||||||||||||||||||||||||
427 | \snippet qml/anchoranimation.qml 0 | - | ||||||||||||||||||||||||
428 | - | |||||||||||||||||||||||||
429 | When an AnchorAnimation is used in a \l Transition, it will | - | ||||||||||||||||||||||||
430 | animate any AnchorChanges that have occurred during the state change. | - | ||||||||||||||||||||||||
431 | This can be overridden by setting a specific target item using the | - | ||||||||||||||||||||||||
432 | \l {AnchorChanges::target}{AnchorChanges.target} property. | - | ||||||||||||||||||||||||
433 | - | |||||||||||||||||||||||||
434 | \note AnchorAnimation can only be used in a \l Transition and in | - | ||||||||||||||||||||||||
435 | conjunction with an AnchorChange. It cannot be used in behaviors and | - | ||||||||||||||||||||||||
436 | other types of animations. | - | ||||||||||||||||||||||||
437 | - | |||||||||||||||||||||||||
438 | \sa {Animation and Transitions in Qt Quick}, AnchorChanges | - | ||||||||||||||||||||||||
439 | */ | - | ||||||||||||||||||||||||
440 | QQuickAnchorAnimation::QQuickAnchorAnimation(QObject *parent) | - | ||||||||||||||||||||||||
441 | : QQuickAbstractAnimation(*(new QQuickAnchorAnimationPrivate), parent) | - | ||||||||||||||||||||||||
442 | { | - | ||||||||||||||||||||||||
443 | } executed 6 times by 2 tests: end of block Executed by:
| 6 | ||||||||||||||||||||||||
444 | - | |||||||||||||||||||||||||
445 | QQuickAnchorAnimation::~QQuickAnchorAnimation() | - | ||||||||||||||||||||||||
446 | { | - | ||||||||||||||||||||||||
447 | } | - | ||||||||||||||||||||||||
448 | - | |||||||||||||||||||||||||
449 | /*! | - | ||||||||||||||||||||||||
450 | \qmlproperty list<Item> QtQuick::AnchorAnimation::targets | - | ||||||||||||||||||||||||
451 | The items to reanchor. | - | ||||||||||||||||||||||||
452 | - | |||||||||||||||||||||||||
453 | If no targets are specified all AnchorChanges will be | - | ||||||||||||||||||||||||
454 | animated by the AnchorAnimation. | - | ||||||||||||||||||||||||
455 | */ | - | ||||||||||||||||||||||||
456 | QQmlListProperty<QQuickItem> QQuickAnchorAnimation::targets() | - | ||||||||||||||||||||||||
457 | { | - | ||||||||||||||||||||||||
458 | Q_D(QQuickAnchorAnimation); | - | ||||||||||||||||||||||||
459 | return QQmlListProperty<QQuickItem>(this, d->targets); never executed: return QQmlListProperty<QQuickItem>(this, d->targets); | 0 | ||||||||||||||||||||||||
460 | } | - | ||||||||||||||||||||||||
461 | - | |||||||||||||||||||||||||
462 | /*! | - | ||||||||||||||||||||||||
463 | \qmlproperty int QtQuick::AnchorAnimation::duration | - | ||||||||||||||||||||||||
464 | This property holds the duration of the animation, in milliseconds. | - | ||||||||||||||||||||||||
465 | - | |||||||||||||||||||||||||
466 | The default value is 250. | - | ||||||||||||||||||||||||
467 | */ | - | ||||||||||||||||||||||||
468 | int QQuickAnchorAnimation::duration() const | - | ||||||||||||||||||||||||
469 | { | - | ||||||||||||||||||||||||
470 | Q_D(const QQuickAnchorAnimation); | - | ||||||||||||||||||||||||
471 | return d->duration; never executed: return d->duration; | 0 | ||||||||||||||||||||||||
472 | } | - | ||||||||||||||||||||||||
473 | - | |||||||||||||||||||||||||
474 | void QQuickAnchorAnimation::setDuration(int duration) | - | ||||||||||||||||||||||||
475 | { | - | ||||||||||||||||||||||||
476 | if (duration < 0) {
| 0-4 | ||||||||||||||||||||||||
477 | qmlWarning(this) << tr("Cannot set a duration of < 0"); | - | ||||||||||||||||||||||||
478 | return; never executed: return; | 0 | ||||||||||||||||||||||||
479 | } | - | ||||||||||||||||||||||||
480 | - | |||||||||||||||||||||||||
481 | Q_D(QQuickAnchorAnimation); | - | ||||||||||||||||||||||||
482 | if (d->duration == duration)
| 0-4 | ||||||||||||||||||||||||
483 | return; never executed: return; | 0 | ||||||||||||||||||||||||
484 | d->duration = duration; | - | ||||||||||||||||||||||||
485 | emit durationChanged(duration); | - | ||||||||||||||||||||||||
486 | } executed 4 times by 2 tests: end of block Executed by:
| 4 | ||||||||||||||||||||||||
487 | - | |||||||||||||||||||||||||
488 | /*! | - | ||||||||||||||||||||||||
489 | \qmlpropertygroup QtQuick::AnchorAnimation::easing | - | ||||||||||||||||||||||||
490 | \qmlproperty enumeration QtQuick::AnchorAnimation::easing.type | - | ||||||||||||||||||||||||
491 | \qmlproperty real QtQuick::AnchorAnimation::easing.amplitude | - | ||||||||||||||||||||||||
492 | \qmlproperty real QtQuick::AnchorAnimation::easing.overshoot | - | ||||||||||||||||||||||||
493 | \qmlproperty real QtQuick::AnchorAnimation::easing.period | - | ||||||||||||||||||||||||
494 | \brief Specifies the easing curve used for the animation | - | ||||||||||||||||||||||||
495 | - | |||||||||||||||||||||||||
496 | To specify an easing curve you need to specify at least the type. For some curves you can also specify | - | ||||||||||||||||||||||||
497 | amplitude, period and/or overshoot. The default easing curve is | - | ||||||||||||||||||||||||
498 | Linear. | - | ||||||||||||||||||||||||
499 | - | |||||||||||||||||||||||||
500 | \qml | - | ||||||||||||||||||||||||
501 | AnchorAnimation { easing.type: Easing.InOutQuad } | - | ||||||||||||||||||||||||
502 | \endqml | - | ||||||||||||||||||||||||
503 | - | |||||||||||||||||||||||||
504 | See the \l{PropertyAnimation::easing.type} documentation for information | - | ||||||||||||||||||||||||
505 | about the different types of easing curves. | - | ||||||||||||||||||||||||
506 | */ | - | ||||||||||||||||||||||||
507 | QEasingCurve QQuickAnchorAnimation::easing() const | - | ||||||||||||||||||||||||
508 | { | - | ||||||||||||||||||||||||
509 | Q_D(const QQuickAnchorAnimation); | - | ||||||||||||||||||||||||
510 | return d->easing; never executed: return d->easing; | 0 | ||||||||||||||||||||||||
511 | } | - | ||||||||||||||||||||||||
512 | - | |||||||||||||||||||||||||
513 | void QQuickAnchorAnimation::setEasing(const QEasingCurve &e) | - | ||||||||||||||||||||||||
514 | { | - | ||||||||||||||||||||||||
515 | Q_D(QQuickAnchorAnimation); | - | ||||||||||||||||||||||||
516 | if (d->easing == e)
| 0-2 | ||||||||||||||||||||||||
517 | return; never executed: return; | 0 | ||||||||||||||||||||||||
518 | - | |||||||||||||||||||||||||
519 | d->easing = e; | - | ||||||||||||||||||||||||
520 | emit easingChanged(e); | - | ||||||||||||||||||||||||
521 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||||||||
522 | - | |||||||||||||||||||||||||
523 | QAbstractAnimationJob* QQuickAnchorAnimation::transition(QQuickStateActions &actions, | - | ||||||||||||||||||||||||
524 | QQmlProperties &modified, | - | ||||||||||||||||||||||||
525 | TransitionDirection direction, | - | ||||||||||||||||||||||||
526 | QObject *defaultTarget) | - | ||||||||||||||||||||||||
527 | { | - | ||||||||||||||||||||||||
528 | Q_UNUSED(modified); | - | ||||||||||||||||||||||||
529 | Q_UNUSED(defaultTarget); | - | ||||||||||||||||||||||||
530 | Q_D(QQuickAnchorAnimation); | - | ||||||||||||||||||||||||
531 | QQuickAnimationPropertyUpdater *data = new QQuickAnimationPropertyUpdater; | - | ||||||||||||||||||||||||
532 | data->interpolatorType = QMetaType::QReal; | - | ||||||||||||||||||||||||
533 | data->interpolator = d->interpolator; | - | ||||||||||||||||||||||||
534 | data->reverse = direction == Backward ? true : false;
| 0-12 | ||||||||||||||||||||||||
535 | data->fromSourced = false; | - | ||||||||||||||||||||||||
536 | data->fromDefined = false; | - | ||||||||||||||||||||||||
537 | - | |||||||||||||||||||||||||
538 | for (int ii = 0; ii < actions.count(); ++ii) {
| 10-12 | ||||||||||||||||||||||||
539 | QQuickStateAction &action = actions[ii]; | - | ||||||||||||||||||||||||
540 | if (action.event && action.event->type() == QQuickStateActionEvent::AnchorChanges
| 0-10 | ||||||||||||||||||||||||
541 | && (d->targets.isEmpty() || d->targets.contains(static_cast<QQuickAnchorChanges*>(action.event)->object()))) {
| 0-10 | ||||||||||||||||||||||||
542 | data->actions << static_cast<QQuickAnchorChanges*>(action.event)->additionalActions(); | - | ||||||||||||||||||||||||
543 | } executed 10 times by 2 tests: end of block Executed by:
| 10 | ||||||||||||||||||||||||
544 | } executed 10 times by 2 tests: end of block Executed by:
| 10 | ||||||||||||||||||||||||
545 | - | |||||||||||||||||||||||||
546 | QQuickBulkValueAnimator *animator = new QQuickBulkValueAnimator; | - | ||||||||||||||||||||||||
547 | if (data->actions.count()) {
| 2-10 | ||||||||||||||||||||||||
548 | animator->setAnimValue(data); | - | ||||||||||||||||||||||||
549 | animator->setFromSourcedValue(&data->fromSourced); | - | ||||||||||||||||||||||||
550 | } else { executed 10 times by 2 tests: end of block Executed by:
| 10 | ||||||||||||||||||||||||
551 | delete data; | - | ||||||||||||||||||||||||
552 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||||||||
553 | - | |||||||||||||||||||||||||
554 | animator->setDuration(d->duration); | - | ||||||||||||||||||||||||
555 | animator->setEasingCurve(d->easing); | - | ||||||||||||||||||||||||
556 | return initInstance(animator); executed 12 times by 2 tests: return initInstance(animator); Executed by:
| 12 | ||||||||||||||||||||||||
557 | } | - | ||||||||||||||||||||||||
558 | - | |||||||||||||||||||||||||
559 | - | |||||||||||||||||||||||||
560 | #if QT_CONFIG(quick_path) | - | ||||||||||||||||||||||||
561 | /*! | - | ||||||||||||||||||||||||
562 | \qmltype PathAnimation | - | ||||||||||||||||||||||||
563 | \instantiates QQuickPathAnimation | - | ||||||||||||||||||||||||
564 | \inqmlmodule QtQuick | - | ||||||||||||||||||||||||
565 | \ingroup qtquick-animation-properties | - | ||||||||||||||||||||||||
566 | \inherits Animation | - | ||||||||||||||||||||||||
567 | \since 5.0 | - | ||||||||||||||||||||||||
568 | \brief Animates an item along a path. | - | ||||||||||||||||||||||||
569 | - | |||||||||||||||||||||||||
570 | When used in a transition, the path can be specified without start | - | ||||||||||||||||||||||||
571 | or end points, for example: | - | ||||||||||||||||||||||||
572 | \qml | - | ||||||||||||||||||||||||
573 | PathAnimation { | - | ||||||||||||||||||||||||
574 | path: Path { | - | ||||||||||||||||||||||||
575 | //no startX, startY | - | ||||||||||||||||||||||||
576 | PathCurve { x: 100; y: 100} | - | ||||||||||||||||||||||||
577 | PathCurve {} //last element is empty with no end point specified | - | ||||||||||||||||||||||||
578 | } | - | ||||||||||||||||||||||||
579 | } | - | ||||||||||||||||||||||||
580 | \endqml | - | ||||||||||||||||||||||||
581 | - | |||||||||||||||||||||||||
582 | In the above case, the path start will be the item's current position, and the | - | ||||||||||||||||||||||||
583 | path end will be the item's target position in the target state. | - | ||||||||||||||||||||||||
584 | - | |||||||||||||||||||||||||
585 | \sa {Animation and Transitions in Qt Quick}, PathInterpolator | - | ||||||||||||||||||||||||
586 | */ | - | ||||||||||||||||||||||||
587 | QQuickPathAnimation::QQuickPathAnimation(QObject *parent) | - | ||||||||||||||||||||||||
588 | : QQuickAbstractAnimation(*(new QQuickPathAnimationPrivate), parent) | - | ||||||||||||||||||||||||
589 | { | - | ||||||||||||||||||||||||
590 | } executed 16 times by 2 tests: end of block Executed by:
| 16 | ||||||||||||||||||||||||
591 | - | |||||||||||||||||||||||||
592 | QQuickPathAnimation::~QQuickPathAnimation() | - | ||||||||||||||||||||||||
593 | { | - | ||||||||||||||||||||||||
594 | typedef QHash<QQuickItem*, QQuickPathAnimationAnimator* >::iterator ActiveAnimationsIt; | - | ||||||||||||||||||||||||
595 | - | |||||||||||||||||||||||||
596 | Q_D(QQuickPathAnimation); | - | ||||||||||||||||||||||||
597 | for (ActiveAnimationsIt it = d->activeAnimations.begin(), end = d->activeAnimations.end(); it != end; ++it)
| 8-10 | ||||||||||||||||||||||||
598 | it.value()->clearTemplate(); executed 8 times by 1 test: it.value()->clearTemplate(); Executed by:
| 8 | ||||||||||||||||||||||||
599 | } executed 10 times by 2 tests: end of block Executed by:
| 10 | ||||||||||||||||||||||||
600 | - | |||||||||||||||||||||||||
601 | /*! | - | ||||||||||||||||||||||||
602 | \qmlproperty int QtQuick::PathAnimation::duration | - | ||||||||||||||||||||||||
603 | This property holds the duration of the animation, in milliseconds. | - | ||||||||||||||||||||||||
604 | - | |||||||||||||||||||||||||
605 | The default value is 250. | - | ||||||||||||||||||||||||
606 | */ | - | ||||||||||||||||||||||||
607 | int QQuickPathAnimation::duration() const | - | ||||||||||||||||||||||||
608 | { | - | ||||||||||||||||||||||||
609 | Q_D(const QQuickPathAnimation); | - | ||||||||||||||||||||||||
610 | return d->duration; executed 2 times by 1 test: return d->duration; Executed by:
| 2 | ||||||||||||||||||||||||
611 | } | - | ||||||||||||||||||||||||
612 | - | |||||||||||||||||||||||||
613 | void QQuickPathAnimation::setDuration(int duration) | - | ||||||||||||||||||||||||
614 | { | - | ||||||||||||||||||||||||
615 | if (duration < 0) {
| 0-16 | ||||||||||||||||||||||||
616 | qmlWarning(this) << tr("Cannot set a duration of < 0"); | - | ||||||||||||||||||||||||
617 | return; never executed: return; | 0 | ||||||||||||||||||||||||
618 | } | - | ||||||||||||||||||||||||
619 | - | |||||||||||||||||||||||||
620 | Q_D(QQuickPathAnimation); | - | ||||||||||||||||||||||||
621 | if (d->duration == duration)
| 0-16 | ||||||||||||||||||||||||
622 | return; never executed: return; | 0 | ||||||||||||||||||||||||
623 | d->duration = duration; | - | ||||||||||||||||||||||||
624 | emit durationChanged(duration); | - | ||||||||||||||||||||||||
625 | } executed 16 times by 2 tests: end of block Executed by:
| 16 | ||||||||||||||||||||||||
626 | - | |||||||||||||||||||||||||
627 | /*! | - | ||||||||||||||||||||||||
628 | \qmlpropertygroup QtQuick::PathAnimation::easing | - | ||||||||||||||||||||||||
629 | \qmlproperty enumeration QtQuick::PathAnimation::easing.type | - | ||||||||||||||||||||||||
630 | \qmlproperty real QtQuick::PathAnimation::easing.amplitude | - | ||||||||||||||||||||||||
631 | \qmlproperty list<real> QtQuick::PathAnimation::easing.bezierCurve | - | ||||||||||||||||||||||||
632 | \qmlproperty real QtQuick::PathAnimation::easing.overshoot | - | ||||||||||||||||||||||||
633 | \qmlproperty real QtQuick::PathAnimation::easing.period | - | ||||||||||||||||||||||||
634 | \brief the easing curve used for the animation. | - | ||||||||||||||||||||||||
635 | - | |||||||||||||||||||||||||
636 | To specify an easing curve you need to specify at least the type. For some curves you can also specify | - | ||||||||||||||||||||||||
637 | amplitude, period, overshoot or custom bezierCurve data. The default easing curve is \c Easing.Linear. | - | ||||||||||||||||||||||||
638 | - | |||||||||||||||||||||||||
639 | See the \l{PropertyAnimation::easing.type} documentation for information | - | ||||||||||||||||||||||||
640 | about the different types of easing curves. | - | ||||||||||||||||||||||||
641 | */ | - | ||||||||||||||||||||||||
642 | QEasingCurve QQuickPathAnimation::easing() const | - | ||||||||||||||||||||||||
643 | { | - | ||||||||||||||||||||||||
644 | Q_D(const QQuickPathAnimation); | - | ||||||||||||||||||||||||
645 | return d->easingCurve; executed 4 times by 2 tests: return d->easingCurve; Executed by:
| 4 | ||||||||||||||||||||||||
646 | } | - | ||||||||||||||||||||||||
647 | - | |||||||||||||||||||||||||
648 | void QQuickPathAnimation::setEasing(const QEasingCurve &e) | - | ||||||||||||||||||||||||
649 | { | - | ||||||||||||||||||||||||
650 | Q_D(QQuickPathAnimation); | - | ||||||||||||||||||||||||
651 | if (d->easingCurve == e)
| 0-4 | ||||||||||||||||||||||||
652 | return; never executed: return; | 0 | ||||||||||||||||||||||||
653 | - | |||||||||||||||||||||||||
654 | d->easingCurve = e; | - | ||||||||||||||||||||||||
655 | emit easingChanged(e); | - | ||||||||||||||||||||||||
656 | } executed 4 times by 2 tests: end of block Executed by:
| 4 | ||||||||||||||||||||||||
657 | - | |||||||||||||||||||||||||
658 | /*! | - | ||||||||||||||||||||||||
659 | \qmlproperty Path QtQuick::PathAnimation::path | - | ||||||||||||||||||||||||
660 | This property holds the path to animate along. | - | ||||||||||||||||||||||||
661 | - | |||||||||||||||||||||||||
662 | For more information on defining a path see the \l Path documentation. | - | ||||||||||||||||||||||||
663 | */ | - | ||||||||||||||||||||||||
664 | QQuickPath *QQuickPathAnimation::path() const | - | ||||||||||||||||||||||||
665 | { | - | ||||||||||||||||||||||||
666 | Q_D(const QQuickPathAnimation); | - | ||||||||||||||||||||||||
667 | return d->path; never executed: return d->path; | 0 | ||||||||||||||||||||||||
668 | } | - | ||||||||||||||||||||||||
669 | - | |||||||||||||||||||||||||
670 | void QQuickPathAnimation::setPath(QQuickPath *path) | - | ||||||||||||||||||||||||
671 | { | - | ||||||||||||||||||||||||
672 | Q_D(QQuickPathAnimation); | - | ||||||||||||||||||||||||
673 | if (d->path == path)
| 0-16 | ||||||||||||||||||||||||
674 | return; never executed: return; | 0 | ||||||||||||||||||||||||
675 | - | |||||||||||||||||||||||||
676 | d->path = path; | - | ||||||||||||||||||||||||
677 | emit pathChanged(); | - | ||||||||||||||||||||||||
678 | } executed 16 times by 2 tests: end of block Executed by:
| 16 | ||||||||||||||||||||||||
679 | - | |||||||||||||||||||||||||
680 | /*! | - | ||||||||||||||||||||||||
681 | \qmlproperty Item QtQuick::PathAnimation::target | - | ||||||||||||||||||||||||
682 | This property holds the item to animate. | - | ||||||||||||||||||||||||
683 | */ | - | ||||||||||||||||||||||||
684 | QQuickItem *QQuickPathAnimation::target() const | - | ||||||||||||||||||||||||
685 | { | - | ||||||||||||||||||||||||
686 | Q_D(const QQuickPathAnimation); | - | ||||||||||||||||||||||||
687 | return d->target; executed 2 times by 1 test: return d->target; Executed by:
| 2 | ||||||||||||||||||||||||
688 | } | - | ||||||||||||||||||||||||
689 | - | |||||||||||||||||||||||||
690 | void QQuickPathAnimation::setTargetObject(QQuickItem *target) | - | ||||||||||||||||||||||||
691 | { | - | ||||||||||||||||||||||||
692 | Q_D(QQuickPathAnimation); | - | ||||||||||||||||||||||||
693 | if (d->target == target)
| 0-16 | ||||||||||||||||||||||||
694 | return; never executed: return; | 0 | ||||||||||||||||||||||||
695 | - | |||||||||||||||||||||||||
696 | d->target = target; | - | ||||||||||||||||||||||||
697 | emit targetChanged(); | - | ||||||||||||||||||||||||
698 | } executed 16 times by 2 tests: end of block Executed by:
| 16 | ||||||||||||||||||||||||
699 | - | |||||||||||||||||||||||||
700 | /*! | - | ||||||||||||||||||||||||
701 | \qmlproperty enumeration QtQuick::PathAnimation::orientation | - | ||||||||||||||||||||||||
702 | This property controls the rotation of the item as it animates along the path. | - | ||||||||||||||||||||||||
703 | - | |||||||||||||||||||||||||
704 | If a value other than \c Fixed is specified, the PathAnimation will rotate the | - | ||||||||||||||||||||||||
705 | item to achieve the specified orientation as it travels along the path. | - | ||||||||||||||||||||||||
706 | - | |||||||||||||||||||||||||
707 | \list | - | ||||||||||||||||||||||||
708 | \li PathAnimation.Fixed (default) - the PathAnimation will not control | - | ||||||||||||||||||||||||
709 | the rotation of the item. | - | ||||||||||||||||||||||||
710 | \li PathAnimation.RightFirst - The right side of the item will lead along the path. | - | ||||||||||||||||||||||||
711 | \li PathAnimation.LeftFirst - The left side of the item will lead along the path. | - | ||||||||||||||||||||||||
712 | \li PathAnimation.BottomFirst - The bottom of the item will lead along the path. | - | ||||||||||||||||||||||||
713 | \li PathAnimation.TopFirst - The top of the item will lead along the path. | - | ||||||||||||||||||||||||
714 | \endlist | - | ||||||||||||||||||||||||
715 | */ | - | ||||||||||||||||||||||||
716 | QQuickPathAnimation::Orientation QQuickPathAnimation::orientation() const | - | ||||||||||||||||||||||||
717 | { | - | ||||||||||||||||||||||||
718 | Q_D(const QQuickPathAnimation); | - | ||||||||||||||||||||||||
719 | return d->orientation; executed 4 times by 1 test: return d->orientation; Executed by:
| 4 | ||||||||||||||||||||||||
720 | } | - | ||||||||||||||||||||||||
721 | - | |||||||||||||||||||||||||
722 | void QQuickPathAnimation::setOrientation(Orientation orientation) | - | ||||||||||||||||||||||||
723 | { | - | ||||||||||||||||||||||||
724 | Q_D(QQuickPathAnimation); | - | ||||||||||||||||||||||||
725 | if (d->orientation == orientation)
| 0-6 | ||||||||||||||||||||||||
726 | return; never executed: return; | 0 | ||||||||||||||||||||||||
727 | - | |||||||||||||||||||||||||
728 | d->orientation = orientation; | - | ||||||||||||||||||||||||
729 | emit orientationChanged(d->orientation); | - | ||||||||||||||||||||||||
730 | } executed 6 times by 2 tests: end of block Executed by:
| 6 | ||||||||||||||||||||||||
731 | - | |||||||||||||||||||||||||
732 | /*! | - | ||||||||||||||||||||||||
733 | \qmlproperty point QtQuick::PathAnimation::anchorPoint | - | ||||||||||||||||||||||||
734 | This property holds the anchor point for the item being animated. | - | ||||||||||||||||||||||||
735 | - | |||||||||||||||||||||||||
736 | By default, the upper-left corner of the target (its 0,0 point) | - | ||||||||||||||||||||||||
737 | will be anchored to (or follow) the path. The anchorPoint property can be used to | - | ||||||||||||||||||||||||
738 | specify a different point for anchoring. For example, specifying an anchorPoint of | - | ||||||||||||||||||||||||
739 | 5,5 for a 10x10 item means the center of the item will follow the path. | - | ||||||||||||||||||||||||
740 | */ | - | ||||||||||||||||||||||||
741 | QPointF QQuickPathAnimation::anchorPoint() const | - | ||||||||||||||||||||||||
742 | { | - | ||||||||||||||||||||||||
743 | Q_D(const QQuickPathAnimation); | - | ||||||||||||||||||||||||
744 | return d->anchorPoint; never executed: return d->anchorPoint; | 0 | ||||||||||||||||||||||||
745 | } | - | ||||||||||||||||||||||||
746 | - | |||||||||||||||||||||||||
747 | void QQuickPathAnimation::setAnchorPoint(const QPointF &point) | - | ||||||||||||||||||||||||
748 | { | - | ||||||||||||||||||||||||
749 | Q_D(QQuickPathAnimation); | - | ||||||||||||||||||||||||
750 | if (d->anchorPoint == point)
| 0-2 | ||||||||||||||||||||||||
751 | return; never executed: return; | 0 | ||||||||||||||||||||||||
752 | - | |||||||||||||||||||||||||
753 | d->anchorPoint = point; | - | ||||||||||||||||||||||||
754 | emit anchorPointChanged(point); | - | ||||||||||||||||||||||||
755 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||||||||
756 | - | |||||||||||||||||||||||||
757 | /*! | - | ||||||||||||||||||||||||
758 | \qmlproperty real QtQuick::PathAnimation::orientationEntryDuration | - | ||||||||||||||||||||||||
759 | This property holds the duration (in milliseconds) of the transition in to the orientation. | - | ||||||||||||||||||||||||
760 | - | |||||||||||||||||||||||||
761 | If an orientation has been specified for the PathAnimation, and the starting | - | ||||||||||||||||||||||||
762 | rotation of the item does not match that given by the orientation, | - | ||||||||||||||||||||||||
763 | orientationEntryDuration can be used to smoothly transition from the item's | - | ||||||||||||||||||||||||
764 | starting rotation to the rotation given by the path orientation. | - | ||||||||||||||||||||||||
765 | */ | - | ||||||||||||||||||||||||
766 | int QQuickPathAnimation::orientationEntryDuration() const | - | ||||||||||||||||||||||||
767 | { | - | ||||||||||||||||||||||||
768 | Q_D(const QQuickPathAnimation); | - | ||||||||||||||||||||||||
769 | return d->entryDuration; executed 2 times by 1 test: return d->entryDuration; Executed by:
| 2 | ||||||||||||||||||||||||
770 | } | - | ||||||||||||||||||||||||
771 | - | |||||||||||||||||||||||||
772 | void QQuickPathAnimation::setOrientationEntryDuration(int duration) | - | ||||||||||||||||||||||||
773 | { | - | ||||||||||||||||||||||||
774 | Q_D(QQuickPathAnimation); | - | ||||||||||||||||||||||||
775 | if (d->entryDuration == duration)
| 0-2 | ||||||||||||||||||||||||
776 | return; never executed: return; | 0 | ||||||||||||||||||||||||
777 | d->entryDuration = duration; | - | ||||||||||||||||||||||||
778 | emit orientationEntryDurationChanged(duration); | - | ||||||||||||||||||||||||
779 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||||||||
780 | - | |||||||||||||||||||||||||
781 | /*! | - | ||||||||||||||||||||||||
782 | \qmlproperty real QtQuick::PathAnimation::orientationExitDuration | - | ||||||||||||||||||||||||
783 | This property holds the duration (in milliseconds) of the transition out of the orientation. | - | ||||||||||||||||||||||||
784 | - | |||||||||||||||||||||||||
785 | If an orientation and endRotation have been specified for the PathAnimation, | - | ||||||||||||||||||||||||
786 | orientationExitDuration can be used to smoothly transition from the rotation given | - | ||||||||||||||||||||||||
787 | by the path orientation to the specified endRotation. | - | ||||||||||||||||||||||||
788 | */ | - | ||||||||||||||||||||||||
789 | int QQuickPathAnimation::orientationExitDuration() const | - | ||||||||||||||||||||||||
790 | { | - | ||||||||||||||||||||||||
791 | Q_D(const QQuickPathAnimation); | - | ||||||||||||||||||||||||
792 | return d->exitDuration; executed 2 times by 1 test: return d->exitDuration; Executed by:
| 2 | ||||||||||||||||||||||||
793 | } | - | ||||||||||||||||||||||||
794 | - | |||||||||||||||||||||||||
795 | void QQuickPathAnimation::setOrientationExitDuration(int duration) | - | ||||||||||||||||||||||||
796 | { | - | ||||||||||||||||||||||||
797 | Q_D(QQuickPathAnimation); | - | ||||||||||||||||||||||||
798 | if (d->exitDuration == duration)
| 0-2 | ||||||||||||||||||||||||
799 | return; never executed: return; | 0 | ||||||||||||||||||||||||
800 | d->exitDuration = duration; | - | ||||||||||||||||||||||||
801 | emit orientationExitDurationChanged(duration); | - | ||||||||||||||||||||||||
802 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||||||||
803 | - | |||||||||||||||||||||||||
804 | /*! | - | ||||||||||||||||||||||||
805 | \qmlproperty real QtQuick::PathAnimation::endRotation | - | ||||||||||||||||||||||||
806 | This property holds the ending rotation for the target. | - | ||||||||||||||||||||||||
807 | - | |||||||||||||||||||||||||
808 | If an orientation has been specified for the PathAnimation, | - | ||||||||||||||||||||||||
809 | and the path doesn't end with the item at the desired rotation, | - | ||||||||||||||||||||||||
810 | the endRotation property can be used to manually specify an end | - | ||||||||||||||||||||||||
811 | rotation. | - | ||||||||||||||||||||||||
812 | - | |||||||||||||||||||||||||
813 | This property is typically used with orientationExitDuration, as specifying | - | ||||||||||||||||||||||||
814 | an endRotation without an orientationExitDuration may cause a jump to | - | ||||||||||||||||||||||||
815 | the final rotation, rather than a smooth transition. | - | ||||||||||||||||||||||||
816 | */ | - | ||||||||||||||||||||||||
817 | qreal QQuickPathAnimation::endRotation() const | - | ||||||||||||||||||||||||
818 | { | - | ||||||||||||||||||||||||
819 | Q_D(const QQuickPathAnimation); | - | ||||||||||||||||||||||||
820 | return d->endRotation.isNull ? qreal(0) : d->endRotation.value; executed 2 times by 1 test: return d->endRotation.isNull ? qreal(0) : d->endRotation.value; Executed by:
| 2 | ||||||||||||||||||||||||
821 | } | - | ||||||||||||||||||||||||
822 | - | |||||||||||||||||||||||||
823 | void QQuickPathAnimation::setEndRotation(qreal rotation) | - | ||||||||||||||||||||||||
824 | { | - | ||||||||||||||||||||||||
825 | Q_D(QQuickPathAnimation); | - | ||||||||||||||||||||||||
826 | if (!d->endRotation.isNull && d->endRotation == rotation)
| 0-2 | ||||||||||||||||||||||||
827 | return; never executed: return; | 0 | ||||||||||||||||||||||||
828 | - | |||||||||||||||||||||||||
829 | d->endRotation = rotation; | - | ||||||||||||||||||||||||
830 | emit endRotationChanged(d->endRotation); | - | ||||||||||||||||||||||||
831 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||||||||
832 | - | |||||||||||||||||||||||||
833 | QAbstractAnimationJob* QQuickPathAnimation::transition(QQuickStateActions &actions, | - | ||||||||||||||||||||||||
834 | QQmlProperties &modified, | - | ||||||||||||||||||||||||
835 | TransitionDirection direction, | - | ||||||||||||||||||||||||
836 | QObject *defaultTarget) | - | ||||||||||||||||||||||||
837 | { | - | ||||||||||||||||||||||||
838 | Q_D(QQuickPathAnimation); | - | ||||||||||||||||||||||||
839 | - | |||||||||||||||||||||||||
840 | QQuickItem *target = d->target ? d->target : qobject_cast<QQuickItem*>(defaultTarget);
| 0-24 | ||||||||||||||||||||||||
841 | - | |||||||||||||||||||||||||
842 | QQuickPathAnimationUpdater prevData; | - | ||||||||||||||||||||||||
843 | bool havePrevData = false; | - | ||||||||||||||||||||||||
844 | if (d->activeAnimations.contains(target)) {
| 8-16 | ||||||||||||||||||||||||
845 | havePrevData = true; | - | ||||||||||||||||||||||||
846 | prevData = *d->activeAnimations[target]->pathUpdater(); | - | ||||||||||||||||||||||||
847 | } executed 8 times by 1 test: end of block Executed by:
| 8 | ||||||||||||||||||||||||
848 | - | |||||||||||||||||||||||||
849 | for (auto it = d->activeAnimations.begin(); it != d->activeAnimations.end();) {
| 8-24 | ||||||||||||||||||||||||
850 | QQuickPathAnimationAnimator *anim = it.value(); | - | ||||||||||||||||||||||||
851 | if (anim->state() == QAbstractAnimationJob::Stopped) {
| 0-8 | ||||||||||||||||||||||||
852 | anim->clearTemplate(); | - | ||||||||||||||||||||||||
853 | it = d->activeAnimations.erase(it); | - | ||||||||||||||||||||||||
854 | } else { executed 8 times by 1 test: end of block Executed by:
| 8 | ||||||||||||||||||||||||
855 | ++it; | - | ||||||||||||||||||||||||
856 | } never executed: end of block | 0 | ||||||||||||||||||||||||
857 | } | - | ||||||||||||||||||||||||
858 | - | |||||||||||||||||||||||||
859 | QQuickPathAnimationUpdater *data = new QQuickPathAnimationUpdater(); | - | ||||||||||||||||||||||||
860 | QQuickPathAnimationAnimator *pa = new QQuickPathAnimationAnimator(d); | - | ||||||||||||||||||||||||
861 | - | |||||||||||||||||||||||||
862 | d->activeAnimations[target] = pa; | - | ||||||||||||||||||||||||
863 | - | |||||||||||||||||||||||||
864 | data->orientation = d->orientation; | - | ||||||||||||||||||||||||
865 | data->anchorPoint = d->anchorPoint; | - | ||||||||||||||||||||||||
866 | data->entryInterval = d->duration ? qreal(d->entryDuration) / d->duration : qreal(0);
| 0-24 | ||||||||||||||||||||||||
867 | data->exitInterval = d->duration ? qreal(d->exitDuration) / d->duration : qreal(0);
| 0-24 | ||||||||||||||||||||||||
868 | data->endRotation = d->endRotation; | - | ||||||||||||||||||||||||
869 | data->reverse = direction == Backward ? true : false;
| 2-22 | ||||||||||||||||||||||||
870 | data->fromSourced = false; | - | ||||||||||||||||||||||||
871 | data->fromDefined = (d->path && d->path->hasStartX() && d->path->hasStartY()) ? true : false;
| 0-24 | ||||||||||||||||||||||||
872 | data->toDefined = d->path ? true : false;
| 0-24 | ||||||||||||||||||||||||
873 | int origModifiedSize = modified.count(); | - | ||||||||||||||||||||||||
874 | - | |||||||||||||||||||||||||
875 | for (int i = 0; i < actions.count(); ++i) {
| 8-24 | ||||||||||||||||||||||||
876 | QQuickStateAction &action = actions[i]; | - | ||||||||||||||||||||||||
877 | if (action.event)
| 0-8 | ||||||||||||||||||||||||
878 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||
879 | if (action.specifiedObject == target && action.property.name() == QLatin1String("x")) {
| 0-8 | ||||||||||||||||||||||||
880 | data->toX = action.toValue.toReal(); | - | ||||||||||||||||||||||||
881 | modified << action.property; | - | ||||||||||||||||||||||||
882 | action.fromValue = action.toValue; | - | ||||||||||||||||||||||||
883 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||||||||||||||
884 | if (action.specifiedObject == target && action.property.name() == QLatin1String("y")) {
| 0-8 | ||||||||||||||||||||||||
885 | data->toY = action.toValue.toReal(); | - | ||||||||||||||||||||||||
886 | modified << action.property; | - | ||||||||||||||||||||||||
887 | action.fromValue = action.toValue; | - | ||||||||||||||||||||||||
888 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||||||||||||||
889 | } executed 8 times by 1 test: end of block Executed by:
| 8 | ||||||||||||||||||||||||
890 | - | |||||||||||||||||||||||||
891 | if (target && d->path &&
| 0-24 | ||||||||||||||||||||||||
892 | (modified.count() > origModifiedSize || data->toDefined)) {
| 0-20 | ||||||||||||||||||||||||
893 | data->target = target; | - | ||||||||||||||||||||||||
894 | data->path = d->path; | - | ||||||||||||||||||||||||
895 | data->path->invalidateSequentialHistory(); | - | ||||||||||||||||||||||||
896 | - | |||||||||||||||||||||||||
897 | if (havePrevData) {
| 8-16 | ||||||||||||||||||||||||
898 | // get the original start angle that was used (so we can exactly reverse). | - | ||||||||||||||||||||||||
899 | data->startRotation = prevData.startRotation; | - | ||||||||||||||||||||||||
900 | - | |||||||||||||||||||||||||
901 | // treat interruptions specially, otherwise we end up with strange paths | - | ||||||||||||||||||||||||
902 | if ((data->reverse || prevData.reverse) && prevData.currentV > 0 && prevData.currentV < 1) {
| 0-6 | ||||||||||||||||||||||||
903 | if (!data->fromDefined && !data->toDefined && !prevData.painterPath.isEmpty()) {
| 0 | ||||||||||||||||||||||||
904 | QPointF pathPos = QQuickPath::sequentialPointAt(prevData.painterPath, prevData.pathLength, prevData.attributePoints, prevData.prevBez, prevData.currentV); | - | ||||||||||||||||||||||||
905 | if (!prevData.anchorPoint.isNull())
| 0 | ||||||||||||||||||||||||
906 | pathPos -= prevData.anchorPoint; never executed: pathPos -= prevData.anchorPoint; | 0 | ||||||||||||||||||||||||
907 | if (pathPos == data->target->position()) { //only treat as interruption if we interrupted ourself
| 0 | ||||||||||||||||||||||||
908 | data->painterPath = prevData.painterPath; | - | ||||||||||||||||||||||||
909 | data->toDefined = data->fromDefined = data->fromSourced = true; | - | ||||||||||||||||||||||||
910 | data->prevBez.isValid = false; | - | ||||||||||||||||||||||||
911 | data->interruptStart = prevData.currentV; | - | ||||||||||||||||||||||||
912 | data->startRotation = prevData.startRotation; | - | ||||||||||||||||||||||||
913 | data->pathLength = prevData.pathLength; | - | ||||||||||||||||||||||||
914 | data->attributePoints = prevData.attributePoints; | - | ||||||||||||||||||||||||
915 | } never executed: end of block | 0 | ||||||||||||||||||||||||
916 | } never executed: end of block | 0 | ||||||||||||||||||||||||
917 | } never executed: end of block | 0 | ||||||||||||||||||||||||
918 | } executed 8 times by 1 test: end of block Executed by:
| 8 | ||||||||||||||||||||||||
919 | pa->setFromSourcedValue(&data->fromSourced); | - | ||||||||||||||||||||||||
920 | pa->setAnimValue(data); | - | ||||||||||||||||||||||||
921 | pa->setDuration(d->duration); | - | ||||||||||||||||||||||||
922 | pa->setEasingCurve(d->easingCurve); | - | ||||||||||||||||||||||||
923 | return initInstance(pa); executed 24 times by 2 tests: return initInstance(pa); Executed by:
| 24 | ||||||||||||||||||||||||
924 | } else { | - | ||||||||||||||||||||||||
925 | pa->setFromSourcedValue(nullptr); | - | ||||||||||||||||||||||||
926 | pa->setAnimValue(nullptr); | - | ||||||||||||||||||||||||
927 | delete pa; | - | ||||||||||||||||||||||||
928 | delete data; | - | ||||||||||||||||||||||||
929 | } never executed: end of block | 0 | ||||||||||||||||||||||||
930 | return nullptr; never executed: return nullptr; | 0 | ||||||||||||||||||||||||
931 | } | - | ||||||||||||||||||||||||
932 | - | |||||||||||||||||||||||||
933 | void QQuickPathAnimationUpdater::setValue(qreal v) | - | ||||||||||||||||||||||||
934 | { | - | ||||||||||||||||||||||||
935 | v = qMin(qMax(v, (qreal)0.0), (qreal)1.0);; | - | ||||||||||||||||||||||||
936 | - | |||||||||||||||||||||||||
937 | if (interruptStart.isValid()) {
| 0-287 | ||||||||||||||||||||||||
938 | if (reverse)
| 0 | ||||||||||||||||||||||||
939 | v = 1 - v; never executed: v = 1 - v; | 0 | ||||||||||||||||||||||||
940 | qreal end = reverse ? 0.0 : 1.0;
| 0 | ||||||||||||||||||||||||
941 | v = interruptStart + v * (end-interruptStart); | - | ||||||||||||||||||||||||
942 | } never executed: end of block | 0 | ||||||||||||||||||||||||
943 | currentV = v; | - | ||||||||||||||||||||||||
944 | bool atStart = ((reverse && v == 1.0) || (!reverse && v == 0.0));
| 2-247 | ||||||||||||||||||||||||
945 | if (!fromSourced && (!fromDefined || !toDefined)) {
| 0-170 | ||||||||||||||||||||||||
946 | qreal startX = reverse ? toX + anchorPoint.x() : target->x() + anchorPoint.x();
| 2-8 | ||||||||||||||||||||||||
947 | qreal startY = reverse ? toY + anchorPoint.y() : target->y() + anchorPoint.y();
| 2-8 | ||||||||||||||||||||||||
948 | qreal endX = reverse ? target->x() + anchorPoint.x() : toX + anchorPoint.x();
| 2-8 | ||||||||||||||||||||||||
949 | qreal endY = reverse ? target->y() + anchorPoint.y() : toY + anchorPoint.y();
| 2-8 | ||||||||||||||||||||||||
950 | - | |||||||||||||||||||||||||
951 | prevBez.isValid = false; | - | ||||||||||||||||||||||||
952 | painterPath = path->createPath(QPointF(startX, startY), QPointF(endX, endY), QStringList(), pathLength, attributePoints); | - | ||||||||||||||||||||||||
953 | fromSourced = true; | - | ||||||||||||||||||||||||
954 | } executed 10 times by 1 test: end of block Executed by:
| 10 | ||||||||||||||||||||||||
955 | - | |||||||||||||||||||||||||
956 | qreal angle; | - | ||||||||||||||||||||||||
957 | bool fixed = orientation == QQuickPathAnimation::Fixed; | - | ||||||||||||||||||||||||
958 | QPointF currentPos = !painterPath.isEmpty() ? path->sequentialPointAt(painterPath, pathLength, attributePoints, prevBez, v, fixed ? nullptr : &angle) : path->sequentialPointAt(v, fixed ? nullptr : &angle);
| 127-160 | ||||||||||||||||||||||||
959 | - | |||||||||||||||||||||||||
960 | //adjust position according to anchor point | - | ||||||||||||||||||||||||
961 | if (!anchorPoint.isNull()) {
| 0-287 | ||||||||||||||||||||||||
962 | currentPos -= anchorPoint; | - | ||||||||||||||||||||||||
963 | if (atStart) {
| 0 | ||||||||||||||||||||||||
964 | if (!anchorPoint.isNull() && !fixed)
| 0 | ||||||||||||||||||||||||
965 | target->setTransformOriginPoint(anchorPoint); never executed: target->setTransformOriginPoint(anchorPoint); | 0 | ||||||||||||||||||||||||
966 | } never executed: end of block | 0 | ||||||||||||||||||||||||
967 | } never executed: end of block | 0 | ||||||||||||||||||||||||
968 | - | |||||||||||||||||||||||||
969 | target->setPosition(currentPos); | - | ||||||||||||||||||||||||
970 | - | |||||||||||||||||||||||||
971 | //adjust angle according to orientation | - | ||||||||||||||||||||||||
972 | if (!fixed) {
| 12-275 | ||||||||||||||||||||||||
973 | switch (orientation) { | - | ||||||||||||||||||||||||
974 | case QQuickPathAnimation::RightFirst: executed 12 times by 1 test: case QQuickPathAnimation::RightFirst: Executed by:
| 12 | ||||||||||||||||||||||||
975 | angle = -angle; | - | ||||||||||||||||||||||||
976 | break; executed 12 times by 1 test: break; Executed by:
| 12 | ||||||||||||||||||||||||
977 | case QQuickPathAnimation::TopFirst: never executed: case QQuickPathAnimation::TopFirst: | 0 | ||||||||||||||||||||||||
978 | angle = -angle + 90; | - | ||||||||||||||||||||||||
979 | break; never executed: break; | 0 | ||||||||||||||||||||||||
980 | case QQuickPathAnimation::LeftFirst: never executed: case QQuickPathAnimation::LeftFirst: | 0 | ||||||||||||||||||||||||
981 | angle = -angle + 180; | - | ||||||||||||||||||||||||
982 | break; never executed: break; | 0 | ||||||||||||||||||||||||
983 | case QQuickPathAnimation::BottomFirst: never executed: case QQuickPathAnimation::BottomFirst: | 0 | ||||||||||||||||||||||||
984 | angle = -angle + 270; | - | ||||||||||||||||||||||||
985 | break; never executed: break; | 0 | ||||||||||||||||||||||||
986 | default: never executed: default: | 0 | ||||||||||||||||||||||||
987 | angle = 0; | - | ||||||||||||||||||||||||
988 | break; never executed: break; | 0 | ||||||||||||||||||||||||
989 | } | - | ||||||||||||||||||||||||
990 | - | |||||||||||||||||||||||||
991 | if (atStart && !reverse) {
| 0-8 | ||||||||||||||||||||||||
992 | startRotation = target->rotation(); | - | ||||||||||||||||||||||||
993 | - | |||||||||||||||||||||||||
994 | //shortest distance to correct orientation | - | ||||||||||||||||||||||||
995 | qreal diff = angle - startRotation; | - | ||||||||||||||||||||||||
996 | while (diff > 180.0) {
| 0-4 | ||||||||||||||||||||||||
997 | startRotation.value += 360.0; | - | ||||||||||||||||||||||||
998 | diff -= 360.0; | - | ||||||||||||||||||||||||
999 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1000 | while (diff < -180.0) {
| 2-4 | ||||||||||||||||||||||||
1001 | startRotation.value -= 360.0; | - | ||||||||||||||||||||||||
1002 | diff += 360.0; | - | ||||||||||||||||||||||||
1003 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||||||||
1004 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||||||||||||||
1005 | - | |||||||||||||||||||||||||
1006 | //smoothly transition to the desired orientation | - | ||||||||||||||||||||||||
1007 | //TODO: shortest distance calculations | - | ||||||||||||||||||||||||
1008 | if (startRotation.isValid()) {
| 0-12 | ||||||||||||||||||||||||
1009 | if (reverse && v == 0.0)
| 0-12 | ||||||||||||||||||||||||
1010 | angle = startRotation; never executed: angle = startRotation; | 0 | ||||||||||||||||||||||||
1011 | else if (v < entryInterval)
| 2-10 | ||||||||||||||||||||||||
1012 | angle = angle * v / entryInterval + startRotation * (entryInterval - v) / entryInterval; executed 2 times by 1 test: angle = angle * v / entryInterval + startRotation * (entryInterval - v) / entryInterval; Executed by:
| 2 | ||||||||||||||||||||||||
1013 | } executed 12 times by 1 test: end of block Executed by:
| 12 | ||||||||||||||||||||||||
1014 | if (endRotation.isValid()) {
| 6 | ||||||||||||||||||||||||
1015 | qreal exitStart = 1 - entryInterval; | - | ||||||||||||||||||||||||
1016 | if (!reverse && v == 1.0)
| 0-6 | ||||||||||||||||||||||||
1017 | angle = endRotation; executed 2 times by 1 test: angle = endRotation; Executed by:
| 2 | ||||||||||||||||||||||||
1018 | else if (v > exitStart)
| 0-4 | ||||||||||||||||||||||||
1019 | angle = endRotation * (v - exitStart) / exitInterval + angle * (exitInterval - (v - exitStart)) / exitInterval; never executed: angle = endRotation * (v - exitStart) / exitInterval + angle * (exitInterval - (v - exitStart)) / exitInterval; | 0 | ||||||||||||||||||||||||
1020 | } executed 6 times by 1 test: end of block Executed by:
| 6 | ||||||||||||||||||||||||
1021 | target->setRotation(angle); | - | ||||||||||||||||||||||||
1022 | } executed 12 times by 1 test: end of block Executed by:
| 12 | ||||||||||||||||||||||||
1023 | - | |||||||||||||||||||||||||
1024 | /* | - | ||||||||||||||||||||||||
1025 | NOTE: we don't always reset the transform origin, as it can cause a | - | ||||||||||||||||||||||||
1026 | visual jump if ending on an angle. This means that in some cases | - | ||||||||||||||||||||||||
1027 | (anchor point and orientation both specified, and ending at an angle) | - | ||||||||||||||||||||||||
1028 | the transform origin will always be set after running the path animation. | - | ||||||||||||||||||||||||
1029 | */ | - | ||||||||||||||||||||||||
1030 | if ((reverse && v == 0.0) || (!reverse && v == 1.0)) {
| 2-247 | ||||||||||||||||||||||||
1031 | if (!anchorPoint.isNull() && !fixed && qFuzzyIsNull(angle))
| 0-26 | ||||||||||||||||||||||||
1032 | target->setTransformOriginPoint(QPointF()); never executed: target->setTransformOriginPoint(QPointF()); | 0 | ||||||||||||||||||||||||
1033 | } executed 26 times by 1 test: end of block Executed by:
| 26 | ||||||||||||||||||||||||
1034 | } executed 287 times by 1 test: end of block Executed by:
| 287 | ||||||||||||||||||||||||
1035 | - | |||||||||||||||||||||||||
1036 | QQuickPathAnimationAnimator::QQuickPathAnimationAnimator(QQuickPathAnimationPrivate *priv) | - | ||||||||||||||||||||||||
1037 | : animationTemplate(priv) | - | ||||||||||||||||||||||||
1038 | { | - | ||||||||||||||||||||||||
1039 | } executed 24 times by 2 tests: end of block Executed by:
| 24 | ||||||||||||||||||||||||
1040 | - | |||||||||||||||||||||||||
1041 | QQuickPathAnimationAnimator::~QQuickPathAnimationAnimator() | - | ||||||||||||||||||||||||
1042 | { | - | ||||||||||||||||||||||||
1043 | if (animationTemplate && pathUpdater()) {
| 0-14 | ||||||||||||||||||||||||
1044 | QHash<QQuickItem*, QQuickPathAnimationAnimator* >::iterator it = | - | ||||||||||||||||||||||||
1045 | animationTemplate->activeAnimations.find(pathUpdater()->target); | - | ||||||||||||||||||||||||
1046 | if (it != animationTemplate->activeAnimations.end() && it.value() == this)
| 0-2 | ||||||||||||||||||||||||
1047 | animationTemplate->activeAnimations.erase(it); executed 2 times by 1 test: animationTemplate->activeAnimations.erase(it); Executed by:
| 2 | ||||||||||||||||||||||||
1048 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||||||||
1049 | } executed 16 times by 2 tests: end of block Executed by:
| 16 | ||||||||||||||||||||||||
1050 | - | |||||||||||||||||||||||||
1051 | #endif // quick_path | - | ||||||||||||||||||||||||
1052 | - | |||||||||||||||||||||||||
1053 | QT_END_NAMESPACE | - | ||||||||||||||||||||||||
1054 | - | |||||||||||||||||||||||||
1055 | #include "moc_qquickitemanimation_p.cpp" | - | ||||||||||||||||||||||||
Source code | Switch to Preprocessed file |