From a14d8bf655917dcf806e22bdfafb03a35f5c8680 Mon Sep 17 00:00:00 2001 From: Peter Penz Date: Thu, 25 Aug 2011 16:52:14 +0200 Subject: [PATCH] Fix smooth-scrolling issue in combination with key-presses 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 | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/kitemviews/kitemlistcontainer.cpp b/src/kitemviews/kitemlistcontainer.cpp index 2eb94c901..ec759bdb3 100644 --- a/src/kitemviews/kitemlistcontainer.cpp +++ b/src/kitemviews/kitemlistcontainer.cpp @@ -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); } } -- 2.47.3