diff --git a/src/gui.cpp b/src/gui.cpp index bf18fb07..07bf543d 100644 --- a/src/gui.cpp +++ b/src/gui.cpp @@ -594,18 +594,24 @@ void GUI::keys() msgBox.setWindowTitle(tr("Keyboard controls")); msgBox.setText("

" + tr("Keyboard controls") + "

"); msgBox.setInformativeText( - "
" + tr("Next file") - + "" + QKeySequence(NEXT_KEY).toString() + "
" + + tr("Next file") + "" + QKeySequence(NEXT_KEY).toString() + "
" + tr("Previous file") + "" + QKeySequence(PREV_KEY).toString() + "
" + tr("First file") + "" + QKeySequence(FIRST_KEY).toString() + "
" + tr("Last file") + "" + QKeySequence(LAST_KEY).toString() - + "
" + tr("Append modifier") - + "SHIFT
" - + tr("Next map") + "" + NEXT_MAP_SHORTCUT.toString() - + "
" + tr("Previous map") + "" - + PREV_MAP_SHORTCUT.toString() + "
"); + + "
" + tr("Append file") + + "" + QKeySequence(MODIFIER).toString() + tr("Next/Previous") + + "
" + tr("Next map") + + "" + NEXT_MAP_SHORTCUT.toString() + "
" + + tr("Previous map") + "" + PREV_MAP_SHORTCUT.toString() + + "
" + tr("Zoom in") + + "" + QKeySequence(ZOOM_IN).toString() + + "
" + tr("Zoom out") + "" + + QKeySequence(ZOOM_OUT).toString() + "
" + + tr("Digital zoom") + "" + QKeySequence(MODIFIER).toString() + + tr("Zoom") + "
"); msgBox.exec(); } @@ -1321,6 +1327,8 @@ void GUI::keyPressEvent(QKeyEvent *event) closeFiles(); openFile(file); } + + QMainWindow::keyPressEvent(event); } void GUI::closeEvent(QCloseEvent *event) diff --git a/src/keys.h b/src/keys.h index 76d20dec..29013a4d 100644 --- a/src/keys.h +++ b/src/keys.h @@ -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 diff --git a/src/pathitem.cpp b/src/pathitem.cpp index 930b48e3..9eff33d2 100644 --- a/src/pathitem.cpp +++ b/src/pathitem.cpp @@ -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(); diff --git a/src/pathitem.h b/src/pathitem.h index 17be16d0..e4a90aca 100644 --- a/src/pathitem.h +++ b/src/pathitem.h @@ -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; diff --git a/src/pathview.cpp b/src/pathview.cpp index 07177878..ec6f7f68 100644 --- a/src/pathview.cpp +++ b/src/pathview.cpp @@ -1,7 +1,7 @@ #include #include #include -#include +#include #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 &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::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 &waypoints) pi->setZValue(1); pi->showLabel(_showPOILabels); pi->setVisible(_showPOI); + pi->setFlag(QGraphicsItem::ItemIgnoresTransformations); _scene->addItem(pi); _pois.insert(w, pi); @@ -357,22 +370,62 @@ void PathView::redraw() resetCachedContent(); } -void PathView::zoom(const QPoint &pos, const Coordinates &c) +void PathView::resetDigitalZoom() { - QPoint offset = pos - viewport()->rect().center(); + _digitalZoom = 0; - rescale(); + resetTransform(); - QPointF center = _map->ll2xy(c) - offset; - centerOn(center); + setTrackWidth(_trackWidth); + setRouteWidth(_routeWidth); +} - _res = _map->resolution(center); - _mapScale->setResolution(_res); +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(); + + QPointF center = _map->ll2xy(c) - offset; + centerOn(center); + + _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) diff --git a/src/pathview.h b/src/pathview.h index 999741a9..3e3ee14b 100644 --- a/src/pathview.h +++ b/src/pathview.h @@ -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; };