68int QParallelAnimationGroup::duration()
const
70 Q_D(
const QParallelAnimationGroup);
73 for (
auto ani : std::as_const(d->animations)) {
74 const int currentDuration = ani->totalDuration();
75 if (currentDuration == -1)
78 ret = qMax(ret, currentDuration);
87void QParallelAnimationGroup::updateCurrentTime(
int currentTime)
89 Q_D(QParallelAnimationGroup);
90 if (d->animations.isEmpty())
93 if (d->currentLoop > d->lastLoop) {
95 int dura = duration();
97 for (
auto animation : std::as_const(d->animations)) {
98 if (animation->state() != QAbstractAnimation::Stopped)
99 animation->setCurrentTime(dura);
102 }
else if (d->currentLoop < d->lastLoop) {
104 for (
auto animation : std::as_const(d->animations)) {
107 d->applyGroupState(animation);
108 animation->setCurrentTime(0);
113#ifdef QANIMATION_DEBUG
114 qDebug(
"QParallellAnimationGroup %5d: setCurrentTime(%d), loop:%d, last:%d, timeFwd:%d, lastcurrent:%d, %d",
115 __LINE__, d->currentTime, d->currentLoop, d->lastLoop, timeFwd, d->lastCurrentTime, state());
118 for (
auto animation : std::as_const(d->animations)) {
119 const int dura = animation->totalDuration();
121 if (d->currentLoop > d->lastLoop
124 || d->shouldAnimationStart(animation, d->lastCurrentTime > dura )) {
125 d->applyGroupState(animation);
128 if (animation->state() == state()) {
129 animation->setCurrentTime(currentTime);
130 if (dura > 0 && currentTime > dura)
134 d->lastLoop = d->currentLoop;
135 d->lastCurrentTime = currentTime;
141void QParallelAnimationGroup::updateState(QAbstractAnimation::State newState,
142 QAbstractAnimation::State oldState)
144 Q_D(QParallelAnimationGroup);
145 QAnimationGroup::updateState(newState, oldState);
149 for (
auto ani : std::as_const(d->animations))
151 d->disconnectUncontrolledAnimations();
154 for (
auto ani : std::as_const(d->animations)) {
155 if (ani->state() == Running)
160 d->connectUncontrolledAnimations();
161 for (
auto animation : std::as_const(d->animations)) {
162 if (oldState == Stopped)
164 animation->setDirection(d->direction);
165 if (d->shouldAnimationStart(animation, oldState == Stopped))
172void QParallelAnimationGroupPrivate::_q_uncontrolledAnimationFinished()
174 Q_Q(QParallelAnimationGroup);
176 QAbstractAnimation *animation = qobject_cast<QAbstractAnimation *>(q->sender());
179 int uncontrolledRunningCount = 0;
180 if (animation->duration() == -1 || animation->loopCount() < 0) {
181 for (
AnimationTimeHashIt it = uncontrolledFinishTime.begin(), cend = uncontrolledFinishTime.end(); it != cend; ++it) {
182 if (it.key() == animation) {
183 *it = animation->currentTime();
185 if (it.value() == -1)
186 ++uncontrolledRunningCount;
190 if (uncontrolledRunningCount > 0)
194 for (
auto ani : std::as_const(animations))
195 maxDuration = qMax(maxDuration, ani->totalDuration());
197 if (currentTime >= maxDuration)
209void QParallelAnimationGroupPrivate::connectUncontrolledAnimations()
211 for (
auto animation : std::as_const(animations)) {
212 if (animation->duration() == -1 || animation->loopCount() < 0) {
213 uncontrolledFinishTime[animation] = -1;
214 connectUncontrolledAnimation(animation);
219bool QParallelAnimationGroupPrivate::shouldAnimationStart(QAbstractAnimation *animation,
bool startIfAtEnd)
const
221 const int dura = animation->totalDuration();
223 return !isUncontrolledAnimationFinished(animation);
225 return currentTime <= dura;
226 if (direction == QAbstractAnimation::Forward)
227 return currentTime < dura;
229 return currentTime && currentTime <= dura;
254void QParallelAnimationGroupPrivate::animationRemoved(qsizetype index, QAbstractAnimation *anim)
256 QAnimationGroupPrivate::animationRemoved(index, anim);
257 disconnectUncontrolledAnimation(anim);
258 uncontrolledFinishTime.remove(anim);
264void QParallelAnimationGroup::updateDirection(QAbstractAnimation::Direction direction)
266 Q_D(QParallelAnimationGroup);
268 if (state() != Stopped) {
269 for (
auto ani : std::as_const(d->animations))
270 ani->setDirection(direction);
272 if (direction == Forward) {
274 d->lastCurrentTime = 0;
277 d->lastLoop = (d->loopCount == -1 ? 0 : d->loopCount - 1);
278 d->lastCurrentTime = duration();