mirror of
https://github.com/tumic0/GPXSee.git
synced 2024-11-24 03:35:53 +01:00
parent
3d0c36b459
commit
12f3c252bb
@ -157,7 +157,8 @@ HEADERS += src/common/config.h \
|
||||
src/data/dem.h \
|
||||
src/data/polygon.h \
|
||||
src/data/area.h \
|
||||
src/map/obliquestereographic.h
|
||||
src/map/obliquestereographic.h \
|
||||
src/GUI/coordinatesitem.h
|
||||
SOURCES += src/main.cpp \
|
||||
src/common/coordinates.cpp \
|
||||
src/common/rectc.cpp \
|
||||
@ -271,7 +272,8 @@ SOURCES += src/main.cpp \
|
||||
src/data/slfparser.cpp \
|
||||
src/data/dem.cpp \
|
||||
src/data/polygon.cpp \
|
||||
src/map/obliquestereographic.cpp
|
||||
src/map/obliquestereographic.cpp \
|
||||
src/GUI/coordinatesitem.cpp
|
||||
|
||||
greaterThan(QT_MAJOR_VERSION, 4) {
|
||||
HEADERS += src/data/geojsonparser.h
|
||||
|
56
src/GUI/coordinatesitem.cpp
Normal file
56
src/GUI/coordinatesitem.cpp
Normal file
@ -0,0 +1,56 @@
|
||||
#include <QFontMetrics>
|
||||
#include <QPainter>
|
||||
#include "font.h"
|
||||
#include "coordinatesitem.h"
|
||||
|
||||
|
||||
CoordinatesItem::CoordinatesItem(QGraphicsItem *parent) : QGraphicsItem(parent)
|
||||
{
|
||||
_format = DecimalDegrees;
|
||||
|
||||
_font.setPixelSize(FONT_SIZE);
|
||||
_font.setFamily(FONT_FAMILY);
|
||||
|
||||
updateBoundingRect();
|
||||
}
|
||||
|
||||
void CoordinatesItem::paint(QPainter *painter,
|
||||
const QStyleOptionGraphicsItem *option, QWidget *widget)
|
||||
{
|
||||
Q_UNUSED(option);
|
||||
Q_UNUSED(widget);
|
||||
|
||||
if (!_c.isValid())
|
||||
return;
|
||||
|
||||
QFontMetrics fm(_font);
|
||||
painter->setFont(_font);
|
||||
painter->drawText(0, -fm.descent(), Format::coordinates(_c, _format));
|
||||
|
||||
/*
|
||||
painter->setPen(Qt::red);
|
||||
painter->drawRect(boundingRect());
|
||||
*/
|
||||
}
|
||||
|
||||
void CoordinatesItem::setCoordinates(const Coordinates &c)
|
||||
{
|
||||
_c = c;
|
||||
update();
|
||||
}
|
||||
|
||||
void CoordinatesItem::setFormat(const CoordinatesFormat &format)
|
||||
{
|
||||
prepareGeometryChange();
|
||||
|
||||
_format = format;
|
||||
updateBoundingRect();
|
||||
}
|
||||
|
||||
void CoordinatesItem::updateBoundingRect()
|
||||
{
|
||||
QFontMetrics fm(_font);
|
||||
_boundingRect = fm.tightBoundingRect(Format::coordinates(
|
||||
Coordinates(-180, -90), _format));
|
||||
_boundingRect.moveBottom(-fm.descent());
|
||||
}
|
30
src/GUI/coordinatesitem.h
Normal file
30
src/GUI/coordinatesitem.h
Normal file
@ -0,0 +1,30 @@
|
||||
#ifndef COORDINATESITEM_H
|
||||
#define COORDINATESITEM_H
|
||||
|
||||
#include <QGraphicsItem>
|
||||
#include <QFont>
|
||||
#include "common/coordinates.h"
|
||||
#include "format.h"
|
||||
|
||||
class CoordinatesItem : public QGraphicsItem
|
||||
{
|
||||
public:
|
||||
CoordinatesItem(QGraphicsItem *parent = 0);
|
||||
|
||||
QRectF boundingRect() const {return _boundingRect;}
|
||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
||||
QWidget *widget);
|
||||
|
||||
void setCoordinates(const Coordinates &c);
|
||||
void setFormat(const CoordinatesFormat &format);
|
||||
|
||||
private:
|
||||
void updateBoundingRect();
|
||||
|
||||
Coordinates _c;
|
||||
CoordinatesFormat _format;
|
||||
QRectF _boundingRect;
|
||||
QFont _font;
|
||||
};
|
||||
|
||||
#endif // COORDINATESITEM_H
|
@ -313,6 +313,11 @@ void GUI::createActions()
|
||||
_showMapAction->setEnabled(false);
|
||||
_clearMapCacheAction->setEnabled(false);
|
||||
}
|
||||
_showCoordinatesAction = new QAction(tr("Show cursor coordinates"), this);
|
||||
_showCoordinatesAction->setMenuRole(QAction::NoRole);
|
||||
_showCoordinatesAction->setCheckable(true);
|
||||
connect(_showCoordinatesAction, SIGNAL(triggered(bool)), _mapView,
|
||||
SLOT(showCoordinates(bool)));
|
||||
|
||||
// Data actions
|
||||
_showTracksAction = new QAction(tr("Show tracks"), this);
|
||||
@ -502,6 +507,8 @@ void GUI::createMenus()
|
||||
_mapMenu->addAction(_loadMapAction);
|
||||
_mapMenu->addAction(_clearMapCacheAction);
|
||||
_mapMenu->addSeparator();
|
||||
_mapMenu->addAction(_showCoordinatesAction);
|
||||
_mapMenu->addSeparator();
|
||||
_mapMenu->addAction(_showMapAction);
|
||||
|
||||
QMenu *graphMenu = menuBar()->addMenu(tr("&Graph"));
|
||||
@ -1674,6 +1681,8 @@ void GUI::writeSettings()
|
||||
settings.setValue(CURRENT_MAP_SETTING, _map->name());
|
||||
if (_showMapAction->isChecked() != SHOW_MAP_DEFAULT)
|
||||
settings.setValue(SHOW_MAP_SETTING, _showMapAction->isChecked());
|
||||
if (_showCoordinatesAction->isChecked() != SHOW_COORDINATES_DEFAULT)
|
||||
settings.setValue(SHOW_COORDINATES_SETTING, _showMapAction->isChecked());
|
||||
settings.endGroup();
|
||||
|
||||
settings.beginGroup(GRAPH_SETTINGS_GROUP);
|
||||
@ -1897,6 +1906,11 @@ void GUI::readSettings()
|
||||
int index = mapIndex(settings.value(CURRENT_MAP_SETTING).toString());
|
||||
_mapActions.at(index)->trigger();
|
||||
}
|
||||
if (settings.value(SHOW_COORDINATES_SETTING, SHOW_COORDINATES_DEFAULT)
|
||||
.toBool()) {
|
||||
_showCoordinatesAction->setChecked(true);
|
||||
_mapView->showCoordinates(true);
|
||||
}
|
||||
settings.endGroup();
|
||||
|
||||
settings.beginGroup(GRAPH_SETTINGS_GROUP);
|
||||
|
@ -193,6 +193,7 @@ private:
|
||||
QAction *_showAreasAction;
|
||||
QAction *_showRouteWaypointsAction;
|
||||
QAction *_showMarkersAction;
|
||||
QAction *_showCoordinatesAction;
|
||||
QAction *_openOptionsAction;
|
||||
QAction *_mapsEnd;
|
||||
QList<QAction*> _mapActions;
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include "waypointitem.h"
|
||||
#include "areaitem.h"
|
||||
#include "scaleitem.h"
|
||||
#include "coordinatesitem.h"
|
||||
#include "keys.h"
|
||||
#include "mapview.h"
|
||||
|
||||
@ -21,6 +22,7 @@
|
||||
#define MIN_DIGITAL_ZOOM -3
|
||||
#define MARGIN 10
|
||||
#define SCALE_OFFSET 7
|
||||
#define COORDINATES_OFFSET SCALE_OFFSET
|
||||
|
||||
|
||||
MapView::MapView(Map *map, POI *poi, QWidget *parent)
|
||||
@ -41,6 +43,10 @@ MapView::MapView(Map *map, POI *poi, QWidget *parent)
|
||||
_mapScale = new ScaleItem();
|
||||
_mapScale->setZValue(2.0);
|
||||
_scene->addItem(_mapScale);
|
||||
_coordinates = new CoordinatesItem();
|
||||
_coordinates->setZValue(2.0);
|
||||
_coordinates->setVisible(false);
|
||||
_scene->addItem(_coordinates);
|
||||
|
||||
_map = map;
|
||||
_map->load();
|
||||
@ -95,6 +101,8 @@ void MapView::centerOn(const QPointF &pos)
|
||||
QRectF vr(mapToScene(viewport()->rect()).boundingRect());
|
||||
_res = _map->resolution(vr);
|
||||
_mapScale->setResolution(_res);
|
||||
if (_coordinates->isVisible() && underMouse())
|
||||
_coordinates->setCoordinates(_map->xy2ll(pos));
|
||||
}
|
||||
|
||||
PathItem *MapView::addTrack(const Track &track)
|
||||
@ -423,6 +431,8 @@ void MapView::setCoordinatesFormat(CoordinatesFormat format)
|
||||
|
||||
_coordinatesFormat = format;
|
||||
|
||||
_coordinates->setFormat(_coordinatesFormat);
|
||||
|
||||
for (int i = 0; i < _waypoints.count(); i++)
|
||||
_waypoints.at(i)->setToolTipFormat(_units, _coordinatesFormat);
|
||||
for (int i = 0; i < _routes.count(); i++)
|
||||
@ -624,8 +634,10 @@ void MapView::clear()
|
||||
_waypoints.clear();
|
||||
|
||||
_scene->removeItem(_mapScale);
|
||||
_scene->removeItem(_coordinates);
|
||||
_scene->clear();
|
||||
_scene->addItem(_mapScale);
|
||||
_scene->addItem(_coordinates);
|
||||
|
||||
_palette.reset();
|
||||
|
||||
@ -736,6 +748,12 @@ void MapView::showPOILabels(bool show)
|
||||
updatePOIVisibility();
|
||||
}
|
||||
|
||||
void MapView::showCoordinates(bool show)
|
||||
{
|
||||
_coordinates->setVisible(show);
|
||||
setMouseTracking(show);
|
||||
}
|
||||
|
||||
void MapView::setPOIOverlap(bool overlap)
|
||||
{
|
||||
_overlapPOIs = overlap;
|
||||
@ -880,11 +898,18 @@ void MapView::resizeEvent(QResizeEvent *event)
|
||||
|
||||
void MapView::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
QPointF scenePos = mapToScene(rect().bottomRight() + QPoint(
|
||||
QPointF scaleScenePos = mapToScene(rect().bottomRight() + QPoint(
|
||||
-(SCALE_OFFSET + _mapScale->boundingRect().width()),
|
||||
-(SCALE_OFFSET + _mapScale->boundingRect().height())));
|
||||
if (_mapScale->pos() != scenePos && !_plot)
|
||||
_mapScale->setPos(scenePos);
|
||||
if (_mapScale->pos() != scaleScenePos && !_plot)
|
||||
_mapScale->setPos(scaleScenePos);
|
||||
|
||||
if (_coordinates->isVisible()) {
|
||||
QPointF coordinatesScenePos = mapToScene(rect().bottomLeft()
|
||||
+ QPoint(COORDINATES_OFFSET, -COORDINATES_OFFSET));
|
||||
if (_coordinates->pos() != coordinatesScenePos && !_plot)
|
||||
_coordinates->setPos(coordinatesScenePos);
|
||||
}
|
||||
|
||||
QGraphicsView::paintEvent(event);
|
||||
}
|
||||
@ -902,6 +927,20 @@ void MapView::scrollContentsBy(int dx, int dy)
|
||||
}
|
||||
}
|
||||
|
||||
void MapView::mouseMoveEvent(QMouseEvent *event)
|
||||
{
|
||||
if (_coordinates->isVisible())
|
||||
_coordinates->setCoordinates(_map->xy2ll(mapToScene(event->pos())));
|
||||
|
||||
QGraphicsView::mouseMoveEvent(event);
|
||||
}
|
||||
|
||||
void MapView::leaveEvent(QEvent *event)
|
||||
{
|
||||
_coordinates->setCoordinates(Coordinates());
|
||||
QGraphicsView::leaveEvent(event);
|
||||
}
|
||||
|
||||
void MapView::useOpenGL(bool use)
|
||||
{
|
||||
_opengl = use;
|
||||
|
@ -23,6 +23,7 @@ class TrackItem;
|
||||
class RouteItem;
|
||||
class WaypointItem;
|
||||
class ScaleItem;
|
||||
class CoordinatesItem;
|
||||
class PathItem;
|
||||
class GraphItem;
|
||||
class AreaItem;
|
||||
@ -75,6 +76,7 @@ public slots:
|
||||
void showWaypoints(bool show);
|
||||
void showRouteWaypoints(bool show);
|
||||
void showMarkers(bool show);
|
||||
void showCoordinates(bool show);
|
||||
void clearMapCache();
|
||||
void setCoordinatesFormat(CoordinatesFormat format);
|
||||
void setDevicePixelRatio(qreal deviceRatio, qreal mapRatio);
|
||||
@ -108,9 +110,12 @@ private:
|
||||
void resizeEvent(QResizeEvent *event);
|
||||
void paintEvent(QPaintEvent *event);
|
||||
void scrollContentsBy(int dx, int dy);
|
||||
void mouseMoveEvent(QMouseEvent *event);
|
||||
void leaveEvent(QEvent *event);
|
||||
|
||||
QGraphicsScene *_scene;
|
||||
ScaleItem *_mapScale;
|
||||
CoordinatesItem *_coordinates;
|
||||
QList<TrackItem*> _tracks;
|
||||
QList<RouteItem*> _routes;
|
||||
QList<WaypointItem*> _waypoints;
|
||||
|
@ -36,6 +36,8 @@
|
||||
#define CURRENT_MAP_SETTING "map"
|
||||
#define SHOW_MAP_SETTING "show"
|
||||
#define SHOW_MAP_DEFAULT true
|
||||
#define SHOW_COORDINATES_SETTING "coordinates"
|
||||
#define SHOW_COORDINATES_DEFAULT false
|
||||
|
||||
#define POI_SETTINGS_GROUP "POI"
|
||||
#define OVERLAP_POI_SETTING "overlap"
|
||||
|
Loading…
Reference in New Issue
Block a user