]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Fix smooth-scrolling issue in combination with key-presses
authorPeter Penz <peter.penz19@gmail.com>
Thu, 25 Aug 2011 14:52:14 +0000 (16:52 +0200)
committerPeter Penz <peter.penz19@gmail.com>
Thu, 25 Aug 2011 14:53:45 +0000 (16:53 +0200)
If e.g. the down-arrow-key is pressed constantly the view does not
scroll as the animation always will get restarted. Assure that
the animation proceeds in this case.

src/kitemviews/kitemlistcontainer.cpp

index 2eb94c901ac5ba11d11651b30a230902b95d5dc5..ec759bdb32a26bcddb39c3b11c4c5b3e81789ed9 100644 (file)
@@ -128,21 +128,30 @@ void KItemListContainer::scrollContentsBy(int dx, int dy)
         // Stopping a running animation means skipping the range from the current offset
         // until the target offset. To prevent skipping of the range the difference
         // is added to the new target offset.
-        const qreal targetOffset = m_smoothScrollingAnimation->endValue().toReal();
-        offsetDiff += (currentOffset - targetOffset);
+        const qreal oldEndOffset = m_smoothScrollingAnimation->endValue().toReal();
+        offsetDiff += (currentOffset - oldEndOffset);
     }
 
-    const qreal newOffset = currentOffset - offsetDiff;
+    const qreal endOffset = currentOffset - offsetDiff;
 
     if (m_smoothScrolling || animRunning) {
+        qreal startOffset = currentOffset;
+        if (animRunning) {
+            // If the animation was running and has been interrupted by assigning a new end-offset
+            // one frame must be added to the start-offset to keep the animation smooth. This also
+            // assures that animation proceeds even in cases where new end-offset are triggered
+            // within a very short timeslots.
+            startOffset += (endOffset - currentOffset) * 1000 / (m_smoothScrollingAnimation->duration() * 60);
+        }
+
         m_smoothScrollingAnimation->stop();
-        m_smoothScrollingAnimation->setStartValue(currentOffset);
-        m_smoothScrollingAnimation->setEndValue(newOffset);
+        m_smoothScrollingAnimation->setStartValue(startOffset);
+        m_smoothScrollingAnimation->setEndValue(endOffset);
         m_smoothScrollingAnimation->setEasingCurve(animRunning ? QEasingCurve::OutQuad : QEasingCurve::InOutQuad);
         m_smoothScrollingAnimation->start();
-        view->setOffset(currentOffset);
+        view->setOffset(startOffset);
     } else {
-        view->setOffset(newOffset);
+        view->setOffset(endOffset);
     }
 }