1 | /**************************************************************************** |
---|---|
2 | ** |
3 | ** Copyright (C) 2016 Jolla Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the QtQml module of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:LGPL$ |
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 https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://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 3 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 3 requirements |
23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
24 | ** |
25 | ** GNU General Public License Usage |
26 | ** Alternatively, this file may be used under the terms of the GNU |
27 | ** General Public License version 2.0 or (at your option) the GNU General |
28 | ** Public license version 3 or any later version approved by the KDE Free |
29 | ** Qt Foundation. The licenses are as published by the Free Software |
30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
31 | ** included in the packaging of this file. Please review the following |
32 | ** information to ensure the GNU General Public License requirements will |
33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
35 | ** |
36 | ** $QT_END_LICENSE$ |
37 | ** |
38 | ****************************************************************************/ |
39 | |
40 | #include "private/qcontinuinganimationgroupjob_p.h" |
41 | #include "private/qanimationjobutil_p.h" |
42 | |
43 | QT_BEGIN_NAMESPACE |
44 | |
45 | QContinuingAnimationGroupJob::QContinuingAnimationGroupJob() |
46 | { |
47 | } |
48 | |
49 | QContinuingAnimationGroupJob::~QContinuingAnimationGroupJob() |
50 | { |
51 | } |
52 | |
53 | void QContinuingAnimationGroupJob::updateCurrentTime(int /*currentTime*/) |
54 | { |
55 | Q_ASSERT(firstChild()); |
56 | |
57 | for (QAbstractAnimationJob *animation = firstChild(); animation; animation = animation->nextSibling()) { |
58 | if (animation->state() == state()) { |
59 | RETURN_IF_DELETED(animation->setCurrentTime(m_currentTime)); |
60 | } |
61 | } |
62 | } |
63 | |
64 | void QContinuingAnimationGroupJob::updateState(QAbstractAnimationJob::State newState, |
65 | QAbstractAnimationJob::State oldState) |
66 | { |
67 | QAnimationGroupJob::updateState(newState, oldState); |
68 | |
69 | switch (newState) { |
70 | case Stopped: |
71 | for (QAbstractAnimationJob *animation = firstChild(); animation; animation = animation->nextSibling()) |
72 | animation->stop(); |
73 | break; |
74 | case Paused: |
75 | for (QAbstractAnimationJob *animation = firstChild(); animation; animation = animation->nextSibling()) |
76 | if (animation->isRunning()) |
77 | animation->pause(); |
78 | break; |
79 | case Running: |
80 | if (!firstChild()) { |
81 | stop(); |
82 | return; |
83 | } |
84 | for (QAbstractAnimationJob *animation = firstChild(); animation; animation = animation->nextSibling()) { |
85 | resetUncontrolledAnimationFinishTime(anim: animation); |
86 | animation->setDirection(m_direction); |
87 | animation->start(); |
88 | } |
89 | break; |
90 | } |
91 | } |
92 | |
93 | void QContinuingAnimationGroupJob::updateDirection(QAbstractAnimationJob::Direction direction) |
94 | { |
95 | if (!isStopped()) { |
96 | for (QAbstractAnimationJob *animation = firstChild(); animation; animation = animation->nextSibling()) { |
97 | animation->setDirection(direction); |
98 | } |
99 | } |
100 | } |
101 | |
102 | void QContinuingAnimationGroupJob::uncontrolledAnimationFinished(QAbstractAnimationJob *animation) |
103 | { |
104 | Q_ASSERT(animation && (animation->duration() == -1)); |
105 | int uncontrolledRunningCount = 0; |
106 | |
107 | for (QAbstractAnimationJob *child = firstChild(); child; child = child->nextSibling()) { |
108 | if (child == animation) |
109 | setUncontrolledAnimationFinishTime(anim: animation, time: animation->currentTime()); |
110 | else if (uncontrolledAnimationFinishTime(anim: child) == -1) |
111 | ++uncontrolledRunningCount; |
112 | } |
113 | |
114 | if (uncontrolledRunningCount > 0) |
115 | return; |
116 | |
117 | setUncontrolledAnimationFinishTime(anim: this, time: currentTime()); |
118 | stop(); |
119 | } |
120 | |
121 | void QContinuingAnimationGroupJob::debugAnimation(QDebug d) const |
122 | { |
123 | d << "ContinuingAnimationGroupJob("<< Qt::hex << (const void *) this << Qt::dec << ")"; |
124 | |
125 | debugChildren(d); |
126 | } |
127 | |
128 | QT_END_NAMESPACE |
129 | |
130 |