1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-28 05:34:47 +01:00

Added track zoom in/out keyboard controll.

This commit is contained in:
Martin Tůma 2016-07-21 22:39:53 +02:00
parent 2695745d82
commit 33b6e8954c
2 changed files with 31 additions and 5 deletions

View File

@ -319,16 +319,13 @@ void TrackView::rescale()
_mapScale->setZoom(_zoom); _mapScale->setZoom(_zoom);
} }
void TrackView::wheelEvent(QWheelEvent *event) void TrackView::zoom(int z, const QPointF &pos)
{ {
if (_paths.isEmpty() && _locations.isEmpty()) if (_paths.isEmpty() && _locations.isEmpty())
return; return;
QPointF pos = mapToScene(event->pos());
qreal scale = _scale; qreal scale = _scale;
_zoom = z;
_zoom = (event->delta() > 0) ?
qMin(_zoom + 1, ZOOM_MAX) : qMax(_zoom - 1, ZOOM_MIN);
rescale(mapScale(_zoom)); rescale(mapScale(_zoom));
QRectF br = trackBoundingRect() | waypointBoundingRect(); QRectF br = trackBoundingRect() | waypointBoundingRect();
@ -346,6 +343,33 @@ void TrackView::wheelEvent(QWheelEvent *event)
resetCachedContent(); 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) void TrackView::plot(QPainter *painter, const QRectF &target)
{ {
QRect orig, adj; QRect orig, adj;

View File

@ -54,8 +54,10 @@ private:
qreal mapScale(int zoom) const; qreal mapScale(int zoom) const;
void rescale(qreal scale); void rescale(qreal scale);
void rescale(); void rescale();
void zoom(int z, const QPointF &pos);
void wheelEvent(QWheelEvent *event); void wheelEvent(QWheelEvent *event);
void keyPressEvent(QKeyEvent *event);
void drawBackground(QPainter *painter, const QRectF &rect); void drawBackground(QPainter *painter, const QRectF &rect);
void resizeEvent(QResizeEvent *e); void resizeEvent(QResizeEvent *e);
void paintEvent(QPaintEvent *e); void paintEvent(QPaintEvent *e);