1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtQml module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #ifndef QABSTRACTANIMATIONJOB_P_H
43 #define QABSTRACTANIMATIONJOB_P_H
45 #include <private/qtqmlglobal_p.h>
46 #include <QtCore/QObject>
47 #include <QtCore/private/qabstractanimation_p.h>
48 #include "private/qpodvector_p.h"
56 class QAnimationGroupJob;
57 class QAnimationJobChangeListener;
58 class Q_QML_PRIVATE_EXPORT QAbstractAnimationJob
60 Q_DISABLE_COPY(QAbstractAnimationJob)
73 QAbstractAnimationJob();
74 virtual ~QAbstractAnimationJob();
77 inline QAnimationGroupJob *group() const {return m_group;}
79 inline int loopCount() const {return m_loopCount;}
80 void setLoopCount(int loopCount);
82 int totalDuration() const;
83 virtual int duration() const {return 0;}
85 inline QAbstractAnimationJob::Direction direction() const {return m_direction;}
86 void setDirection(QAbstractAnimationJob::Direction direction);
89 inline int currentTime() const {return m_totalCurrentTime;}
90 inline int currentLoopTime() const {return m_currentTime;}
91 inline int currentLoop() const {return m_currentLoop;}
92 inline QAbstractAnimationJob::State state() const {return m_state;}
93 inline bool isRunning() { return m_state == Running; }
94 inline bool isStopped() { return m_state == Stopped; }
95 inline bool isPaused() { return m_state == Paused; }
96 void setDisableUserControl();
97 void setEnableUserControl();
98 bool userControlDisabled() const;
100 void setCurrentTime(int msecs);
113 Q_DECLARE_FLAGS(ChangeTypes, ChangeType)
115 void addAnimationChangeListener(QAnimationJobChangeListener *listener, QAbstractAnimationJob::ChangeTypes);
116 void removeAnimationChangeListener(QAnimationJobChangeListener *listener, QAbstractAnimationJob::ChangeTypes);
117 QAbstractAnimationJob *nextSibling() const { return m_nextSibling; }
118 QAbstractAnimationJob *previousSibling() const { return m_previousSibling; }
121 virtual void updateCurrentTime(int) {}
122 virtual void updateState(QAbstractAnimationJob::State newState, QAbstractAnimationJob::State oldState);
123 virtual void updateDirection(QAbstractAnimationJob::Direction direction);
124 virtual void topLevelAnimationLoopChanged() {}
126 void setState(QAbstractAnimationJob::State state);
129 void stateChanged(QAbstractAnimationJob::State newState, QAbstractAnimationJob::State oldState);
130 void currentLoopChanged();
131 void directionChanged(QAbstractAnimationJob::Direction);
132 void currentTimeChanged(int currentTime);
136 QAnimationGroupJob *m_group;
137 QAbstractAnimationJob::Direction m_direction;
140 QAbstractAnimationJob::State m_state;
141 int m_totalCurrentTime;
144 //records the finish time for an uncontrolled animation (used by animation groups)
145 int m_uncontrolledFinishTime;
147 struct ChangeListener {
148 ChangeListener(QAnimationJobChangeListener *l, QAbstractAnimationJob::ChangeTypes t) : listener(l), types(t) {}
149 QAnimationJobChangeListener *listener;
150 QAbstractAnimationJob::ChangeTypes types;
151 bool operator==(const ChangeListener &other) const { return listener == other.listener && types == other.types; }
153 QPODVector<ChangeListener,1> changeListeners;
155 QAbstractAnimationJob *m_nextSibling;
156 QAbstractAnimationJob *m_previousSibling;
159 bool m_hasRegisteredTimer:1;
162 bool m_disableUserControl:1;
163 bool m_hasCurrentTimeChangeListeners:1;
165 friend class QQmlAnimationTimer;
166 friend class QAnimationGroupJob;
169 class Q_AUTOTEST_EXPORT QAnimationJobChangeListener
172 virtual void animationFinished(QAbstractAnimationJob *) {}
173 virtual void animationStateChanged(QAbstractAnimationJob *, QAbstractAnimationJob::State, QAbstractAnimationJob::State) {}
174 virtual void animationCurrentLoopChanged(QAbstractAnimationJob *) {}
175 virtual void animationCurrentTimeChanged(QAbstractAnimationJob *, int) {}
178 class Q_QML_PRIVATE_EXPORT QQmlAnimationTimer : public QAbstractAnimationTimer
182 QQmlAnimationTimer();
185 static QQmlAnimationTimer *instance();
186 static QQmlAnimationTimer *instance(bool create);
188 static void registerAnimation(QAbstractAnimationJob *animation, bool isTopLevel);
189 static void unregisterAnimation(QAbstractAnimationJob *animation);
192 this is used for updating the currentTime of all animations in case the pause
193 timer is active or, otherwise, only of the animation passed as parameter.
195 static void ensureTimerUpdate();
198 this will evaluate the need of restarting the pause timer in case there is still
199 some pause animations running.
201 static void updateAnimationTimer();
203 void restartAnimationTimer();
204 void updateAnimationsTime(qint64 timeStep);
206 int currentDelta() { return lastDelta; }
208 //useful for profiling/debugging
209 int runningAnimationCount() { return animations.count(); }
212 void startAnimations();
218 int currentAnimationIdx;
220 bool startAnimationPending;
221 bool stopTimerPending;
223 QList<QAbstractAnimationJob*> animations, animationsToStart;
225 // this is the count of running animations that are not a group neither a pause animation
226 int runningLeafAnimations;
227 QList<QAbstractAnimationJob*> runningPauseAnimations;
229 void registerRunningAnimation(QAbstractAnimationJob *animation);
230 void unregisterRunningAnimation(QAbstractAnimationJob *animation);
232 int closestPauseAnimationTimeToFinish();
235 Q_DECLARE_OPERATORS_FOR_FLAGS(QAbstractAnimationJob::ChangeTypes)
241 #endif // QABSTRACTANIMATIONJOB_P_H