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