From 10944d4194439759b71a6ebc01cc8478d92e6521 Mon Sep 17 00:00:00 2001 From: Maxim Mikityanskiy Date: Tue, 1 Sep 2015 20:52:49 +0200 Subject: [PATCH] Scrolling fixes for Dolphin KItemListSmoothScroller::handleWheelEvent has some issues: 1. When I scroll file list holding mouse over the list, one mouse wheel tick corresponds to 1/4 page interval, but when I hover on QScrollBar, one wheel tick corresponds to 1 page interval. 2. In KItemListSmoothScroller::eventFilter we don't return true, so that QScrollBar also handles this event, and total scroll interval is m_scrollBar->pageStep() + m_scrollBar->singleStep(). 3. When I use touchpad that supports smooth scrolling via XInput2, and I hover it over QScrollBar, I can only scroll content if I move my fingers very fast, because numSteps = event->delta() / 8 / 15 is just zero unless I move very fast (event->delta() in this case is less than 120). 4. Holding Shift while scrolling has no effect when holding mouse over QScrollBar in contrast to scrolling faster when holding mouse over file list. The patch eliminates all these issues making the behavior of KItemListSmoothScroller the same as in KItemListContainer::wheelEvent, adding support for QWheelEvent::pixelDelta() and removing usage of deprecated QWheelEvent::delta(). REVIEW: 124670 FIXED-IN: 15.12.0 --- .../private/kitemlistsmoothscroller.cpp | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/kitemviews/private/kitemlistsmoothscroller.cpp b/src/kitemviews/private/kitemlistsmoothscroller.cpp index e70f47890..2bd467aa5 100644 --- a/src/kitemviews/private/kitemlistsmoothscroller.cpp +++ b/src/kitemviews/private/kitemlistsmoothscroller.cpp @@ -172,7 +172,7 @@ bool KItemListSmoothScroller::eventFilter(QObject* obj, QEvent* event) case QEvent::Wheel: handleWheelEvent(static_cast(event)); - break; + return true; // eat event so that QScrollBar does not scroll one step more by itself default: break; @@ -192,15 +192,25 @@ void KItemListSmoothScroller::slotAnimationStateChanged(QAbstractAnimation::Stat void KItemListSmoothScroller::handleWheelEvent(QWheelEvent* event) { - const int numDegrees = event->delta() / 8; - const int numSteps = numDegrees / 15; - const bool previous = m_smoothScrolling; m_smoothScrolling = true; - const int value = m_scrollBar->value(); - const int pageStep = m_scrollBar->pageStep(); - m_scrollBar->setValue(value - numSteps * pageStep); + int numPixels; + if (!event->pixelDelta().isNull()) { + numPixels = event->pixelDelta().y(); + } else { + const int numDegrees = event->angleDelta().y() / 8; + const int numSteps = numDegrees / 15; + numPixels = numSteps * m_scrollBar->pageStep() / 4; + } + int value = m_scrollBar->value(); + if (event->modifiers().testFlag(Qt::ShiftModifier)) { + const int scrollingDirection = numPixels > 0 ? 1 : -1; + value -= m_scrollBar->pageStep() * scrollingDirection; + } else { + value -= numPixels; + } + m_scrollBar->setValue(value); m_smoothScrolling = previous;