QStyleAnimation: writable duration & delay properties
authorJ-P Nurmi <jpnurmi@digia.com>
Tue, 23 Oct 2012 12:36:59 +0000 (14:36 +0200)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Thu, 25 Oct 2012 12:10:04 +0000 (14:10 +0200)
These will be needed by upcoming QFadeStyleAnimation and QBlendStyleAnimation.

Change-Id: Ibc5092d5dbd834cb9b16353d3e83b95b04d9484b
Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@digia.com>
src/widgets/styles/qstyleanimation.cpp
src/widgets/styles/qstyleanimation_p.h

index 6b12ca9..d81532f 100644 (file)
@@ -48,7 +48,7 @@
 QT_BEGIN_NAMESPACE
 
 QStyleAnimation::QStyleAnimation(QObject *target) : QAbstractAnimation(),
-    _startTime(QTime::currentTime())
+    _delay(0), _duration(-1), _startTime(QTime::currentTime())
 {
     if (target) {
         moveToThread(target->thread());
@@ -61,14 +61,29 @@ QStyleAnimation::~QStyleAnimation()
 {
 }
 
+QObject *QStyleAnimation::target() const
+{
+    return parent();
+}
+
 int QStyleAnimation::duration() const
 {
-    return -1;
+    return _duration;
 }
 
-QObject *QStyleAnimation::target() const
+void QStyleAnimation::setDuration(int duration)
 {
-    return parent();
+    _duration = duration;
+}
+
+int QStyleAnimation::delay() const
+{
+    return _delay;
+}
+
+void QStyleAnimation::setDelay(int delay)
+{
+    _delay = delay;
 }
 
 QTime QStyleAnimation::startTime() const
@@ -89,7 +104,7 @@ void QStyleAnimation::updateTarget()
 
 bool QStyleAnimation::isUpdateNeeded() const
 {
-    return true;
+    return currentTime() > _delay;
 }
 
 void QStyleAnimation::updateCurrentTime(int)
@@ -137,11 +152,13 @@ void QProgressStyleAnimation::setSpeed(int speed)
 
 bool QProgressStyleAnimation::isUpdateNeeded() const
 {
-    int current = animationStep();
-    if (_step == -1 || _step != current)
-    {
-        _step = current;
-        return true;
+    if (QStyleAnimation::isUpdateNeeded()) {
+        int current = animationStep();
+        if (_step == -1 || _step != current)
+        {
+            _step = current;
+            return true;
+        }
     }
     return false;
 }
index 577b1d7..3188eeb 100644 (file)
@@ -66,9 +66,14 @@ public:
     QStyleAnimation(QObject *target);
     virtual ~QStyleAnimation();
 
-    int duration() const;
     QObject *target() const;
 
+    int duration() const;
+    void setDuration(int duration);
+
+    int delay() const;
+    void setDelay(int delay);
+
     QTime startTime() const;
     void setStartTime(const QTime &time);
 
@@ -79,6 +84,8 @@ protected:
     virtual void updateCurrentTime(int time);
 
 private:
+    int _delay;
+    int _duration;
     QTime _startTime;
 };