1// Copyright (C) 2016 Jolla Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "private/qcontinuinganimationgroupjob_p.h"
5#include "private/qanimationjobutil_p.h"
6
7QT_BEGIN_NAMESPACE
8
9QContinuingAnimationGroupJob::QContinuingAnimationGroupJob()
10{
11}
12
13QContinuingAnimationGroupJob::~QContinuingAnimationGroupJob()
14{
15}
16
17void QContinuingAnimationGroupJob::updateCurrentTime(int /*currentTime*/)
18{
19 Q_ASSERT(!m_children.isEmpty());
20 for (QAbstractAnimationJob *animation : m_children) {
21 if (animation->state() == state()) {
22 RETURN_IF_DELETED(animation->setCurrentTime(m_currentTime));
23 }
24 }
25}
26
27void QContinuingAnimationGroupJob::updateState(QAbstractAnimationJob::State newState,
28 QAbstractAnimationJob::State oldState)
29{
30 QAnimationGroupJob::updateState(newState, oldState);
31
32 switch (newState) {
33 case Stopped:
34 for (QAbstractAnimationJob *animation : m_children)
35 animation->stop();
36 break;
37 case Paused:
38 for (QAbstractAnimationJob *animation : m_children)
39 if (animation->isRunning())
40 animation->pause();
41 break;
42 case Running:
43 if (m_children.isEmpty()) {
44 stop();
45 return;
46 }
47 for (QAbstractAnimationJob *animation : m_children) {
48 RETURN_IF_DELETED(resetUncontrolledAnimationFinishTime(animation));
49 animation->setDirection(m_direction);
50 RETURN_IF_DELETED(animation->start());
51 }
52 break;
53 }
54}
55
56void QContinuingAnimationGroupJob::updateDirection(QAbstractAnimationJob::Direction direction)
57{
58 if (!isStopped()) {
59 for (QAbstractAnimationJob *animation : m_children)
60 animation->setDirection(direction);
61 }
62}
63
64void QContinuingAnimationGroupJob::uncontrolledAnimationFinished(QAbstractAnimationJob *animation)
65{
66 Q_ASSERT(animation && (animation->duration() == -1));
67 int uncontrolledRunningCount = 0;
68
69 for (QAbstractAnimationJob *child : m_children) {
70 if (child == animation)
71 setUncontrolledAnimationFinishTime(anim: animation, time: animation->currentTime());
72 else if (uncontrolledAnimationFinishTime(anim: child) == -1)
73 ++uncontrolledRunningCount;
74 }
75
76 if (uncontrolledRunningCount > 0)
77 return;
78
79 setUncontrolledAnimationFinishTime(anim: this, time: currentTime());
80 stop();
81}
82
83void QContinuingAnimationGroupJob::debugAnimation(QDebug d) const
84{
85 d << "ContinuingAnimationGroupJob(" << Qt::hex << (const void *) this << Qt::dec << ")";
86
87 debugChildren(d);
88}
89
90QT_END_NAMESPACE
91
92

source code of qtdeclarative/src/qml/animations/qcontinuinganimationgroupjob.cpp