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
This commit is contained in:
Maxim Mikityanskiy 2015-09-01 20:52:49 +02:00 committed by Emmanuel Pescosta
parent 9ed9689cca
commit 10944d4194

View file

@ -172,7 +172,7 @@ bool KItemListSmoothScroller::eventFilter(QObject* obj, QEvent* event)
case QEvent::Wheel:
handleWheelEvent(static_cast<QWheelEvent*>(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;