Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qanimationgroupjob.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant
4
5#include "private/qanimationgroupjob_p.h"
6
7QT_BEGIN_NAMESPACE
8
9QAnimationGroupJob::QAnimationGroupJob()
10{
11 m_isGroup = true;
12}
13
14void QAnimationGroupJob::ungroupChild(QAbstractAnimationJob *animation)
15{
16 Q_ASSERT(animation);
17 Q_ASSERT(animation->m_group == this);
18 m_children.remove(animation);
19 animation->m_group = nullptr;
20}
21
22void QAnimationGroupJob::handleAnimationRemoved(QAbstractAnimationJob *animation)
23{
24 resetUncontrolledAnimationFinishTime(animation);
25 if (m_children.isEmpty()) {
26 m_currentTime = 0;
27 stop();
28 }
29}
30
31QAnimationGroupJob::~QAnimationGroupJob()
32{
33 while (QAbstractAnimationJob *animation = m_children.first()) {
34 ungroupChild(animation);
35 handleAnimationRemoved(animation);
36 delete animation;
37 }
38}
39
40void QAnimationGroupJob::topLevelAnimationLoopChanged()
41{
42 for (QAbstractAnimationJob *animation : m_children)
43 animation->fireTopLevelAnimationLoopChanged();
44}
45
46void QAnimationGroupJob::appendAnimation(QAbstractAnimationJob *animation)
47{
48 if (QAnimationGroupJob *oldGroup = animation->m_group)
49 oldGroup->removeAnimation(animation);
50
51 Q_ASSERT(!animation->isInList());
52
53 m_children.append(animation);
54 animation->m_group = this;
55 animationInserted(animation);
56}
57
58void QAnimationGroupJob::prependAnimation(QAbstractAnimationJob *animation)
59{
60 if (QAnimationGroupJob *oldGroup = animation->m_group)
61 oldGroup->removeAnimation(animation);
62
63 Q_ASSERT(!animation->isInList());
64
65 m_children.prepend(animation);
66 animation->m_group = this;
67 animationInserted(animation);
68}
69
70void QAnimationGroupJob::removeAnimation(QAbstractAnimationJob *animation)
71{
72 QAbstractAnimationJob *prev = m_children.prev(animation);
73 QAbstractAnimationJob *next = m_children.next(animation);
74 ungroupChild(animation);
75 animationRemoved(animation, prev, next);
76}
77
78void QAnimationGroupJob::clear()
79{
80 while (QAbstractAnimationJob *child = m_children.first()) {
81 removeAnimation(child);
82 delete child;
83 }
84
85 Q_ASSERT(m_children.isEmpty());
86}
87
88void QAnimationGroupJob::resetUncontrolledAnimationsFinishTime()
89{
90 for (QAbstractAnimationJob *animation : m_children) {
91 if (animation->duration() == -1 || animation->loopCount() < 0) {
92 resetUncontrolledAnimationFinishTime(animation);
93 }
94 }
95}
96
97void QAnimationGroupJob::resetUncontrolledAnimationFinishTime(QAbstractAnimationJob *anim)
98{
99 setUncontrolledAnimationFinishTime(anim, -1);
100}
101
102void QAnimationGroupJob::setUncontrolledAnimationFinishTime(QAbstractAnimationJob *anim, int time)
103{
104 anim->m_uncontrolledFinishTime = time;
105}
106
107void QAnimationGroupJob::uncontrolledAnimationFinished(QAbstractAnimationJob *animation)
108{
109 Q_UNUSED(animation);
110}
111
112void QAnimationGroupJob::animationRemoved(QAbstractAnimationJob* anim, QAbstractAnimationJob* , QAbstractAnimationJob* )
113{
114 handleAnimationRemoved(anim);
115}
116
117void QAnimationGroupJob::debugChildren(QDebug d) const
118{
119 int indentLevel = 1;
120 const QAnimationGroupJob *group = this;
121 while ((group = group->m_group))
122 ++indentLevel;
123
124 QByteArray ind(indentLevel, ' ');
125 for (const QAbstractAnimationJob *child : m_children)
126 d << "\n" << ind.constData() << child;
127}
128
129QT_END_NAMESPACE