Commit 17c26699 authored by David Hurka's avatar David Hurka 🐬
Browse files

Fix scrolling with scrollbar when the slider is not clicked

This fixes scrolling with the scrollbar,
so it is not reset when scrolling on the viewport afterwards.

PageView’s QSroller was not correctly updated by update_scroller,
because it was connected to QAbstractSlider::sliderMoved and sliderReleased,
which are only emitted while the “slider is down”,
i. e. not when the user scrolls the scrollbar other than dragging the slider.
Now update_scroller is connected to actionTriggered(),
which is emitted for all user interactions.

Note that scrolling using the scrollbar calls QAbstractScrollArea::scrollContentsBy(),
and so bypasses smooth scrolling of the QScroller. This could be considered a feature,
otherwise it is more a bug in Qt than in Okular, because we can not ignore scrollContentsBy().

Steps to reproduce:
1. Open a long document
2. Click on the vertical scrollbar below the slider
3. Okular scrolls one page down
4. Scroll in the viewport
5. Okular starts scrolling from the position from step 1.

Test plan:
* Scroll using scrollbar
  + Click on the vertical scrollbar below the slider
  + Middle-click on the vertical scrollbar below the slider
  + Click on the little arrow of the vertical scrollbar
  + Scroll using a scrolling device (e. g. `xdotool click 4`) on the vertical scrollbar
  + Drag the slider of the scrollbar
* “cross-product” verify QScroller state
  + Scroll using a scrolling device on the viewport
  + Scroll using Browse tool dragging
  + Scroll the viewport by clicking a point in the thumbnails view
  + Scroll the viewport using arrow keys and Page Up/Down keys

BUG: 421159
parent c8cf6513
Pipeline #37410 passed with stage
in 105 minutes and 57 seconds
......@@ -436,13 +436,16 @@ PageView::PageView(QWidget *parent, Okular::Document *document)
connect(horizontalScrollBar(), &QAbstractSlider::valueChanged, this, &PageView::slotRequestVisiblePixmaps);
connect(verticalScrollBar(), &QAbstractSlider::valueChanged, this, &PageView::slotRequestVisiblePixmaps);
// Keep the scroller in sync with user input on the scrollbars.
// QAbstractSlider::sliderMoved() and sliderReleased are the intuitive signals,
// but are only emitted when the “slider is down”, i. e. not when the user scrolls on the scrollbar.
// QAbstractSlider::actionTriggered() is emitted in all user input cases,
// but before the value() changes, so we need queued connection here.
auto update_scroller = [=]() {
d->scroller->scrollTo(QPoint(horizontalScrollBar()->value(), verticalScrollBar()->value()), 0); // sync scroller with scrollbar
};
connect(verticalScrollBar(), &QAbstractSlider::sliderReleased, this, update_scroller);
connect(horizontalScrollBar(), &QAbstractSlider::sliderReleased, this, update_scroller);
connect(verticalScrollBar(), &QAbstractSlider::sliderMoved, this, update_scroller);
connect(horizontalScrollBar(), &QAbstractSlider::sliderMoved, this, update_scroller);
connect(verticalScrollBar(), &QAbstractSlider::actionTriggered, this, update_scroller, Qt::QueuedConnection);
connect(horizontalScrollBar(), &QAbstractSlider::actionTriggered, this, update_scroller, Qt::QueuedConnection);
connect(&d->dragScrollTimer, &QTimer::timeout, this, &PageView::slotDragScroll);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment