1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-24 03:35:53 +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);
}
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;

View File

@ -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);