1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2025-06-27 03:29:16 +02:00

Added support for waypoint icons

This commit is contained in:
2021-10-10 08:38:38 +02:00
parent 5fdbf2e5d6
commit fb8f0c4372
184 changed files with 854 additions and 282 deletions

View File

@ -13,6 +13,7 @@
#include "map/gcs.h"
#include "map/pcs.h"
#include "data/dem.h"
#include "data/waypoint.h"
#include "gui.h"
#include "mapaction.h"
#include "app.h"
@ -57,6 +58,7 @@ App::App(int &argc, char **argv) : QApplication(argc, argv)
loadDatums();
loadPCSs();
Waypoint::loadSymbolIcons(ProgramPaths::symbolsDir());
_gui = new GUI();
}

View File

@ -269,6 +269,11 @@ void GUI::createActions()
_overlapPOIAction->setCheckable(true);
connect(_overlapPOIAction, &QAction::triggered, _mapView,
&MapView::showOverlappedPOIs);
_showPOIIconsAction = new QAction(tr("Show POI icons"), this);
_showPOIIconsAction->setMenuRole(QAction::NoRole);
_showPOIIconsAction->setCheckable(true);
connect(_showPOIIconsAction, &QAction::triggered, _mapView,
&MapView::showPOIIcons);
_showPOILabelsAction = new QAction(tr("Show POI labels"), this);
_showPOILabelsAction->setMenuRole(QAction::NoRole);
_showPOILabelsAction->setCheckable(true);
@ -343,6 +348,11 @@ void GUI::createActions()
_showAreasAction->setMenuRole(QAction::NoRole);
_showAreasAction->setCheckable(true);
connect(_showAreasAction, &QAction::triggered, this, &GUI::showAreas);
_showWaypointIconsAction = new QAction(tr("Waypoint icons"), this);
_showWaypointIconsAction->setMenuRole(QAction::NoRole);
_showWaypointIconsAction->setCheckable(true);
connect(_showWaypointIconsAction, &QAction::triggered, _mapView,
&MapView::showWaypointIcons);
_showWaypointLabelsAction = new QAction(tr("Waypoint labels"), this);
_showWaypointLabelsAction->setMenuRole(QAction::NoRole);
_showWaypointLabelsAction->setCheckable(true);
@ -572,6 +582,7 @@ void GUI::createMenus()
graphMenu->addAction(_showGraphsAction);
QMenu *dataMenu = menuBar()->addMenu(tr("&Data"));
dataMenu->addAction(_showWaypointIconsAction);
dataMenu->addAction(_showWaypointLabelsAction);
dataMenu->addAction(_showRouteWaypointsAction);
dataMenu->addAction(_showTicksAction);
@ -592,6 +603,7 @@ void GUI::createMenus()
_poiMenu->addAction(_selectAllPOIAction);
_poiMenu->addAction(_unselectAllPOIAction);
_poiMenu->addSeparator();
_poiMenu->addAction(_showPOIIconsAction);
_poiMenu->addAction(_showPOILabelsAction);
_poiMenu->addAction(_overlapPOIAction);
_poiMenu->addSeparator();
@ -2145,6 +2157,9 @@ void GUI::writeSettings()
if (_showPOILabelsAction->isChecked() != SHOW_POI_LABELS_DEFAULT)
settings.setValue(SHOW_POI_LABELS_SETTING,
_showPOILabelsAction->isChecked());
if (_showPOIIconsAction->isChecked() != SHOW_POI_ICONS_DEFAULT)
settings.setValue(SHOW_POI_ICONS_SETTING,
_showPOIIconsAction->isChecked());
int j = 0;
QList<QAction*> poiActions(_poisActionGroup->actions());
@ -2171,6 +2186,9 @@ void GUI::writeSettings()
_showWaypointsAction->isChecked());
if (_showAreasAction->isChecked() != SHOW_AREAS_DEFAULT)
settings.setValue(SHOW_AREAS_SETTING, _showAreasAction->isChecked());
if (_showWaypointIconsAction->isChecked() != SHOW_WAYPOINT_ICONS_DEFAULT)
settings.setValue(SHOW_WAYPOINT_ICONS_SETTING,
_showWaypointIconsAction->isChecked());
if (_showWaypointLabelsAction->isChecked() != SHOW_WAYPOINT_LABELS_DEFAULT)
settings.setValue(SHOW_WAYPOINT_LABELS_SETTING,
_showWaypointLabelsAction->isChecked());
@ -2433,6 +2451,9 @@ void GUI::readSettings(QString &activeMap, QStringList &disabledPOIs)
_mapView->showOverlappedPOIs(false);
else
_overlapPOIAction->setChecked(true);
if (settings.value(SHOW_POI_ICONS_SETTING, SHOW_POI_ICONS_DEFAULT)
.toBool())
_showPOIIconsAction->trigger();
if (!settings.value(SHOW_POI_LABELS_SETTING, SHOW_POI_LABELS_DEFAULT)
.toBool())
_mapView->showPOILabels(false);
@ -2473,6 +2494,9 @@ void GUI::readSettings(QString &activeMap, QStringList &disabledPOIs)
_mapView->showAreas(false);
else
_showAreasAction->setChecked(true);
if (settings.value(SHOW_WAYPOINT_ICONS_SETTING,
SHOW_WAYPOINT_ICONS_DEFAULT).toBool())
_showWaypointIconsAction->trigger();
if (!settings.value(SHOW_WAYPOINT_LABELS_SETTING,
SHOW_WAYPOINT_LABELS_DEFAULT).toBool())
_mapView->showWaypointLabels(false);

View File

@ -196,6 +196,7 @@ private:
QAction *_showPOIAction;
QAction *_overlapPOIAction;
QAction *_showPOILabelsAction;
QAction *_showPOIIconsAction;
QAction *_showMapAction;
QAction *_fullscreenAction;
QAction *_loadMapAction;
@ -225,6 +226,7 @@ private:
QAction *_showRoutesAction;
QAction *_showWaypointsAction;
QAction *_showWaypointLabelsAction;
QAction *_showWaypointIconsAction;
QAction *_showAreasAction;
QAction *_showRouteWaypointsAction;
QAction *_hideMarkersAction;

View File

@ -89,8 +89,10 @@ MapView::MapView(Map *map, POI *poi, QWidget *parent)
_showAreas = true;
_showWaypoints = true;
_showWaypointLabels = true;
_showWaypointIcons = false;
_showPOI = true;
_showPOILabels = true;
_showPOIIcons = false;
_overlapPOIs = true;
_showRouteWaypoints = true;
_showMarkers = true;
@ -169,6 +171,7 @@ PathItem *MapView::addRoute(const Route &route)
ri->setVisible(_showRoutes);
ri->showWaypoints(_showRouteWaypoints);
ri->showWaypointLabels(_showWaypointLabels);
ri->showWaypointIcons(_showWaypointLabels);
ri->setDigitalZoom(_digitalZoom);
ri->setMarkerColor(_markerColor);
ri->showMarker(_showMarkers);
@ -217,6 +220,7 @@ void MapView::addWaypoints(const QVector<Waypoint> &waypoints)
wi->setSize(_waypointSize);
wi->setColor(_waypointColor);
wi->showLabel(_showWaypointLabels);
wi->showIcon(_showWaypointIcons);
wi->setVisible(_showWaypoints);
wi->setDigitalZoom(_digitalZoom);
_scene->addItem(wi);
@ -478,6 +482,7 @@ void MapView::addPOI(const QList<Waypoint> &waypoints)
pi->setSize(_poiSize);
pi->setColor(_poiColor);
pi->showLabel(_showPOILabels);
pi->showIcon(_showPOIIcons);
pi->setVisible(_showPOI);
pi->setDigitalZoom(_digitalZoom);
_scene->addItem(pi);
@ -492,9 +497,9 @@ void MapView::setUnits(Units units)
PathItem::setUnits(units);
for (int i = 0; i < _tracks.count(); i++)
_tracks[i]->updateTicks();
_tracks.at(i)->updateTicks();
for (int i = 0; i < _routes.count(); i++)
_routes[i]->updateTicks();
_routes.at(i)->updateTicks();
_mapScale->setUnits(units);
}
@ -505,9 +510,9 @@ void MapView::setCoordinatesFormat(CoordinatesFormat format)
PathItem::setCoordinatesFormat(format);
for (int i = 0; i < _tracks.count(); i++)
_tracks[i]->updateMarkerInfo();
_tracks.at(i)->updateMarkerInfo();
for (int i = 0; i < _routes.count(); i++)
_routes[i]->updateMarkerInfo();
_routes.at(i)->updateMarkerInfo();
_coordinates->setFormat(format);
}
@ -518,9 +523,9 @@ void MapView::setTimeZone(const QTimeZone &zone)
PathItem::setTimeZone(zone);
for (int i = 0; i < _tracks.count(); i++)
_tracks[i]->updateMarkerInfo();
_tracks.at(i)->updateMarkerInfo();
for (int i = 0; i < _routes.count(); i++)
_routes[i]->updateMarkerInfo();
_routes.at(i)->updateMarkerInfo();
}
void MapView::clearMapCache()
@ -819,6 +824,16 @@ void MapView::showWaypointLabels(bool show)
_routes.at(i)->showWaypointLabels(show);
}
void MapView::showWaypointIcons(bool show)
{
_showWaypointIcons = show;
for (int i = 0; i < _waypoints.size(); i++)
_waypoints.at(i)->showIcon(show);
for (int i = 0; i < _routes.size(); i++)
_routes.at(i)->showWaypointIcons(show);
}
void MapView::showRouteWaypoints(bool show)
{
_showRouteWaypoints = show;
@ -884,6 +899,17 @@ void MapView::showPOILabels(bool show)
updatePOIVisibility();
}
void MapView::showPOIIcons(bool show)
{
_showPOIIcons = show;
for (POIHash::const_iterator it = _pois.constBegin();
it != _pois.constEnd(); it++)
it.value()->showIcon(show);
updatePOIVisibility();
}
void MapView::showCoordinates(bool show)
{
_coordinates->setVisible(show);

View File

@ -95,12 +95,14 @@ public slots:
void showMap(bool show);
void showPOI(bool show);
void showPOILabels(bool show);
void showPOIIcons(bool show);
void showCoordinates(bool show);
void showTicks(bool show);
void showMarkers(bool show);
void showMarkerInfo(MarkerInfoItem::Type type);
void showOverlappedPOIs(bool show);
void showWaypointLabels(bool show);
void showWaypointIcons(bool show);
void showTracks(bool show);
void showRoutes(bool show);
void showAreas(bool show);
@ -165,7 +167,7 @@ private:
bool _showMap, _showTracks, _showRoutes, _showAreas, _showWaypoints,
_showWaypointLabels, _showPOI, _showPOILabels, _showRouteWaypoints,
_showMarkers, _showPathTicks;
_showMarkers, _showPathTicks, _showPOIIcons, _showWaypointIcons;
MarkerInfoItem::Type _markerInfoType;
bool _overlapPOIs;
int _trackWidth, _routeWidth, _areaWidth;

View File

@ -53,7 +53,7 @@ RouteItem::RouteItem(const Route &route, Map *map, QGraphicsItem *parent)
void RouteItem::setMap(Map *map)
{
for (int i = 0; i < _waypoints.count(); i++)
_waypoints[i]->setMap(map);
_waypoints.at(i)->setMap(map);
PathItem::setMap(map);
}
@ -61,19 +61,25 @@ void RouteItem::setMap(Map *map)
void RouteItem::showWaypoints(bool show)
{
for (int i = 0; i < _waypoints.count(); i++)
_waypoints[i]->setVisible(show);
_waypoints.at(i)->setVisible(show);
}
void RouteItem::showWaypointLabels(bool show)
{
for (int i = 0; i < _waypoints.count(); i++)
_waypoints[i]->showLabel(show);
_waypoints.at(i)->showLabel(show);
}
void RouteItem::showWaypointIcons(bool show)
{
for (int i = 0; i < _waypoints.count(); i++)
_waypoints.at(i)->showIcon(show);
}
void RouteItem::setDigitalZoom(int zoom)
{
for (int i = 0; i < _waypoints.count(); i++)
_waypoints[i]->setDigitalZoom(zoom);
_waypoints.at(i)->setDigitalZoom(zoom);
PathItem::setDigitalZoom(zoom);
}

View File

@ -20,6 +20,7 @@ public:
void showWaypoints(bool show);
void showWaypointLabels(bool show);
void showWaypointIcons(bool show);
ToolTip info() const;
QDateTime date() const {return QDateTime();}

View File

@ -40,6 +40,9 @@
#define POI_SETTINGS_GROUP "POI"
#define OVERLAP_POI_SETTING "overlap"
#define OVERLAP_POI_DEFAULT false
#define SHOW_POI_ICONS_SETTING "icons"
#define SHOW_POI_ICONS_DEFAULT true
#define SHOW_POI_LABELS_SETTING "labels"
#define SHOW_POI_LABELS_DEFAULT true
#define SHOW_POI_SETTING "show"
@ -58,6 +61,8 @@
#define SHOW_AREAS_DEFAULT true
#define SHOW_ROUTE_WAYPOINTS_SETTING "routeWaypoints"
#define SHOW_ROUTE_WAYPOINTS_DEFAULT true
#define SHOW_WAYPOINT_ICONS_SETTING "waypointIcons"
#define SHOW_WAYPOINT_ICONS_DEFAULT false
#define SHOW_WAYPOINT_LABELS_SETTING "waypointLabels"
#define SHOW_WAYPOINT_LABELS_DEFAULT true
#define SHOW_MARKERS_SETTING "positionMarkers"

View File

@ -44,6 +44,8 @@ ToolTip WaypointItem::info() const
&& _waypoint.comment() != _waypoint.description())
tt.insert(qApp->translate("WaypointItem", "Comment"),
_waypoint.comment());
if (!_waypoint.symbol().isEmpty())
tt.insert(qApp->translate("WaypointItem", "Symbol"), _waypoint.symbol());
if (!_waypoint.address().isEmpty()) {
QString addr(_waypoint.address());
addr.replace('\n', "<br/>");
@ -63,6 +65,7 @@ ToolTip WaypointItem::info() const
}
tt.insert(qApp->translate("WaypointItem", "Links"), links);
}
tt.setImages(_waypoint.images());
return tt;
@ -73,9 +76,14 @@ WaypointItem::WaypointItem(const Waypoint &waypoint, Map *map,
{
_waypoint = waypoint;
_showLabel = true;
_showIcon = false;
_size = 8;
_color = Qt::black;
_icon = (_waypoint.icon().isNull())
? Waypoint::symbolIcon(_waypoint.symbol())
: &_waypoint.icon();
_font.setPixelSize(FS(_size));
_font.setFamily(FONT_FAMILY);
@ -95,11 +103,22 @@ void WaypointItem::updateCache()
QFontMetrics fm(_font);
_labelBB = fm.tightBoundingRect(_waypoint.name());
p.addRect(-pointSize/2, -pointSize/2, pointSize, pointSize);
p.addRect(pointSize/2, pointSize/2, _labelBB.width(), _labelBB.height()
+ fm.descent());
} else
p.addRect(-pointSize/2, -pointSize/2, pointSize, pointSize);
if (_showIcon && _icon) {
p.addRect(-_icon->width()/2.0, -_icon->height(), _icon->width(),
_icon->height());
p.addRect(0, 0, _labelBB.width(), _labelBB.height() + fm.descent());
} else {
p.addRect(-pointSize/2, -pointSize/2, pointSize, pointSize);
p.addRect(pointSize/2, pointSize/2, _labelBB.width(),
_labelBB.height() + fm.descent());
}
} else {
if (_showIcon && _icon)
p.addRect(-_icon->width()/2, -_icon->height(), _icon->width(),
_icon->height());
else
p.addRect(-pointSize/2, -pointSize/2, pointSize, pointSize);
}
_shape = p;
}
@ -115,12 +134,19 @@ void WaypointItem::paint(QPainter *painter,
if (_showLabel) {
painter->setFont(_font);
painter->drawText(pointSize/2 - qMax(_labelBB.x(), 0), pointSize/2
+ _labelBB.height(), _waypoint.name());
if (_showIcon && _icon)
painter->drawText(-qMax(_labelBB.x(), 0), _labelBB.height(),
_waypoint.name());
else
painter->drawText(pointSize/2 - qMax(_labelBB.x(), 0), pointSize/2
+ _labelBB.height(), _waypoint.name());
}
painter->setBrush(QBrush(_color, Qt::SolidPattern));
painter->drawEllipse(-pointSize/2, -pointSize/2, pointSize, pointSize);
if (_showIcon && _icon)
painter->drawPixmap(-_icon->width()/2.0, -_icon->height(), *_icon);
else
painter->drawEllipse(-pointSize/2, -pointSize/2, pointSize, pointSize);
/*
painter->setPen(Qt::red);
@ -159,6 +185,16 @@ void WaypointItem::showLabel(bool show)
updateCache();
}
void WaypointItem::showIcon(bool show)
{
if (_showIcon == show)
return;
prepareGeometryChange();
_showIcon = show;
updateCache();
}
void WaypointItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{
Q_UNUSED(event);

View File

@ -23,6 +23,7 @@ public:
void setSize(int size);
void setColor(const QColor &color);
void showLabel(bool show);
void showIcon(bool show);
void setDigitalZoom(int zoom) {setScale(pow(2, -zoom));}
QPainterPath shape() const {return _shape;}
@ -50,8 +51,10 @@ private:
QColor _color;
int _size;
bool _showLabel;
bool _showIcon;
QFont _font;
QRect _labelBB;
const QPixmap *_icon;
static Units _units;
static CoordinatesFormat _format;