From cf4f9b6f980cfe58e05a4e2afa05d98dc54b31d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20T=C5=AFma?= Date: Tue, 29 Dec 2020 18:36:23 +0100 Subject: [PATCH] Fixed digital zoom on OS X --- src/GUI/mapview.cpp | 23 ++++++++++++++--------- src/GUI/mapview.h | 2 +- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/GUI/mapview.cpp b/src/GUI/mapview.cpp index cf9df962..5b0a2297 100644 --- a/src/GUI/mapview.cpp +++ b/src/GUI/mapview.cpp @@ -515,10 +515,8 @@ void MapView::digitalZoom(int zoom) _coordinates->setDigitalZoom(_digitalZoom); } -void MapView::zoom(int zoom, const QPoint &pos) +void MapView::zoom(int zoom, const QPoint &pos, bool shift) { - bool shift = QApplication::keyboardModifiers() & Qt::ShiftModifier; - if (_digitalZoom) { if (((_digitalZoom > 0 && zoom > 0) && (!shift || _digitalZoom >= MAX_DIGITAL_ZOOM)) || ((_digitalZoom < 0 && zoom < 0) && (!shift @@ -544,21 +542,28 @@ void MapView::zoom(int zoom, const QPoint &pos) void MapView::wheelEvent(QWheelEvent *event) { static int deg = 0; + bool shift = (event->modifiers() & MODIFIER) ? true : false; + // Shift inverts the wheel axis on OS X, so use scrolling in both axis for + // the zoom. + int delta = event->angleDelta().y() + ? event->angleDelta().y() : event->angleDelta().x(); - deg += event->angleDelta().y() / 8; + deg += delta / 8; if (qAbs(deg) < 15) return; deg = 0; #if QT_VERSION < QT_VERSION_CHECK(5, 15, 0) - zoom((event->angleDelta().y() > 0) ? 1 : -1, event->pos()); + zoom((delta > 0) ? 1 : -1, event->pos(), shift); #else // QT 5.15 - zoom((event->angleDelta().y() > 0) ? 1 : -1, event->position().toPoint()); + zoom((delta > 0) ? 1 : -1, event->position().toPoint(), shift); #endif // QT 5.15 } void MapView::mouseDoubleClickEvent(QMouseEvent *event) { + bool shift = (event->modifiers() & MODIFIER) ? true : false; + QGraphicsView::mouseDoubleClickEvent(event); if (event->isAccepted()) return; @@ -566,13 +571,13 @@ void MapView::mouseDoubleClickEvent(QMouseEvent *event) if (event->button() != Qt::LeftButton && event->button() != Qt::RightButton) return; - zoom((event->button() == Qt::LeftButton) ? 1 : -1, event->pos()); + zoom((event->button() == Qt::LeftButton) ? 1 : -1, event->pos(), shift); } void MapView::keyPressEvent(QKeyEvent *event) { int z; - + bool shift = (event->modifiers() & MODIFIER) ? true : false; QPoint pos = viewport()->rect().center(); if (event->key() == ZOOM_IN) @@ -592,7 +597,7 @@ void MapView::keyPressEvent(QKeyEvent *event) return; } - zoom(z, pos); + zoom(z, pos, shift); } void MapView::keyReleaseEvent(QKeyEvent *event) diff --git a/src/GUI/mapview.h b/src/GUI/mapview.h index 98b56b90..7757272a 100644 --- a/src/GUI/mapview.h +++ b/src/GUI/mapview.h @@ -123,7 +123,7 @@ private: QPointF contentCenter() const; void rescale(); void centerOn(const QPointF &pos); - void zoom(int zoom, const QPoint &pos); + void zoom(int zoom, const QPoint &pos, bool shift); void digitalZoom(int zoom); void updatePOIVisibility(); void skipColor() {_palette.nextColor();}