diff --git a/src/GUI/areaitem.cpp b/src/GUI/areaitem.cpp index 32076e44..47d8681f 100644 --- a/src/GUI/areaitem.cpp +++ b/src/GUI/areaitem.cpp @@ -27,20 +27,13 @@ AreaItem::AreaItem(const Area &area, Map *map, GraphicsItem *parent) { _map = map; _digitalZoom = 0; + _width = 2; + _opacity = 0.5; + _color = Qt::black; + _penStyle = Qt::SolidLine; - if (_area.style().isValid()) { - _width = (_area.style().width() >= 0) - ? _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); - } + _pen = QPen(strokeColor(), width()); + _brush = QBrush(fillColor()); updatePainterPath(); @@ -98,60 +91,85 @@ void AreaItem::setMap(Map *map) 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) { - if (_area.style().isValid()) - return; - if (_pen.color() == color) - return; + _color = color; + updateColor(); +} - QColor bc(color); - bc.setAlphaF(_opacity * color.alphaF()); - - _pen.setColor(color); - _brush = QBrush(bc); +void AreaItem::updateColor() +{ + _pen.setColor(strokeColor()); + _brush = QBrush(fillColor()); update(); } void AreaItem::setOpacity(qreal opacity) { - if (_area.style().isValid()) - return; - if (_opacity == opacity) - return; - _opacity = opacity; - QColor bc(_pen.color()); - bc.setAlphaF(_opacity * _pen.color().alphaF()); - _brush = QBrush(bc); + updateColor(); +} - update(); +qreal AreaItem::width() const +{ + return (_useStyle && _area.style().width() > 0) + ? _area.style().width() : _width; } void AreaItem::setWidth(qreal width) { - if (_area.style().width() >= 0) - return; - if (_width == width) - return; - - prepareGeometryChange(); - _width = width; - _pen.setWidthF(_width * pow(2, -_digitalZoom)); + updateWidth(); } -void AreaItem::setStyle(Qt::PenStyle style) +void AreaItem::updateWidth() { - if (_area.style().isValid()) - return; - if (_pen.style() == style) - return; + prepareGeometryChange(); - _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(); } +void AreaItem::updateStyle() +{ + updateColor(); + updateWidth(); + updatePenStyle(); +} + void AreaItem::setDigitalZoom(int zoom) { if (_digitalZoom == zoom) diff --git a/src/GUI/areaitem.h b/src/GUI/areaitem.h index bf351ec6..d989fb72 100644 --- a/src/GUI/areaitem.h +++ b/src/GUI/areaitem.h @@ -22,8 +22,9 @@ public: void setColor(const QColor &color); void setOpacity(qreal opacity); void setWidth(qreal width); - void setStyle(Qt::PenStyle style); + void setPenStyle(Qt::PenStyle style); void setDigitalZoom(int zoom); + void updateStyle(); ToolTip info() const; @@ -34,16 +35,26 @@ protected: private: QPainterPath painterPath(const Polygon &polygon); void updatePainterPath(); + void updateColor(); + void updateWidth(); + void updatePenStyle(); + qreal width() const; + const QColor &strokeColor() const; + QColor fillColor() const; + Qt::PenStyle penStyle() const; Area _area; + Map *_map; - int _digitalZoom; qreal _width; + QColor _color; + qreal _opacity; + Qt::PenStyle _penStyle; + int _digitalZoom; + QPen _pen; QBrush _brush; - qreal _opacity; - QPainterPath _painterPath; }; diff --git a/src/GUI/graphicsscene.cpp b/src/GUI/graphicsscene.cpp index a51a5754..bee469b6 100644 --- a/src/GUI/graphicsscene.cpp +++ b/src/GUI/graphicsscene.cpp @@ -4,6 +4,8 @@ #include "graphicsscene.h" +bool GraphicsItem::_useStyle = false; + /* Standard GraphicsScene::items() is not pixel accurate, so we use the following function which has the same logic as used in the original QGraphicsScene::helpEvent() function. */ diff --git a/src/GUI/graphicsscene.h b/src/GUI/graphicsscene.h index f5b32d67..69d434a9 100644 --- a/src/GUI/graphicsscene.h +++ b/src/GUI/graphicsscene.h @@ -12,6 +12,11 @@ public: virtual ToolTip info() const = 0; int type() const {return QGraphicsItem::UserType + 1;} + + static void useStyle(bool use) {_useStyle = use;} + +protected: + static bool _useStyle; }; class GraphicsScene : public QGraphicsScene diff --git a/src/GUI/graphitem.cpp b/src/GUI/graphitem.cpp index a641981b..13c372fa 100644 --- a/src/GUI/graphitem.cpp +++ b/src/GUI/graphitem.cpp @@ -11,9 +11,11 @@ GraphItem::GraphItem(const Graph &graph, GraphType type, int width, Q_ASSERT(_graph.isValid()); _units = Metric; - _pen = QPen(graph.color().isValid() ? graph.color() : color, width, style, - Qt::FlatCap); _sx = 0; _sy = 0; + _color = color; + + _pen = QPen(GraphItem::color(), width, style, Qt::FlatCap); + _time = _graph.hasTime(); setZValue(2.0); setAcceptHoverEvents(true); @@ -53,14 +55,21 @@ void GraphItem::setGraphType(GraphType type) updateBounds(); } +const QColor &GraphItem::color() const +{ + return (_useStyle && _graph.color().isValid()) + ? _graph.color() : _color; +} + void GraphItem::setColor(const QColor &color) { - if (_graph.color().isValid()) - return; - if (_pen.color() == color) - return; + _color = color; + updateColor(); +} - _pen.setColor(color); +void GraphItem::updateColor() +{ + _pen.setColor(color()); update(); } @@ -76,6 +85,13 @@ void GraphItem::setWidth(int width) updateShape(); } +void GraphItem::updateStyle() +{ + updateColor(); + if (_secondaryGraph) + _secondaryGraph->updateStyle(); +} + const GraphSegment *GraphItem::segment(qreal x, GraphType type) const { int low = 0; diff --git a/src/GUI/graphitem.h b/src/GUI/graphitem.h index 2f602ea7..cfa6bdd9 100644 --- a/src/GUI/graphitem.h +++ b/src/GUI/graphitem.h @@ -35,6 +35,7 @@ public: void setColor(const QColor &color); void setWidth(int width); void setUnits(Units units) {_units = units;} + void updateStyle(); GraphItem *secondaryGraph() const {return _secondaryGraph;} void setSecondaryGraph(GraphItem *graph) {_secondaryGraph = graph;} @@ -63,13 +64,18 @@ private: void updatePath(); void updateShape(); void updateBounds(); + void updateColor(); + const QColor &color() const; Graph _graph; + + QColor _color; GraphType _type; + qreal _sx, _sy; + QPainterPath _path; QPainterPath _shape; QRectF _bounds; - qreal _sx, _sy; QPen _pen; bool _time; diff --git a/src/GUI/gui.cpp b/src/GUI/gui.cpp index f8ce63cc..91031b03 100644 --- a/src/GUI/gui.cpp +++ b/src/GUI/gui.cpp @@ -429,6 +429,11 @@ void GUI::createActions() _showMarkerCoordinatesAction->setMenuRole(QAction::NoRole); _showMarkerCoordinatesAction->setCheckable(true); _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 _downloadDEMAction = new QAction(tr("Download DEM data"), this); @@ -655,6 +660,8 @@ void GUI::createMenus() markerMenu->addAction(_showMarkerDateAction); markerMenu->addAction(_showMarkerCoordinatesAction); dataMenu->addSeparator(); + dataMenu->addAction(_useStylesAction); + dataMenu->addSeparator(); dataMenu->addAction(_showTracksAction); dataMenu->addAction(_showRoutesAction); dataMenu->addAction(_showAreasAction); diff --git a/src/GUI/gui.h b/src/GUI/gui.h index a41a32aa..b097531d 100644 --- a/src/GUI/gui.h +++ b/src/GUI/gui.h @@ -266,6 +266,7 @@ private: QAction *_showMarkerDateAction; QAction *_showMarkerCoordinatesAction; QAction *_showTicksAction; + QAction *_useStylesAction; QAction *_showCoordinatesAction; QAction *_openOptionsAction; QAction *_downloadDEMAction; diff --git a/src/GUI/mapitem.cpp b/src/GUI/mapitem.cpp index 996c7f8d..e0005819 100644 --- a/src/GUI/mapitem.cpp +++ b/src/GUI/mapitem.cpp @@ -186,7 +186,7 @@ void MapItem::setWidth(qreal width) _pen.setWidthF(_width * pow(2, -_digitalZoom)); } -void MapItem::setStyle(Qt::PenStyle style) +void MapItem::setPenStyle(Qt::PenStyle style) { if (_pen.style() == style) return; diff --git a/src/GUI/mapitem.h b/src/GUI/mapitem.h index 8186e0a0..0ae93a45 100644 --- a/src/GUI/mapitem.h +++ b/src/GUI/mapitem.h @@ -23,7 +23,7 @@ public: void setColor(const QColor &color); void setOpacity(qreal opacity); void setWidth(qreal width); - void setStyle(Qt::PenStyle style); + void setPenStyle(Qt::PenStyle style); void setDigitalZoom(int zoom); ToolTip info() const; diff --git a/src/GUI/mapview.cpp b/src/GUI/mapview.cpp index d12ddaf5..4ddc2f1f 100644 --- a/src/GUI/mapview.cpp +++ b/src/GUI/mapview.cpp @@ -158,7 +158,7 @@ PathItem *MapView::addTrack(const Track &track) _tr |= ti->path().boundingRect(); ti->setColor(_palette.nextColor()); ti->setWidth(_trackWidth); - ti->setStyle(_trackStyle); + ti->setPenStyle(_trackStyle); ti->setVisible(_showTracks); ti->setDigitalZoom(_digitalZoom); ti->setMarkerColor(_markerColor); @@ -185,7 +185,7 @@ PathItem *MapView::addRoute(const Route &route) _rr |= ri->path().boundingRect(); ri->setColor(_palette.nextColor()); ri->setWidth(_routeWidth); - ri->setStyle(_routeStyle); + ri->setPenStyle(_routeStyle); ri->setVisible(_showRoutes); ri->showWaypoints(_showRouteWaypoints); ri->showWaypointLabels(_showWaypointLabels); @@ -213,7 +213,7 @@ void MapView::addArea(const Area &area) AreaItem *ai = new AreaItem(area, _map); ai->setColor(_palette.nextColor()); ai->setWidth(_areaWidth); - ai->setStyle(_areaStyle); + ai->setPenStyle(_areaStyle); ai->setOpacity(_areaOpacity); ai->setDigitalZoom(_digitalZoom); ai->setVisible(_showAreas); @@ -254,7 +254,7 @@ MapItem *MapView::addMap(MapAction *map) MapItem *mi = new MapItem(map, _map); mi->setColor(_palette.nextColor()); mi->setWidth(_areaWidth); - mi->setStyle(_areaStyle); + mi->setPenStyle(_areaStyle); mi->setOpacity(_areaOpacity); mi->setDigitalZoom(_digitalZoom); mi->setVisible(_showAreas); @@ -541,7 +541,7 @@ void MapView::setUnits(Units units) void MapView::setCoordinatesFormat(CoordinatesFormat format) { WaypointItem::setCoordinatesFormat(format); - PathItem::setCoordinatesFormat(format); + MarkerInfoItem::setCoordinatesFormat(format); for (int i = 0; i < _tracks.count(); i++) _tracks.at(i)->updateMarkerInfo(); @@ -1034,7 +1034,7 @@ void MapView::setTrackStyle(Qt::PenStyle style) _trackStyle = style; for (int i = 0; i < _tracks.count(); i++) - _tracks.at(i)->setStyle(style); + _tracks.at(i)->setPenStyle(style); } void MapView::setRouteStyle(Qt::PenStyle style) @@ -1042,7 +1042,7 @@ void MapView::setRouteStyle(Qt::PenStyle style) _routeStyle = style; for (int i = 0; i < _routes.count(); i++) - _routes.at(i)->setStyle(style); + _routes.at(i)->setPenStyle(style); } void MapView::setAreaStyle(Qt::PenStyle style) @@ -1050,7 +1050,7 @@ void MapView::setAreaStyle(Qt::PenStyle style) _areaStyle = style; for (int i = 0; i < _areas.count(); i++) - _areas.at(i)->setStyle(style); + _areas.at(i)->setPenStyle(style); } void MapView::setAreaOpacity(int opacity) @@ -1253,6 +1253,20 @@ void MapView::useAntiAliasing(bool 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) { _markerColor = color; diff --git a/src/GUI/mapview.h b/src/GUI/mapview.h index a051e896..d3bedbd4 100644 --- a/src/GUI/mapview.h +++ b/src/GUI/mapview.h @@ -129,6 +129,7 @@ public slots: void setMarkerPosition(qreal pos); void followPosition(bool follow); void showMotionInfo(bool show); + void useStyles(bool use); private slots: void updatePOI(); diff --git a/src/GUI/pathitem.cpp b/src/GUI/pathitem.cpp index 47877922..3ef21de3 100644 --- a/src/GUI/pathitem.cpp +++ b/src/GUI/pathitem.cpp @@ -19,6 +19,9 @@ #define GEOGRAPHICAL_MILE 1855.3248 +Units PathItem::_units = Metric; +QTimeZone PathItem::_timeZone = QTimeZone::utc(); + static inline bool isValid(const QPointF &p) { return (!std::isnan(p.x()) && !std::isnan(p.y())); @@ -29,23 +32,21 @@ static inline unsigned segments(qreal distance) return ceil(distance / GEOGRAPHICAL_MILE); } -Units PathItem::_units = Metric; -QTimeZone PathItem::_timeZone = QTimeZone::utc(); - -PathItem::PathItem(const Path &path, const LineStyle &style, Map *map, - QGraphicsItem *parent) : GraphicsItem(parent), _path(path), _style(style), - _map(map), _graph(0) +PathItem::PathItem(const Path &path, Map *map, QGraphicsItem *parent) + : GraphicsItem(parent), _path(path), _map(map), _graph(0) { Q_ASSERT(_path.isValid()); _digitalZoom = 0; - _width = (_style.width() >= 0) ? _style.width() : 3; - _pen = _style.color().isValid() - ? QPen(_style.color(), _width) : QPen(QBrush(Qt::SolidPattern), _width); + _width = 3; + _color = Qt::black; + _penStyle = Qt::SolidLine; _showMarker = true; _showTicks = false; _markerInfoType = MarkerInfoItem::None; + _pen = QPen(color(), width()); + updatePainterPath(); updateShape(); updateTicks(); @@ -152,42 +153,65 @@ void PathItem::setMap(Map *map) _marker->setPos(pos); } +const QColor &PathItem::color() const +{ + return (_useStyle && _path.style().color().isValid()) + ? _path.style().color() : _color; +} + void PathItem::setColor(const QColor &color) { - if (_style.color().isValid()) - return; - if (_pen.color() == color) - return; + _color = color; + updateColor(); +} - _pen.setColor(color); +void PathItem::updateColor() +{ + const QColor &c(color()); + + _pen.setColor(c); for (int i = 0; i < _ticks.size(); i++) - _ticks[i]->setColor(color); + _ticks[i]->setColor(c); update(); } +qreal PathItem::width() const +{ + return (_useStyle && _path.style().width() > 0) + ? _path.style().width() : _width; +} + void PathItem::setWidth(qreal width) { - if (_style.color().isValid()) - return; - if (_width == width) - return; + _width = width; + updateWidth(); +} +void PathItem::updateWidth() +{ prepareGeometryChange(); - _width = width; - _pen.setWidthF(_width * pow(2, -_digitalZoom)); + _pen.setWidthF(width() * pow(2, -_digitalZoom)); updateShape(); } -void PathItem::setStyle(Qt::PenStyle style) +Qt::PenStyle PathItem::penStyle() const { - if (_pen.style() == style) - return; + return _useStyle ? Qt::SolidLine : _penStyle; +} - _pen.setStyle(style); +void PathItem::setPenStyle(Qt::PenStyle style) +{ + _penStyle = style; + updatePenStyle(); +} + +void PathItem::updatePenStyle() +{ + _pen.setStyle(penStyle()); update(); } @@ -199,7 +223,7 @@ void PathItem::setDigitalZoom(int zoom) prepareGeometryChange(); _digitalZoom = zoom; - _pen.setWidthF(_width * pow(2, -_digitalZoom)); + _pen.setWidthF(width() * pow(2, -_digitalZoom)); _marker->setScale(pow(2, -_digitalZoom)); for (int i = 0; i < _ticks.size(); i++) _ticks.at(i)->setDigitalZoom(zoom); @@ -207,6 +231,19 @@ void PathItem::setDigitalZoom(int zoom) 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 { for (int i = 0; i < _path.size(); i++) @@ -324,10 +361,10 @@ void PathItem::setMarkerColor(const QColor &color) void PathItem::hover(bool hover) { if (hover) { - _pen.setWidth((_width + 1) * pow(2, -_digitalZoom)); + _pen.setWidth((width() + 1) * pow(2, -_digitalZoom)); setZValue(zValue() + 1.0); } else { - _pen.setWidth(_width * pow(2, -_digitalZoom)); + _pen.setWidth(width() * pow(2, -_digitalZoom)); setZValue(zValue() - 1.0); } @@ -418,6 +455,12 @@ void PathItem::addGraph(GraphItem *graph) if (graph) { connect(this, &PathItem::selected, graph, &GraphItem::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); - _pen.setWidthF((_width + 1) * pow(2, -_digitalZoom)); + _pen.setWidthF((width() + 1) * pow(2, -_digitalZoom)); setZValue(zValue() + 1.0); update(); @@ -441,7 +484,7 @@ void PathItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) { Q_UNUSED(event); - _pen.setWidthF(_width * pow(2, -_digitalZoom)); + _pen.setWidthF(width() * pow(2, -_digitalZoom)); setZValue(zValue() - 1.0); update(); diff --git a/src/GUI/pathitem.h b/src/GUI/pathitem.h index cc1dbab6..b54a1839 100644 --- a/src/GUI/pathitem.h +++ b/src/GUI/pathitem.h @@ -1,14 +1,12 @@ #ifndef PATHITEM_H #define PATHITEM_H -#include #include #include #include "data/path.h" -#include "data/link.h" -#include "data/style.h" #include "graphicsscene.h" #include "markerinfoitem.h" +#include "format.h" #include "units.h" class Map; @@ -21,8 +19,7 @@ class PathItem : public QObject, public GraphicsItem Q_OBJECT public: - PathItem(const Path &path, const LineStyle &style, Map *map, - QGraphicsItem *parent = 0); + PathItem(const Path &path, Map *map, QGraphicsItem *parent = 0); virtual ~PathItem() {} QPainterPath shape() const {return _shape;} @@ -41,7 +38,7 @@ public: void setColor(const QColor &color); void setWidth(qreal width); - void setStyle(Qt::PenStyle style); + void setPenStyle(Qt::PenStyle style); void setDigitalZoom(int zoom); void setMarkerColor(const QColor &color); void showMarker(bool show); @@ -52,11 +49,10 @@ public: void updateTicks(); void updateMarkerInfo(); + void updateStyle(); static void setUnits(Units units) {_units = units;} static void setTimeZone(const QTimeZone &zone) {_timeZone = zone;} - static void setCoordinatesFormat(const CoordinatesFormat &format) - {MarkerInfoItem::setCoordinatesFormat(format);} public slots: void hover(bool hover); @@ -69,11 +65,6 @@ protected: void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); void mousePressEvent(QGraphicsSceneMouseEvent *event); - QString _name; - QString _desc; - QString _comment; - QVector _links; - static Units _units; static QTimeZone _timeZone; @@ -84,29 +75,37 @@ private: void updateShape(); void addSegment(const Coordinates &c1, const Coordinates &c2); void setMarkerInfo(qreal pos); + void updateColor(); + void updateWidth(); + void updatePenStyle(); + qreal width() const; + const QColor &color() const; + Qt::PenStyle penStyle() const; qreal xInM() const; unsigned tickSize() const; Path _path; - LineStyle _style; + Map *_map; QList _graphs; GraphItem *_graph; - qreal _markerDistance; - int _digitalZoom; - - qreal _width; - QPen _pen; - QPainterPath _shape; - QPainterPath _painterPath; - bool _showMarker; - bool _showTicks; - MarkerInfoItem::Type _markerInfoType; - MarkerItem *_marker; MarkerInfoItem *_markerInfo; QVector _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 diff --git a/src/GUI/planeitem.h b/src/GUI/planeitem.h index 9a65d217..40b196c0 100644 --- a/src/GUI/planeitem.h +++ b/src/GUI/planeitem.h @@ -17,8 +17,9 @@ public: virtual void setColor(const QColor &color) = 0; virtual void setOpacity(qreal opacity) = 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 updateStyle() {} }; #endif // PLANEITEM_H diff --git a/src/GUI/routeitem.cpp b/src/GUI/routeitem.cpp index c9222a21..782abb46 100644 --- a/src/GUI/routeitem.cpp +++ b/src/GUI/routeitem.cpp @@ -36,7 +36,7 @@ ToolTip RouteItem::info() const } 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(); diff --git a/src/GUI/routeitem.h b/src/GUI/routeitem.h index 72894205..dad0d840 100644 --- a/src/GUI/routeitem.h +++ b/src/GUI/routeitem.h @@ -1,6 +1,7 @@ #ifndef ROUTEITEM_H #define ROUTEITEM_H +#include "data/link.h" #include "pathitem.h" class Map; @@ -25,6 +26,10 @@ public: QDateTime date() const {return QDateTime();} private: + QString _name; + QString _desc; + QString _comment; + QVector _links; QVector _waypoints; }; diff --git a/src/GUI/trackitem.cpp b/src/GUI/trackitem.cpp index ff5c0e1f..81cbce4a 100644 --- a/src/GUI/trackitem.cpp +++ b/src/GUI/trackitem.cpp @@ -41,7 +41,7 @@ ToolTip TrackItem::info() const } TrackItem::TrackItem(const Track &track, Map *map, QGraphicsItem *parent) - : PathItem(track.path(), track.style(), map, parent) + : PathItem(track.path(), map, parent) { _name = track.name(); _desc = track.description(); diff --git a/src/GUI/trackitem.h b/src/GUI/trackitem.h index bb55efd5..b6026750 100644 --- a/src/GUI/trackitem.h +++ b/src/GUI/trackitem.h @@ -2,6 +2,7 @@ #define TRACKITEM_H #include +#include "data/link.h" #include "pathitem.h" class Map; @@ -18,6 +19,10 @@ public: QDateTime date() const {return _date;} private: + QString _name; + QString _desc; + QString _comment; + QVector _links; QDateTime _date; qreal _time; qreal _movingTime; diff --git a/src/GUI/waypointitem.cpp b/src/GUI/waypointitem.cpp index f2ace662..349836d8 100644 --- a/src/GUI/waypointitem.cpp +++ b/src/GUI/waypointitem.cpp @@ -12,7 +12,6 @@ #define FS(size) \ ((int)((qreal)size * 1.41)) - Units WaypointItem::_units = Metric; CoordinatesFormat WaypointItem::_format = DecimalDegrees; QTimeZone WaypointItem::_timeZone = QTimeZone::utc(); @@ -77,16 +76,14 @@ WaypointItem::WaypointItem(const Waypoint &waypoint, Map *map, _waypoint = waypoint; _showLabel = true; _showIcon = false; - _size = (_waypoint.style().size() >= 0) - ? _waypoint.style().size() : 8; - _color = (_waypoint.style().color().isValid()) - ? _waypoint.style().color() : Qt::black; + _size = 8; + _color = Qt::black; _icon = (_waypoint.style().icon().isNull()) ? Waypoint::symbolIcon(_waypoint.symbol()) : &_waypoint.style().icon(); - _font.setPixelSize(FS(_size)); + _font.setPixelSize(FS(size())); _font.setFamily(FONT_FAMILY); updateCache(); @@ -99,7 +96,7 @@ WaypointItem::WaypointItem(const Waypoint &waypoint, Map *map, void WaypointItem::updateCache() { QPainterPath p; - qreal pointSize = _font.bold() ? HS(_size) : _size; + qreal pointSize = _font.bold() ? HS(size()) : size(); const QPixmap &icon = _waypoint.style().icon(); if (_showLabel && !_waypoint.name().isEmpty()) { @@ -149,10 +146,10 @@ void WaypointItem::paint(QPainter *painter, { Q_UNUSED(option); Q_UNUSED(widget); - qreal pointSize = _font.bold() ? HS(_size) : _size; + qreal pointSize = _font.bold() ? HS(size()) : size(); const QPixmap &icon = _waypoint.style().icon(); - painter->setPen(_color); + painter->setPen(color()); if (_showLabel && !_waypoint.name().isEmpty()) { painter->setFont(_font); @@ -168,7 +165,7 @@ void WaypointItem::paint(QPainter *painter, + _labelBB.height(), _waypoint.name()); } - painter->setBrush(QBrush(_color, Qt::SolidPattern)); + painter->setBrush(QBrush(color(), Qt::SolidPattern)); if (_showIcon && _icon) { if (_font.bold()) painter->drawPixmap(-_icon->width() * 0.625, icon.isNull() @@ -186,30 +183,48 @@ void WaypointItem::paint(QPainter *painter, //painter->drawPath(_shape); } +int WaypointItem::size() const +{ + return (_useStyle && _waypoint.style().size() > 0) + ? _waypoint.style().size() : _size; +} + void WaypointItem::setSize(int size) { - if (_waypoint.style().size() >= 0) - return; - if (_size == size) - return; - - prepareGeometryChange(); _size = size; - _font.setPixelSize(FS(_size)); + updateSize(); +} + +void WaypointItem::updateSize() +{ + prepareGeometryChange(); + _font.setPixelSize(FS(size())); updateCache(); } +const QColor &WaypointItem::color() const +{ + return (_useStyle && _waypoint.style().color().isValid()) + ? _waypoint.style().color() : _color; +} + void WaypointItem::setColor(const QColor &color) { - if (_waypoint.style().color().isValid()) - return; - if (_color == color) - return; - _color = color; + updateColor(); +} + +void WaypointItem::updateColor() +{ update(); } +void WaypointItem::updateStyle() +{ + updateSize(); + updateColor(); +} + void WaypointItem::showLabel(bool show) { if (_showLabel == show) diff --git a/src/GUI/waypointitem.h b/src/GUI/waypointitem.h index a81540d8..95e3dc9f 100644 --- a/src/GUI/waypointitem.h +++ b/src/GUI/waypointitem.h @@ -2,14 +2,12 @@ #define WAYPOINTITEM_H #include -#include #include #include #include "data/waypoint.h" #include "map/map.h" -#include "units.h" -#include "graphicsscene.h" #include "format.h" +#include "graphicsscene.h" class WaypointItem : public GraphicsItem @@ -25,6 +23,7 @@ public: void showLabel(bool show); void showIcon(bool show); void setDigitalZoom(int zoom) {setScale(pow(2, -zoom));} + void updateStyle(); QPainterPath shape() const {return _shape;} QRectF boundingRect() const {return _shape.boundingRect();} @@ -45,16 +44,22 @@ protected: private: void updateCache(); + void updateColor(); + void updateSize(); + int size() const; + const QColor &color() const; Waypoint _waypoint; - QPainterPath _shape; + QColor _color; int _size; bool _showLabel; bool _showIcon; + QFont _font; QRect _labelBB; const QPixmap *_icon; + QPainterPath _shape; static Units _units; static CoordinatesFormat _format; diff --git a/src/data/path.h b/src/data/path.h index 74cfa572..d5a92636 100644 --- a/src/data/path.h +++ b/src/data/path.h @@ -5,6 +5,7 @@ #include #include "common/coordinates.h" #include "common/rectc.h" +#include "style.h" class PathPoint { @@ -34,6 +35,12 @@ class Path : public QList public: bool isValid() const; RectC boundingRect() const; + + const LineStyle &style() const {return _style;} + void setStyle(const LineStyle &style) {_style = style;} + +private: + LineStyle _style; }; #endif // PATH_H diff --git a/src/data/route.cpp b/src/data/route.cpp index 3aa57736..92b80761 100644 --- a/src/data/route.cpp +++ b/src/data/route.cpp @@ -25,6 +25,8 @@ Path Route::path() const for (int i = 0; i < _data.size(); i++) ps.append(PathPoint(_data.at(i).coordinates(), _distance.at(i))); + ret.setStyle(_data.style()); + return ret; } diff --git a/src/data/track.cpp b/src/data/track.cpp index 18350965..4ad53133 100644 --- a/src/data/track.cpp +++ b/src/data/track.cpp @@ -607,6 +607,8 @@ Path Track::path() const seg.distance.at(j))); } + ret.setStyle(_data.style()); + return ret; }