Use QBasicTimer rather than QTimer in SmoothedAnimation
authorMartin Jones <martin.jones@nokia.com>
Wed, 28 Sep 2011 00:12:08 +0000 (10:12 +1000)
committerQt by Nokia <qt-info@nokia.com>
Wed, 28 Sep 2011 03:25:55 +0000 (05:25 +0200)
QBasicTimer does the same job for lower cost.

Change-Id: I11d7033b9c456129f3f984c8baafa717f5b25d99
Reviewed-on: http://codereview.qt-project.org/5649
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Michael Brasser <michael.brasser@nokia.com>

src/declarative/util/qdeclarativesmoothedanimation.cpp
src/declarative/util/qdeclarativesmoothedanimation_p_p.h

index d306f8a..dd7bfe2 100644 (file)
@@ -62,9 +62,6 @@ QSmoothedAnimation::QSmoothedAnimation(QObject *parent)
       reversingMode(QDeclarativeSmoothedAnimation::Eased), initialVelocity(0),
       trackVelocity(0), initialValue(0), invert(false), finalDuration(-1), lastTime(0)
 {
-    delayedStopTimer.setInterval(DELAY_STOP_TIMER_INTERVAL);
-    delayedStopTimer.setSingleShot(true);
-    connect(&delayedStopTimer, SIGNAL(timeout()), this, SLOT(stop()));
 }
 
 void QSmoothedAnimation::restart()
@@ -82,10 +79,20 @@ void QSmoothedAnimation::updateState(QAbstractAnimation::State newState, QAbstra
         init();
 }
 
+void QSmoothedAnimation::timerEvent(QTimerEvent *event)
+{
+    if (event->timerId() == delayedStopTimer.timerId()) {
+        delayedStopTimer.stop();
+        stop();
+    } else {
+        QAbstractAnimation::timerEvent(event);
+    }
+}
+
 void QSmoothedAnimation::delayedStop()
 {
     if (!delayedStopTimer.isActive())
-        delayedStopTimer.start();
+        delayedStopTimer.start(DELAY_STOP_TIMER_INTERVAL, this);
 }
 
 int QSmoothedAnimation::duration() const
index 161fb11..224dc75 100644 (file)
@@ -61,7 +61,7 @@
 #include <qparallelanimationgroup.h>
 
 #include <private/qobject_p.h>
-#include <QTimer>
+#include <QBasicTimer>
 
 QT_BEGIN_NAMESPACE
 
@@ -89,6 +89,7 @@ public:
 protected:
     virtual void updateCurrentTime(int);
     virtual void updateState(QAbstractAnimation::State, QAbstractAnimation::State);
+    virtual void timerEvent(QTimerEvent *);
 
 private:
     qreal easeFollow(qreal);
@@ -115,7 +116,7 @@ private:
     bool recalc();
     void delayedStop();
 
-    QTimer delayedStopTimer;
+    QBasicTimer delayedStopTimer;
 };
 
 class QDeclarativeSmoothedAnimationPrivate : public QDeclarativePropertyAnimationPrivate