Line | Source Code | Coverage |
---|
1 | /**************************************************************************** | - |
2 | ** | - |
3 | ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). | - |
4 | ** Contact: http://www.qt-project.org/legal | - |
5 | ** | - |
6 | ** This file is part of the QtCore 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 Digia. For licensing terms and | - |
14 | ** conditions see http://qt.digia.com/licensing. For further information | - |
15 | ** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software | - |
20 | ** Foundation and appearing in the file LICENSE.LGPL included in the | - |
21 | ** packaging of this file. Please review the following information to | - |
22 | ** ensure the GNU Lesser General Public License version 2.1 requirements | - |
23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - |
24 | ** | - |
25 | ** In addition, as a special exception, Digia gives you certain additional | - |
26 | ** rights. These rights are described in the Digia Qt LGPL Exception | - |
27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - |
28 | ** | - |
29 | ** GNU General Public License Usage | - |
30 | ** Alternatively, this file may be used under the terms of the GNU | - |
31 | ** General Public License version 3.0 as published by the Free Software | - |
32 | ** Foundation and appearing in the file LICENSE.GPL included in the | - |
33 | ** packaging of this file. Please review the following information to | - |
34 | ** ensure the GNU General Public License version 3.0 requirements will be | - |
35 | ** met: http://www.gnu.org/copyleft/gpl.html. | - |
36 | ** | - |
37 | ** | - |
38 | ** $QT_END_LICENSE$ | - |
39 | ** | - |
40 | ****************************************************************************/ | - |
41 | | - |
42 | /*! | - |
43 | \class QSequentialAnimationGroup | - |
44 | \inmodule QtCore | - |
45 | \brief The QSequentialAnimationGroup class provides a sequential group of animations. | - |
46 | \since 4.6 | - |
47 | \ingroup animation | - |
48 | | - |
49 | QSequentialAnimationGroup is a QAnimationGroup that runs its | - |
50 | animations in sequence, i.e., it starts one animation after | - |
51 | another has finished playing. The animations are played in the | - |
52 | order they are added to the group (using | - |
53 | \l{QAnimationGroup::}{addAnimation()} or | - |
54 | \l{QAnimationGroup::}{insertAnimation()}). The animation group | - |
55 | finishes when its last animation has finished. | - |
56 | | - |
57 | At each moment there is at most one animation that is active in | - |
58 | the group; it is returned by currentAnimation(). An empty group | - |
59 | has no current animation. | - |
60 | | - |
61 | A sequential animation group can be treated as any other | - |
62 | animation, i.e., it can be started, stopped, and added to other | - |
63 | groups. You can also call addPause() or insertPause() to add a | - |
64 | pause to a sequential animation group. | - |
65 | | - |
66 | \code | - |
67 | QSequentialAnimationGroup *group = new QSequentialAnimationGroup; | - |
68 | | - |
69 | group->addAnimation(anim1); | - |
70 | group->addAnimation(anim2); | - |
71 | | - |
72 | group->start(); | - |
73 | \endcode | - |
74 | | - |
75 | In this example, \c anim1 and \c anim2 are two already set up | - |
76 | \l{QPropertyAnimation}s. | - |
77 | | - |
78 | \sa QAnimationGroup, QAbstractAnimation, {The Animation Framework} | - |
79 | */ | - |
80 | | - |
81 | #include "qsequentialanimationgroup.h" | - |
82 | #include "qsequentialanimationgroup_p.h" | - |
83 | | - |
84 | #include "qpauseanimation.h" | - |
85 | | - |
86 | #include <QtCore/qdebug.h> | - |
87 | | - |
88 | #ifndef QT_NO_ANIMATION | - |
89 | | - |
90 | QT_BEGIN_NAMESPACE | - |
91 | | - |
92 | bool QSequentialAnimationGroupPrivate::atEnd() const | - |
93 | { | - |
94 | // we try to detect if we're at the end of the group | - |
95 | //this is true if the following conditions are true: | - |
96 | // 1. we're in the last loop | - |
97 | // 2. the direction is forward | - |
98 | // 3. the current animation is the last one | - |
99 | // 4. the current animation has reached its end | - |
100 | const int animTotalCurrentTime = QAbstractAnimationPrivate::get(currentAnimation)->totalCurrentTime; executed (the execution status of this line is deduced): const int animTotalCurrentTime = QAbstractAnimationPrivate::get(currentAnimation)->totalCurrentTime; | - |
101 | return (currentLoop == loopCount - 1 executed: return (currentLoop == loopCount - 1 && direction == QAbstractAnimation::Forward && currentAnimation == animations.last() && animTotalCurrentTime == animationActualTotalDuration(currentAnimationIndex)); Execution Count:620 | 620 |
102 | && direction == QAbstractAnimation::Forward executed: return (currentLoop == loopCount - 1 && direction == QAbstractAnimation::Forward && currentAnimation == animations.last() && animTotalCurrentTime == animationActualTotalDuration(currentAnimationIndex)); Execution Count:620 | 620 |
103 | && currentAnimation == animations.last() executed: return (currentLoop == loopCount - 1 && direction == QAbstractAnimation::Forward && currentAnimation == animations.last() && animTotalCurrentTime == animationActualTotalDuration(currentAnimationIndex)); Execution Count:620 | 620 |
104 | && animTotalCurrentTime == animationActualTotalDuration(currentAnimationIndex)); executed: return (currentLoop == loopCount - 1 && direction == QAbstractAnimation::Forward && currentAnimation == animations.last() && animTotalCurrentTime == animationActualTotalDuration(currentAnimationIndex)); Execution Count:620 | 620 |
105 | } | - |
106 | | - |
107 | int QSequentialAnimationGroupPrivate::animationActualTotalDuration(int index) const | - |
108 | { | - |
109 | QAbstractAnimation *anim = animations.at(index); executed (the execution status of this line is deduced): QAbstractAnimation *anim = animations.at(index); | - |
110 | int ret = anim->totalDuration(); executed (the execution status of this line is deduced): int ret = anim->totalDuration(); | - |
111 | if (ret == -1 && actualDuration.size() > index) evaluated: ret == -1 yes Evaluation Count:77 | yes Evaluation Count:1228 |
evaluated: actualDuration.size() > index yes Evaluation Count:21 | yes Evaluation Count:56 |
| 21-1228 |
112 | ret = actualDuration.at(index); //we can try the actual duration there executed: ret = actualDuration.at(index); Execution Count:21 | 21 |
113 | return ret; executed: return ret; Execution Count:1305 | 1305 |
114 | } | - |
115 | | - |
116 | QSequentialAnimationGroupPrivate::AnimationIndex QSequentialAnimationGroupPrivate::indexForCurrentTime() const | - |
117 | { | - |
118 | Q_ASSERT(!animations.isEmpty()); executed (the execution status of this line is deduced): qt_noop(); | - |
119 | | - |
120 | AnimationIndex ret; executed (the execution status of this line is deduced): AnimationIndex ret; | - |
121 | int duration = 0; executed (the execution status of this line is deduced): int duration = 0; | - |
122 | | - |
123 | for (int i = 0; i < animations.size(); ++i) { evaluated: i < animations.size() yes Evaluation Count:949 | yes Evaluation Count:35 |
| 35-949 |
124 | duration = animationActualTotalDuration(i); executed (the execution status of this line is deduced): duration = animationActualTotalDuration(i); | - |
125 | | - |
126 | // 'animation' is the current animation if one of these reasons is true: | - |
127 | // 1. it's duration is undefined | - |
128 | // 2. it ends after msecs | - |
129 | // 3. it is the last animation (this can happen in case there is at least 1 uncontrolled animation) | - |
130 | // 4. it ends exactly in msecs and the direction is backwards | - |
131 | if (duration == -1 || currentTime < (ret.timeOffset + duration) evaluated: duration == -1 yes Evaluation Count:38 | yes Evaluation Count:911 |
evaluated: currentTime < (ret.timeOffset + duration) yes Evaluation Count:545 | yes Evaluation Count:366 |
| 38-911 |
132 | || (currentTime == (ret.timeOffset + duration) && direction == QAbstractAnimation::Backward)) { evaluated: currentTime == (ret.timeOffset + duration) yes Evaluation Count:58 | yes Evaluation Count:308 |
evaluated: direction == QAbstractAnimation::Backward yes Evaluation Count:3 | yes Evaluation Count:55 |
| 3-308 |
133 | ret.index = i; executed (the execution status of this line is deduced): ret.index = i; | - |
134 | return ret; executed: return ret; Execution Count:586 | 586 |
135 | } | - |
136 | | - |
137 | // 'animation' has a non-null defined duration and is not the one at time 'msecs'. | - |
138 | ret.timeOffset += duration; executed (the execution status of this line is deduced): ret.timeOffset += duration; | - |
139 | } executed: } Execution Count:363 | 363 |
140 | | - |
141 | // this can only happen when one of those conditions is true: | - |
142 | // 1. the duration of the group is undefined and we passed its actual duration | - |
143 | // 2. there are only 0-duration animations in the group | - |
144 | ret.timeOffset -= duration; executed (the execution status of this line is deduced): ret.timeOffset -= duration; | - |
145 | ret.index = animations.size() - 1; executed (the execution status of this line is deduced): ret.index = animations.size() - 1; | - |
146 | return ret; executed: return ret; Execution Count:35 | 35 |
147 | } | - |
148 | | - |
149 | void QSequentialAnimationGroupPrivate::restart() | - |
150 | { | - |
151 | // restarting the group by making the first/last animation the current one | - |
152 | if (direction == QAbstractAnimation::Forward) { evaluated: direction == QAbstractAnimation::Forward yes Evaluation Count:45 | yes Evaluation Count:1 |
| 1-45 |
153 | lastLoop = 0; executed (the execution status of this line is deduced): lastLoop = 0; | - |
154 | if (currentAnimationIndex == 0) evaluated: currentAnimationIndex == 0 yes Evaluation Count:34 | yes Evaluation Count:11 |
| 11-34 |
155 | activateCurrentAnimation(); executed: activateCurrentAnimation(); Execution Count:34 | 34 |
156 | else | - |
157 | setCurrentAnimation(0); executed: setCurrentAnimation(0); Execution Count:11 | 11 |
158 | } else { // direction == QAbstractAnimation::Backward | - |
159 | lastLoop = loopCount - 1; executed (the execution status of this line is deduced): lastLoop = loopCount - 1; | - |
160 | int index = animations.size() - 1; executed (the execution status of this line is deduced): int index = animations.size() - 1; | - |
161 | if (currentAnimationIndex == index) partially evaluated: currentAnimationIndex == index yes Evaluation Count:1 | no Evaluation Count:0 |
| 0-1 |
162 | activateCurrentAnimation(); executed: activateCurrentAnimation(); Execution Count:1 | 1 |
163 | else | - |
164 | setCurrentAnimation(index); never executed: setCurrentAnimation(index); | 0 |
165 | } | - |
166 | } | - |
167 | | - |
168 | /*! | - |
169 | \internal | - |
170 | This manages advancing the execution of a group running forwards (time has gone forward), | - |
171 | which is the same behaviour for rewinding the execution of a group running backwards | - |
172 | (time has gone backward). | - |
173 | */ | - |
174 | void QSequentialAnimationGroupPrivate::advanceForwards(const AnimationIndex &newAnimationIndex) | - |
175 | { | - |
176 | if (lastLoop < currentLoop) { evaluated: lastLoop < currentLoop yes Evaluation Count:7 | yes Evaluation Count:50 |
| 7-50 |
177 | // we need to fast forward to the end | - |
178 | for (int i = currentAnimationIndex; i < animations.size(); ++i) { evaluated: i < animations.size() yes Evaluation Count:13 | yes Evaluation Count:7 |
| 7-13 |
179 | QAbstractAnimation *anim = animations.at(i); executed (the execution status of this line is deduced): QAbstractAnimation *anim = animations.at(i); | - |
180 | setCurrentAnimation(i, true); executed (the execution status of this line is deduced): setCurrentAnimation(i, true); | - |
181 | anim->setCurrentTime(animationActualTotalDuration(i)); executed (the execution status of this line is deduced): anim->setCurrentTime(animationActualTotalDuration(i)); | - |
182 | } executed: } Execution Count:13 | 13 |
183 | // this will make sure the current animation is reset to the beginning | - |
184 | if (animations.size() == 1) evaluated: animations.size() == 1 yes Evaluation Count:2 | yes Evaluation Count:5 |
| 2-5 |
185 | // we need to force activation because setCurrentAnimation will have no effect | - |
186 | activateCurrentAnimation(); executed: activateCurrentAnimation(); Execution Count:2 | 2 |
187 | else | - |
188 | setCurrentAnimation(0, true); executed: setCurrentAnimation(0, true); Execution Count:5 | 5 |
189 | } | - |
190 | | - |
191 | // and now we need to fast forward from the current position to | - |
192 | for (int i = currentAnimationIndex; i < newAnimationIndex.index; ++i) { //### WRONG, evaluated: i < newAnimationIndex.index yes Evaluation Count:65 | yes Evaluation Count:57 |
| 57-65 |
193 | QAbstractAnimation *anim = animations.at(i); executed (the execution status of this line is deduced): QAbstractAnimation *anim = animations.at(i); | - |
194 | setCurrentAnimation(i, true); executed (the execution status of this line is deduced): setCurrentAnimation(i, true); | - |
195 | anim->setCurrentTime(animationActualTotalDuration(i)); executed (the execution status of this line is deduced): anim->setCurrentTime(animationActualTotalDuration(i)); | - |
196 | } executed: } Execution Count:65 | 65 |
197 | // setting the new current animation will happen later | - |
198 | } executed: } Execution Count:57 | 57 |
199 | | - |
200 | /*! | - |
201 | \internal | - |
202 | This manages rewinding the execution of a group running forwards (time has gone forward), | - |
203 | which is the same behaviour for advancing the execution of a group running backwards | - |
204 | (time has gone backward). | - |
205 | */ | - |
206 | void QSequentialAnimationGroupPrivate::rewindForwards(const AnimationIndex &newAnimationIndex) | - |
207 | { | - |
208 | if (lastLoop > currentLoop) { evaluated: lastLoop > currentLoop yes Evaluation Count:1 | yes Evaluation Count:3 |
| 1-3 |
209 | // we need to fast rewind to the beginning | - |
210 | for (int i = currentAnimationIndex; i >= 0 ; --i) { evaluated: i >= 0 yes Evaluation Count:4 | yes Evaluation Count:1 |
| 1-4 |
211 | QAbstractAnimation *anim = animations.at(i); executed (the execution status of this line is deduced): QAbstractAnimation *anim = animations.at(i); | - |
212 | setCurrentAnimation(i, true); executed (the execution status of this line is deduced): setCurrentAnimation(i, true); | - |
213 | anim->setCurrentTime(0); executed (the execution status of this line is deduced): anim->setCurrentTime(0); | - |
214 | } executed: } Execution Count:4 | 4 |
215 | // this will make sure the current animation is reset to the end | - |
216 | if (animations.size() == 1) partially evaluated: animations.size() == 1 no Evaluation Count:0 | yes Evaluation Count:1 |
| 0-1 |
217 | // we need to force activation because setCurrentAnimation will have no effect | - |
218 | activateCurrentAnimation(); never executed: activateCurrentAnimation(); | 0 |
219 | else | - |
220 | setCurrentAnimation(animations.count() - 1, true); executed: setCurrentAnimation(animations.count() - 1, true); Execution Count:1 | 1 |
221 | } | - |
222 | | - |
223 | // and now we need to fast rewind from the current position to | - |
224 | for (int i = currentAnimationIndex; i > newAnimationIndex.index; --i) { evaluated: i > newAnimationIndex.index yes Evaluation Count:9 | yes Evaluation Count:4 |
| 4-9 |
225 | QAbstractAnimation *anim = animations.at(i); executed (the execution status of this line is deduced): QAbstractAnimation *anim = animations.at(i); | - |
226 | setCurrentAnimation(i, true); executed (the execution status of this line is deduced): setCurrentAnimation(i, true); | - |
227 | anim->setCurrentTime(0); executed (the execution status of this line is deduced): anim->setCurrentTime(0); | - |
228 | } executed: } Execution Count:9 | 9 |
229 | // setting the new current animation will happen later | - |
230 | } executed: } Execution Count:4 | 4 |
231 | | - |
232 | /*! | - |
233 | \fn QSequentialAnimationGroup::currentAnimationChanged(QAbstractAnimation *current) | - |
234 | | - |
235 | QSequentialAnimationGroup emits this signal when currentAnimation | - |
236 | has been changed. \a current is the current animation. | - |
237 | | - |
238 | \sa currentAnimation() | - |
239 | */ | - |
240 | | - |
241 | | - |
242 | /*! | - |
243 | Constructs a QSequentialAnimationGroup. | - |
244 | \a parent is passed to QObject's constructor. | - |
245 | */ | - |
246 | QSequentialAnimationGroup::QSequentialAnimationGroup(QObject *parent) | - |
247 | : QAnimationGroup(*new QSequentialAnimationGroupPrivate, parent) | - |
248 | { | - |
249 | } executed: } Execution Count:64 | 64 |
250 | | - |
251 | /*! | - |
252 | \internal | - |
253 | */ | - |
254 | QSequentialAnimationGroup::QSequentialAnimationGroup(QSequentialAnimationGroupPrivate &dd, | - |
255 | QObject *parent) | - |
256 | : QAnimationGroup(dd, parent) | - |
257 | { | - |
258 | } | 0 |
259 | | - |
260 | /*! | - |
261 | Destroys the animation group. It will also destroy all its animations. | - |
262 | */ | - |
263 | QSequentialAnimationGroup::~QSequentialAnimationGroup() | - |
264 | { | - |
265 | } | - |
266 | | - |
267 | /*! | - |
268 | Adds a pause of \a msecs to this animation group. | - |
269 | The pause is considered as a special type of animation, thus | - |
270 | \l{QAnimationGroup::animationCount()}{animationCount} will be | - |
271 | increased by one. | - |
272 | | - |
273 | \sa insertPause(), QAnimationGroup::addAnimation() | - |
274 | */ | - |
275 | QPauseAnimation *QSequentialAnimationGroup::addPause(int msecs) | - |
276 | { | - |
277 | QPauseAnimation *pause = new QPauseAnimation(msecs); executed (the execution status of this line is deduced): QPauseAnimation *pause = new QPauseAnimation(msecs); | - |
278 | addAnimation(pause); executed (the execution status of this line is deduced): addAnimation(pause); | - |
279 | return pause; executed: return pause; Execution Count:22 | 22 |
280 | } | - |
281 | | - |
282 | /*! | - |
283 | Inserts a pause of \a msecs milliseconds at \a index in this animation | - |
284 | group. | - |
285 | | - |
286 | \sa addPause(), QAnimationGroup::insertAnimation() | - |
287 | */ | - |
288 | QPauseAnimation *QSequentialAnimationGroup::insertPause(int index, int msecs) | - |
289 | { | - |
290 | Q_D(const QSequentialAnimationGroup); never executed (the execution status of this line is deduced): const QSequentialAnimationGroupPrivate * const d = d_func(); | - |
291 | | - |
292 | if (index < 0 || index > d->animations.size()) { never evaluated: index < 0 never evaluated: index > d->animations.size() | 0 |
293 | qWarning("QSequentialAnimationGroup::insertPause: index is out of bounds"); never executed (the execution status of this line is deduced): QMessageLogger("animation/qsequentialanimationgroup.cpp", 293, __PRETTY_FUNCTION__).warning("QSequentialAnimationGroup::insertPause: index is out of bounds"); | - |
294 | return 0; never executed: return 0; | 0 |
295 | } | - |
296 | | - |
297 | QPauseAnimation *pause = new QPauseAnimation(msecs); never executed (the execution status of this line is deduced): QPauseAnimation *pause = new QPauseAnimation(msecs); | - |
298 | insertAnimation(index, pause); never executed (the execution status of this line is deduced): insertAnimation(index, pause); | - |
299 | return pause; never executed: return pause; | 0 |
300 | } | - |
301 | | - |
302 | | - |
303 | /*! | - |
304 | \property QSequentialAnimationGroup::currentAnimation | - |
305 | Returns the animation in the current time. | - |
306 | | - |
307 | \sa currentAnimationChanged() | - |
308 | */ | - |
309 | QAbstractAnimation *QSequentialAnimationGroup::currentAnimation() const | - |
310 | { | - |
311 | Q_D(const QSequentialAnimationGroup); executed (the execution status of this line is deduced): const QSequentialAnimationGroupPrivate * const d = d_func(); | - |
312 | return d->currentAnimation; executed: return d->currentAnimation; Execution Count:28 | 28 |
313 | } | - |
314 | | - |
315 | /*! | - |
316 | \reimp | - |
317 | */ | - |
318 | int QSequentialAnimationGroup::duration() const | - |
319 | { | - |
320 | Q_D(const QSequentialAnimationGroup); executed (the execution status of this line is deduced): const QSequentialAnimationGroupPrivate * const d = d_func(); | - |
321 | int ret = 0; executed (the execution status of this line is deduced): int ret = 0; | - |
322 | | - |
323 | for (int i = 0; i < d->animations.size(); ++i) { evaluated: i < d->animations.size() yes Evaluation Count:4321 | yes Evaluation Count:1924 |
| 1924-4321 |
324 | QAbstractAnimation *animation = d->animations.at(i); executed (the execution status of this line is deduced): QAbstractAnimation *animation = d->animations.at(i); | - |
325 | const int currentDuration = animation->totalDuration(); executed (the execution status of this line is deduced): const int currentDuration = animation->totalDuration(); | - |
326 | if (currentDuration == -1) evaluated: currentDuration == -1 yes Evaluation Count:65 | yes Evaluation Count:4256 |
| 65-4256 |
327 | return -1; // Undetermined length executed: return -1; Execution Count:65 | 65 |
328 | | - |
329 | ret += currentDuration; executed (the execution status of this line is deduced): ret += currentDuration; | - |
330 | } executed: } Execution Count:4256 | 4256 |
331 | | - |
332 | return ret; executed: return ret; Execution Count:1924 | 1924 |
333 | } | - |
334 | | - |
335 | /*! | - |
336 | \reimp | - |
337 | */ | - |
338 | void QSequentialAnimationGroup::updateCurrentTime(int currentTime) | - |
339 | { | - |
340 | Q_D(QSequentialAnimationGroup); executed (the execution status of this line is deduced): QSequentialAnimationGroupPrivate * const d = d_func(); | - |
341 | if (!d->currentAnimation) evaluated: !d->currentAnimation yes Evaluation Count:2 | yes Evaluation Count:621 |
| 2-621 |
342 | return; executed: return; Execution Count:2 | 2 |
343 | | - |
344 | const QSequentialAnimationGroupPrivate::AnimationIndex newAnimationIndex = d->indexForCurrentTime(); executed (the execution status of this line is deduced): const QSequentialAnimationGroupPrivate::AnimationIndex newAnimationIndex = d->indexForCurrentTime(); | - |
345 | | - |
346 | // remove unneeded animations from actualDuration list | - |
347 | while (newAnimationIndex.index < d->actualDuration.size()) evaluated: newAnimationIndex.index < d->actualDuration.size() yes Evaluation Count:1 | yes Evaluation Count:621 |
| 1-621 |
348 | d->actualDuration.removeLast(); executed: d->actualDuration.removeLast(); Execution Count:1 | 1 |
349 | | - |
350 | // newAnimationIndex.index is the new current animation | - |
351 | if (d->lastLoop < d->currentLoop evaluated: d->lastLoop < d->currentLoop yes Evaluation Count:7 | yes Evaluation Count:614 |
| 7-614 |
352 | || (d->lastLoop == d->currentLoop && d->currentAnimationIndex < newAnimationIndex.index)) { evaluated: d->lastLoop == d->currentLoop yes Evaluation Count:613 | yes Evaluation Count:1 |
evaluated: d->currentAnimationIndex < newAnimationIndex.index yes Evaluation Count:50 | yes Evaluation Count:563 |
| 1-613 |
353 | // advancing with forward direction is the same as rewinding with backwards direction | - |
354 | d->advanceForwards(newAnimationIndex); executed (the execution status of this line is deduced): d->advanceForwards(newAnimationIndex); | - |
355 | } else if (d->lastLoop > d->currentLoop executed: } Execution Count:57 evaluated: d->lastLoop > d->currentLoop yes Evaluation Count:1 | yes Evaluation Count:563 |
| 1-563 |
356 | || (d->lastLoop == d->currentLoop && d->currentAnimationIndex > newAnimationIndex.index)) { partially evaluated: d->lastLoop == d->currentLoop yes Evaluation Count:563 | no Evaluation Count:0 |
evaluated: d->currentAnimationIndex > newAnimationIndex.index yes Evaluation Count:3 | yes Evaluation Count:560 |
| 0-563 |
357 | // rewinding with forward direction is the same as advancing with backwards direction | - |
358 | d->rewindForwards(newAnimationIndex); executed (the execution status of this line is deduced): d->rewindForwards(newAnimationIndex); | - |
359 | } executed: } Execution Count:4 | 4 |
360 | | - |
361 | d->setCurrentAnimation(newAnimationIndex.index); executed (the execution status of this line is deduced): d->setCurrentAnimation(newAnimationIndex.index); | - |
362 | | - |
363 | const int newCurrentTime = currentTime - newAnimationIndex.timeOffset; executed (the execution status of this line is deduced): const int newCurrentTime = currentTime - newAnimationIndex.timeOffset; | - |
364 | | - |
365 | if (d->currentAnimation) { evaluated: d->currentAnimation yes Evaluation Count:620 | yes Evaluation Count:1 |
| 1-620 |
366 | d->currentAnimation->setCurrentTime(newCurrentTime); executed (the execution status of this line is deduced): d->currentAnimation->setCurrentTime(newCurrentTime); | - |
367 | if (d->atEnd()) { evaluated: d->atEnd() yes Evaluation Count:35 | yes Evaluation Count:585 |
| 35-585 |
368 | //we make sure that we don't exceed the duration here | - |
369 | d->currentTime += QAbstractAnimationPrivate::get(d->currentAnimation)->totalCurrentTime - newCurrentTime; executed (the execution status of this line is deduced): d->currentTime += QAbstractAnimationPrivate::get(d->currentAnimation)->totalCurrentTime - newCurrentTime; | - |
370 | stop(); executed (the execution status of this line is deduced): stop(); | - |
371 | } executed: } Execution Count:35 | 35 |
372 | } else { executed: } Execution Count:620 | 620 |
373 | //the only case where currentAnimation could be null | - |
374 | //is when all animations have been removed | - |
375 | Q_ASSERT(d->animations.isEmpty()); executed (the execution status of this line is deduced): qt_noop(); | - |
376 | d->currentTime = 0; executed (the execution status of this line is deduced): d->currentTime = 0; | - |
377 | stop(); executed (the execution status of this line is deduced): stop(); | - |
378 | } executed: } Execution Count:1 | 1 |
379 | | - |
380 | d->lastLoop = d->currentLoop; executed (the execution status of this line is deduced): d->lastLoop = d->currentLoop; | - |
381 | } executed: } Execution Count:621 | 621 |
382 | | - |
383 | /*! | - |
384 | \reimp | - |
385 | */ | - |
386 | void QSequentialAnimationGroup::updateState(QAbstractAnimation::State newState, | - |
387 | QAbstractAnimation::State oldState) | - |
388 | { | - |
389 | Q_D(QSequentialAnimationGroup); executed (the execution status of this line is deduced): QSequentialAnimationGroupPrivate * const d = d_func(); | - |
390 | QAnimationGroup::updateState(newState, oldState); executed (the execution status of this line is deduced): QAnimationGroup::updateState(newState, oldState); | - |
391 | | - |
392 | if (!d->currentAnimation) evaluated: !d->currentAnimation yes Evaluation Count:4 | yes Evaluation Count:101 |
| 4-101 |
393 | return; executed: return; Execution Count:4 | 4 |
394 | | - |
395 | switch (newState) { | - |
396 | case Stopped: | - |
397 | d->currentAnimation->stop(); executed (the execution status of this line is deduced): d->currentAnimation->stop(); | - |
398 | break; executed: break; Execution Count:40 | 40 |
399 | case Paused: | - |
400 | if (oldState == d->currentAnimation->state() partially evaluated: oldState == d->currentAnimation->state() yes Evaluation Count:13 | no Evaluation Count:0 |
| 0-13 |
401 | && oldState == QSequentialAnimationGroup::Running) { partially evaluated: oldState == QSequentialAnimationGroup::Running yes Evaluation Count:13 | no Evaluation Count:0 |
| 0-13 |
402 | d->currentAnimation->pause(); executed (the execution status of this line is deduced): d->currentAnimation->pause(); | - |
403 | } executed: } Execution Count:13 | 13 |
404 | else | - |
405 | d->restart(); never executed: d->restart(); | 0 |
406 | break; executed: break; Execution Count:13 | 13 |
407 | case Running: | - |
408 | if (oldState == d->currentAnimation->state() evaluated: oldState == d->currentAnimation->state() yes Evaluation Count:47 | yes Evaluation Count:1 |
| 1-47 |
409 | && oldState == QSequentialAnimationGroup::Paused) evaluated: oldState == QSequentialAnimationGroup::Paused yes Evaluation Count:2 | yes Evaluation Count:45 |
| 2-45 |
410 | d->currentAnimation->start(); executed: d->currentAnimation->start(); Execution Count:2 | 2 |
411 | else | - |
412 | d->restart(); executed: d->restart(); Execution Count:46 | 46 |
413 | break; executed: break; Execution Count:48 | 48 |
414 | } | - |
415 | } executed: } Execution Count:101 | 101 |
416 | | - |
417 | /*! | - |
418 | \reimp | - |
419 | */ | - |
420 | void QSequentialAnimationGroup::updateDirection(QAbstractAnimation::Direction direction) | - |
421 | { | - |
422 | Q_D(QSequentialAnimationGroup); executed (the execution status of this line is deduced): QSequentialAnimationGroupPrivate * const d = d_func(); | - |
423 | // we need to update the direction of the current animation | - |
424 | if (state() != Stopped && d->currentAnimation) partially evaluated: state() != Stopped no Evaluation Count:0 | yes Evaluation Count:2 |
never evaluated: d->currentAnimation | 0-2 |
425 | d->currentAnimation->setDirection(direction); never executed: d->currentAnimation->setDirection(direction); | 0 |
426 | } executed: } Execution Count:2 | 2 |
427 | | - |
428 | /*! | - |
429 | \reimp | - |
430 | */ | - |
431 | bool QSequentialAnimationGroup::event(QEvent *event) | - |
432 | { | - |
433 | return QAnimationGroup::event(event); executed: return QAnimationGroup::event(event); Execution Count:266 | 266 |
434 | } | - |
435 | | - |
436 | void QSequentialAnimationGroupPrivate::setCurrentAnimation(int index, bool intermediate) | - |
437 | { | - |
438 | Q_Q(QSequentialAnimationGroup); executed (the execution status of this line is deduced): QSequentialAnimationGroup * const q = q_func(); | - |
439 | | - |
440 | index = qMin(index, animations.count() - 1); executed (the execution status of this line is deduced): index = qMin(index, animations.count() - 1); | - |
441 | | - |
442 | if (index == -1) { evaluated: index == -1 yes Evaluation Count:23 | yes Evaluation Count:898 |
| 23-898 |
443 | Q_ASSERT(animations.isEmpty()); executed (the execution status of this line is deduced): qt_noop(); | - |
444 | currentAnimationIndex = -1; executed (the execution status of this line is deduced): currentAnimationIndex = -1; | - |
445 | currentAnimation = 0; executed (the execution status of this line is deduced): currentAnimation = 0; | - |
446 | return; executed: return; Execution Count:23 | 23 |
447 | } | - |
448 | | - |
449 | // need these two checks below because this func can be called after the current animation | - |
450 | // has been removed | - |
451 | if (index == currentAnimationIndex && animations.at(index) == currentAnimation) evaluated: index == currentAnimationIndex yes Evaluation Count:720 | yes Evaluation Count:178 |
evaluated: animations.at(index) == currentAnimation yes Evaluation Count:693 | yes Evaluation Count:27 |
| 27-720 |
452 | return; executed: return; Execution Count:693 | 693 |
453 | | - |
454 | // stop the old current animation | - |
455 | if (currentAnimation) evaluated: currentAnimation yes Evaluation Count:140 | yes Evaluation Count:65 |
| 65-140 |
456 | currentAnimation->stop(); executed: currentAnimation->stop(); Execution Count:140 | 140 |
457 | | - |
458 | currentAnimation = animations.at(index); executed (the execution status of this line is deduced): currentAnimation = animations.at(index); | - |
459 | currentAnimationIndex = index; executed (the execution status of this line is deduced): currentAnimationIndex = index; | - |
460 | | - |
461 | emit q->currentAnimationChanged(currentAnimation); executed (the execution status of this line is deduced): q->currentAnimationChanged(currentAnimation); | - |
462 | | - |
463 | activateCurrentAnimation(intermediate); executed (the execution status of this line is deduced): activateCurrentAnimation(intermediate); | - |
464 | } executed: } Execution Count:205 | 205 |
465 | | - |
466 | void QSequentialAnimationGroupPrivate::activateCurrentAnimation(bool intermediate) | - |
467 | { | - |
468 | if (!currentAnimation || state == QSequentialAnimationGroup::Stopped) partially evaluated: !currentAnimation no Evaluation Count:0 | yes Evaluation Count:242 |
evaluated: state == QSequentialAnimationGroup::Stopped yes Evaluation Count:126 | yes Evaluation Count:116 |
| 0-242 |
469 | return; executed: return; Execution Count:126 | 126 |
470 | | - |
471 | currentAnimation->stop(); executed (the execution status of this line is deduced): currentAnimation->stop(); | - |
472 | | - |
473 | // we ensure the direction is consistent with the group's direction | - |
474 | currentAnimation->setDirection(direction); executed (the execution status of this line is deduced): currentAnimation->setDirection(direction); | - |
475 | | - |
476 | // connects to the finish signal of uncontrolled animations | - |
477 | if (currentAnimation->totalDuration() == -1) evaluated: currentAnimation->totalDuration() == -1 yes Evaluation Count:6 | yes Evaluation Count:110 |
| 6-110 |
478 | connectUncontrolledAnimation(currentAnimation); executed: connectUncontrolledAnimation(currentAnimation); Execution Count:6 | 6 |
479 | | - |
480 | currentAnimation->start(); executed (the execution status of this line is deduced): currentAnimation->start(); | - |
481 | if (!intermediate && state == QSequentialAnimationGroup::Paused) evaluated: !intermediate yes Evaluation Count:91 | yes Evaluation Count:25 |
evaluated: state == QSequentialAnimationGroup::Paused yes Evaluation Count:9 | yes Evaluation Count:82 |
| 9-91 |
482 | currentAnimation->pause(); executed: currentAnimation->pause(); Execution Count:9 | 9 |
483 | } executed: } Execution Count:116 | 116 |
484 | | - |
485 | void QSequentialAnimationGroupPrivate::_q_uncontrolledAnimationFinished() | - |
486 | { | - |
487 | Q_Q(QSequentialAnimationGroup); executed (the execution status of this line is deduced): QSequentialAnimationGroup * const q = q_func(); | - |
488 | Q_ASSERT(qobject_cast<QAbstractAnimation *>(q->sender()) == currentAnimation); executed (the execution status of this line is deduced): qt_noop(); | - |
489 | | - |
490 | // we trust the duration returned by the animation | - |
491 | while (actualDuration.size() < (currentAnimationIndex + 1)) evaluated: actualDuration.size() < (currentAnimationIndex + 1) yes Evaluation Count:7 | yes Evaluation Count:6 |
| 6-7 |
492 | actualDuration.append(-1); executed: actualDuration.append(-1); Execution Count:7 | 7 |
493 | actualDuration[currentAnimationIndex] = currentAnimation->currentTime(); executed (the execution status of this line is deduced): actualDuration[currentAnimationIndex] = currentAnimation->currentTime(); | - |
494 | | - |
495 | disconnectUncontrolledAnimation(currentAnimation); executed (the execution status of this line is deduced): disconnectUncontrolledAnimation(currentAnimation); | - |
496 | | - |
497 | if ((direction == QAbstractAnimation::Forward && currentAnimation == animations.last()) partially evaluated: direction == QAbstractAnimation::Forward yes Evaluation Count:6 | no Evaluation Count:0 |
evaluated: currentAnimation == animations.last() yes Evaluation Count:3 | yes Evaluation Count:3 |
| 0-6 |
498 | || (direction == QAbstractAnimation::Backward && currentAnimationIndex == 0)) { partially evaluated: direction == QAbstractAnimation::Backward no Evaluation Count:0 | yes Evaluation Count:3 |
never evaluated: currentAnimationIndex == 0 | 0-3 |
499 | // we don't handle looping of a group with undefined duration | - |
500 | q->stop(); executed (the execution status of this line is deduced): q->stop(); | - |
501 | } else if (direction == QAbstractAnimation::Forward) { executed: } Execution Count:3 partially evaluated: direction == QAbstractAnimation::Forward yes Evaluation Count:3 | no Evaluation Count:0 |
| 0-3 |
502 | // set the current animation to be the next one | - |
503 | setCurrentAnimation(currentAnimationIndex + 1); executed (the execution status of this line is deduced): setCurrentAnimation(currentAnimationIndex + 1); | - |
504 | } else { executed: } Execution Count:3 | 3 |
505 | // set the current animation to be the previous one | - |
506 | setCurrentAnimation(currentAnimationIndex - 1); never executed (the execution status of this line is deduced): setCurrentAnimation(currentAnimationIndex - 1); | - |
507 | } | 0 |
508 | } | - |
509 | | - |
510 | /*! | - |
511 | \internal | - |
512 | This method is called whenever an animation is added to | - |
513 | the group at index \a index. | - |
514 | Note: We only support insertion after the current animation | - |
515 | */ | - |
516 | void QSequentialAnimationGroupPrivate::animationInsertedAt(int index) | - |
517 | { | - |
518 | if (currentAnimation == 0) evaluated: currentAnimation == 0 yes Evaluation Count:65 | yes Evaluation Count:79 |
| 65-79 |
519 | setCurrentAnimation(0); // initialize the current animation executed: setCurrentAnimation(0); Execution Count:65 | 65 |
520 | | - |
521 | if (currentAnimationIndex == index evaluated: currentAnimationIndex == index yes Evaluation Count:66 | yes Evaluation Count:78 |
| 66-78 |
522 | && currentAnimation->currentTime() == 0 && currentAnimation->currentLoop() == 0) { partially evaluated: currentAnimation->currentTime() == 0 yes Evaluation Count:66 | no Evaluation Count:0 |
partially evaluated: currentAnimation->currentLoop() == 0 yes Evaluation Count:66 | no Evaluation Count:0 |
| 0-66 |
523 | //in this case we simply insert an animation before the current one has actually started | - |
524 | setCurrentAnimation(index); executed (the execution status of this line is deduced): setCurrentAnimation(index); | - |
525 | } executed: } Execution Count:66 | 66 |
526 | | - |
527 | //we update currentAnimationIndex in case it has changed (the animation pointer is still valid) | - |
528 | currentAnimationIndex = animations.indexOf(currentAnimation); executed (the execution status of this line is deduced): currentAnimationIndex = animations.indexOf(currentAnimation); | - |
529 | | - |
530 | if (index < currentAnimationIndex || currentLoop != 0) { partially evaluated: index < currentAnimationIndex no Evaluation Count:0 | yes Evaluation Count:144 |
evaluated: currentLoop != 0 yes Evaluation Count:1 | yes Evaluation Count:143 |
| 0-144 |
531 | qWarning("QSequentialGroup::insertAnimation only supports to add animations after the current one."); executed (the execution status of this line is deduced): QMessageLogger("animation/qsequentialanimationgroup.cpp", 531, __PRETTY_FUNCTION__).warning("QSequentialGroup::insertAnimation only supports to add animations after the current one."); | - |
532 | return; //we're not affected because it is added after the current one executed: return; Execution Count:1 | 1 |
533 | } | - |
534 | } executed: } Execution Count:143 | 143 |
535 | | - |
536 | /*! | - |
537 | \internal | - |
538 | This method is called whenever an animation is removed from | - |
539 | the group at index \a index. The animation is no more listed when this | - |
540 | method is called. | - |
541 | */ | - |
542 | void QSequentialAnimationGroupPrivate::animationRemoved(int index, QAbstractAnimation *anim) | - |
543 | { | - |
544 | Q_Q(QSequentialAnimationGroup); executed (the execution status of this line is deduced): QSequentialAnimationGroup * const q = q_func(); | - |
545 | QAnimationGroupPrivate::animationRemoved(index, anim); executed (the execution status of this line is deduced): QAnimationGroupPrivate::animationRemoved(index, anim); | - |
546 | | - |
547 | Q_ASSERT(currentAnimation); // currentAnimation should always be set executed (the execution status of this line is deduced): qt_noop(); | - |
548 | | - |
549 | if (actualDuration.size() > index) evaluated: actualDuration.size() > index yes Evaluation Count:3 | yes Evaluation Count:62 |
| 3-62 |
550 | actualDuration.removeAt(index); executed: actualDuration.removeAt(index); Execution Count:3 | 3 |
551 | | - |
552 | const int currentIndex = animations.indexOf(currentAnimation); executed (the execution status of this line is deduced): const int currentIndex = animations.indexOf(currentAnimation); | - |
553 | if (currentIndex == -1) { evaluated: currentIndex == -1 yes Evaluation Count:58 | yes Evaluation Count:7 |
| 7-58 |
554 | //we're removing the current animation | - |
555 | | - |
556 | disconnectUncontrolledAnimation(currentAnimation); executed (the execution status of this line is deduced): disconnectUncontrolledAnimation(currentAnimation); | - |
557 | | - |
558 | if (index < animations.count()) evaluated: index < animations.count() yes Evaluation Count:25 | yes Evaluation Count:33 |
| 25-33 |
559 | setCurrentAnimation(index); //let's try to take the next one executed: setCurrentAnimation(index); Execution Count:25 | 25 |
560 | else if (index > 0) evaluated: index > 0 yes Evaluation Count:11 | yes Evaluation Count:22 |
| 11-22 |
561 | setCurrentAnimation(index - 1); executed: setCurrentAnimation(index - 1); Execution Count:11 | 11 |
562 | else// case all animations were removed | - |
563 | setCurrentAnimation(-1); executed: setCurrentAnimation(-1); Execution Count:22 | 22 |
564 | } else if (currentAnimationIndex > index) { evaluated: currentAnimationIndex > index yes Evaluation Count:1 | yes Evaluation Count:6 |
| 1-6 |
565 | currentAnimationIndex--; executed (the execution status of this line is deduced): currentAnimationIndex--; | - |
566 | } executed: } Execution Count:1 | 1 |
567 | | - |
568 | // duration of the previous animations up to the current animation | - |
569 | currentTime = 0; executed (the execution status of this line is deduced): currentTime = 0; | - |
570 | for (int i = 0; i < currentAnimationIndex; ++i) { evaluated: i < currentAnimationIndex yes Evaluation Count:7 | yes Evaluation Count:65 |
| 7-65 |
571 | const int current = animationActualTotalDuration(i); executed (the execution status of this line is deduced): const int current = animationActualTotalDuration(i); | - |
572 | currentTime += current; executed (the execution status of this line is deduced): currentTime += current; | - |
573 | } executed: } Execution Count:7 | 7 |
574 | | - |
575 | if (currentIndex != -1) { evaluated: currentIndex != -1 yes Evaluation Count:7 | yes Evaluation Count:58 |
| 7-58 |
576 | //the current animation is not the one being removed | - |
577 | //so we add its current time to the current time of this group | - |
578 | currentTime += QAbstractAnimationPrivate::get(currentAnimation)->totalCurrentTime; executed (the execution status of this line is deduced): currentTime += QAbstractAnimationPrivate::get(currentAnimation)->totalCurrentTime; | - |
579 | } executed: } Execution Count:7 | 7 |
580 | | - |
581 | //let's also update the total current time | - |
582 | totalCurrentTime = currentTime + loopCount * q->duration(); executed (the execution status of this line is deduced): totalCurrentTime = currentTime + loopCount * q->duration(); | - |
583 | } executed: } Execution Count:65 | 65 |
584 | | - |
585 | QT_END_NAMESPACE | - |
586 | | - |
587 | #include "moc_qsequentialanimationgroup.cpp" | - |
588 | | - |
589 | #endif //QT_NO_ANIMATION | - |
590 | | - |
| | |