diff --git a/src/trackview.cpp b/src/trackview.cpp index ecb32c51..cc877411 100644 --- a/src/trackview.cpp +++ b/src/trackview.cpp @@ -319,16 +319,13 @@ void TrackView::rescale() _mapScale->setZoom(_zoom); } -void TrackView::wheelEvent(QWheelEvent *event) +void TrackView::zoom(int z, const QPointF &pos) { if (_paths.isEmpty() && _locations.isEmpty()) return; - QPointF pos = mapToScene(event->pos()); qreal scale = _scale; - - _zoom = (event->delta() > 0) ? - qMin(_zoom + 1, ZOOM_MAX) : qMax(_zoom - 1, ZOOM_MIN); + _zoom = z; rescale(mapScale(_zoom)); QRectF br = trackBoundingRect() | waypointBoundingRect(); @@ -346,6 +343,33 @@ void TrackView::wheelEvent(QWheelEvent *event) resetCachedContent(); } +void TrackView::wheelEvent(QWheelEvent *event) +{ + if (_paths.isEmpty() && _locations.isEmpty()) + return; + + QPointF pos = mapToScene(event->pos()); + int z = (event->delta() > 0) ? + qMin(_zoom + 1, ZOOM_MAX) : qMax(_zoom - 1, ZOOM_MIN); + + zoom(z, pos); +} + +void TrackView::keyPressEvent(QKeyEvent *event) +{ + int z = -1; + + if (event->matches(QKeySequence::ZoomIn)) + z = qMin(_zoom + 1, ZOOM_MAX); + if (event->matches(QKeySequence::ZoomOut)) + z = qMax(_zoom - 1, ZOOM_MIN); + + if (z >= 0) + zoom(z, mapToScene(QRect(QPoint(), size()).center())); + else + QWidget::keyPressEvent(event); +} + void TrackView::plot(QPainter *painter, const QRectF &target) { QRect orig, adj; diff --git a/src/trackview.h b/src/trackview.h index 1506f186..ffbb3d04 100644 --- a/src/trackview.h +++ b/src/trackview.h @@ -54,8 +54,10 @@ private: qreal mapScale(int zoom) const; void rescale(qreal scale); void rescale(); + void zoom(int z, const QPointF &pos); void wheelEvent(QWheelEvent *event); + void keyPressEvent(QKeyEvent *event); void drawBackground(QPainter *painter, const QRectF &rect); void resizeEvent(QResizeEvent *e); void paintEvent(QPaintEvent *e);