OpenCoverage

qquickanimationcontroller.cpp

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/quick/util/qquickanimationcontroller.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
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 "qquickanimationcontroller_p.h"-
41#include <QtQml/qqmlinfo.h>-
42#include <private/qqmlengine_p.h>-
43-
44QT_BEGIN_NAMESPACE-
45-
46-
47class QQuickAnimationControllerPrivate : public QObjectPrivate, QAnimationJobChangeListener-
48{-
49 Q_DECLARE_PUBLIC(QQuickAnimationController)-
50public:-
51 QQuickAnimationControllerPrivate()-
52 : progress(0.0), animation(nullptr), animationInstance(nullptr), finalized(false) {}
executed 10 times by 1 test: end of block
Executed by:
  • tst_qquickanimationcontroller
10
53 void animationFinished(QAbstractAnimationJob *job) override;-
54 void animationCurrentTimeChanged(QAbstractAnimationJob *job, int currentTime) override;-
55-
56-
57 qreal progress;-
58 QQuickAbstractAnimation *animation;-
59 QAbstractAnimationJob *animationInstance;-
60 bool finalized:1;-
61-
62};-
63-
64void QQuickAnimationControllerPrivate::animationFinished(QAbstractAnimationJob *job)-
65{-
66 Q_Q(QQuickAnimationController);-
67 Q_ASSERT(animationInstance && animationInstance == job);-
68 Q_UNUSED(job);-
69-
70 animationInstance->removeAnimationChangeListener(this, QAbstractAnimationJob::Completion | QAbstractAnimationJob::CurrentTime);-
71-
72 if (animationInstance->direction() == QAbstractAnimationJob::Forward && progress != 1) {
animationInsta...onJob::ForwardDescription
TRUEnever evaluated
FALSEnever evaluated
progress != 1Description
TRUEnever evaluated
FALSEnever evaluated
0
73 progress = 1;-
74 emit q->progressChanged();-
75 } else if (animationInstance->direction() == QAbstractAnimationJob::Backward && progress != 0) {
never executed: end of block
animationInsta...nJob::BackwardDescription
TRUEnever evaluated
FALSEnever evaluated
progress != 0Description
TRUEnever evaluated
FALSEnever evaluated
0
76 progress = 0;-
77 emit q->progressChanged();-
78 }
never executed: end of block
0
79-
80}
never executed: end of block
0
81-
82void QQuickAnimationControllerPrivate::animationCurrentTimeChanged(QAbstractAnimationJob *job, int currentTime)-
83{-
84 Q_Q(QQuickAnimationController);-
85 Q_ASSERT(animationInstance && animationInstance == job);-
86 Q_UNUSED(job);-
87 const qreal newProgress = currentTime * 1.0 / animationInstance->duration();-
88 if (progress != newProgress) {
progress != newProgressDescription
TRUEnever evaluated
FALSEnever evaluated
0
89 progress = newProgress;-
90 emit q->progressChanged();-
91 }
never executed: end of block
0
92}
never executed: end of block
0
93-
94/*!-
95 \qmltype AnimationController-
96 \instantiates QQuickAnimationController-
97 \inqmlmodule QtQuick-
98 \ingroup qtquick-animation-control-
99 \brief Enables manual control of animations.-
100-
101 Normally animations are driven by an internal timer, but the AnimationController-
102 allows the given \a animation to be driven by a \a progress value explicitly.-
103*/-
104-
105-
106QQuickAnimationController::QQuickAnimationController(QObject *parent)-
107: QObject(*(new QQuickAnimationControllerPrivate), parent)-
108{-
109}
executed 10 times by 1 test: end of block
Executed by:
  • tst_qquickanimationcontroller
10
110-
111QQuickAnimationController::~QQuickAnimationController()-
112{-
113 Q_D(QQuickAnimationController);-
114 delete d->animationInstance;-
115}
executed 10 times by 1 test: end of block
Executed by:
  • tst_qquickanimationcontroller
10
116-
117/*!-
118 \qmlproperty real QtQuick::AnimationController::progress-
119 This property holds the animation progress value.-
120-
121 The valid \c progress value is 0.0 to 1.0, setting values less than 0 will be converted to 0,-
122 setting values great than 1 will be converted to 1.-
123*/-
124qreal QQuickAnimationController::progress() const-
125{-
126 Q_D(const QQuickAnimationController);-
127 return d->progress;
never executed: return d->progress;
0
128}-
129-
130void QQuickAnimationController::setProgress(qreal progress)-
131{-
132 Q_D(QQuickAnimationController);-
133 progress = qBound(qreal(0), progress, qreal(1));-
134-
135 if (progress != d->progress) {
progress != d->progressDescription
TRUEevaluated 106 times by 1 test
Evaluated by:
  • tst_qquickanimationcontroller
FALSEevaluated 6 times by 1 test
Evaluated by:
  • tst_qquickanimationcontroller
6-106
136 d->progress = progress;-
137 updateProgress();-
138 emit progressChanged();-
139 }
executed 106 times by 1 test: end of block
Executed by:
  • tst_qquickanimationcontroller
106
140}
executed 112 times by 1 test: end of block
Executed by:
  • tst_qquickanimationcontroller
112
141-
142/*!-
143 \qmlproperty Animation QtQuick::AnimationController::animation-
144 \default-
145-
146 This property holds the animation to be controlled by the AnimationController.-
147-
148 Note:An animation controlled by AnimationController will always have its-
149 \c running and \c paused properties set to true. It can not be manually-
150 started or stopped (much like an animation in a Behavior can not be manually started or stopped).-
151*/-
152QQuickAbstractAnimation *QQuickAnimationController::animation() const-
153{-
154 Q_D(const QQuickAnimationController);-
155 return d->animation;
never executed: return d->animation;
0
156}-
157-
158void QQuickAnimationController::classBegin()-
159{-
160 QQmlEnginePrivate *engPriv = QQmlEnginePrivate::get(qmlEngine(this));-
161 engPriv->registerFinalizeCallback(this, this->metaObject()->indexOfSlot("componentFinalized()"));-
162}
executed 10 times by 1 test: end of block
Executed by:
  • tst_qquickanimationcontroller
10
163-
164-
165void QQuickAnimationController::setAnimation(QQuickAbstractAnimation *animation)-
166{-
167 Q_D(QQuickAnimationController);-
168-
169 if (animation != d->animation) {
animation != d->animationDescription
TRUEevaluated 10 times by 1 test
Evaluated by:
  • tst_qquickanimationcontroller
FALSEnever evaluated
0-10
170 if (animation) {
animationDescription
TRUEevaluated 10 times by 1 test
Evaluated by:
  • tst_qquickanimationcontroller
FALSEnever evaluated
0-10
171 if (animation->userControlDisabled()) {
animation->use...trolDisabled()Description
TRUEnever evaluated
FALSEevaluated 10 times by 1 test
Evaluated by:
  • tst_qquickanimationcontroller
0-10
172 qmlWarning(this) << "QQuickAnimationController::setAnimation: the animation is controlled by others, can't be used in AnimationController.";-
173 return;
never executed: return;
0
174 }-
175 animation->setDisableUserControl();-
176 }
executed 10 times by 1 test: end of block
Executed by:
  • tst_qquickanimationcontroller
10
177-
178 if (d->animation)
d->animationDescription
TRUEnever evaluated
FALSEevaluated 10 times by 1 test
Evaluated by:
  • tst_qquickanimationcontroller
0-10
179 d->animation->setEnableUserControl();
never executed: d->animation->setEnableUserControl();
0
180-
181 d->animation = animation;-
182 reload();-
183 emit animationChanged();-
184 }
executed 10 times by 1 test: end of block
Executed by:
  • tst_qquickanimationcontroller
10
185}
executed 10 times by 1 test: end of block
Executed by:
  • tst_qquickanimationcontroller
10
186-
187/*!-
188 \qmlmethod QtQuick::AnimationController::reload()-
189 \brief Reloads the animation properties-
190-
191 If the animation properties changed, calling this method to reload the animation definations.-
192*/-
193void QQuickAnimationController::reload()-
194{-
195 Q_D(QQuickAnimationController);-
196 if (!d->finalized)
!d->finalizedDescription
TRUEevaluated 10 times by 1 test
Evaluated by:
  • tst_qquickanimationcontroller
FALSEevaluated 10 times by 1 test
Evaluated by:
  • tst_qquickanimationcontroller
10
197 return;
executed 10 times by 1 test: return;
Executed by:
  • tst_qquickanimationcontroller
10
198-
199 if (!d->animation) {
!d->animationDescription
TRUEnever evaluated
FALSEevaluated 10 times by 1 test
Evaluated by:
  • tst_qquickanimationcontroller
0-10
200 d->animationInstance = nullptr;-
201 } else {
never executed: end of block
0
202 QQuickStateActions actions;-
203 QQmlProperties properties;-
204 QAbstractAnimationJob *oldInstance = d->animationInstance;-
205 d->animationInstance = d->animation->transition(actions, properties, QQuickAbstractAnimation::Forward);-
206 if (oldInstance && oldInstance != d->animationInstance)
oldInstanceDescription
TRUEnever evaluated
FALSEevaluated 10 times by 1 test
Evaluated by:
  • tst_qquickanimationcontroller
oldInstance !=...mationInstanceDescription
TRUEnever evaluated
FALSEnever evaluated
0-10
207 delete oldInstance;
never executed: delete oldInstance;
0
208 if (d->animationInstance) {
d->animationInstanceDescription
TRUEevaluated 10 times by 1 test
Evaluated by:
  • tst_qquickanimationcontroller
FALSEnever evaluated
0-10
209 d->animationInstance->setLoopCount(1);-
210 d->animationInstance->setDisableUserControl();-
211 d->animationInstance->start();-
212 d->animationInstance->pause();-
213 updateProgress();-
214 }
executed 10 times by 1 test: end of block
Executed by:
  • tst_qquickanimationcontroller
10
215 }
executed 10 times by 1 test: end of block
Executed by:
  • tst_qquickanimationcontroller
10
216}-
217-
218void QQuickAnimationController::updateProgress()-
219{-
220 Q_D(QQuickAnimationController);-
221 if (!d->animationInstance)
!d->animationInstanceDescription
TRUEevaluated 4 times by 1 test
Evaluated by:
  • tst_qquickanimationcontroller
FALSEevaluated 112 times by 1 test
Evaluated by:
  • tst_qquickanimationcontroller
4-112
222 return;
executed 4 times by 1 test: return;
Executed by:
  • tst_qquickanimationcontroller
4
223-
224 d->animationInstance->setDisableUserControl();-
225 d->animationInstance->start();-
226 QQmlAnimationTimer::instance()->unregisterAnimation(d->animationInstance);-
227 d->animationInstance->setCurrentTime(d->progress * d->animationInstance->duration());-
228}
executed 112 times by 1 test: end of block
Executed by:
  • tst_qquickanimationcontroller
112
229-
230void QQuickAnimationController::componentFinalized()-
231{-
232 Q_D(QQuickAnimationController);-
233 d->finalized = true;-
234 reload();-
235}
executed 10 times by 1 test: end of block
Executed by:
  • tst_qquickanimationcontroller
10
236-
237/*!-
238 \qmlmethod QtQuick::AnimationController::completeToBeginning()-
239 \brief Finishes running the controlled animation in a backwards direction.-
240-
241 After calling this method, the animation runs normally from the current progress point-
242 in a backwards direction to the beginning state.-
243-
244 The animation controller's progress value will be automatically updated while the animation is running.-
245-
246 \sa completeToEnd(), progress-
247*/-
248void QQuickAnimationController::completeToBeginning()-
249{-
250 Q_D(QQuickAnimationController);-
251 if (!d->animationInstance)
!d->animationInstanceDescription
TRUEnever evaluated
FALSEnever evaluated
0
252 return;
never executed: return;
0
253-
254 if (d->progress == 0)
d->progress == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
255 return;
never executed: return;
0
256-
257 d->animationInstance->addAnimationChangeListener(d, QAbstractAnimationJob::Completion | QAbstractAnimationJob::CurrentTime);-
258 d->animationInstance->setDirection(QAbstractAnimationJob::Backward);-
259-
260 //Disable and then enable user control to trigger the animation instance's state change-
261 d->animationInstance->setDisableUserControl();-
262 d->animationInstance->setEnableUserControl();-
263 d->animationInstance->start();-
264}
never executed: end of block
0
265-
266/*!-
267 \qmlmethod QtQuick::AnimationController::completeToEnd()-
268 \brief Finishes running the controlled animation in a forwards direction.-
269-
270 After calling this method, the animation runs normally from the current progress point-
271 in a forwards direction to the end state.-
272-
273 The animation controller's progress value will be automatically updated while the animation is running.-
274-
275 \sa completeToBeginning(), progress-
276*/-
277void QQuickAnimationController::completeToEnd()-
278{-
279 Q_D(QQuickAnimationController);-
280 if (!d->animationInstance)
!d->animationInstanceDescription
TRUEnever evaluated
FALSEnever evaluated
0
281 return;
never executed: return;
0
282-
283 if (d->progress == 1)
d->progress == 1Description
TRUEnever evaluated
FALSEnever evaluated
0
284 return;
never executed: return;
0
285-
286 d->animationInstance->addAnimationChangeListener(d, QAbstractAnimationJob::Completion | QAbstractAnimationJob::CurrentTime);-
287 d->animationInstance->setDirection(QAbstractAnimationJob::Forward);-
288-
289 //Disable and then enable user control to trigger the animation instance's state change-
290 d->animationInstance->setDisableUserControl();-
291 d->animationInstance->setEnableUserControl();-
292 d->animationInstance->start();-
293}
never executed: end of block
0
294-
295-
296-
297QT_END_NAMESPACE-
298-
299-
300#include "moc_qquickanimationcontroller_p.cpp"-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.2.0