diff options
Diffstat (limited to 'src/corelib/animation/qabstractanimation_p.h')
-rw-r--r-- | src/corelib/animation/qabstractanimation_p.h | 103 |
1 files changed, 77 insertions, 26 deletions
diff --git a/src/corelib/animation/qabstractanimation_p.h b/src/corelib/animation/qabstractanimation_p.h index a079a71242..2b2d5b8872 100644 --- a/src/corelib/animation/qabstractanimation_p.h +++ b/src/corelib/animation/qabstractanimation_p.h @@ -140,7 +140,20 @@ public: bool running; }; -typedef QElapsedTimer ElapsedTimer; +class Q_CORE_EXPORT QAbstractAnimationTimer : public QObject +{ + Q_OBJECT +public: + QAbstractAnimationTimer() : isRegistered(false), isPaused(false), pauseDuration(0) {} + + virtual void updateAnimationsTime(qint64 delta) = 0; + virtual void restartAnimationTimer() = 0; + virtual int runningAnimationCount() = 0; + + bool isRegistered; + bool isPaused; + int pauseDuration; +}; class Q_CORE_EXPORT QUnifiedTimer : public QObject { @@ -149,12 +162,14 @@ private: QUnifiedTimer(); public: - //XXX this is needed by dui static QUnifiedTimer *instance(); static QUnifiedTimer *instance(bool create); - static void registerAnimation(QAbstractAnimation *animation, bool isTopLevel); - static void unregisterAnimation(QAbstractAnimation *animation); + static void startAnimationTimer(QAbstractAnimationTimer *timer); + static void stopAnimationTimer(QAbstractAnimationTimer *timer); + + static void pauseAnimationTimer(QAbstractAnimationTimer *timer, int duration); + static void resumeAnimationTimer(QAbstractAnimationTimer *timer); //defines the timing interval. Default is DEFAULT_TIMER_INTERVAL void setTimingInterval(int interval); @@ -169,34 +184,22 @@ public: void setSlowModeEnabled(bool enabled) { slowMode = enabled; } void setSlowdownFactor(qreal factor) { slowdownFactor = factor; } - /* - this is used for updating the currentTime of all animations in case the pause - timer is active or, otherwise, only of the animation passed as parameter. - */ - static void ensureTimerUpdate(); - - /* - this will evaluate the need of restarting the pause timer in case there is still - some pause animations running. - */ - static void updateAnimationTimer(); - void installAnimationDriver(QAnimationDriver *driver); void uninstallAnimationDriver(QAnimationDriver *driver); bool canUninstallAnimationDriver(QAnimationDriver *driver); - void restartAnimationTimer(); - void updateAnimationsTime(qint64 timeStep); + void restart(); + void updateAnimationTimers(qint64 currentTick); //useful for profiling/debugging - int runningAnimationCount() { return animations.count(); } + int runningAnimationCount(); void registerProfilerCallback(void (*cb)(qint64)); protected: void timerEvent(QTimerEvent *); private Q_SLOTS: - void startAnimations(); + void startTimers(); void stopTimer(); private: @@ -207,18 +210,17 @@ private: QDefaultAnimationDriver defaultDriver; QBasicTimer pauseTimer; - // timer used to delay the check if we should start/stop the animation timer - QBasicTimer startStopAnimationTimer; - ElapsedTimer time; + QElapsedTimer time; qint64 lastTick; int timingInterval; int currentAnimationIdx; bool insideTick; + bool insideRestart; bool consistentTiming; bool slowMode; - bool startAnimationPending; + bool startTimersPending; bool stopTimerPending; // This factor will be used to divide the DEFAULT_TIMER_INTERVAL at each tick @@ -226,6 +228,57 @@ private: // stops all animations. qreal slowdownFactor; + QList<QAbstractAnimationTimer*> animationTimers, animationTimersToStart; + QList<QAbstractAnimationTimer*> pausedAnimationTimers; + + void localRestart(); + int closestPausedAnimationTimerTimeToFinish(); + + void (*profilerCallback)(qint64); +}; + +class QAnimationTimer : public QAbstractAnimationTimer +{ + Q_OBJECT +private: + QAnimationTimer(); + +public: + static QAnimationTimer *instance(); + static QAnimationTimer *instance(bool create); + + static void registerAnimation(QAbstractAnimation *animation, bool isTopLevel); + static void unregisterAnimation(QAbstractAnimation *animation); + + /* + this is used for updating the currentTime of all animations in case the pause + timer is active or, otherwise, only of the animation passed as parameter. + */ + static void ensureTimerUpdate(); + + /* + this will evaluate the need of restarting the pause timer in case there is still + some pause animations running. + */ + static void updateAnimationTimer(); + + void restartAnimationTimer(); + void updateAnimationsTime(qint64 delta); + + //useful for profiling/debugging + int runningAnimationCount() { return animations.count(); } + +private Q_SLOTS: + void startAnimations(); + void stopTimer(); + +private: + qint64 lastTick; + int currentAnimationIdx; + bool insideTick; + bool startAnimationPending; + bool stopTimerPending; + QList<QAbstractAnimation*> animations, animationsToStart; // this is the count of running animations that are not a group neither a pause animation @@ -236,8 +289,6 @@ private: void unregisterRunningAnimation(QAbstractAnimation *animation); int closestPauseAnimationTimeToFinish(); - - void (*profilerCallback)(qint64); }; QT_END_NAMESPACE |