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
qabstractanimation_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 reason:default
4
5#ifndef QABSTRACTANIMATION_P_H
6#define QABSTRACTANIMATION_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API.
13// 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 <QtCore/qbasictimer.h>
20#include <QtCore/qdatetime.h>
21#include <QtCore/qelapsedtimer.h>
22#include <private/qobject_p.h>
23#include <private/qproperty_p.h>
24#include <qabstractanimation.h>
25
26#if defined(Q_OS_WASM)
27#include <QtCore/private/qwasmanimationdriver_p.h>
28#endif
29
31
32QT_BEGIN_NAMESPACE
33
34class QAnimationGroup;
35class QAbstractAnimation;
36class Q_CORE_EXPORT QAbstractAnimationPrivate : public QObjectPrivate
37{
38public:
39 QAbstractAnimationPrivate();
40 virtual ~QAbstractAnimationPrivate();
41
42 static QAbstractAnimationPrivate *get(QAbstractAnimation *q)
43 {
44 return q->d_func();
45 }
46
47 Q_OBJECT_BINDABLE_PROPERTY_WITH_ARGS(QAbstractAnimationPrivate, QAbstractAnimation::State,
48 state, QAbstractAnimation::Stopped)
49 void setState(QAbstractAnimation::State state);
50
51 void setDirection(QAbstractAnimation::Direction direction)
52 {
53 q_func()->setDirection(direction);
54 }
55 void emitDirectionChanged() { Q_EMIT q_func()->directionChanged(direction); }
56 Q_OBJECT_COMPAT_PROPERTY_WITH_ARGS(QAbstractAnimationPrivate, QAbstractAnimation::Direction,
57 direction, &QAbstractAnimationPrivate::setDirection,
58 &QAbstractAnimationPrivate::emitDirectionChanged,
59 QAbstractAnimation::Forward)
60
61 void setCurrentTime(int msecs) { q_func()->setCurrentTime(msecs); }
62 Q_OBJECT_COMPAT_PROPERTY_WITH_ARGS(QAbstractAnimationPrivate, int, totalCurrentTime,
63 &QAbstractAnimationPrivate::setCurrentTime, 0)
64 int currentTime = 0;
65
66 Q_OBJECT_BINDABLE_PROPERTY_WITH_ARGS(QAbstractAnimationPrivate, int, loopCount, 1)
67
68 void emitCurrentLoopChanged() { Q_EMIT q_func()->currentLoopChanged(currentLoop); }
69 Q_OBJECT_COMPAT_PROPERTY_WITH_ARGS(QAbstractAnimationPrivate, int, currentLoop, nullptr,
70 &QAbstractAnimationPrivate::emitCurrentLoopChanged, 0)
71
72 bool deleteWhenStopped = false;
73 bool hasRegisteredTimer = false;
74 bool isPause = false;
75 bool isGroup = false;
76
77 QAnimationGroup *group = nullptr;
78
79private:
80 Q_DECLARE_PUBLIC(QAbstractAnimation)
81};
82
83
84class QUnifiedTimer;
86{
88public:
91
92protected:
93 void timerEvent(QTimerEvent *e) override;
94
95private Q_SLOTS:
96 void startTimer();
97 void stopTimer();
98
99private:
100 QBasicTimer m_timer;
101 QUnifiedTimer *m_unified_timer;
102};
103
104class Q_CORE_EXPORT QAnimationDriverPrivate : public QObjectPrivate
105{
106public:
107 QAnimationDriverPrivate();
108 ~QAnimationDriverPrivate() override;
109
110 QElapsedTimer timer;
111 bool running = false;
112};
113
114class Q_CORE_EXPORT QAbstractAnimationTimer : public QObject
115{
116 Q_OBJECT
117public:
118 QAbstractAnimationTimer();
119 ~QAbstractAnimationTimer() override;
120
121 virtual void updateAnimationsTime(qint64 delta) = 0;
122 virtual void restartAnimationTimer() = 0;
123#define QT_QAbstractAnimationTimer_runningAnimationCount_IS_CONST
124 virtual qsizetype runningAnimationCount() const = 0;
125
126 bool isRegistered = false;
127 bool isPaused = false;
128 int pauseDuration = 0;
129};
130
131class Q_CORE_EXPORT QUnifiedTimer : public QObject
132{
133 Q_OBJECT
134private:
135 QUnifiedTimer();
136
137public:
138 ~QUnifiedTimer() override;
139
140 static QUnifiedTimer *instance();
141 static QUnifiedTimer *instance(bool create);
142
143 static void startAnimationTimer(QAbstractAnimationTimer *timer);
144 static void stopAnimationTimer(QAbstractAnimationTimer *timer);
145
146 static void pauseAnimationTimer(QAbstractAnimationTimer *timer, int duration);
147 static void resumeAnimationTimer(QAbstractAnimationTimer *timer);
148
149 //defines the timing interval. Default is DEFAULT_TIMER_INTERVAL
150 void setTimingInterval(int interval);
151
152 /*
153 this allows to have a consistent timer interval at each tick from the timer
154 not taking the real time that passed into account.
155 */
156 void setConsistentTiming(bool consistent) { consistentTiming = consistent; }
157
158 // This facilitates both fine-tuning of complex animations by slowing them
159 // them down, and reducing execution time of auto tests by speeding them up.
160 qreal getSpeedModifier() const { return speedModifier; }
161 void setSpeedModifier(qreal speed) { speedModifier = speed; }
162
163 void installAnimationDriver(QAnimationDriver *driver);
164 void uninstallAnimationDriver(QAnimationDriver *driver);
165 bool canUninstallAnimationDriver(QAnimationDriver *driver);
166
167 void restart();
168 void maybeUpdateAnimationsToCurrentTime();
169 void updateAnimationTimers();
170
171 //useful for profiling/debugging
172 qsizetype runningAnimationCount() const;
173 void registerProfilerCallback(void (*cb)(qint64));
174
175 void startAnimationDriver();
176 void stopAnimationDriver();
177 qint64 elapsed() const;
178
179protected:
180 void timerEvent(QTimerEvent *) override;
181
182private Q_SLOTS:
183 void startTimers();
184 void stopTimer();
185
186private:
187 friend class QDefaultAnimationDriver;
188 friend class QAnimationDriver;
189
190 QAnimationDriver *driver;
191#if defined(Q_OS_WASM)
192 QWasmAnimationDriver defaultDriver;
193#else
194 QDefaultAnimationDriver defaultDriver;
195#endif
196
197 QBasicTimer pauseTimer;
198
199 QElapsedTimer time;
200
201 qint64 lastTick;
202 int timingInterval;
203 int currentAnimationIdx;
204 bool insideTick;
205 bool insideRestart;
206 bool consistentTiming;
207 bool startTimersPending;
208 bool stopTimerPending;
209 bool allowNegativeDelta;
210
211 // This factor will be used to multiply the DEFAULT_TIMER_INTERVAL (16) at each tick
212 // if it's not equal to 1. Setting it to less than 1 / 16 (0.0625) stops all animations.
213 qreal speedModifier;
214
215 QList<QAbstractAnimationTimer*> animationTimers, animationTimersToStart;
216 QList<QAbstractAnimationTimer*> pausedAnimationTimers;
217
218 void localRestart();
219 int closestPausedAnimationTimerTimeToFinish();
220
221 void (*profilerCallback)(qint64);
222
223 qint64 driverStartTime; // The time the animation driver was started
224 qint64 temporalDrift; // The delta between animation driver time and wall time.
225};
226
228{
230private:
232
233public:
235
236 static QAnimationTimer *instance();
237 static QAnimationTimer *instance(bool create);
238
239 static void registerAnimation(QAbstractAnimation *animation, bool isTopLevel);
240 static void unregisterAnimation(QAbstractAnimation *animation);
241
242 /*
243 this is used for updating the currentTime of all animations in case the pause
244 timer is active or, otherwise, only of the animation passed as parameter.
245 */
246 static void ensureTimerUpdate();
247
248 /*
249 this will evaluate the need of restarting the pause timer in case there is still
250 some pause animations running.
251 */
252 static void updateAnimationTimer();
253
255 void updateAnimationsTime(qint64 delta) override;
256
257 //useful for profiling/debugging
258 qsizetype runningAnimationCount() const override { return animations.size(); }
259
260private Q_SLOTS:
261 void startAnimations();
262 void stopTimer();
263
264private:
265 qint64 lastTick;
266 int currentAnimationIdx;
267 bool insideTick;
268 bool startAnimationPending;
269 bool stopTimerPending;
270
271 QList<QAbstractAnimation*> animations, animationsToStart;
272
273 // this is the count of running animations that are not a group neither a pause animation
274 int runningLeafAnimations;
275 QList<QAbstractAnimation*> runningPauseAnimations;
276
277 void registerRunningAnimation(QAbstractAnimation *animation);
278 void unregisterRunningAnimation(QAbstractAnimation *animation);
279
280 int closestPauseAnimationTimeToFinish();
281};
282
283QT_END_NAMESPACE
284
285#endif //QABSTRACTANIMATION_P_H
\inmodule QtCore
\inmodule QtCore
static void unregisterAnimation(QAbstractAnimation *animation)
qsizetype runningAnimationCount() const override
static QAnimationTimer * instance(bool create)
static void updateAnimationTimer()
void updateAnimationsTime(qint64 delta) override
~QAnimationTimer() override
void restartAnimationTimer() override
static void ensureTimerUpdate()
static void registerAnimation(QAbstractAnimation *animation, bool isTopLevel)
static QAnimationTimer * instance()
void timerEvent(QTimerEvent *e) override
This event handler can be reimplemented in a subclass to receive timer events for the object.
\inmodule QtCore
Combined button and popup list for selecting options.
QList< QAbstractAnimation * >::ConstIterator AnimationListConstIt
#define DEFAULT_TIMER_INTERVAL
QT_BEGIN_NAMESPACE typedef QList< QAbstractAnimationTimer * >::ConstIterator TimerListConstIt
#define PAUSE_TIMER_COARSE_THRESHOLD
QT_REQUIRE_CONFIG(animation)
QT_REQUIRE_CONFIG(animation)