summaryrefslogtreecommitdiffstats
path: root/src/corelib/animation
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/animation')
-rw-r--r--src/corelib/animation/qabstractanimation.cpp2
-rw-r--r--src/corelib/animation/qabstractanimation_p.h62
2 files changed, 62 insertions, 2 deletions
diff --git a/src/corelib/animation/qabstractanimation.cpp b/src/corelib/animation/qabstractanimation.cpp
index 2b4ab478c7..b7afd9f3cc 100644
--- a/src/corelib/animation/qabstractanimation.cpp
+++ b/src/corelib/animation/qabstractanimation.cpp
@@ -242,7 +242,7 @@ void QUnifiedTimer::timerEvent(QTimerEvent *event)
animationTimer.stop();
isPauseTimerActive = false;
// invalidate the start reference time
- time = QTime();
+ time.invalidate();
} else {
restartAnimationTimer();
if (!time.isValid()) {
diff --git a/src/corelib/animation/qabstractanimation_p.h b/src/corelib/animation/qabstractanimation_p.h
index ad35d893d9..8bc3224be2 100644
--- a/src/corelib/animation/qabstractanimation_p.h
+++ b/src/corelib/animation/qabstractanimation_p.h
@@ -58,6 +58,10 @@
#include <QtCore/qtimer.h>
#include <private/qobject_p.h>
+#ifdef Q_OS_WIN
+#include <qt_windows.h>
+#endif
+
#ifndef QT_NO_ANIMATION
QT_BEGIN_NAMESPACE
@@ -109,6 +113,61 @@ private:
Q_DECLARE_PUBLIC(QAbstractAnimation)
};
+class ElapsedTimer
+{
+public:
+ ElapsedTimer() {
+ invalidate();
+ }
+
+ void invalidate() {
+ m_started = -1;
+ }
+
+ bool isValid() const {
+ return m_started >= 0;
+ }
+
+ void start() {
+ m_started = getTickCount_sys();
+ }
+
+ qint64 elapsed() const {
+ qint64 current = getTickCount_sys();
+ qint64 delta = current - m_started;
+ if (delta < 0)
+ delta += getPeriod_sys(); //we wrapped around
+ return delta;
+ }
+
+private:
+ enum {
+ MSECS_PER_HOUR = 3600000,
+ MSECS_PER_MIN = 60000
+ };
+
+ qint64 m_started;
+
+ quint64 getPeriod_sys() const {
+#ifdef Q_OS_WIN
+ return Q_UINT64_C(0x100000000);
+#else
+ // fallback
+ return 86400 * 1000;
+#endif
+ }
+
+ qint64 getTickCount_sys() const {
+#ifdef Q_OS_WIN
+ return ::GetTickCount();
+#else
+ // fallback
+ const QTime t = QTime::currentTime();
+ return MSECS_PER_HOUR * t.hour() + MSECS_PER_MIN * t.minute() + 1000 * t.second() + t.msec();
+#endif
+ }
+};
+
class QUnifiedTimer : public QObject
{
@@ -162,7 +221,8 @@ private:
// timer used to delay the check if we should start/stop the animation timer
QBasicTimer startStopAnimationTimer;
- QTime time;
+ ElapsedTimer time;
+
int lastTick;
int timingInterval;
int currentAnimationIdx;