1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-30 22:51:16 +01:00

Added digital zoom

This commit is contained in:
Martin Tůma 2017-04-05 22:53:25 +02:00
parent 33cb944e36
commit 03ef7a9147
6 changed files with 109 additions and 46 deletions

View File

@ -594,18 +594,24 @@ void GUI::keys()
msgBox.setWindowTitle(tr("Keyboard controls")); msgBox.setWindowTitle(tr("Keyboard controls"));
msgBox.setText("<h3>" + tr("Keyboard controls") + "</h3>"); msgBox.setText("<h3>" + tr("Keyboard controls") + "</h3>");
msgBox.setInformativeText( msgBox.setInformativeText(
"<div><table width=\"300\"><tr><td>" + tr("Next file") "<style>td {padding-right: 1.5em;}</style><div><table><tr><td>"
+ "</td><td><i>" + QKeySequence(NEXT_KEY).toString() + tr("Next file") + "</td><td><i>" + QKeySequence(NEXT_KEY).toString()
+ "</i></td></tr><tr><td>" + tr("Previous file") + "</i></td></tr><tr><td>" + tr("Previous file")
+ "</td><td><i>" + QKeySequence(PREV_KEY).toString() + "</td><td><i>" + QKeySequence(PREV_KEY).toString()
+ "</i></td></tr><tr><td>" + tr("First file") + "</td><td><i>" + "</i></td></tr><tr><td>" + tr("First file") + "</td><td><i>"
+ QKeySequence(FIRST_KEY).toString() + "</i></td></tr><tr><td>" + QKeySequence(FIRST_KEY).toString() + "</i></td></tr><tr><td>"
+ tr("Last file") + "</td><td><i>" + QKeySequence(LAST_KEY).toString() + tr("Last file") + "</td><td><i>" + QKeySequence(LAST_KEY).toString()
+ "</i></td></tr><tr><td>" + tr("Append modifier") + "</i></td></tr><tr><td>" + tr("Append file")
+ "</td><td><i>SHIFT</i></td></tr><tr><td></td><td></td></tr><tr><td>" + "</td><td><i>" + QKeySequence(MODIFIER).toString() + tr("Next/Previous")
+ tr("Next map") + "</td><td><i>" + NEXT_MAP_SHORTCUT.toString() + "</i></td></tr><tr><td></td><td></td></tr><tr><td>" + tr("Next map")
+ "</i></td></tr><tr><td>" + tr("Previous map") + "</td><td><i>" + "</td><td><i>" + NEXT_MAP_SHORTCUT.toString() + "</i></td></tr><tr><td>"
+ PREV_MAP_SHORTCUT.toString() + "</i></td></tr></table></div>"); + tr("Previous map") + "</td><td><i>" + PREV_MAP_SHORTCUT.toString()
+ "</i></td></tr><tr><td></td><td></td></tr><tr><td>" + tr("Zoom in")
+ "</td><td><i>" + QKeySequence(ZOOM_IN).toString()
+ "</i></td></tr><tr><td>" + tr("Zoom out") + "</td><td><i>"
+ QKeySequence(ZOOM_OUT).toString() + "</i></td></tr><tr><td>"
+ tr("Digital zoom") + "</td><td><i>" + QKeySequence(MODIFIER).toString()
+ tr("Zoom") + "</i></td></tr></table></div>");
msgBox.exec(); msgBox.exec();
} }
@ -1321,6 +1327,8 @@ void GUI::keyPressEvent(QKeyEvent *event)
closeFiles(); closeFiles();
openFile(file); openFile(file);
} }
QMainWindow::keyPressEvent(event);
} }
void GUI::closeEvent(QCloseEvent *event) void GUI::closeEvent(QCloseEvent *event)

View File

@ -10,6 +10,9 @@
#define LAST_KEY Qt::Key_End #define LAST_KEY Qt::Key_End
#define MODIFIER Qt::ShiftModifier #define MODIFIER Qt::ShiftModifier
#define ZOOM_IN QKeySequence::ZoomIn
#define ZOOM_OUT QKeySequence::ZoomOut
#define QUIT_SHORTCUT QKeySequence(QKeySequence::Quit) #define QUIT_SHORTCUT QKeySequence(QKeySequence::Quit)
#define OPEN_SHORTCUT QKeySequence(QKeySequence::Open) #define OPEN_SHORTCUT QKeySequence(QKeySequence::Open)
#define CLOSE_SHORTCUT QKeySequence(QKeySequence::Close) #define CLOSE_SHORTCUT QKeySequence(QKeySequence::Close)
@ -22,6 +25,7 @@
#define SHOW_GRAPHS_SHORTCUT QKeySequence(Qt::CTRL + Qt::Key_G) #define SHOW_GRAPHS_SHORTCUT QKeySequence(Qt::CTRL + Qt::Key_G)
#define DISTANCE_GRAPH_SHORTCUT QKeySequence(Qt::CTRL + Qt::Key_D) #define DISTANCE_GRAPH_SHORTCUT QKeySequence(Qt::CTRL + Qt::Key_D)
#define TIME_GRAPH_SHORTCUT QKeySequence(Qt::CTRL + Qt::Key_T) #define TIME_GRAPH_SHORTCUT QKeySequence(Qt::CTRL + Qt::Key_T)
#ifdef Q_OS_MAC #ifdef Q_OS_MAC
#define FULLSCREEN_SHORTCUT QKeySequence(Qt::META + Qt::CTRL + Qt::Key_F) #define FULLSCREEN_SHORTCUT QKeySequence(Qt::META + Qt::CTRL + Qt::Key_F)
#else // Q_OS_MAC #else // Q_OS_MAC

View File

@ -24,6 +24,7 @@ PathItem::PathItem(const Path &path, Map *map, QGraphicsItem *parent)
_marker = new MarkerItem(this); _marker = new MarkerItem(this);
_marker->setPos(position(_path.at(0).distance())); _marker->setPos(position(_path.at(0).distance()));
_marker->setFlag(QGraphicsItem::ItemIgnoresTransformations);
_md = _path.at(0).distance(); _md = _path.at(0).distance();
setCursor(Qt::ArrowCursor); setCursor(Qt::ArrowCursor);
@ -79,7 +80,7 @@ void PathItem::setColor(const QColor &color)
update(); update();
} }
void PathItem::setWidth(int width) void PathItem::setWidth(qreal width)
{ {
prepareGeometryChange(); prepareGeometryChange();

View File

@ -26,7 +26,7 @@ public:
void setMap(Map *map); void setMap(Map *map);
void setColor(const QColor &color); void setColor(const QColor &color);
void setWidth(int width); void setWidth(qreal width);
void setStyle(Qt::PenStyle style); void setStyle(Qt::PenStyle style);
void showMarker(bool show) {_marker->setVisible(show);} void showMarker(bool show) {_marker->setVisible(show);}
@ -52,7 +52,7 @@ private:
Map *_map; Map *_map;
qreal _md; qreal _md;
int _width; qreal _width;
QPen _pen; QPen _pen;
QPainterPath _shape; QPainterPath _shape;
QPainterPath _painterPath; QPainterPath _painterPath;

View File

@ -1,7 +1,7 @@
#include <QGraphicsView> #include <QGraphicsView>
#include <QGraphicsScene> #include <QGraphicsScene>
#include <QWheelEvent> #include <QWheelEvent>
#include <QSysInfo> #include <QApplication>
#include "opengl.h" #include "opengl.h"
#include "misc.h" #include "misc.h"
#include "poi.h" #include "poi.h"
@ -12,9 +12,11 @@
#include "routeitem.h" #include "routeitem.h"
#include "waypointitem.h" #include "waypointitem.h"
#include "scaleitem.h" #include "scaleitem.h"
#include "keys.h"
#include "pathview.h" #include "pathview.h"
#define MAX_ZOOM 1
#define MIN_ZOOM -3
#define MARGIN 10.0 #define MARGIN 10.0
#define SCALE_OFFSET 7 #define SCALE_OFFSET 7
@ -48,6 +50,7 @@ PathView::PathView(Map *map, POI *poi, QWidget *parent)
_mapScale = new ScaleItem(); _mapScale = new ScaleItem();
_mapScale->setZValue(2.0); _mapScale->setZValue(2.0);
_mapScale->setFlag(QGraphicsItem::ItemIgnoresTransformations);
_map = map; _map = map;
_poi = poi; _poi = poi;
@ -71,6 +74,7 @@ PathView::PathView(Map *map, POI *poi, QWidget *parent)
_routeStyle = Qt::DashLine; _routeStyle = Qt::DashLine;
_plot = false; _plot = false;
_digitalZoom = 0;
_scene->setSceneRect(_map->bounds()); _scene->setSceneRect(_map->bounds());
_res = _map->resolution(_scene->sceneRect().center()); _res = _map->resolution(_scene->sceneRect().center());
@ -93,7 +97,7 @@ PathItem *PathView::addTrack(const Track &track)
_tracks.append(ti); _tracks.append(ti);
_tr |= ti->path().boundingRect(); _tr |= ti->path().boundingRect();
ti->setColor(_palette.nextColor()); ti->setColor(_palette.nextColor());
ti->setWidth(_trackWidth); ti->setWidth(_trackWidth * pow(2, -_digitalZoom));
ti->setStyle(_trackStyle); ti->setStyle(_trackStyle);
ti->setVisible(_showTracks); ti->setVisible(_showTracks);
_scene->addItem(ti); _scene->addItem(ti);
@ -114,7 +118,7 @@ PathItem *PathView::addRoute(const Route &route)
_routes.append(ri); _routes.append(ri);
_rr |= ri->path().boundingRect(); _rr |= ri->path().boundingRect();
ri->setColor(_palette.nextColor()); ri->setColor(_palette.nextColor());
ri->setWidth(_routeWidth); ri->setWidth(_routeWidth * pow(2, -_digitalZoom));
ri->setStyle(_routeStyle); ri->setStyle(_routeStyle);
ri->setVisible(_showRoutes); ri->setVisible(_showRoutes);
ri->showWaypoints(_showRouteWaypoints); ri->showWaypoints(_showRouteWaypoints);
@ -138,6 +142,7 @@ void PathView::addWaypoints(const QList<Waypoint> &waypoints)
wi->setZValue(1); wi->setZValue(1);
wi->showLabel(_showWaypointLabels); wi->showLabel(_showWaypointLabels);
wi->setVisible(_showWaypoints); wi->setVisible(_showWaypoints);
wi->setFlag(QGraphicsItem::ItemIgnoresTransformations);
_scene->addItem(wi); _scene->addItem(wi);
} }
@ -268,6 +273,8 @@ void PathView::setMap(Map *map)
_map->load(); _map->load();
connect(_map, SIGNAL(loaded()), this, SLOT(redraw())); connect(_map, SIGNAL(loaded()), this, SLOT(redraw()));
resetDigitalZoom();
mapScale(); mapScale();
_scene->setSceneRect(_map->bounds()); _scene->setSceneRect(_map->bounds());
@ -278,6 +285,11 @@ void PathView::setMap(Map *map)
for (int i = 0; i < _waypoints.size(); i++) for (int i = 0; i < _waypoints.size(); i++)
_waypoints.at(i)->setMap(map); _waypoints.at(i)->setMap(map);
QHash<Waypoint, WaypointItem*>::const_iterator it;
for (it = _pois.constBegin(); it != _pois.constEnd(); it++)
it.value()->setMap(_map);
updatePOIVisibility();
QPointF center = contentCenter(); QPointF center = contentCenter();
centerOn(center); centerOn(center);
@ -328,6 +340,7 @@ void PathView::addPOI(const QVector<Waypoint> &waypoints)
pi->setZValue(1); pi->setZValue(1);
pi->showLabel(_showPOILabels); pi->showLabel(_showPOILabels);
pi->setVisible(_showPOI); pi->setVisible(_showPOI);
pi->setFlag(QGraphicsItem::ItemIgnoresTransformations);
_scene->addItem(pi); _scene->addItem(pi);
_pois.insert(w, pi); _pois.insert(w, pi);
@ -357,8 +370,44 @@ void PathView::redraw()
resetCachedContent(); resetCachedContent();
} }
void PathView::zoom(const QPoint &pos, const Coordinates &c) void PathView::resetDigitalZoom()
{ {
_digitalZoom = 0;
resetTransform();
setTrackWidth(_trackWidth);
setRouteWidth(_routeWidth);
}
void PathView::digitalZoom(int zoom)
{
_digitalZoom += zoom;
scale(pow(2, zoom), pow(2, zoom));
setTrackWidth(_trackWidth);
setRouteWidth(_routeWidth);
_mapScale->setResolution(_res * pow(2, -_digitalZoom));
}
void PathView::zoom(int zoom, const QPoint &pos, const Coordinates &c)
{
bool shift = QApplication::keyboardModifiers() & Qt::ShiftModifier;
if (_digitalZoom) {
if (((_digitalZoom > 0 && zoom > 0) && (!shift || _digitalZoom
>= MAX_ZOOM)) || ((_digitalZoom < 0 && zoom < 0) && (!shift
|| _digitalZoom <= MIN_ZOOM)))
return;
digitalZoom(zoom);
} else {
qreal os, ns;
os = _map->zoom();
ns = (zoom > 0) ? _map->zoomIn() : _map->zoomOut();
if (ns != os) {
QPoint offset = pos - viewport()->rect().center(); QPoint offset = pos - viewport()->rect().center();
rescale(); rescale();
@ -368,11 +417,15 @@ void PathView::zoom(const QPoint &pos, const Coordinates &c)
_res = _map->resolution(center); _res = _map->resolution(center);
_mapScale->setResolution(_res); _mapScale->setResolution(_res);
} else {
if (shift)
digitalZoom(zoom);
}
}
} }
void PathView::wheelEvent(QWheelEvent *event) void PathView::wheelEvent(QWheelEvent *event)
{ {
qreal os, ns;
static int deg = 0; static int deg = 0;
deg += event->delta() / 8; deg += event->delta() / 8;
@ -380,48 +433,39 @@ void PathView::wheelEvent(QWheelEvent *event)
return; return;
deg = 0; deg = 0;
os = _map->zoom();
Coordinates c = _map->xy2ll(mapToScene(event->pos())); Coordinates c = _map->xy2ll(mapToScene(event->pos()));
zoom((event->delta() > 0) ? 1 : -1, event->pos(), c);
ns = (event->delta() > 0) ? _map->zoomIn() : _map->zoomOut();
if (ns != os)
zoom(event->pos(), c);
} }
void PathView::mouseDoubleClickEvent(QMouseEvent *event) void PathView::mouseDoubleClickEvent(QMouseEvent *event)
{ {
qreal os, ns;
if (event->button() != Qt::LeftButton && event->button() != Qt::RightButton) if (event->button() != Qt::LeftButton && event->button() != Qt::RightButton)
return; return;
os = _map->zoom();
Coordinates c = _map->xy2ll(mapToScene(event->pos())); Coordinates c = _map->xy2ll(mapToScene(event->pos()));
zoom((event->button() == Qt::LeftButton) ? 1 : -1, event->pos(), c);
ns = (event->button() == Qt::LeftButton) ? _map->zoomIn() : _map->zoomOut();
if (ns != os)
zoom(event->pos(), c);
} }
void PathView::keyPressEvent(QKeyEvent *event) void PathView::keyPressEvent(QKeyEvent *event)
{ {
qreal os, ns; int z;
os = _map->zoom();
QPoint pos = QRect(QPoint(), viewport()->size()).center(); QPoint pos = QRect(QPoint(), viewport()->size()).center();
Coordinates c = _map->xy2ll(mapToScene(pos)); Coordinates c = _map->xy2ll(mapToScene(pos));
if (event->matches(QKeySequence::ZoomIn)) if (event->matches(ZOOM_IN))
ns = _map->zoomIn(); z = 1;
else if (event->matches(QKeySequence::ZoomOut)) else if (event->matches(ZOOM_OUT))
ns = _map->zoomOut(); z = -1;
else { else {
QWidget::keyPressEvent(event); if (_digitalZoom && event->key() == Qt::Key_Escape )
resetDigitalZoom();
QGraphicsView::keyPressEvent(event);
return; return;
} }
if (ns != os) zoom(z, pos, c);
zoom(pos, c);
} }
void PathView::plot(QPainter *painter, const QRectF &target) void PathView::plot(QPainter *painter, const QRectF &target)
@ -474,6 +518,9 @@ void PathView::clear()
_tr = QRectF(); _rr = QRectF(); _wr = QRectF(); _tr = QRectF(); _rr = QRectF(); _wr = QRectF();
_wp = QPointF(); _wp = QPointF();
_digitalZoom = 0;
resetTransform();
} }
void PathView::showTracks(bool show) void PathView::showTracks(bool show)
@ -559,7 +606,7 @@ void PathView::setTrackWidth(int width)
_trackWidth = width; _trackWidth = width;
for (int i = 0; i < _tracks.count(); i++) for (int i = 0; i < _tracks.count(); i++)
_tracks.at(i)->setWidth(width); _tracks.at(i)->setWidth(width * pow(2, -_digitalZoom));
} }
void PathView::setRouteWidth(int width) void PathView::setRouteWidth(int width)
@ -567,7 +614,7 @@ void PathView::setRouteWidth(int width)
_routeWidth = width; _routeWidth = width;
for (int i = 0; i < _routes.count(); i++) for (int i = 0; i < _routes.count(); i++)
_routes.at(i)->setWidth(width); _routes.at(i)->setWidth(width * pow(2, -_digitalZoom));
} }
void PathView::setTrackStyle(Qt::PenStyle style) void PathView::setTrackStyle(Qt::PenStyle style)

View File

@ -76,7 +76,9 @@ private:
qreal mapScale() const; qreal mapScale() const;
QPointF contentCenter() const; QPointF contentCenter() const;
void rescale(); void rescale();
void zoom(const QPoint &pos, const Coordinates &c); void zoom(int zoom, const QPoint &pos, const Coordinates &c);
void digitalZoom(int zoom);
void resetDigitalZoom();
void updatePOIVisibility(); void updatePOIVisibility();
void updateWaypointsBoundingRect(const QPointF &wp); void updateWaypointsBoundingRect(const QPointF &wp);
@ -118,6 +120,7 @@ private:
Qt::PenStyle _trackStyle; Qt::PenStyle _trackStyle;
Qt::PenStyle _routeStyle; Qt::PenStyle _routeStyle;
int _digitalZoom;
bool _plot; bool _plot;
}; };