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