summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
authorThierry Bastian <thierry.bastian@nokia.com>2009-05-07 12:44:22 (GMT)
committerThierry Bastian <thierry.bastian@nokia.com>2009-05-07 12:45:46 (GMT)
commit8b57ae82ef507db1912a35fbe5d60f2cc3668cdb (patch)
tree1a0626de0d692a01c747e28180d0fd92680c1bf7 /src/corelib
parent8da0e32d111bbada65d60fa26e14ca72211517b6 (diff)
downloadQt-8b57ae82ef507db1912a35fbe5d60f2cc3668cdb.zip
Qt-8b57ae82ef507db1912a35fbe5d60f2cc3668cdb.tar.gz
Qt-8b57ae82ef507db1912a35fbe5d60f2cc3668cdb.tar.bz2
change the API of private class for QAbstractAnimation to allow setting
the timer interval. We also export the private clas so it can be used by other modules
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/animation/qabstractanimation.cpp34
-rw-r--r--src/corelib/animation/qabstractanimation_p.h15
2 files changed, 35 insertions, 14 deletions
diff --git a/src/corelib/animation/qabstractanimation.cpp b/src/corelib/animation/qabstractanimation.cpp
index 93ecc73..6a824b6 100644
--- a/src/corelib/animation/qabstractanimation.cpp
+++ b/src/corelib/animation/qabstractanimation.cpp
@@ -156,13 +156,13 @@
#include <QtCore/qcoreevent.h>
#include <QtCore/qpointer.h>
-#define TIMER_INTERVAL 16
+#define DEFAULT_TIMER_INTERVAL 16
QT_BEGIN_NAMESPACE
Q_GLOBAL_STATIC(QThreadStorage<QUnifiedTimer *>, unifiedTimer);
-QUnifiedTimer::QUnifiedTimer() : QObject(), lastTick(0), consistentTimingInterval(0)
+QUnifiedTimer::QUnifiedTimer() : QObject(), lastTick(0), timingInterval(DEFAULT_TIMER_INTERVAL), consistentTiming(false)
{
}
@@ -190,13 +190,29 @@ void QUnifiedTimer::updateRecentlyStartedAnimations()
}
/*
- this allows to haeve a consistent timer interval at each tick from the timer
+ defines the timing interval. Default is DEFAULT_TIMER_INTERVAL
+*/
+void QUnifiedTimer::setTimingInterval(int interval)
+{
+ timingInterval = interval;
+ if (animationTimer.isActive()) {
+ //we changed the timing interval
+ animationTimer.start(timingInterval, this);
+ }
+}
+
+/*
+ this allows to have a consistent timer interval at each tick from the timer
not taking the real time that passed into account.
- Just set this to 0 if you want to get back to a time-driven behaviour.
- */
-void QUnifiedTimer::setConsitentTiming(int interval)
+*/
+void QUnifiedTimer::setConsitentTiming(bool b)
+{
+ consistentTiming = b;
+}
+
+int QUnifiedTimer::elapsedTime() const
{
- consistentTimingInterval = interval;
+ return lastTick;
}
void QUnifiedTimer::timerEvent(QTimerEvent *event)
@@ -204,7 +220,7 @@ void QUnifiedTimer::timerEvent(QTimerEvent *event)
//this is simply the time we last received a tick
const int oldLastTick = lastTick;
if (time.isValid())
- lastTick = consistentTimingInterval > 0 ? oldLastTick + consistentTimingInterval : time.elapsed();
+ lastTick = consistentTiming ? oldLastTick + timingInterval : time.elapsed();
//we transfer the waiting animations into the "really running" state
updateRecentlyStartedAnimations();
@@ -215,7 +231,7 @@ void QUnifiedTimer::timerEvent(QTimerEvent *event)
animationTimer.stop();
time = QTime();
} else {
- animationTimer.start(TIMER_INTERVAL, this);
+ animationTimer.start(timingInterval, this);
lastTick = 0;
time.start();
}
diff --git a/src/corelib/animation/qabstractanimation_p.h b/src/corelib/animation/qabstractanimation_p.h
index 0e10b9a..49c0195 100644
--- a/src/corelib/animation/qabstractanimation_p.h
+++ b/src/corelib/animation/qabstractanimation_p.h
@@ -110,7 +110,7 @@ private:
};
-class QUnifiedTimer : public QObject
+class Q_CORE_EXPORT QUnifiedTimer : public QObject
{
private:
QUnifiedTimer();
@@ -118,13 +118,17 @@ private:
public:
static QUnifiedTimer *instance();
- void timerEvent(QTimerEvent *);
- void updateTimer();
void registerAnimation(QAbstractAnimation *animation);
void unregisterAnimation(QAbstractAnimation *animation);
- void setConsitentTiming(int interval);
+ void setTimingInterval(int interval);
+ void setConsitentTiming(bool consistent);
+
+ int elapsedTime() const;
+protected:
+ void timerEvent(QTimerEvent *);
+ void updateTimer();
private:
void updateRecentlyStartedAnimations();
@@ -132,7 +136,8 @@ private:
QBasicTimer animationTimer, startStopAnimationTimer;
QTime time;
int lastTick;
- int consistentTimingInterval;
+ int timingInterval;
+ bool consistentTiming;
QList<QAbstractAnimation*> animations, animationsToStart;
};