~ubuntu-branches/ubuntu/wily/qtbase-opensource-src/wily

« back to all changes in this revision

Viewing changes to src/corelib/animation/qabstractanimation_p.h

  • Committer: Package Import Robot
  • Author(s): Timo Jyrinki
  • Date: 2013-02-05 12:46:17 UTC
  • Revision ID: package-import@ubuntu.com-20130205124617-c8jouts182j002fx
Tags: upstream-5.0.1+dfsg
ImportĀ upstreamĀ versionĀ 5.0.1+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
 
4
** Contact: http://www.qt-project.org/legal
 
5
**
 
6
** This file is part of the QtCore module of the Qt Toolkit.
 
7
**
 
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.
 
16
**
 
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.
 
24
**
 
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.
 
28
**
 
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.
 
36
**
 
37
**
 
38
** $QT_END_LICENSE$
 
39
**
 
40
****************************************************************************/
 
41
 
 
42
#ifndef QABSTRACTANIMATION_P_H
 
43
#define QABSTRACTANIMATION_P_H
 
44
 
 
45
//
 
46
//  W A R N I N G
 
47
//  -------------
 
48
//
 
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.
 
52
//
 
53
// We mean it.
 
54
//
 
55
 
 
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>
 
62
 
 
63
#ifndef QT_NO_ANIMATION
 
64
 
 
65
QT_BEGIN_NAMESPACE
 
66
 
 
67
class QAnimationGroup;
 
68
class QAbstractAnimation;
 
69
class QAbstractAnimationPrivate : public QObjectPrivate
 
70
{
 
71
public:
 
72
    QAbstractAnimationPrivate()
 
73
        : state(QAbstractAnimation::Stopped),
 
74
          direction(QAbstractAnimation::Forward),
 
75
          totalCurrentTime(0),
 
76
          currentTime(0),
 
77
          loopCount(1),
 
78
          currentLoop(0),
 
79
          deleteWhenStopped(false),
 
80
          hasRegisteredTimer(false),
 
81
          isPause(false),
 
82
          isGroup(false),
 
83
          group(0)
 
84
    {
 
85
    }
 
86
 
 
87
    virtual ~QAbstractAnimationPrivate() {}
 
88
 
 
89
    static QAbstractAnimationPrivate *get(QAbstractAnimation *q)
 
90
    {
 
91
        return q->d_func();
 
92
    }
 
93
 
 
94
    QAbstractAnimation::State state;
 
95
    QAbstractAnimation::Direction direction;
 
96
    void setState(QAbstractAnimation::State state);
 
97
 
 
98
    int totalCurrentTime;
 
99
    int currentTime;
 
100
    int loopCount;
 
101
    int currentLoop;
 
102
 
 
103
    bool deleteWhenStopped;
 
104
    bool hasRegisteredTimer;
 
105
    bool isPause;
 
106
    bool isGroup;
 
107
 
 
108
    QAnimationGroup *group;
 
109
 
 
110
private:
 
111
    Q_DECLARE_PUBLIC(QAbstractAnimation)
 
112
};
 
113
 
 
114
 
 
115
class QUnifiedTimer;
 
116
class QDefaultAnimationDriver : public QAnimationDriver
 
117
{
 
118
    Q_OBJECT
 
119
public:
 
120
    QDefaultAnimationDriver(QUnifiedTimer *timer);
 
121
    void timerEvent(QTimerEvent *e);
 
122
 
 
123
private Q_SLOTS:
 
124
    void startTimer();
 
125
    void stopTimer();
 
126
 
 
127
private:
 
128
    QBasicTimer m_timer;
 
129
    QUnifiedTimer *m_unified_timer;
 
130
};
 
131
 
 
132
class Q_CORE_EXPORT QAnimationDriverPrivate : public QObjectPrivate
 
133
{
 
134
public:
 
135
    QAnimationDriverPrivate() : running(false), startTime(0) {}
 
136
    bool running;
 
137
    qint64 startTime;
 
138
};
 
139
 
 
140
class Q_CORE_EXPORT QAbstractAnimationTimer : public QObject
 
141
{
 
142
    Q_OBJECT
 
143
public:
 
144
    QAbstractAnimationTimer() : isRegistered(false), isPaused(false), pauseDuration(0) {}
 
145
 
 
146
    virtual void updateAnimationsTime(qint64 delta) = 0;
 
147
    virtual void restartAnimationTimer() = 0;
 
148
    virtual int runningAnimationCount() = 0;
 
149
 
 
150
    bool isRegistered;
 
151
    bool isPaused;
 
152
    int pauseDuration;
 
153
};
 
154
 
 
155
class Q_CORE_EXPORT QUnifiedTimer : public QObject
 
156
{
 
157
    Q_OBJECT
 
158
private:
 
159
    QUnifiedTimer();
 
160
 
 
161
public:
 
162
    static QUnifiedTimer *instance();
 
163
    static QUnifiedTimer *instance(bool create);
 
164
 
 
165
    static void startAnimationTimer(QAbstractAnimationTimer *timer);
 
166
    static void stopAnimationTimer(QAbstractAnimationTimer *timer);
 
167
 
 
168
    static void pauseAnimationTimer(QAbstractAnimationTimer *timer, int duration);
 
169
    static void resumeAnimationTimer(QAbstractAnimationTimer *timer);
 
170
 
 
171
    //defines the timing interval. Default is DEFAULT_TIMER_INTERVAL
 
172
    void setTimingInterval(int interval);
 
173
 
 
174
    /*
 
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.
 
177
    */
 
178
    void setConsistentTiming(bool consistent) { consistentTiming = consistent; }
 
179
 
 
180
    //these facilitate fine-tuning of complex animations
 
181
    void setSlowModeEnabled(bool enabled) { slowMode = enabled; }
 
182
    void setSlowdownFactor(qreal factor) { slowdownFactor = factor; }
 
183
 
 
184
    void installAnimationDriver(QAnimationDriver *driver);
 
185
    void uninstallAnimationDriver(QAnimationDriver *driver);
 
186
    bool canUninstallAnimationDriver(QAnimationDriver *driver);
 
187
 
 
188
    void restart();
 
189
    void maybeUpdateAnimationsToCurrentTime();
 
190
    void updateAnimationTimers(qint64 currentTick);
 
191
 
 
192
    //useful for profiling/debugging
 
193
    int runningAnimationCount();
 
194
    void registerProfilerCallback(void (*cb)(qint64));
 
195
 
 
196
protected:
 
197
    void timerEvent(QTimerEvent *);
 
198
 
 
199
private Q_SLOTS:
 
200
    void startTimers();
 
201
    void stopTimer();
 
202
 
 
203
private:
 
204
    friend class QDefaultAnimationDriver;
 
205
    friend class QAnimationDriver;
 
206
 
 
207
    QAnimationDriver *driver;
 
208
    QDefaultAnimationDriver defaultDriver;
 
209
 
 
210
    QBasicTimer pauseTimer;
 
211
 
 
212
    QElapsedTimer time;
 
213
 
 
214
    qint64 lastTick;
 
215
    int timingInterval;
 
216
    int currentAnimationIdx;
 
217
    bool insideTick;
 
218
    bool insideRestart;
 
219
    bool consistentTiming;
 
220
    bool slowMode;
 
221
    bool startTimersPending;
 
222
    bool stopTimerPending;
 
223
 
 
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;
 
228
 
 
229
    QList<QAbstractAnimationTimer*> animationTimers, animationTimersToStart;
 
230
    QList<QAbstractAnimationTimer*> pausedAnimationTimers;
 
231
 
 
232
    void localRestart();
 
233
    int closestPausedAnimationTimerTimeToFinish();
 
234
 
 
235
    void (*profilerCallback)(qint64);
 
236
};
 
237
 
 
238
class QAnimationTimer : public QAbstractAnimationTimer
 
239
{
 
240
    Q_OBJECT
 
241
private:
 
242
    QAnimationTimer();
 
243
 
 
244
public:
 
245
    static QAnimationTimer *instance();
 
246
    static QAnimationTimer *instance(bool create);
 
247
 
 
248
    static void registerAnimation(QAbstractAnimation *animation, bool isTopLevel);
 
249
    static void unregisterAnimation(QAbstractAnimation *animation);
 
250
 
 
251
    /*
 
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.
 
254
    */
 
255
    static void ensureTimerUpdate();
 
256
 
 
257
    /*
 
258
        this will evaluate the need of restarting the pause timer in case there is still
 
259
        some pause animations running.
 
260
    */
 
261
    static void updateAnimationTimer();
 
262
 
 
263
    void restartAnimationTimer();
 
264
    void updateAnimationsTime(qint64 delta);
 
265
 
 
266
    //useful for profiling/debugging
 
267
    int runningAnimationCount() { return animations.count(); }
 
268
 
 
269
private Q_SLOTS:
 
270
    void startAnimations();
 
271
    void stopTimer();
 
272
 
 
273
private:
 
274
    qint64 lastTick;
 
275
    int currentAnimationIdx;
 
276
    bool insideTick;
 
277
    bool startAnimationPending;
 
278
    bool stopTimerPending;
 
279
 
 
280
    QList<QAbstractAnimation*> animations, animationsToStart;
 
281
 
 
282
    // this is the count of running animations that are not a group neither a pause animation
 
283
    int runningLeafAnimations;
 
284
    QList<QAbstractAnimation*> runningPauseAnimations;
 
285
 
 
286
    void registerRunningAnimation(QAbstractAnimation *animation);
 
287
    void unregisterRunningAnimation(QAbstractAnimation *animation);
 
288
 
 
289
    int closestPauseAnimationTimeToFinish();
 
290
};
 
291
 
 
292
QT_END_NAMESPACE
 
293
 
 
294
#endif //QT_NO_ANIMATION
 
295
 
 
296
#endif //QABSTRACTANIMATION_P_H