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 | |
7 | QT_BEGIN_NAMESPACE |
8 | |
9 | QContinuingAnimationGroupJob::QContinuingAnimationGroupJob() |
10 | { |
11 | } |
12 | |
13 | QContinuingAnimationGroupJob::~QContinuingAnimationGroupJob() |
14 | { |
15 | } |
16 | |
17 | void 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 | |
27 | void 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 | |
56 | void QContinuingAnimationGroupJob::updateDirection(QAbstractAnimationJob::Direction direction) |
57 | { |
58 | if (!isStopped()) { |
59 | for (QAbstractAnimationJob *animation : m_children) |
60 | animation->setDirection(direction); |
61 | } |
62 | } |
63 | |
64 | void 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 | |
83 | void QContinuingAnimationGroupJob::debugAnimation(QDebug d) const |
84 | { |
85 | d << "ContinuingAnimationGroupJob("<< Qt::hex << (const void *) this << Qt::dec << ")"; |
86 | |
87 | debugChildren(d); |
88 | } |
89 | |
90 | QT_END_NAMESPACE |
91 | |
92 |