diff options
authorHenrik Fehlauer <[email protected]>2017-10-22 11:30:23 +0200
committerHenrik Fehlauer <[email protected]>2017-10-22 11:37:39 +0200
commit1069882e3f92712dff02885a308f116318956740 (patch)
parente014d581e52b04dfbf1b576abe84962910ab5f6a (diff)
Fix zoom slider toolbuttons not disabling properly
Summary: Moving the zoom slider should disable the zoom buttons next to it when reaching the maximum or minimum value respectively, but this was only the case when changing sliding direction again. This lag is caused by the `SignalBlocker` in `ZoomWidget::setZoom` used to enable a smoother scroll, but disabling synchronisation of `QSlider::sliderPosition` and `QSlider::value` at the same time. The fix is inspired by 84910f85152f. In addition, when resizing the window in "Fit" zoom mode, the button to zoom out would not get disabled, even though "Fit" is the minimum zoom level. This is caused by calculating the minimum zoom in `updateZoomSnapValues` based on the old window geometry. Therefore, `updateZoomSnapValues` should be called only after `resizeAdapterWidget`. Note: Compared to a similar approach in D7972#152758, we avoid calling `resizeAdapterWidget` unnecessarily and also stop `resizeAdapterWidget` and `setGeometry` calling each other in a potentially infinite loop. Trying to move `updateZoomSnapValues` inside of `resizeAdapterWidget` sadly breaks the zoom slider when advancing to the next image. Depends on D7972. Test Plan: Tried various combinations of zoom (Fit, slider, keyboard) and view modes (browse, view single image, compare images, thumbnails, birds eye view) while resizing the window and switching between images. Toolbuttons get disabled as they should and no (new) bugs were observed. Nevertheless please test carefully, as this part of the code base is quite complex. Reviewers: #kde_applications, ngraham, vtasoulas, gateau Reviewed By: ngraham, gateau Differential Revision:
2 files changed, 6 insertions, 4 deletions
diff --git a/lib/documentview/documentview.cpp b/lib/documentview/documentview.cpp
index 82def26..29c6367 100644
--- a/lib/documentview/documentview.cpp
+++ b/lib/documentview/documentview.cpp
@@ -578,6 +578,7 @@ qreal DocumentView::zoom() const
void DocumentView::resizeEvent(QGraphicsSceneResizeEvent *event)
+ d->resizeAdapterWidget();
@@ -667,7 +668,6 @@ qreal DocumentView::minimumZoom() const
void DocumentView::setCompareMode(bool compare)
d->mCompareMode = compare;
- d->resizeAdapterWidget();
if (compare) {
@@ -729,7 +729,6 @@ void DocumentView::emitFocused()
void DocumentView::setGeometry(const QRectF& rect)
- d->resizeAdapterWidget();
if (d->mBirdEyeView) {
diff --git a/lib/zoomslider.cpp b/lib/zoomslider.cpp
index ea9514e..c5fd514 100644
--- a/lib/zoomslider.cpp
+++ b/lib/zoomslider.cpp
@@ -45,8 +45,11 @@ struct ZoomSliderPrivate
void updateButtons()
- mZoomOutButton->setEnabled(mSlider->value() > mSlider->minimum());
- mZoomInButton->setEnabled(mSlider->value() < mSlider->maximum());
+ // Use QSlider::sliderPosition(), not QSlider::value() because when we are
+ // called from slotZoomSliderActionTriggered(), QSlider::value() has not
+ // been updated yet.
+ mZoomOutButton->setEnabled(mSlider->sliderPosition() > mSlider->minimum());
+ mZoomInButton->setEnabled(mSlider->sliderPosition() < mSlider->maximum());