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

Made data styles usage configurable

This commit is contained in:
Martin Tůma 2022-09-25 02:15:24 +02:00
parent 36b5746456
commit a59e7a058d
24 changed files with 316 additions and 151 deletions

View File

@ -27,20 +27,13 @@ AreaItem::AreaItem(const Area &area, Map *map, GraphicsItem *parent)
{ {
_map = map; _map = map;
_digitalZoom = 0; _digitalZoom = 0;
_width = 2;
_opacity = 0.5;
_color = Qt::black;
_penStyle = Qt::SolidLine;
if (_area.style().isValid()) { _pen = QPen(strokeColor(), width());
_width = (_area.style().width() >= 0) _brush = QBrush(fillColor());
? _area.style().width() : 2;
_pen = _area.style().stroke().isValid()
? QPen(area.style().stroke(), _width) : QPen(Qt::NoPen);
_brush = _area.style().fill().isValid()
? QBrush(_area.style().fill()) : QBrush(Qt::NoBrush);
} else {
_width = 2;
_opacity = 0.5;
QBrush brush(Qt::SolidPattern);
_pen = QPen(brush, _width);
}
updatePainterPath(); updatePainterPath();
@ -98,60 +91,85 @@ void AreaItem::setMap(Map *map)
updatePainterPath(); updatePainterPath();
} }
const QColor &AreaItem::strokeColor() const
{
return (_useStyle && _area.style().isValid())
? _area.style().stroke() : _color;
}
QColor AreaItem::fillColor() const
{
if (_useStyle && _area.style().isValid())
return _area.style().fill();
else {
QColor fc(_color);
fc.setAlphaF(_opacity * _color.alphaF());
return fc;
}
}
void AreaItem::setColor(const QColor &color) void AreaItem::setColor(const QColor &color)
{ {
if (_area.style().isValid()) _color = color;
return; updateColor();
if (_pen.color() == color) }
return;
QColor bc(color); void AreaItem::updateColor()
bc.setAlphaF(_opacity * color.alphaF()); {
_pen.setColor(strokeColor());
_pen.setColor(color); _brush = QBrush(fillColor());
_brush = QBrush(bc);
update(); update();
} }
void AreaItem::setOpacity(qreal opacity) void AreaItem::setOpacity(qreal opacity)
{ {
if (_area.style().isValid())
return;
if (_opacity == opacity)
return;
_opacity = opacity; _opacity = opacity;
QColor bc(_pen.color()); updateColor();
bc.setAlphaF(_opacity * _pen.color().alphaF()); }
_brush = QBrush(bc);
update(); qreal AreaItem::width() const
{
return (_useStyle && _area.style().width() > 0)
? _area.style().width() : _width;
} }
void AreaItem::setWidth(qreal width) void AreaItem::setWidth(qreal width)
{ {
if (_area.style().width() >= 0)
return;
if (_width == width)
return;
prepareGeometryChange();
_width = width; _width = width;
_pen.setWidthF(_width * pow(2, -_digitalZoom)); updateWidth();
} }
void AreaItem::setStyle(Qt::PenStyle style) void AreaItem::updateWidth()
{ {
if (_area.style().isValid()) prepareGeometryChange();
return;
if (_pen.style() == style)
return;
_pen.setStyle(style); _pen.setWidthF(width() * pow(2, -_digitalZoom));
}
Qt::PenStyle AreaItem::penStyle() const
{
return _useStyle ? Qt::SolidLine : _penStyle;
}
void AreaItem::setPenStyle(Qt::PenStyle style)
{
_penStyle = style;
updatePenStyle();
}
void AreaItem::updatePenStyle()
{
_pen.setStyle(penStyle());
update(); update();
} }
void AreaItem::updateStyle()
{
updateColor();
updateWidth();
updatePenStyle();
}
void AreaItem::setDigitalZoom(int zoom) void AreaItem::setDigitalZoom(int zoom)
{ {
if (_digitalZoom == zoom) if (_digitalZoom == zoom)

View File

@ -22,8 +22,9 @@ public:
void setColor(const QColor &color); void setColor(const QColor &color);
void setOpacity(qreal opacity); void setOpacity(qreal opacity);
void setWidth(qreal width); void setWidth(qreal width);
void setStyle(Qt::PenStyle style); void setPenStyle(Qt::PenStyle style);
void setDigitalZoom(int zoom); void setDigitalZoom(int zoom);
void updateStyle();
ToolTip info() const; ToolTip info() const;
@ -34,16 +35,26 @@ protected:
private: private:
QPainterPath painterPath(const Polygon &polygon); QPainterPath painterPath(const Polygon &polygon);
void updatePainterPath(); void updatePainterPath();
void updateColor();
void updateWidth();
void updatePenStyle();
qreal width() const;
const QColor &strokeColor() const;
QColor fillColor() const;
Qt::PenStyle penStyle() const;
Area _area; Area _area;
Map *_map; Map *_map;
int _digitalZoom;
qreal _width; qreal _width;
QColor _color;
qreal _opacity;
Qt::PenStyle _penStyle;
int _digitalZoom;
QPen _pen; QPen _pen;
QBrush _brush; QBrush _brush;
qreal _opacity;
QPainterPath _painterPath; QPainterPath _painterPath;
}; };

View File

@ -4,6 +4,8 @@
#include "graphicsscene.h" #include "graphicsscene.h"
bool GraphicsItem::_useStyle = false;
/* Standard GraphicsScene::items() is not pixel accurate, so we use the /* Standard GraphicsScene::items() is not pixel accurate, so we use the
following function which has the same logic as used in the original following function which has the same logic as used in the original
QGraphicsScene::helpEvent() function. */ QGraphicsScene::helpEvent() function. */

View File

@ -12,6 +12,11 @@ public:
virtual ToolTip info() const = 0; virtual ToolTip info() const = 0;
int type() const {return QGraphicsItem::UserType + 1;} int type() const {return QGraphicsItem::UserType + 1;}
static void useStyle(bool use) {_useStyle = use;}
protected:
static bool _useStyle;
}; };
class GraphicsScene : public QGraphicsScene class GraphicsScene : public QGraphicsScene

View File

@ -11,9 +11,11 @@ GraphItem::GraphItem(const Graph &graph, GraphType type, int width,
Q_ASSERT(_graph.isValid()); Q_ASSERT(_graph.isValid());
_units = Metric; _units = Metric;
_pen = QPen(graph.color().isValid() ? graph.color() : color, width, style,
Qt::FlatCap);
_sx = 0; _sy = 0; _sx = 0; _sy = 0;
_color = color;
_pen = QPen(GraphItem::color(), width, style, Qt::FlatCap);
_time = _graph.hasTime(); _time = _graph.hasTime();
setZValue(2.0); setZValue(2.0);
setAcceptHoverEvents(true); setAcceptHoverEvents(true);
@ -53,14 +55,21 @@ void GraphItem::setGraphType(GraphType type)
updateBounds(); updateBounds();
} }
const QColor &GraphItem::color() const
{
return (_useStyle && _graph.color().isValid())
? _graph.color() : _color;
}
void GraphItem::setColor(const QColor &color) void GraphItem::setColor(const QColor &color)
{ {
if (_graph.color().isValid()) _color = color;
return; updateColor();
if (_pen.color() == color) }
return;
_pen.setColor(color); void GraphItem::updateColor()
{
_pen.setColor(color());
update(); update();
} }
@ -76,6 +85,13 @@ void GraphItem::setWidth(int width)
updateShape(); updateShape();
} }
void GraphItem::updateStyle()
{
updateColor();
if (_secondaryGraph)
_secondaryGraph->updateStyle();
}
const GraphSegment *GraphItem::segment(qreal x, GraphType type) const const GraphSegment *GraphItem::segment(qreal x, GraphType type) const
{ {
int low = 0; int low = 0;

View File

@ -35,6 +35,7 @@ public:
void setColor(const QColor &color); void setColor(const QColor &color);
void setWidth(int width); void setWidth(int width);
void setUnits(Units units) {_units = units;} void setUnits(Units units) {_units = units;}
void updateStyle();
GraphItem *secondaryGraph() const {return _secondaryGraph;} GraphItem *secondaryGraph() const {return _secondaryGraph;}
void setSecondaryGraph(GraphItem *graph) {_secondaryGraph = graph;} void setSecondaryGraph(GraphItem *graph) {_secondaryGraph = graph;}
@ -63,13 +64,18 @@ private:
void updatePath(); void updatePath();
void updateShape(); void updateShape();
void updateBounds(); void updateBounds();
void updateColor();
const QColor &color() const;
Graph _graph; Graph _graph;
QColor _color;
GraphType _type; GraphType _type;
qreal _sx, _sy;
QPainterPath _path; QPainterPath _path;
QPainterPath _shape; QPainterPath _shape;
QRectF _bounds; QRectF _bounds;
qreal _sx, _sy;
QPen _pen; QPen _pen;
bool _time; bool _time;

View File

@ -429,6 +429,11 @@ void GUI::createActions()
_showMarkerCoordinatesAction->setMenuRole(QAction::NoRole); _showMarkerCoordinatesAction->setMenuRole(QAction::NoRole);
_showMarkerCoordinatesAction->setCheckable(true); _showMarkerCoordinatesAction->setCheckable(true);
_showMarkerCoordinatesAction->setActionGroup(markerInfoGroup); _showMarkerCoordinatesAction->setActionGroup(markerInfoGroup);
_useStylesAction = new QAction(tr("Use styles"), this);
_useStylesAction->setMenuRole(QAction::NoRole);
_useStylesAction->setCheckable(true);
connect(_useStylesAction, &QAction::triggered, _mapView,
&MapView::useStyles);
// DEM actions // DEM actions
_downloadDEMAction = new QAction(tr("Download DEM data"), this); _downloadDEMAction = new QAction(tr("Download DEM data"), this);
@ -655,6 +660,8 @@ void GUI::createMenus()
markerMenu->addAction(_showMarkerDateAction); markerMenu->addAction(_showMarkerDateAction);
markerMenu->addAction(_showMarkerCoordinatesAction); markerMenu->addAction(_showMarkerCoordinatesAction);
dataMenu->addSeparator(); dataMenu->addSeparator();
dataMenu->addAction(_useStylesAction);
dataMenu->addSeparator();
dataMenu->addAction(_showTracksAction); dataMenu->addAction(_showTracksAction);
dataMenu->addAction(_showRoutesAction); dataMenu->addAction(_showRoutesAction);
dataMenu->addAction(_showAreasAction); dataMenu->addAction(_showAreasAction);

View File

@ -266,6 +266,7 @@ private:
QAction *_showMarkerDateAction; QAction *_showMarkerDateAction;
QAction *_showMarkerCoordinatesAction; QAction *_showMarkerCoordinatesAction;
QAction *_showTicksAction; QAction *_showTicksAction;
QAction *_useStylesAction;
QAction *_showCoordinatesAction; QAction *_showCoordinatesAction;
QAction *_openOptionsAction; QAction *_openOptionsAction;
QAction *_downloadDEMAction; QAction *_downloadDEMAction;

View File

@ -186,7 +186,7 @@ void MapItem::setWidth(qreal width)
_pen.setWidthF(_width * pow(2, -_digitalZoom)); _pen.setWidthF(_width * pow(2, -_digitalZoom));
} }
void MapItem::setStyle(Qt::PenStyle style) void MapItem::setPenStyle(Qt::PenStyle style)
{ {
if (_pen.style() == style) if (_pen.style() == style)
return; return;

View File

@ -23,7 +23,7 @@ public:
void setColor(const QColor &color); void setColor(const QColor &color);
void setOpacity(qreal opacity); void setOpacity(qreal opacity);
void setWidth(qreal width); void setWidth(qreal width);
void setStyle(Qt::PenStyle style); void setPenStyle(Qt::PenStyle style);
void setDigitalZoom(int zoom); void setDigitalZoom(int zoom);
ToolTip info() const; ToolTip info() const;

View File

@ -158,7 +158,7 @@ PathItem *MapView::addTrack(const Track &track)
_tr |= ti->path().boundingRect(); _tr |= ti->path().boundingRect();
ti->setColor(_palette.nextColor()); ti->setColor(_palette.nextColor());
ti->setWidth(_trackWidth); ti->setWidth(_trackWidth);
ti->setStyle(_trackStyle); ti->setPenStyle(_trackStyle);
ti->setVisible(_showTracks); ti->setVisible(_showTracks);
ti->setDigitalZoom(_digitalZoom); ti->setDigitalZoom(_digitalZoom);
ti->setMarkerColor(_markerColor); ti->setMarkerColor(_markerColor);
@ -185,7 +185,7 @@ PathItem *MapView::addRoute(const Route &route)
_rr |= ri->path().boundingRect(); _rr |= ri->path().boundingRect();
ri->setColor(_palette.nextColor()); ri->setColor(_palette.nextColor());
ri->setWidth(_routeWidth); ri->setWidth(_routeWidth);
ri->setStyle(_routeStyle); ri->setPenStyle(_routeStyle);
ri->setVisible(_showRoutes); ri->setVisible(_showRoutes);
ri->showWaypoints(_showRouteWaypoints); ri->showWaypoints(_showRouteWaypoints);
ri->showWaypointLabels(_showWaypointLabels); ri->showWaypointLabels(_showWaypointLabels);
@ -213,7 +213,7 @@ void MapView::addArea(const Area &area)
AreaItem *ai = new AreaItem(area, _map); AreaItem *ai = new AreaItem(area, _map);
ai->setColor(_palette.nextColor()); ai->setColor(_palette.nextColor());
ai->setWidth(_areaWidth); ai->setWidth(_areaWidth);
ai->setStyle(_areaStyle); ai->setPenStyle(_areaStyle);
ai->setOpacity(_areaOpacity); ai->setOpacity(_areaOpacity);
ai->setDigitalZoom(_digitalZoom); ai->setDigitalZoom(_digitalZoom);
ai->setVisible(_showAreas); ai->setVisible(_showAreas);
@ -254,7 +254,7 @@ MapItem *MapView::addMap(MapAction *map)
MapItem *mi = new MapItem(map, _map); MapItem *mi = new MapItem(map, _map);
mi->setColor(_palette.nextColor()); mi->setColor(_palette.nextColor());
mi->setWidth(_areaWidth); mi->setWidth(_areaWidth);
mi->setStyle(_areaStyle); mi->setPenStyle(_areaStyle);
mi->setOpacity(_areaOpacity); mi->setOpacity(_areaOpacity);
mi->setDigitalZoom(_digitalZoom); mi->setDigitalZoom(_digitalZoom);
mi->setVisible(_showAreas); mi->setVisible(_showAreas);
@ -541,7 +541,7 @@ void MapView::setUnits(Units units)
void MapView::setCoordinatesFormat(CoordinatesFormat format) void MapView::setCoordinatesFormat(CoordinatesFormat format)
{ {
WaypointItem::setCoordinatesFormat(format); WaypointItem::setCoordinatesFormat(format);
PathItem::setCoordinatesFormat(format); MarkerInfoItem::setCoordinatesFormat(format);
for (int i = 0; i < _tracks.count(); i++) for (int i = 0; i < _tracks.count(); i++)
_tracks.at(i)->updateMarkerInfo(); _tracks.at(i)->updateMarkerInfo();
@ -1034,7 +1034,7 @@ void MapView::setTrackStyle(Qt::PenStyle style)
_trackStyle = style; _trackStyle = style;
for (int i = 0; i < _tracks.count(); i++) for (int i = 0; i < _tracks.count(); i++)
_tracks.at(i)->setStyle(style); _tracks.at(i)->setPenStyle(style);
} }
void MapView::setRouteStyle(Qt::PenStyle style) void MapView::setRouteStyle(Qt::PenStyle style)
@ -1042,7 +1042,7 @@ void MapView::setRouteStyle(Qt::PenStyle style)
_routeStyle = style; _routeStyle = style;
for (int i = 0; i < _routes.count(); i++) for (int i = 0; i < _routes.count(); i++)
_routes.at(i)->setStyle(style); _routes.at(i)->setPenStyle(style);
} }
void MapView::setAreaStyle(Qt::PenStyle style) void MapView::setAreaStyle(Qt::PenStyle style)
@ -1050,7 +1050,7 @@ void MapView::setAreaStyle(Qt::PenStyle style)
_areaStyle = style; _areaStyle = style;
for (int i = 0; i < _areas.count(); i++) for (int i = 0; i < _areas.count(); i++)
_areas.at(i)->setStyle(style); _areas.at(i)->setPenStyle(style);
} }
void MapView::setAreaOpacity(int opacity) void MapView::setAreaOpacity(int opacity)
@ -1253,6 +1253,20 @@ void MapView::useAntiAliasing(bool use)
setRenderHint(QPainter::Antialiasing, use); setRenderHint(QPainter::Antialiasing, use);
} }
void MapView::useStyles(bool use)
{
GraphicsItem::useStyle(use);
for (int i = 0; i < _tracks.size(); i++)
_tracks.at(i)->updateStyle();
for (int i = 0; i < _routes.size(); i++)
_routes.at(i)->updateStyle();
for (int i = 0; i < _areas.size(); i++)
_areas.at(i)->updateStyle();
for (int i = 0; i < _waypoints.size(); i++)
_waypoints.at(i)->updateStyle();
}
void MapView::setMarkerColor(const QColor &color) void MapView::setMarkerColor(const QColor &color)
{ {
_markerColor = color; _markerColor = color;

View File

@ -129,6 +129,7 @@ public slots:
void setMarkerPosition(qreal pos); void setMarkerPosition(qreal pos);
void followPosition(bool follow); void followPosition(bool follow);
void showMotionInfo(bool show); void showMotionInfo(bool show);
void useStyles(bool use);
private slots: private slots:
void updatePOI(); void updatePOI();

View File

@ -19,6 +19,9 @@
#define GEOGRAPHICAL_MILE 1855.3248 #define GEOGRAPHICAL_MILE 1855.3248
Units PathItem::_units = Metric;
QTimeZone PathItem::_timeZone = QTimeZone::utc();
static inline bool isValid(const QPointF &p) static inline bool isValid(const QPointF &p)
{ {
return (!std::isnan(p.x()) && !std::isnan(p.y())); return (!std::isnan(p.x()) && !std::isnan(p.y()));
@ -29,23 +32,21 @@ static inline unsigned segments(qreal distance)
return ceil(distance / GEOGRAPHICAL_MILE); return ceil(distance / GEOGRAPHICAL_MILE);
} }
Units PathItem::_units = Metric; PathItem::PathItem(const Path &path, Map *map, QGraphicsItem *parent)
QTimeZone PathItem::_timeZone = QTimeZone::utc(); : GraphicsItem(parent), _path(path), _map(map), _graph(0)
PathItem::PathItem(const Path &path, const LineStyle &style, Map *map,
QGraphicsItem *parent) : GraphicsItem(parent), _path(path), _style(style),
_map(map), _graph(0)
{ {
Q_ASSERT(_path.isValid()); Q_ASSERT(_path.isValid());
_digitalZoom = 0; _digitalZoom = 0;
_width = (_style.width() >= 0) ? _style.width() : 3; _width = 3;
_pen = _style.color().isValid() _color = Qt::black;
? QPen(_style.color(), _width) : QPen(QBrush(Qt::SolidPattern), _width); _penStyle = Qt::SolidLine;
_showMarker = true; _showMarker = true;
_showTicks = false; _showTicks = false;
_markerInfoType = MarkerInfoItem::None; _markerInfoType = MarkerInfoItem::None;
_pen = QPen(color(), width());
updatePainterPath(); updatePainterPath();
updateShape(); updateShape();
updateTicks(); updateTicks();
@ -152,42 +153,65 @@ void PathItem::setMap(Map *map)
_marker->setPos(pos); _marker->setPos(pos);
} }
const QColor &PathItem::color() const
{
return (_useStyle && _path.style().color().isValid())
? _path.style().color() : _color;
}
void PathItem::setColor(const QColor &color) void PathItem::setColor(const QColor &color)
{ {
if (_style.color().isValid()) _color = color;
return; updateColor();
if (_pen.color() == color) }
return;
_pen.setColor(color); void PathItem::updateColor()
{
const QColor &c(color());
_pen.setColor(c);
for (int i = 0; i < _ticks.size(); i++) for (int i = 0; i < _ticks.size(); i++)
_ticks[i]->setColor(color); _ticks[i]->setColor(c);
update(); update();
} }
qreal PathItem::width() const
{
return (_useStyle && _path.style().width() > 0)
? _path.style().width() : _width;
}
void PathItem::setWidth(qreal width) void PathItem::setWidth(qreal width)
{ {
if (_style.color().isValid()) _width = width;
return; updateWidth();
if (_width == width) }
return;
void PathItem::updateWidth()
{
prepareGeometryChange(); prepareGeometryChange();
_width = width; _pen.setWidthF(width() * pow(2, -_digitalZoom));
_pen.setWidthF(_width * pow(2, -_digitalZoom));
updateShape(); updateShape();
} }
void PathItem::setStyle(Qt::PenStyle style) Qt::PenStyle PathItem::penStyle() const
{ {
if (_pen.style() == style) return _useStyle ? Qt::SolidLine : _penStyle;
return; }
_pen.setStyle(style); void PathItem::setPenStyle(Qt::PenStyle style)
{
_penStyle = style;
updatePenStyle();
}
void PathItem::updatePenStyle()
{
_pen.setStyle(penStyle());
update(); update();
} }
@ -199,7 +223,7 @@ void PathItem::setDigitalZoom(int zoom)
prepareGeometryChange(); prepareGeometryChange();
_digitalZoom = zoom; _digitalZoom = zoom;
_pen.setWidthF(_width * pow(2, -_digitalZoom)); _pen.setWidthF(width() * pow(2, -_digitalZoom));
_marker->setScale(pow(2, -_digitalZoom)); _marker->setScale(pow(2, -_digitalZoom));
for (int i = 0; i < _ticks.size(); i++) for (int i = 0; i < _ticks.size(); i++)
_ticks.at(i)->setDigitalZoom(zoom); _ticks.at(i)->setDigitalZoom(zoom);
@ -207,6 +231,19 @@ void PathItem::setDigitalZoom(int zoom)
updateShape(); updateShape();
} }
void PathItem::updateStyle()
{
updateColor();
updateWidth();
updatePenStyle();
for (int i = 0; i < _graphs.size(); i++) {
GraphItem *graph = _graphs.at(i);
if (graph)
graph->updateStyle();
}
}
const PathSegment *PathItem::segment(qreal x) const const PathSegment *PathItem::segment(qreal x) const
{ {
for (int i = 0; i < _path.size(); i++) for (int i = 0; i < _path.size(); i++)
@ -324,10 +361,10 @@ void PathItem::setMarkerColor(const QColor &color)
void PathItem::hover(bool hover) void PathItem::hover(bool hover)
{ {
if (hover) { if (hover) {
_pen.setWidth((_width + 1) * pow(2, -_digitalZoom)); _pen.setWidth((width() + 1) * pow(2, -_digitalZoom));
setZValue(zValue() + 1.0); setZValue(zValue() + 1.0);
} else { } else {
_pen.setWidth(_width * pow(2, -_digitalZoom)); _pen.setWidth(width() * pow(2, -_digitalZoom));
setZValue(zValue() - 1.0); setZValue(zValue() - 1.0);
} }
@ -418,6 +455,12 @@ void PathItem::addGraph(GraphItem *graph)
if (graph) { if (graph) {
connect(this, &PathItem::selected, graph, &GraphItem::hover); connect(this, &PathItem::selected, graph, &GraphItem::hover);
connect(graph, &GraphItem::selected, this, &PathItem::hover); connect(graph, &GraphItem::selected, this, &PathItem::hover);
if (graph->secondaryGraph()) {
connect(this, &PathItem::selected, graph->secondaryGraph(),
&GraphItem::hover);
connect(graph->secondaryGraph(), &GraphItem::selected, this,
&PathItem::hover);
}
} }
} }
@ -430,7 +473,7 @@ void PathItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{ {
Q_UNUSED(event); Q_UNUSED(event);
_pen.setWidthF((_width + 1) * pow(2, -_digitalZoom)); _pen.setWidthF((width() + 1) * pow(2, -_digitalZoom));
setZValue(zValue() + 1.0); setZValue(zValue() + 1.0);
update(); update();
@ -441,7 +484,7 @@ void PathItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{ {
Q_UNUSED(event); Q_UNUSED(event);
_pen.setWidthF(_width * pow(2, -_digitalZoom)); _pen.setWidthF(width() * pow(2, -_digitalZoom));
setZValue(zValue() - 1.0); setZValue(zValue() - 1.0);
update(); update();

View File

@ -1,14 +1,12 @@
#ifndef PATHITEM_H #ifndef PATHITEM_H
#define PATHITEM_H #define PATHITEM_H
#include <QGraphicsObject>
#include <QPen> #include <QPen>
#include <QTimeZone> #include <QTimeZone>
#include "data/path.h" #include "data/path.h"
#include "data/link.h"
#include "data/style.h"
#include "graphicsscene.h" #include "graphicsscene.h"
#include "markerinfoitem.h" #include "markerinfoitem.h"
#include "format.h"
#include "units.h" #include "units.h"
class Map; class Map;
@ -21,8 +19,7 @@ class PathItem : public QObject, public GraphicsItem
Q_OBJECT Q_OBJECT
public: public:
PathItem(const Path &path, const LineStyle &style, Map *map, PathItem(const Path &path, Map *map, QGraphicsItem *parent = 0);
QGraphicsItem *parent = 0);
virtual ~PathItem() {} virtual ~PathItem() {}
QPainterPath shape() const {return _shape;} QPainterPath shape() const {return _shape;}
@ -41,7 +38,7 @@ public:
void setColor(const QColor &color); void setColor(const QColor &color);
void setWidth(qreal width); void setWidth(qreal width);
void setStyle(Qt::PenStyle style); void setPenStyle(Qt::PenStyle style);
void setDigitalZoom(int zoom); void setDigitalZoom(int zoom);
void setMarkerColor(const QColor &color); void setMarkerColor(const QColor &color);
void showMarker(bool show); void showMarker(bool show);
@ -52,11 +49,10 @@ public:
void updateTicks(); void updateTicks();
void updateMarkerInfo(); void updateMarkerInfo();
void updateStyle();
static void setUnits(Units units) {_units = units;} static void setUnits(Units units) {_units = units;}
static void setTimeZone(const QTimeZone &zone) {_timeZone = zone;} static void setTimeZone(const QTimeZone &zone) {_timeZone = zone;}
static void setCoordinatesFormat(const CoordinatesFormat &format)
{MarkerInfoItem::setCoordinatesFormat(format);}
public slots: public slots:
void hover(bool hover); void hover(bool hover);
@ -69,11 +65,6 @@ protected:
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
void mousePressEvent(QGraphicsSceneMouseEvent *event); void mousePressEvent(QGraphicsSceneMouseEvent *event);
QString _name;
QString _desc;
QString _comment;
QVector<Link> _links;
static Units _units; static Units _units;
static QTimeZone _timeZone; static QTimeZone _timeZone;
@ -84,29 +75,37 @@ private:
void updateShape(); void updateShape();
void addSegment(const Coordinates &c1, const Coordinates &c2); void addSegment(const Coordinates &c1, const Coordinates &c2);
void setMarkerInfo(qreal pos); void setMarkerInfo(qreal pos);
void updateColor();
void updateWidth();
void updatePenStyle();
qreal width() const;
const QColor &color() const;
Qt::PenStyle penStyle() const;
qreal xInM() const; qreal xInM() const;
unsigned tickSize() const; unsigned tickSize() const;
Path _path; Path _path;
LineStyle _style;
Map *_map; Map *_map;
QList<GraphItem *> _graphs; QList<GraphItem *> _graphs;
GraphItem *_graph; GraphItem *_graph;
qreal _markerDistance;
int _digitalZoom;
qreal _width;
QPen _pen;
QPainterPath _shape;
QPainterPath _painterPath;
bool _showMarker;
bool _showTicks;
MarkerInfoItem::Type _markerInfoType;
MarkerItem *_marker; MarkerItem *_marker;
MarkerInfoItem *_markerInfo; MarkerInfoItem *_markerInfo;
QVector<PathTickItem*> _ticks; QVector<PathTickItem*> _ticks;
QPen _pen;
QPainterPath _shape;
QPainterPath _painterPath;
qreal _width;
QColor _color;
Qt::PenStyle _penStyle;
bool _showMarker;
bool _showTicks;
MarkerInfoItem::Type _markerInfoType;
qreal _markerDistance;
int _digitalZoom;
}; };
#endif // PATHITEM_H #endif // PATHITEM_H

View File

@ -17,8 +17,9 @@ public:
virtual void setColor(const QColor &color) = 0; virtual void setColor(const QColor &color) = 0;
virtual void setOpacity(qreal opacity) = 0; virtual void setOpacity(qreal opacity) = 0;
virtual void setWidth(qreal width) = 0; virtual void setWidth(qreal width) = 0;
virtual void setStyle(Qt::PenStyle style) = 0; virtual void setPenStyle(Qt::PenStyle style) = 0;
virtual void setDigitalZoom(int zoom) = 0; virtual void setDigitalZoom(int zoom) = 0;
virtual void updateStyle() {}
}; };
#endif // PLANEITEM_H #endif // PLANEITEM_H

View File

@ -36,7 +36,7 @@ ToolTip RouteItem::info() const
} }
RouteItem::RouteItem(const Route &route, Map *map, QGraphicsItem *parent) RouteItem::RouteItem(const Route &route, Map *map, QGraphicsItem *parent)
: PathItem(route.path(), route.style(), map, parent) : PathItem(route.path(), map, parent)
{ {
const RouteData &waypoints = route.data(); const RouteData &waypoints = route.data();

View File

@ -1,6 +1,7 @@
#ifndef ROUTEITEM_H #ifndef ROUTEITEM_H
#define ROUTEITEM_H #define ROUTEITEM_H
#include "data/link.h"
#include "pathitem.h" #include "pathitem.h"
class Map; class Map;
@ -25,6 +26,10 @@ public:
QDateTime date() const {return QDateTime();} QDateTime date() const {return QDateTime();}
private: private:
QString _name;
QString _desc;
QString _comment;
QVector<Link> _links;
QVector<WaypointItem*> _waypoints; QVector<WaypointItem*> _waypoints;
}; };

View File

@ -41,7 +41,7 @@ ToolTip TrackItem::info() const
} }
TrackItem::TrackItem(const Track &track, Map *map, QGraphicsItem *parent) TrackItem::TrackItem(const Track &track, Map *map, QGraphicsItem *parent)
: PathItem(track.path(), track.style(), map, parent) : PathItem(track.path(), map, parent)
{ {
_name = track.name(); _name = track.name();
_desc = track.description(); _desc = track.description();

View File

@ -2,6 +2,7 @@
#define TRACKITEM_H #define TRACKITEM_H
#include <QDateTime> #include <QDateTime>
#include "data/link.h"
#include "pathitem.h" #include "pathitem.h"
class Map; class Map;
@ -18,6 +19,10 @@ public:
QDateTime date() const {return _date;} QDateTime date() const {return _date;}
private: private:
QString _name;
QString _desc;
QString _comment;
QVector<Link> _links;
QDateTime _date; QDateTime _date;
qreal _time; qreal _time;
qreal _movingTime; qreal _movingTime;

View File

@ -12,7 +12,6 @@
#define FS(size) \ #define FS(size) \
((int)((qreal)size * 1.41)) ((int)((qreal)size * 1.41))
Units WaypointItem::_units = Metric; Units WaypointItem::_units = Metric;
CoordinatesFormat WaypointItem::_format = DecimalDegrees; CoordinatesFormat WaypointItem::_format = DecimalDegrees;
QTimeZone WaypointItem::_timeZone = QTimeZone::utc(); QTimeZone WaypointItem::_timeZone = QTimeZone::utc();
@ -77,16 +76,14 @@ WaypointItem::WaypointItem(const Waypoint &waypoint, Map *map,
_waypoint = waypoint; _waypoint = waypoint;
_showLabel = true; _showLabel = true;
_showIcon = false; _showIcon = false;
_size = (_waypoint.style().size() >= 0) _size = 8;
? _waypoint.style().size() : 8; _color = Qt::black;
_color = (_waypoint.style().color().isValid())
? _waypoint.style().color() : Qt::black;
_icon = (_waypoint.style().icon().isNull()) _icon = (_waypoint.style().icon().isNull())
? Waypoint::symbolIcon(_waypoint.symbol()) ? Waypoint::symbolIcon(_waypoint.symbol())
: &_waypoint.style().icon(); : &_waypoint.style().icon();
_font.setPixelSize(FS(_size)); _font.setPixelSize(FS(size()));
_font.setFamily(FONT_FAMILY); _font.setFamily(FONT_FAMILY);
updateCache(); updateCache();
@ -99,7 +96,7 @@ WaypointItem::WaypointItem(const Waypoint &waypoint, Map *map,
void WaypointItem::updateCache() void WaypointItem::updateCache()
{ {
QPainterPath p; QPainterPath p;
qreal pointSize = _font.bold() ? HS(_size) : _size; qreal pointSize = _font.bold() ? HS(size()) : size();
const QPixmap &icon = _waypoint.style().icon(); const QPixmap &icon = _waypoint.style().icon();
if (_showLabel && !_waypoint.name().isEmpty()) { if (_showLabel && !_waypoint.name().isEmpty()) {
@ -149,10 +146,10 @@ void WaypointItem::paint(QPainter *painter,
{ {
Q_UNUSED(option); Q_UNUSED(option);
Q_UNUSED(widget); Q_UNUSED(widget);
qreal pointSize = _font.bold() ? HS(_size) : _size; qreal pointSize = _font.bold() ? HS(size()) : size();
const QPixmap &icon = _waypoint.style().icon(); const QPixmap &icon = _waypoint.style().icon();
painter->setPen(_color); painter->setPen(color());
if (_showLabel && !_waypoint.name().isEmpty()) { if (_showLabel && !_waypoint.name().isEmpty()) {
painter->setFont(_font); painter->setFont(_font);
@ -168,7 +165,7 @@ void WaypointItem::paint(QPainter *painter,
+ _labelBB.height(), _waypoint.name()); + _labelBB.height(), _waypoint.name());
} }
painter->setBrush(QBrush(_color, Qt::SolidPattern)); painter->setBrush(QBrush(color(), Qt::SolidPattern));
if (_showIcon && _icon) { if (_showIcon && _icon) {
if (_font.bold()) if (_font.bold())
painter->drawPixmap(-_icon->width() * 0.625, icon.isNull() painter->drawPixmap(-_icon->width() * 0.625, icon.isNull()
@ -186,30 +183,48 @@ void WaypointItem::paint(QPainter *painter,
//painter->drawPath(_shape); //painter->drawPath(_shape);
} }
int WaypointItem::size() const
{
return (_useStyle && _waypoint.style().size() > 0)
? _waypoint.style().size() : _size;
}
void WaypointItem::setSize(int size) void WaypointItem::setSize(int size)
{ {
if (_waypoint.style().size() >= 0)
return;
if (_size == size)
return;
prepareGeometryChange();
_size = size; _size = size;
_font.setPixelSize(FS(_size)); updateSize();
}
void WaypointItem::updateSize()
{
prepareGeometryChange();
_font.setPixelSize(FS(size()));
updateCache(); updateCache();
} }
const QColor &WaypointItem::color() const
{
return (_useStyle && _waypoint.style().color().isValid())
? _waypoint.style().color() : _color;
}
void WaypointItem::setColor(const QColor &color) void WaypointItem::setColor(const QColor &color)
{ {
if (_waypoint.style().color().isValid())
return;
if (_color == color)
return;
_color = color; _color = color;
updateColor();
}
void WaypointItem::updateColor()
{
update(); update();
} }
void WaypointItem::updateStyle()
{
updateSize();
updateColor();
}
void WaypointItem::showLabel(bool show) void WaypointItem::showLabel(bool show)
{ {
if (_showLabel == show) if (_showLabel == show)

View File

@ -2,14 +2,12 @@
#define WAYPOINTITEM_H #define WAYPOINTITEM_H
#include <cmath> #include <cmath>
#include <QGraphicsItem>
#include <QFont> #include <QFont>
#include <QTimeZone> #include <QTimeZone>
#include "data/waypoint.h" #include "data/waypoint.h"
#include "map/map.h" #include "map/map.h"
#include "units.h"
#include "graphicsscene.h"
#include "format.h" #include "format.h"
#include "graphicsscene.h"
class WaypointItem : public GraphicsItem class WaypointItem : public GraphicsItem
@ -25,6 +23,7 @@ public:
void showLabel(bool show); void showLabel(bool show);
void showIcon(bool show); void showIcon(bool show);
void setDigitalZoom(int zoom) {setScale(pow(2, -zoom));} void setDigitalZoom(int zoom) {setScale(pow(2, -zoom));}
void updateStyle();
QPainterPath shape() const {return _shape;} QPainterPath shape() const {return _shape;}
QRectF boundingRect() const {return _shape.boundingRect();} QRectF boundingRect() const {return _shape.boundingRect();}
@ -45,16 +44,22 @@ protected:
private: private:
void updateCache(); void updateCache();
void updateColor();
void updateSize();
int size() const;
const QColor &color() const;
Waypoint _waypoint; Waypoint _waypoint;
QPainterPath _shape;
QColor _color; QColor _color;
int _size; int _size;
bool _showLabel; bool _showLabel;
bool _showIcon; bool _showIcon;
QFont _font; QFont _font;
QRect _labelBB; QRect _labelBB;
const QPixmap *_icon; const QPixmap *_icon;
QPainterPath _shape;
static Units _units; static Units _units;
static CoordinatesFormat _format; static CoordinatesFormat _format;

View File

@ -5,6 +5,7 @@
#include <QRectF> #include <QRectF>
#include "common/coordinates.h" #include "common/coordinates.h"
#include "common/rectc.h" #include "common/rectc.h"
#include "style.h"
class PathPoint class PathPoint
{ {
@ -34,6 +35,12 @@ class Path : public QList<PathSegment>
public: public:
bool isValid() const; bool isValid() const;
RectC boundingRect() const; RectC boundingRect() const;
const LineStyle &style() const {return _style;}
void setStyle(const LineStyle &style) {_style = style;}
private:
LineStyle _style;
}; };
#endif // PATH_H #endif // PATH_H

View File

@ -25,6 +25,8 @@ Path Route::path() const
for (int i = 0; i < _data.size(); i++) for (int i = 0; i < _data.size(); i++)
ps.append(PathPoint(_data.at(i).coordinates(), _distance.at(i))); ps.append(PathPoint(_data.at(i).coordinates(), _distance.at(i)));
ret.setStyle(_data.style());
return ret; return ret;
} }

View File

@ -607,6 +607,8 @@ Path Track::path() const
seg.distance.at(j))); seg.distance.at(j)));
} }
ret.setStyle(_data.style());
return ret; return ret;
} }