diff options
| author | Peter Penz <[email protected]> | 2011-08-25 16:52:14 +0200 |
|---|---|---|
| committer | Peter Penz <[email protected]> | 2011-08-25 16:53:45 +0200 |
| commit | a14d8bf655917dcf806e22bdfafb03a35f5c8680 (patch) | |
| tree | 1324deab2ea56b4afe4e7c2797f318c4ea31bb34 /src/kitemviews/kitemlistcontainer.cpp | |
| parent | 04dec30c805f506ba0135636a19970bf01c66209 (diff) | |
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.
Diffstat (limited to 'src/kitemviews/kitemlistcontainer.cpp')
| -rw-r--r-- | src/kitemviews/kitemlistcontainer.cpp | 23 |
1 files 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); } } |
