Commit e014d581 authored by Nathaniel Graham's avatar Nathaniel Graham

Scroll wheel and touchpad zoom in smaller increments

Summary:
BUG: 307637

Change the zoom speed so that the scroll wheel and touchpad zoom behavior matches that of Inkscape and Krita: for more than 100%, the zoom is increased by sqrt(2); for less than 100%, the zoom is decreased by sqrt(0.5). In practice this means the following zoom levels:

35% → 50% → 71% → 100% → 141% → 200% → 283% → 400% → 566% → 800%

This feels much more comfortable and offers more control compared to the current ever-accelerating zoom speed.

Submitting this patch on behalf of  Vangelis Tasoulas.

Test Plan: Tested in KDE Neon. Works as advertised.

Reviewers: #kde_applications, vtasoulas, lukas, gateau, rkflx

Reviewed By: vtasoulas, rkflx

Subscribers: ltoscano, anthonyfieroni, rkflx

Differential Revision: https://phabricator.kde.org/D7972
parent e4b02eef
......@@ -21,6 +21,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA
// Self
#include "documentview.h"
// C++ Standard library
#include <cmath>
// Qt
#include <QApplication>
#include <QGraphicsLinearLayout>
......@@ -71,6 +74,8 @@ namespace Gwenview
static const qreal REAL_DELTA = 0.001;
static const qreal MAXIMUM_ZOOM_VALUE = qreal(DocumentView::MaximumZoom);
static const auto MINSTEP = sqrt(0.5);
static const auto MAXSTEP = sqrt(2.0);
static const int COMPARE_MARGIN = 4;
......@@ -263,18 +268,17 @@ struct DocumentViewPrivate
qreal min = q->minimumZoom();
mZoomSnapValues.clear();
if (min < 1.) {
mZoomSnapValues << min;
for (qreal invZoom = 16.; invZoom > 1.; invZoom /= 2.) {
qreal zoom = 1. / invZoom;
if (zoom > min) {
mZoomSnapValues << zoom;
}
}
for (qreal zoom = MINSTEP; zoom > min; zoom *= MINSTEP) {
mZoomSnapValues << zoom;
}
for (qreal zoom = 1; zoom <= MAXIMUM_ZOOM_VALUE ; zoom += 1.) {
mZoomSnapValues << min;
std::reverse(mZoomSnapValues.begin(), mZoomSnapValues.end());
for (qreal zoom = 1; zoom < MAXIMUM_ZOOM_VALUE; zoom *= MAXSTEP) {
mZoomSnapValues << zoom;
}
mZoomSnapValues << MAXIMUM_ZOOM_VALUE;
q->minimumZoomChanged(min);
}
......@@ -572,6 +576,12 @@ qreal DocumentView::zoom() const
return d->mAdapter->zoom();
}
void DocumentView::resizeEvent(QGraphicsSceneResizeEvent *event)
{
d->updateZoomSnapValues();
QGraphicsWidget::resizeEvent(event);
}
void DocumentView::wheelEvent(QGraphicsSceneWheelEvent* event)
{
if (d->mAdapter->canZoom() && event->modifiers() & Qt::ControlModifier) {
......
......@@ -197,6 +197,7 @@ Q_SIGNALS:
protected:
void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0) Q_DECL_OVERRIDE;
void resizeEvent(QGraphicsSceneResizeEvent* event) Q_DECL_OVERRIDE;
void wheelEvent(QGraphicsSceneWheelEvent* event) Q_DECL_OVERRIDE;
void contextMenuEvent(QGraphicsSceneContextMenuEvent* event) Q_DECL_OVERRIDE;
bool sceneEventFilter(QGraphicsItem*, QEvent*) Q_DECL_OVERRIDE;
......
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