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
qabstractanimationjob_p.h
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#ifndef QABSTRACTANIMATIONJOB_P_H
6#define QABSTRACTANIMATIONJOB_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <private/qtqmlglobal_p.h>
20#include <private/qanimationjobutil_p.h>
21#include <private/qdoubleendedlist_p.h>
22#include <QtCore/QObject>
23#include <QtCore/private/qabstractanimation_p.h>
24#include <vector>
25
27
28QT_BEGIN_NAMESPACE
29
30class QAnimationGroupJob;
31class QAnimationJobChangeListener;
32class QQmlAnimationTimer;
33
34class Q_QML_EXPORT QAbstractAnimationJob : public QInheritedListNode
35{
36 Q_DISABLE_COPY(QAbstractAnimationJob)
37public:
38 enum Direction {
39 Forward,
40 Backward
41 };
42
43 enum State {
44 Stopped,
45 Paused,
46 Running
47 };
48
49 QAbstractAnimationJob();
50 virtual ~QAbstractAnimationJob();
51
52 //definition
53 inline QAnimationGroupJob *group() const {return m_group;}
54
55 inline int loopCount() const {return m_loopCount;}
56 void setLoopCount(int loopCount);
57
58 int totalDuration() const;
59 virtual int duration() const {return 0;}
60
61 inline QAbstractAnimationJob::Direction direction() const {return m_direction;}
62 void setDirection(QAbstractAnimationJob::Direction direction);
63
64 //state
65 inline int currentTime() const {return m_totalCurrentTime;}
66 inline int currentLoopTime() const {return m_currentTime;}
67 inline int currentLoop() const {return m_currentLoop;}
68 inline QAbstractAnimationJob::State state() const {return m_state;}
69 inline bool isRunning() { return m_state == Running; }
70 inline bool isStopped() { return m_state == Stopped; }
71 inline bool isPaused() { return m_state == Paused; }
72 void setDisableUserControl();
73 void setEnableUserControl();
74 bool userControlDisabled() const;
75
76 void setCurrentTime(int msecs);
77
78 void start();
79 void pause();
80 void resume();
81 void stop();
82 void complete();
83
84 enum ChangeType {
85 Completion = 0x01,
86 StateChange = 0x02,
87 CurrentLoop = 0x04,
88 CurrentTime = 0x08
89 };
90 Q_DECLARE_FLAGS(ChangeTypes, ChangeType)
91
92 void addAnimationChangeListener(QAnimationJobChangeListener *listener, QAbstractAnimationJob::ChangeTypes);
93 void removeAnimationChangeListener(QAnimationJobChangeListener *listener, QAbstractAnimationJob::ChangeTypes);
94
95 bool isGroup() const { return m_isGroup; }
96 bool isRenderThreadJob() const { return m_isRenderThreadJob; }
97 bool isRenderThreadProxy() const { return m_isRenderThreadProxy; }
98
99 SelfDeletable m_selfDeletable;
100protected:
101 virtual void updateCurrentTime(int) {}
102 virtual void updateLoopCount(int) {}
103 virtual void updateState(QAbstractAnimationJob::State newState, QAbstractAnimationJob::State oldState);
104 virtual void updateDirection(QAbstractAnimationJob::Direction direction);
105 virtual void topLevelAnimationLoopChanged() {}
106
107 virtual void debugAnimation(QDebug d) const;
108
109 void fireTopLevelAnimationLoopChanged();
110
111 void setState(QAbstractAnimationJob::State state);
112
113 void finished();
114 void stateChanged(QAbstractAnimationJob::State newState, QAbstractAnimationJob::State oldState);
115 void currentLoopChanged();
116 void directionChanged(QAbstractAnimationJob::Direction);
117 void currentTimeChanged(int currentTime);
118
119 //definition
120 int m_loopCount;
121 QAnimationGroupJob *m_group;
122 QAbstractAnimationJob::Direction m_direction;
123
124 //state
125 QAbstractAnimationJob::State m_state;
126 int m_totalCurrentTime;
127 int m_currentTime;
128 int m_currentLoop;
129 //records the finish time for an uncontrolled animation (used by animation groups)
130 int m_uncontrolledFinishTime;
131 int m_currentLoopStartTime; // used together with m_uncontrolledFinishTime
132
133 struct ChangeListener {
134 ChangeListener(QAnimationJobChangeListener *l, QAbstractAnimationJob::ChangeTypes t) : listener(l), types(t) {}
135 QAnimationJobChangeListener *listener;
136 QAbstractAnimationJob::ChangeTypes types;
137 bool operator==(const ChangeListener &other) const { return listener == other.listener && types == other.types; }
138 };
139 std::vector<ChangeListener> changeListeners;
140
141 QQmlAnimationTimer *m_timer = nullptr;
142
143 bool m_hasRegisteredTimer:1;
144 bool m_isPause:1;
145 bool m_isGroup:1;
146 bool m_disableUserControl:1;
147 bool m_hasCurrentTimeChangeListeners:1;
148 bool m_isRenderThreadJob:1;
149 bool m_isRenderThreadProxy:1;
150
151 friend class QQmlAnimationTimer;
152 friend class QAnimationGroupJob;
153 friend Q_QML_EXPORT QDebug operator<<(QDebug, const QAbstractAnimationJob *job);
154};
155
157{
158public:
159 virtual ~QAnimationJobChangeListener();
160 virtual void animationFinished(QAbstractAnimationJob *) {}
161 virtual void animationStateChanged(QAbstractAnimationJob *, QAbstractAnimationJob::State, QAbstractAnimationJob::State) {}
162 virtual void animationCurrentLoopChanged(QAbstractAnimationJob *) {}
163 virtual void animationCurrentTimeChanged(QAbstractAnimationJob *, int) {}
164};
165
166class Q_QML_EXPORT QQmlAnimationTimer : public QAbstractAnimationTimer
167{
168 Q_OBJECT
169private:
170 QQmlAnimationTimer();
171
172public:
173 ~QQmlAnimationTimer(); // must be destructible by QThreadStorage
174
175 static QQmlAnimationTimer *instance();
176 static QQmlAnimationTimer *instance(bool create);
177
178 void registerAnimation(QAbstractAnimationJob *animation, bool isTopLevel);
179 void unregisterAnimation(QAbstractAnimationJob *animation);
180
181 /*
182 this is used for updating the currentTime of all animations in case the pause
183 timer is active or, otherwise, only of the animation passed as parameter.
184 */
185 void ensureTimerUpdate();
186
187 /*
188 this will evaluate the need of restarting the pause timer in case there is still
189 some pause animations running.
190 */
191 void updateAnimationTimer();
192
193 void restartAnimationTimer() override;
194 void updateAnimationsTime(qint64 timeStep) override;
195
196 //useful for profiling/debugging
197#ifdef QT_QAbstractAnimationTimer_runningAnimationCount_IS_CONST
198 qsizetype runningAnimationCount() const override { return animations.size(); }
199#else
200 int runningAnimationCount() override { return animations.size(); }
201#endif
202
203 bool hasStartAnimationPending() const { return startAnimationPending; }
204
205public Q_SLOTS:
206 void startAnimations();
207 void stopTimer();
208
209private:
210 qint64 lastTick;
211 int currentAnimationIdx;
212 bool insideTick;
213 bool startAnimationPending;
214 bool stopTimerPending;
215
216 QList<QAbstractAnimationJob*> animations, animationsToStart;
217
218 // this is the count of running animations that are not a group neither a pause animation
219 int runningLeafAnimations;
220 QList<QAbstractAnimationJob*> runningPauseAnimations;
221
222 void registerRunningAnimation(QAbstractAnimationJob *animation);
223 void unregisterRunningAnimation(QAbstractAnimationJob *animation);
224 void unsetJobTimer(QAbstractAnimationJob *animation);
225
226 int closestPauseAnimationTimeToFinish();
227};
228
229Q_DECLARE_OPERATORS_FOR_FLAGS(QAbstractAnimationJob::ChangeTypes)
230
231Q_QML_EXPORT QDebug operator<<(QDebug, const QAbstractAnimationJob *job);
232
233QT_END_NAMESPACE
234
235#endif // QABSTRACTANIMATIONJOB_P_H
QT_REQUIRE_CONFIG(qml_animation)