1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company 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/qanimationgroupjob_p.h"
41
42QT_BEGIN_NAMESPACE
43
44QAnimationGroupJob::QAnimationGroupJob()
45 : QAbstractAnimationJob(), m_firstChild(nullptr), m_lastChild(nullptr)
46{
47 m_isGroup = true;
48}
49
50void QAnimationGroupJob::ungroupChild(QAbstractAnimationJob *animation)
51{
52 Q_ASSERT(animation);
53 Q_ASSERT(animation->m_group == this);
54 QAbstractAnimationJob *prev = animation->previousSibling();
55 QAbstractAnimationJob *next = animation->nextSibling();
56
57 if (prev)
58 prev->m_nextSibling = next;
59 else
60 m_firstChild = next;
61
62 if (next)
63 next->m_previousSibling = prev;
64 else
65 m_lastChild = prev;
66
67 animation->m_previousSibling = nullptr;
68 animation->m_nextSibling = nullptr;
69
70 animation->m_group = nullptr;
71}
72
73void QAnimationGroupJob::handleAnimationRemoved(QAbstractAnimationJob *animation)
74{
75 resetUncontrolledAnimationFinishTime(anim: animation);
76 if (!firstChild()) {
77 m_currentTime = 0;
78 stop();
79 }
80}
81
82QAnimationGroupJob::~QAnimationGroupJob()
83{
84 while (QAbstractAnimationJob *animation = firstChild()) {
85 ungroupChild(animation);
86 handleAnimationRemoved(animation);
87 delete animation;
88 }
89}
90
91void QAnimationGroupJob::topLevelAnimationLoopChanged()
92{
93 for (QAbstractAnimationJob *animation = firstChild(); animation; animation = animation->nextSibling())
94 animation->fireTopLevelAnimationLoopChanged();
95}
96
97void QAnimationGroupJob::appendAnimation(QAbstractAnimationJob *animation)
98{
99 if (QAnimationGroupJob *oldGroup = animation->m_group)
100 oldGroup->removeAnimation(animation);
101
102 Q_ASSERT(!animation->previousSibling() && !animation->nextSibling());
103
104 if (m_lastChild)
105 m_lastChild->m_nextSibling = animation;
106 else
107 m_firstChild = animation;
108 animation->m_previousSibling = m_lastChild;
109 m_lastChild = animation;
110
111 animation->m_group = this;
112 animationInserted(animation);
113}
114
115void QAnimationGroupJob::prependAnimation(QAbstractAnimationJob *animation)
116{
117 if (QAnimationGroupJob *oldGroup = animation->m_group)
118 oldGroup->removeAnimation(animation);
119
120 Q_ASSERT(!previousSibling() && !nextSibling());
121
122 if (m_firstChild)
123 m_firstChild->m_previousSibling = animation;
124 else
125 m_lastChild = animation;
126 animation->m_nextSibling = m_firstChild;
127 m_firstChild = animation;
128
129 animation->m_group = this;
130 animationInserted(animation);
131}
132
133void QAnimationGroupJob::removeAnimation(QAbstractAnimationJob *animation)
134{
135 QAbstractAnimationJob *prev = animation->previousSibling();
136 QAbstractAnimationJob *next = animation->nextSibling();
137 ungroupChild(animation);
138 animationRemoved(animation, prev, next);
139}
140
141void QAnimationGroupJob::clear()
142{
143 while (QAbstractAnimationJob *child = firstChild()) {
144 removeAnimation(animation: child);
145 delete child;
146 }
147 m_firstChild = nullptr;
148 m_lastChild = nullptr;
149}
150
151void QAnimationGroupJob::resetUncontrolledAnimationsFinishTime()
152{
153 for (QAbstractAnimationJob *animation = firstChild(); animation; animation = animation->nextSibling()) {
154 if (animation->duration() == -1 || animation->loopCount() < 0) {
155 resetUncontrolledAnimationFinishTime(anim: animation);
156 }
157 }
158}
159
160void QAnimationGroupJob::resetUncontrolledAnimationFinishTime(QAbstractAnimationJob *anim)
161{
162 setUncontrolledAnimationFinishTime(anim, time: -1);
163}
164
165void QAnimationGroupJob::setUncontrolledAnimationFinishTime(QAbstractAnimationJob *anim, int time)
166{
167 anim->m_uncontrolledFinishTime = time;
168}
169
170void QAnimationGroupJob::uncontrolledAnimationFinished(QAbstractAnimationJob *animation)
171{
172 Q_UNUSED(animation);
173}
174
175void QAnimationGroupJob::animationRemoved(QAbstractAnimationJob* anim, QAbstractAnimationJob* , QAbstractAnimationJob* )
176{
177 handleAnimationRemoved(animation: anim);
178}
179
180void QAnimationGroupJob::debugChildren(QDebug d) const
181{
182 int indentLevel = 1;
183 const QAnimationGroupJob *group = this;
184 while ((group = group->m_group))
185 ++indentLevel;
186
187 QByteArray ind(indentLevel, ' ');
188 for (QAbstractAnimationJob *child = firstChild(); child; child = child->nextSibling())
189 d << "\n" << ind.constData() << child;
190}
191
192QT_END_NAMESPACE
193

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