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.setText("<h3>" + tr("Keyboard controls") + "</h3>");
msgBox.setInformativeText(
"<div><table width=\"300\"><tr><td>" + tr("Next file")
+ "</td><td><i>" + QKeySequence(NEXT_KEY).toString()
"<style>td {padding-right: 1.5em;}</style><div><table><tr><td>"
+ tr("Next file") + "</td><td><i>" + QKeySequence(NEXT_KEY).toString()
+ "</i></td></tr><tr><td>" + tr("Previous file")
+ "</td><td><i>" + QKeySequence(PREV_KEY).toString()
+ "</i></td></tr><tr><td>" + tr("First file") + "</td><td><i>"
+ QKeySequence(FIRST_KEY).toString() + "</i></td></tr><tr><td>"
+ tr("Last file") + "</td><td><i>" + QKeySequence(LAST_KEY).toString()
+ "</i></td></tr><tr><td>" + tr("Append modifier")
+ "</td><td><i>SHIFT</i></td></tr><tr><td></td><td></td></tr><tr><td>"
+ tr("Next map") + "</td><td><i>" + NEXT_MAP_SHORTCUT.toString()
+ "</i></td></tr><tr><td>" + tr("Previous map") + "</td><td><i>"
+ PREV_MAP_SHORTCUT.toString() + "</i></td></tr></table></div>");
+ "</i></td></tr><tr><td>" + tr("Append file")
+ "</td><td><i>" + QKeySequence(MODIFIER).toString() + tr("Next/Previous")
+ "</i></td></tr><tr><td></td><td></td></tr><tr><td>" + tr("Next map")
+ "</td><td><i>" + NEXT_MAP_SHORTCUT.toString() + "</i></td></tr><tr><td>"
+ 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();
}
@ -1321,6 +1327,8 @@ void GUI::keyPressEvent(QKeyEvent *event)
closeFiles();
openFile(file);
}
QMainWindow::keyPressEvent(event);
}
void GUI::closeEvent(QCloseEvent *event)

View File

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

View File

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

View File

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

View File

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

View File

@ -76,7 +76,9 @@ private:
qreal mapScale() const;
QPointF contentCenter() const;
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 updateWaypointsBoundingRect(const QPointF &wp);
@ -118,6 +120,7 @@ private:
Qt::PenStyle _trackStyle;
Qt::PenStyle _routeStyle;
int _digitalZoom;
bool _plot;
};