1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-24 11:45:53 +01:00

Fixed digital zoom on OS X

This commit is contained in:
Martin Tůma 2020-12-29 18:36:23 +01:00
parent 9b3ed7ef1d
commit cf4f9b6f98
2 changed files with 15 additions and 10 deletions

View File

@ -515,10 +515,8 @@ void MapView::digitalZoom(int zoom)
_coordinates->setDigitalZoom(_digitalZoom); _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) {
if (((_digitalZoom > 0 && zoom > 0) && (!shift || _digitalZoom if (((_digitalZoom > 0 && zoom > 0) && (!shift || _digitalZoom
>= MAX_DIGITAL_ZOOM)) || ((_digitalZoom < 0 && zoom < 0) && (!shift >= 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) void MapView::wheelEvent(QWheelEvent *event)
{ {
static int deg = 0; 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) if (qAbs(deg) < 15)
return; return;
deg = 0; deg = 0;
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 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 #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 #endif // QT 5.15
} }
void MapView::mouseDoubleClickEvent(QMouseEvent *event) void MapView::mouseDoubleClickEvent(QMouseEvent *event)
{ {
bool shift = (event->modifiers() & MODIFIER) ? true : false;
QGraphicsView::mouseDoubleClickEvent(event); QGraphicsView::mouseDoubleClickEvent(event);
if (event->isAccepted()) if (event->isAccepted())
return; return;
@ -566,13 +571,13 @@ void MapView::mouseDoubleClickEvent(QMouseEvent *event)
if (event->button() != Qt::LeftButton && event->button() != Qt::RightButton) if (event->button() != Qt::LeftButton && event->button() != Qt::RightButton)
return; 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) void MapView::keyPressEvent(QKeyEvent *event)
{ {
int z; int z;
bool shift = (event->modifiers() & MODIFIER) ? true : false;
QPoint pos = viewport()->rect().center(); QPoint pos = viewport()->rect().center();
if (event->key() == ZOOM_IN) if (event->key() == ZOOM_IN)
@ -592,7 +597,7 @@ void MapView::keyPressEvent(QKeyEvent *event)
return; return;
} }
zoom(z, pos); zoom(z, pos, shift);
} }
void MapView::keyReleaseEvent(QKeyEvent *event) void MapView::keyReleaseEvent(QKeyEvent *event)

View File

@ -123,7 +123,7 @@ private:
QPointF contentCenter() const; QPointF contentCenter() const;
void rescale(); void rescale();
void centerOn(const QPointF &pos); 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 digitalZoom(int zoom);
void updatePOIVisibility(); void updatePOIVisibility();
void skipColor() {_palette.nextColor();} void skipColor() {_palette.nextColor();}