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;
_digitalZoom = 0;
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);
}
_color = Qt::black;
_penStyle = Qt::SolidLine;
_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)

View File

@ -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;
};

View File

@ -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. */

View File

@ -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

View File

@ -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;

View File

@ -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;

View File

@ -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);

View File

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

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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();

View File

@ -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();

View File

@ -1,14 +1,12 @@
#ifndef PATHITEM_H
#define PATHITEM_H
#include <QGraphicsObject>
#include <QPen>
#include <QTimeZone>
#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<Link> _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<GraphItem *> _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<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

View File

@ -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

View File

@ -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();

View File

@ -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<Link> _links;
QVector<WaypointItem*> _waypoints;
};

View File

@ -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();

View File

@ -2,6 +2,7 @@
#define TRACKITEM_H
#include <QDateTime>
#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<Link> _links;
QDateTime _date;
qreal _time;
qreal _movingTime;

View File

@ -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)

View File

@ -2,14 +2,12 @@
#define WAYPOINTITEM_H
#include <cmath>
#include <QGraphicsItem>
#include <QFont>
#include <QTimeZone>
#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;

View File

@ -5,6 +5,7 @@
#include <QRectF>
#include "common/coordinates.h"
#include "common/rectc.h"
#include "style.h"
class PathPoint
{
@ -34,6 +35,12 @@ class Path : public QList<PathSegment>
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

View File

@ -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;
}

View File

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