1
/****************************************************************************
3
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4
** Contact: http://www.qt-project.org/legal
6
** This file is part of the QtCore module of the Qt Toolkit.
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 Digia. For licensing terms and
14
** conditions see http://qt.digia.com/licensing. For further information
15
** use the contact form at http://qt.digia.com/contact-us.
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 2.1 as published by the Free Software
20
** Foundation and appearing in the file LICENSE.LGPL included in the
21
** packaging of this file. Please review the following information to
22
** ensure the GNU Lesser General Public License version 2.1 requirements
23
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25
** In addition, as a special exception, Digia gives you certain additional
26
** rights. These rights are described in the Digia Qt LGPL Exception
27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29
** GNU General Public License Usage
30
** Alternatively, this file may be used under the terms of the GNU
31
** General Public License version 3.0 as published by the Free Software
32
** Foundation and appearing in the file LICENSE.GPL included in the
33
** packaging of this file. Please review the following information to
34
** ensure the GNU General Public License version 3.0 requirements will be
35
** met: http://www.gnu.org/copyleft/gpl.html.
40
****************************************************************************/
42
#ifndef QABSTRACTANIMATION_P_H
43
#define QABSTRACTANIMATION_P_H
49
// This file is not part of the Qt API. It exists for the convenience
50
// of QIODevice. This header file may change from version to
51
// version without notice, or even be removed.
56
#include <QtCore/qbasictimer.h>
57
#include <QtCore/qdatetime.h>
58
#include <QtCore/qtimer.h>
59
#include <QtCore/qelapsedtimer.h>
60
#include <private/qobject_p.h>
61
#include <qabstractanimation.h>
63
#ifndef QT_NO_ANIMATION
67
class QAnimationGroup;
68
class QAbstractAnimation;
69
class QAbstractAnimationPrivate : public QObjectPrivate
72
QAbstractAnimationPrivate()
73
: state(QAbstractAnimation::Stopped),
74
direction(QAbstractAnimation::Forward),
79
deleteWhenStopped(false),
80
hasRegisteredTimer(false),
87
virtual ~QAbstractAnimationPrivate() {}
89
static QAbstractAnimationPrivate *get(QAbstractAnimation *q)
94
QAbstractAnimation::State state;
95
QAbstractAnimation::Direction direction;
96
void setState(QAbstractAnimation::State state);
103
bool deleteWhenStopped;
104
bool hasRegisteredTimer;
108
QAnimationGroup *group;
111
Q_DECLARE_PUBLIC(QAbstractAnimation)
116
class QDefaultAnimationDriver : public QAnimationDriver
120
QDefaultAnimationDriver(QUnifiedTimer *timer);
121
void timerEvent(QTimerEvent *e);
129
QUnifiedTimer *m_unified_timer;
132
class Q_CORE_EXPORT QAnimationDriverPrivate : public QObjectPrivate
135
QAnimationDriverPrivate() : running(false), startTime(0) {}
140
class Q_CORE_EXPORT QAbstractAnimationTimer : public QObject
144
QAbstractAnimationTimer() : isRegistered(false), isPaused(false), pauseDuration(0) {}
146
virtual void updateAnimationsTime(qint64 delta) = 0;
147
virtual void restartAnimationTimer() = 0;
148
virtual int runningAnimationCount() = 0;
155
class Q_CORE_EXPORT QUnifiedTimer : public QObject
162
static QUnifiedTimer *instance();
163
static QUnifiedTimer *instance(bool create);
165
static void startAnimationTimer(QAbstractAnimationTimer *timer);
166
static void stopAnimationTimer(QAbstractAnimationTimer *timer);
168
static void pauseAnimationTimer(QAbstractAnimationTimer *timer, int duration);
169
static void resumeAnimationTimer(QAbstractAnimationTimer *timer);
171
//defines the timing interval. Default is DEFAULT_TIMER_INTERVAL
172
void setTimingInterval(int interval);
175
this allows to have a consistent timer interval at each tick from the timer
176
not taking the real time that passed into account.
178
void setConsistentTiming(bool consistent) { consistentTiming = consistent; }
180
//these facilitate fine-tuning of complex animations
181
void setSlowModeEnabled(bool enabled) { slowMode = enabled; }
182
void setSlowdownFactor(qreal factor) { slowdownFactor = factor; }
184
void installAnimationDriver(QAnimationDriver *driver);
185
void uninstallAnimationDriver(QAnimationDriver *driver);
186
bool canUninstallAnimationDriver(QAnimationDriver *driver);
189
void maybeUpdateAnimationsToCurrentTime();
190
void updateAnimationTimers(qint64 currentTick);
192
//useful for profiling/debugging
193
int runningAnimationCount();
194
void registerProfilerCallback(void (*cb)(qint64));
197
void timerEvent(QTimerEvent *);
204
friend class QDefaultAnimationDriver;
205
friend class QAnimationDriver;
207
QAnimationDriver *driver;
208
QDefaultAnimationDriver defaultDriver;
210
QBasicTimer pauseTimer;
216
int currentAnimationIdx;
219
bool consistentTiming;
221
bool startTimersPending;
222
bool stopTimerPending;
224
// This factor will be used to divide the DEFAULT_TIMER_INTERVAL at each tick
225
// when slowMode is enabled. Setting it to 0 or higher than DEFAULT_TIMER_INTERVAL (16)
226
// stops all animations.
227
qreal slowdownFactor;
229
QList<QAbstractAnimationTimer*> animationTimers, animationTimersToStart;
230
QList<QAbstractAnimationTimer*> pausedAnimationTimers;
233
int closestPausedAnimationTimerTimeToFinish();
235
void (*profilerCallback)(qint64);
238
class QAnimationTimer : public QAbstractAnimationTimer
245
static QAnimationTimer *instance();
246
static QAnimationTimer *instance(bool create);
248
static void registerAnimation(QAbstractAnimation *animation, bool isTopLevel);
249
static void unregisterAnimation(QAbstractAnimation *animation);
252
this is used for updating the currentTime of all animations in case the pause
253
timer is active or, otherwise, only of the animation passed as parameter.
255
static void ensureTimerUpdate();
258
this will evaluate the need of restarting the pause timer in case there is still
259
some pause animations running.
261
static void updateAnimationTimer();
263
void restartAnimationTimer();
264
void updateAnimationsTime(qint64 delta);
266
//useful for profiling/debugging
267
int runningAnimationCount() { return animations.count(); }
270
void startAnimations();
275
int currentAnimationIdx;
277
bool startAnimationPending;
278
bool stopTimerPending;
280
QList<QAbstractAnimation*> animations, animationsToStart;
282
// this is the count of running animations that are not a group neither a pause animation
283
int runningLeafAnimations;
284
QList<QAbstractAnimation*> runningPauseAnimations;
286
void registerRunningAnimation(QAbstractAnimation *animation);
287
void unregisterRunningAnimation(QAbstractAnimation *animation);
289
int closestPauseAnimationTimeToFinish();
294
#endif //QT_NO_ANIMATION
296
#endif //QABSTRACTANIMATION_P_H