int QSequentialAnimationGroupPrivate::animationActualTotalDuration(int index) const { QAbstractAnimation *anim = animations.at(index); int ret = anim->totalDuration(); if (ret == -1 && actualDuration.size() > index) ret = actualDuration.at(index); //we can try the actual duration there return ret; }
/*! \reimp */ void QParallelAnimationGroup::updateCurrentTime(int currentTime) { Q_D(QParallelAnimationGroup); if (d->animations.isEmpty()) return; if (d->currentLoop > d->lastLoop) { // simulate completion of the loop int dura = duration(); if (dura > 0) { for (int i = 0; i < d->animations.size(); ++i) { QAbstractAnimation *animation = d->animations.at(i); if (animation->state() != QAbstractAnimation::Stopped) d->animations.at(i)->setCurrentTime(dura); // will stop } } } else if (d->currentLoop < d->lastLoop) { // simulate completion of the loop seeking backwards for (int i = 0; i < d->animations.size(); ++i) { QAbstractAnimation *animation = d->animations.at(i); //we need to make sure the animation is in the right state //and then rewind it d->applyGroupState(animation); animation->setCurrentTime(0); animation->stop(); } } #ifdef QANIMATION_DEBUG qDebug("QParallellAnimationGroup %5d: setCurrentTime(%d), loop:%d, last:%d, timeFwd:%d, lastcurrent:%d, %d", __LINE__, d->currentTime, d->currentLoop, d->lastLoop, timeFwd, d->lastCurrentTime, state()); #endif // finally move into the actual time of the current loop for (int i = 0; i < d->animations.size(); ++i) { QAbstractAnimation *animation = d->animations.at(i); const int dura = animation->totalDuration(); //if the loopcount is bigger we should always start all animations if (d->currentLoop > d->lastLoop //if we're at the end of the animation, we need to start it if it wasn't already started in this loop //this happens in Backward direction where not all animations are started at the same time || d->shouldAnimationStart(animation, d->lastCurrentTime > dura /*startIfAtEnd*/)) { d->applyGroupState(animation); } if (animation->state() == state()) { animation->setCurrentTime(currentTime); if (dura > 0 && currentTime > dura) animation->stop(); } } d->lastLoop = d->currentLoop; d->lastCurrentTime = currentTime; }
/*! \reimp */ int QSequentialAnimationGroup::duration() const { Q_D(const QSequentialAnimationGroup); int ret = 0; for (int i = 0; i < d->animations.size(); ++i) { QAbstractAnimation *animation = d->animations.at(i); const int currentDuration = animation->totalDuration(); if (currentDuration == -1) return -1; // Undetermined length ret += currentDuration; } return ret; }