From 539602d43a7214d4dbd182a629c5142af658129f Mon Sep 17 00:00:00 2001 From: Gunnar Sletta Date: Wed, 4 May 2011 10:00:42 +0200 Subject: Make it possible for animation driver to specify the advance time delta --- src/corelib/animation/qabstractanimation.cpp | 66 +++++++++++++++++++++------- src/corelib/animation/qabstractanimation.h | 15 ++++--- src/corelib/animation/qabstractanimation_p.h | 3 +- 3 files changed, 61 insertions(+), 23 deletions(-) diff --git a/src/corelib/animation/qabstractanimation.cpp b/src/corelib/animation/qabstractanimation.cpp index f399d7c4cf..7d74de8e44 100644 --- a/src/corelib/animation/qabstractanimation.cpp +++ b/src/corelib/animation/qabstractanimation.cpp @@ -201,16 +201,17 @@ void QUnifiedTimer::ensureTimerUpdate() { QUnifiedTimer *inst = QUnifiedTimer::instance(false); if (inst && inst->isPauseTimerActive) - inst->updateAnimationsTime(); + inst->updateAnimationsTime(-1); } -void QUnifiedTimer::updateAnimationsTime() +void QUnifiedTimer::updateAnimationsTime(qint64 timeStep) { //setCurrentTime can get this called again while we're the for loop. At least with pauseAnimations if(insideTick) return; - qint64 totalElapsed = time.elapsed(); + qint64 totalElapsed = timeStep >= 0 ? timeStep : time.elapsed(); + // ignore consistentTiming in case the pause timer is active int delta = (consistentTiming && !isPauseTimerActive) ? timingInterval : totalElapsed - lastTick; @@ -303,7 +304,7 @@ void QUnifiedTimer::timerEvent(QTimerEvent *event) if (event->timerId() == animationTimer.timerId()) { // update current time on all top level animations - updateAnimationsTime(); + updateAnimationsTime(-1); restartAnimationTimer(); } } @@ -462,37 +463,56 @@ QAnimationDriver::~QAnimationDriver() uninstall(); } + + /*! - Advances the animation based on the current time. This function should - be continuously called by the driver while the animation is running. + Advances the animation based to the specified \a timeStep. This function should + be continuously called by the driver subclasses while the animation is running. - \internal + If \a timeStep is positive, it will be used as the current time in the + calculations; otherwise, the current clock time will be used. */ -void QAnimationDriver::advance() + +void QAnimationDriver::advanceAnimation(qint64 timeStep) { QUnifiedTimer *instance = QUnifiedTimer::instance(); // update current time on all top level animations - instance->updateAnimationsTime(); + instance->updateAnimationsTime(timeStep); instance->restartAnimationTimer(); } + +/*! + Advances the animation. This function should be continously called + by the driver while the animation is running. + */ + +void QAnimationDriver::advance() +{ + advanceAnimation(-1); +} + + + /*! Installs this animation driver. The animation driver is thread local and will only apply for the thread its installed in. - - \internal */ + void QAnimationDriver::install() { QUnifiedTimer *timer = QUnifiedTimer::instance(true); timer->installAnimationDriver(this); } + + /*! Uninstalls this animation driver. */ + void QAnimationDriver::uninstall() { QUnifiedTimer *timer = QUnifiedTimer::instance(true); @@ -509,7 +529,7 @@ void QAnimationDriver::start() { Q_D(QAnimationDriver); if (!d->running) { - started(); + emit started(); d->running = true; } } @@ -519,16 +539,28 @@ void QAnimationDriver::stop() { Q_D(QAnimationDriver); if (d->running) { - stopped(); + emit stopped(); d->running = false; } } + +/*! + \fn qint64 QAnimationDriver::elapsed() const + + Returns the number of milliseconds since the animations was started. + */ + +qint64 QAnimationDriver::elapsed() const +{ + return QUnifiedTimer::instance()->time.elapsed(); +} + /*! \fn QAnimationDriver::started() - This function is called by the animation framework to notify the driver - that it should start running. + This signal is emitted by the animation framework to notify the driver + that continous animation has started. \internal */ @@ -536,8 +568,8 @@ void QAnimationDriver::stop() /*! \fn QAnimationDriver::stopped() - This function is called by the animation framework to notify the driver - that it should stop running. + This signal is emitted by the animation framework to notify the driver + that continous animation has stopped. \internal */ diff --git a/src/corelib/animation/qabstractanimation.h b/src/corelib/animation/qabstractanimation.h index a0cb0f93d0..91282066a6 100644 --- a/src/corelib/animation/qabstractanimation.h +++ b/src/corelib/animation/qabstractanimation.h @@ -143,24 +143,29 @@ public: QAnimationDriver(QObject *parent = 0); ~QAnimationDriver(); - void advance(); + virtual void advance(); void install(); void uninstall(); bool isRunning() const; + qint64 elapsed() const; + +Q_SIGNALS: + void started(); + void stopped(); + protected: - virtual void started() {}; - virtual void stopped() {}; + void advanceAnimation(qint64 timeStep = -1); + virtual void start(); + virtual void stop(); QAnimationDriver(QAnimationDriverPrivate &dd, QObject *parent = 0); private: friend class QUnifiedTimer; - void start(); - void stop(); }; diff --git a/src/corelib/animation/qabstractanimation_p.h b/src/corelib/animation/qabstractanimation_p.h index 1cba4644a8..de26987721 100644 --- a/src/corelib/animation/qabstractanimation_p.h +++ b/src/corelib/animation/qabstractanimation_p.h @@ -184,7 +184,7 @@ public: bool canUninstallAnimationDriver(QAnimationDriver *driver); void restartAnimationTimer(); - void updateAnimationsTime(); + void updateAnimationsTime(qint64 timeStep); //useful for profiling/debugging int runningAnimationCount() { return animations.count(); } @@ -194,6 +194,7 @@ protected: private: friend class QDefaultAnimationDriver; + friend class QAnimationDriver; QAnimationDriver *driver; QDefaultAnimationDriver defaultDriver; -- cgit v1.2.3