diff --git a/gpxsee.pro b/gpxsee.pro index d5d7541e..1611d5f9 100644 --- a/gpxsee.pro +++ b/gpxsee.pro @@ -19,6 +19,7 @@ equals(QT_MAJOR_VERSION, 5) : lessThan(QT_MINOR_VERSION, 4) {QT += opengl} INCLUDEPATH += ./src HEADERS += src/common/config.h \ + src/GUI/graphicsscene.h \ src/GUI/popup.h \ src/common/staticassert.h \ src/common/coordinates.h \ diff --git a/src/GUI/cadencegraphitem.cpp b/src/GUI/cadencegraphitem.cpp index 29ba0c49..6d0c0297 100644 --- a/src/GUI/cadencegraphitem.cpp +++ b/src/GUI/cadencegraphitem.cpp @@ -9,9 +9,8 @@ CadenceGraphItem::CadenceGraphItem(const Graph &graph, GraphType type, { } -QString CadenceGraphItem::toolTip(Units units) const +QString CadenceGraphItem::info() const { - Q_UNUSED(units); ToolTip tt; QLocale l(QLocale::system()); diff --git a/src/GUI/cadencegraphitem.h b/src/GUI/cadencegraphitem.h index 03cd2bae..3b8db7de 100644 --- a/src/GUI/cadencegraphitem.h +++ b/src/GUI/cadencegraphitem.h @@ -11,7 +11,7 @@ public: CadenceGraphItem(const Graph &graph, GraphType type, int width, const QColor &color, QGraphicsItem *parent = 0); - QString toolTip(Units units) const; + QString info() const; }; #endif // CADENCEGRAPHITEM_H diff --git a/src/GUI/elevationgraphitem.cpp b/src/GUI/elevationgraphitem.cpp index 359b542b..9d08904e 100644 --- a/src/GUI/elevationgraphitem.cpp +++ b/src/GUI/elevationgraphitem.cpp @@ -26,11 +26,11 @@ ElevationGraphItem::ElevationGraphItem(const Graph &graph, GraphType type, } } -QString ElevationGraphItem::toolTip(Units units) const +QString ElevationGraphItem::info() const { ToolTip tt; - qreal scale = (units == Metric) ? 1.0 : M2FT; - QString su = (units == Metric) ? tr("m") : tr("ft"); + qreal scale = (_units == Metric) ? 1.0 : M2FT; + QString su = (_units == Metric) ? tr("m") : tr("ft"); QLocale l(QLocale::system()); tt.insert(tr("Ascent"), l.toString(ascent() * scale, 'f', 0) diff --git a/src/GUI/elevationgraphitem.h b/src/GUI/elevationgraphitem.h index 665e5344..dfae0184 100644 --- a/src/GUI/elevationgraphitem.h +++ b/src/GUI/elevationgraphitem.h @@ -16,7 +16,7 @@ public: qreal max() const {return _max;} qreal min() const {return _min;} - QString toolTip(Units units) const; + QString info() const; private: qreal _ascent, _descent, _min, _max; diff --git a/src/GUI/gearratiographitem.cpp b/src/GUI/gearratiographitem.cpp index 42ff04b8..22cf03fd 100644 --- a/src/GUI/gearratiographitem.cpp +++ b/src/GUI/gearratiographitem.cpp @@ -27,9 +27,8 @@ GearRatioGraphItem::GearRatioGraphItem(const Graph &graph, GraphType type, _top = key; } -QString GearRatioGraphItem::toolTip(Units units) const +QString GearRatioGraphItem::info() const { - Q_UNUSED(units); ToolTip tt; QLocale l(QLocale::system()); diff --git a/src/GUI/gearratiographitem.h b/src/GUI/gearratiographitem.h index b507c704..0998671d 100644 --- a/src/GUI/gearratiographitem.h +++ b/src/GUI/gearratiographitem.h @@ -15,7 +15,7 @@ public: qreal top() const {return _top;} const QMap &map() const {return _map;} - QString toolTip(Units units) const; + QString info() const; private: QMap _map; diff --git a/src/GUI/graphicsscene.h b/src/GUI/graphicsscene.h new file mode 100644 index 00000000..f24985e8 --- /dev/null +++ b/src/GUI/graphicsscene.h @@ -0,0 +1,36 @@ +#ifndef GRAPHICSSCENE_H +#define GRAPHICSSCENE_H + +#include +#include +#include +#include +#include "popup.h" + +class GraphicsItem : public QGraphicsItem +{ +public: + GraphicsItem(QGraphicsItem *parent = 0) : QGraphicsItem(parent) {} + + virtual QString info() const = 0; + int type() const {return QGraphicsItem::UserType + 1;} +}; + +class GraphicsScene : public QGraphicsScene +{ +public: + GraphicsScene(QObject *parent = 0) : QGraphicsScene(parent) {} + +protected: + void helpEvent(QGraphicsSceneHelpEvent *event) + { + QGraphicsItem *item = itemAt(event->scenePos(), QTransform()); + if (item && item->type() == QGraphicsItem::UserType + 1) { + GraphicsItem *mi = static_cast(item); + Popup::show(event->screenPos(), mi->info(), + static_cast(parent())); + } + } +}; + +#endif // GRAPHICSSCENE_H diff --git a/src/GUI/graphitem.cpp b/src/GUI/graphitem.cpp index d36f01f8..b463321f 100644 --- a/src/GUI/graphitem.cpp +++ b/src/GUI/graphitem.cpp @@ -6,7 +6,7 @@ GraphItem::GraphItem(const Graph &graph, GraphType type, int width, const QColor &color, QGraphicsItem *parent) - : QGraphicsObject(parent), _graph(graph), _type(type) + : GraphicsItem(parent), _graph(graph), _type(type) { Q_ASSERT(_graph.isValid()); @@ -309,6 +309,6 @@ void GraphItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) void GraphItem::mousePressEvent(QGraphicsSceneMouseEvent *event) { - Popup::show(event->screenPos(), toolTip(_units), event->widget()); - QGraphicsObject::mousePressEvent(event); + Popup::show(event->screenPos(), info(), event->widget()); + GraphicsItem::mousePressEvent(event); } diff --git a/src/GUI/graphitem.h b/src/GUI/graphitem.h index 7d698455..17c752cb 100644 --- a/src/GUI/graphitem.h +++ b/src/GUI/graphitem.h @@ -5,8 +5,9 @@ #include #include "data/graph.h" #include "units.h" +#include "graphicsscene.h" -class GraphItem : public QGraphicsObject +class GraphItem : public QObject, public GraphicsItem { Q_OBJECT @@ -15,7 +16,7 @@ public: QGraphicsItem *parent = 0); virtual ~GraphItem() {} - virtual QString toolTip(Units units) const = 0; + virtual QString info() const = 0; QPainterPath shape() const {return _shape;} QRectF boundingRect() const {return _shape.boundingRect();} @@ -52,6 +53,8 @@ protected: void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); void mousePressEvent(QGraphicsSceneMouseEvent *event); + Units _units; + private: const GraphSegment *segment(qreal x, GraphType type) const; void updatePath(); @@ -60,13 +63,11 @@ private: Graph _graph; GraphType _type; - Units _units; QPainterPath _path; QPainterPath _shape; QRectF _bounds; qreal _sx, _sy; QPen _pen; - bool _time; }; diff --git a/src/GUI/graphview.cpp b/src/GUI/graphview.cpp index 65dc3261..a48121e4 100644 --- a/src/GUI/graphview.cpp +++ b/src/GUI/graphview.cpp @@ -15,6 +15,7 @@ #include "graphitem.h" #include "pathitem.h" #include "format.h" +#include "graphicsscene.h" #include "graphview.h" @@ -23,7 +24,7 @@ GraphView::GraphView(QWidget *parent) : QGraphicsView(parent) { - _scene = new QGraphicsScene(this); + _scene = new GraphicsScene(this); setScene(_scene); setViewportUpdateMode(QGraphicsView::FullViewportUpdate); @@ -37,9 +38,9 @@ GraphView::GraphView(QWidget *parent) _yAxis = new AxisItem(AxisItem::Y); _yAxis->setZValue(1.0); _slider = new SliderItem(); - _slider->setZValue(3.0); + _slider->setZValue(4.0); _sliderInfo = new SliderInfoItem(_slider); - _sliderInfo->setZValue(3.0); + _sliderInfo->setZValue(4.0); _info = new InfoItem(); _grid = new GridItem(); _message = new QGraphicsSimpleTextItem(tr("Data not available")); diff --git a/src/GUI/graphview.h b/src/GUI/graphview.h index a29c1be2..3cdf51e7 100644 --- a/src/GUI/graphview.h +++ b/src/GUI/graphview.h @@ -17,6 +17,7 @@ class GraphItem; class PathItem; class GridItem; class QGraphicsSimpleTextItem; +class GraphicsScene; class GraphView : public QGraphicsView { @@ -93,7 +94,7 @@ private: void removeItem(QGraphicsItem *item); void addItem(QGraphicsItem *item); - QGraphicsScene *_scene; + GraphicsScene *_scene; AxisItem *_xAxis, *_yAxis; SliderItem *_slider; diff --git a/src/GUI/heartrategraphitem.cpp b/src/GUI/heartrategraphitem.cpp index ee983da9..90436639 100644 --- a/src/GUI/heartrategraphitem.cpp +++ b/src/GUI/heartrategraphitem.cpp @@ -9,9 +9,8 @@ HeartRateGraphItem::HeartRateGraphItem(const Graph &graph, GraphType type, { } -QString HeartRateGraphItem::toolTip(Units units) const +QString HeartRateGraphItem::info() const { - Q_UNUSED(units); ToolTip tt; QLocale l(QLocale::system()); diff --git a/src/GUI/heartrategraphitem.h b/src/GUI/heartrategraphitem.h index 41a0f2c2..cfc60340 100644 --- a/src/GUI/heartrategraphitem.h +++ b/src/GUI/heartrategraphitem.h @@ -11,7 +11,7 @@ public: HeartRateGraphItem(const Graph &graph, GraphType type, int width, const QColor &color, QGraphicsItem *parent = 0); - QString toolTip(Units units) const; + QString info() const; }; #endif // HEARTRATEGRAPHITEM_H diff --git a/src/GUI/mapview.cpp b/src/GUI/mapview.cpp index 0b1ec887..f2a2d9b1 100644 --- a/src/GUI/mapview.cpp +++ b/src/GUI/mapview.cpp @@ -16,6 +16,7 @@ #include "scaleitem.h" #include "coordinatesitem.h" #include "keys.h" +#include "graphicsscene.h" #include "mapview.h" @@ -32,7 +33,7 @@ MapView::MapView(Map *map, POI *poi, QWidget *parent) Q_ASSERT(map != 0); Q_ASSERT(poi != 0); - _scene = new QGraphicsScene(this); + _scene = new GraphicsScene(this); setScene(_scene); setDragMode(QGraphicsView::ScrollHandDrag); setViewportUpdateMode(QGraphicsView::FullViewportUpdate); diff --git a/src/GUI/mapview.h b/src/GUI/mapview.h index 5d5b3c8b..c0800f0f 100644 --- a/src/GUI/mapview.h +++ b/src/GUI/mapview.h @@ -30,6 +30,7 @@ class PathItem; class GraphItem; class AreaItem; class Area; +class GraphicsScene; class MapView : public QGraphicsView { @@ -120,7 +121,7 @@ private: void mouseMoveEvent(QMouseEvent *event); void leaveEvent(QEvent *event); - QGraphicsScene *_scene; + GraphicsScene *_scene; ScaleItem *_mapScale; CoordinatesItem *_coordinates; QList _tracks; diff --git a/src/GUI/pathitem.cpp b/src/GUI/pathitem.cpp index 5d25deb1..89de798f 100644 --- a/src/GUI/pathitem.cpp +++ b/src/GUI/pathitem.cpp @@ -22,7 +22,7 @@ static inline unsigned segments(qreal distance) } PathItem::PathItem(const Path &path, Map *map, QGraphicsItem *parent) - : QGraphicsObject(parent), _path(path), _map(map) + : GraphicsItem(parent), _path(path), _map(map) { Q_ASSERT(_path.isValid()); @@ -385,6 +385,6 @@ void PathItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) void PathItem::mousePressEvent(QGraphicsSceneMouseEvent *event) { - Popup::show(event->screenPos(), toolTip(_units), event->widget()); - QGraphicsObject::mousePressEvent(event); + Popup::show(event->screenPos(), info(), event->widget()); + GraphicsItem::mousePressEvent(event); } diff --git a/src/GUI/pathitem.h b/src/GUI/pathitem.h index b01cfdec..a364f1b2 100644 --- a/src/GUI/pathitem.h +++ b/src/GUI/pathitem.h @@ -6,11 +6,12 @@ #include "data/path.h" #include "markeritem.h" #include "units.h" +#include "graphicsscene.h" class Map; class PathTickItem; -class PathItem : public QGraphicsObject +class PathItem : public QObject, public GraphicsItem { Q_OBJECT @@ -18,8 +19,6 @@ public: PathItem(const Path &path, Map *map, QGraphicsItem *parent = 0); virtual ~PathItem() {} - virtual QString toolTip(Units units) const = 0; - QPainterPath shape() const {return _shape;} QRectF boundingRect() const {return _shape.boundingRect();} void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, @@ -38,8 +37,6 @@ public: void showMarker(bool show); void showTicks(bool show); - Units units() const {return _units;} - public slots: void moveMarker(qreal distance); void hover(bool hover); @@ -52,6 +49,8 @@ protected: void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); void mousePressEvent(QGraphicsSceneMouseEvent *event); + Units _units; + private: const PathSegment *segment(qreal x) const; QPointF position(qreal distance) const; @@ -68,7 +67,6 @@ private: qreal _markerDistance; int _digitalZoom; - Units _units; qreal _width; QPen _pen; QPainterPath _shape; diff --git a/src/GUI/pathtickitem.cpp b/src/GUI/pathtickitem.cpp index 56fe850e..5845ab20 100644 --- a/src/GUI/pathtickitem.cpp +++ b/src/GUI/pathtickitem.cpp @@ -20,7 +20,7 @@ static QFont defaultFont() QFont PathTickItem::_font = defaultFont(); PathTickItem::PathTickItem(const QRectF &tickRect, int value, - QGraphicsItem *parent) : QGraphicsItem(parent), _tickRect(tickRect), + QGraphicsItem *parent) : GraphicsItem(parent), _tickRect(tickRect), _text(QString::number(value)) { _tickRect.moveCenter(QPointF(0, -_tickRect.height()/2.0 - 3)); @@ -76,6 +76,6 @@ QRect PathTickItem::tickRect(int value) void PathTickItem::mousePressEvent(QGraphicsSceneMouseEvent *event) { const PathItem *pi = static_cast(parentItem()); - Popup::show(event->screenPos(), pi->toolTip(pi->units()), event->widget()); + Popup::show(event->screenPos(), pi->info(), event->widget()); QGraphicsItem::mousePressEvent(event); } diff --git a/src/GUI/pathtickitem.h b/src/GUI/pathtickitem.h index d24d31ee..48af0fc5 100644 --- a/src/GUI/pathtickitem.h +++ b/src/GUI/pathtickitem.h @@ -3,8 +3,9 @@ #include #include +#include "graphicsscene.h" -class PathTickItem : public QGraphicsItem +class PathTickItem : public GraphicsItem { public: PathTickItem(const QRectF &tickRect, int value, QGraphicsItem *parent = 0); @@ -16,6 +17,9 @@ public: void setPos(const QPointF &pos); void setColor(const QColor &color) {_brush = QBrush(color);} + int type() const {return parentItem()->type();} + QString info() const {return static_cast(parentItem())->info();} + static QRect tickRect(int value); protected: diff --git a/src/GUI/powergraphitem.cpp b/src/GUI/powergraphitem.cpp index bd5664cb..81c1377a 100644 --- a/src/GUI/powergraphitem.cpp +++ b/src/GUI/powergraphitem.cpp @@ -9,9 +9,8 @@ PowerGraphItem::PowerGraphItem(const Graph &graph, GraphType type, int width, { } -QString PowerGraphItem::toolTip(Units units) const +QString PowerGraphItem::info() const { - Q_UNUSED(units); ToolTip tt; QLocale l(QLocale::system()); diff --git a/src/GUI/powergraphitem.h b/src/GUI/powergraphitem.h index 4f040c71..6d2e6800 100644 --- a/src/GUI/powergraphitem.h +++ b/src/GUI/powergraphitem.h @@ -11,7 +11,7 @@ public: PowerGraphItem(const Graph &graph, GraphType type, int width, const QColor &color, QGraphicsItem *parent = 0); - QString toolTip(Units units) const; + QString info() const; }; #endif // POWERGRAPHITEM_H diff --git a/src/GUI/routeitem.cpp b/src/GUI/routeitem.cpp index e643ae2c..c2681ed2 100644 --- a/src/GUI/routeitem.cpp +++ b/src/GUI/routeitem.cpp @@ -7,7 +7,7 @@ #include "routeitem.h" -QString RouteItem::toolTip(Units units) const +QString RouteItem::info() const { ToolTip tt; @@ -16,7 +16,7 @@ QString RouteItem::toolTip(Units units) const if (!_desc.isEmpty()) tt.insert(tr("Description"), _desc); tt.insert(tr("Distance"), Format::distance(path().last().last().distance(), - units)); + _units)); for (int i = 0; i < _links.size(); i++) { const Link &link = _links.at(i); if (!link.URL().isEmpty()) { @@ -53,7 +53,7 @@ void RouteItem::setMap(Map *map) void RouteItem::setUnits(Units u) { - if (units() == u) + if (_units == u) return; for (int i = 0; i < _waypoints.count(); i++) @@ -70,7 +70,7 @@ void RouteItem::setCoordinatesFormat(CoordinatesFormat format) _coordinatesFormat = format; for (int i = 0; i < _waypoints.count(); i++) - _waypoints[i]->setToolTipFormat(units(), _coordinatesFormat); + _waypoints[i]->setToolTipFormat(_units, _coordinatesFormat); } void RouteItem::showWaypoints(bool show) diff --git a/src/GUI/routeitem.h b/src/GUI/routeitem.h index 8b531946..9811e342 100644 --- a/src/GUI/routeitem.h +++ b/src/GUI/routeitem.h @@ -5,6 +5,7 @@ #include "pathitem.h" #include "units.h" #include "format.h" +#include "graphicsscene.h" class Map; class WaypointItem; @@ -23,7 +24,7 @@ public: void showWaypoints(bool show); void showWaypointLabels(bool show); - QString toolTip(Units units) const; + QString info() const; private: QString _name; diff --git a/src/GUI/speedgraphitem.cpp b/src/GUI/speedgraphitem.cpp index b92d03d3..39d98b1b 100644 --- a/src/GUI/speedgraphitem.cpp +++ b/src/GUI/speedgraphitem.cpp @@ -15,16 +15,16 @@ SpeedGraphItem::SpeedGraphItem(const Graph &graph, GraphType type, int width, _mavg = graph.last().last().s() / movingTime; } -QString SpeedGraphItem::toolTip(Units units) const +QString SpeedGraphItem::info() const { ToolTip tt; - qreal scale = (units == Imperial) ? MS2MIH : (units == Nautical) + qreal scale = (_units == Imperial) ? MS2MIH : (_units == Nautical) ? MS2KN : MS2KMH; - QString su = (units == Imperial) ? tr("mi/h") : (units == Nautical) + QString su = (_units == Imperial) ? tr("mi/h") : (_units == Nautical) ? tr("kn") : tr("km/h"); QString pace = Format::timeSpan((3600.0 / ((_timeType == Total) ? avg() * scale : mavg() * scale)), false); - QString pu = (units == Metric) ? tr("min/km") : (units == Imperial) ? + QString pu = (_units == Metric) ? tr("min/km") : (_units == Imperial) ? tr("min/mi") : tr("min/nmi"); QLocale l(QLocale::system()); diff --git a/src/GUI/speedgraphitem.h b/src/GUI/speedgraphitem.h index 6bc79ade..4c45f43c 100644 --- a/src/GUI/speedgraphitem.h +++ b/src/GUI/speedgraphitem.h @@ -16,7 +16,7 @@ public: qreal mavg() const {return _mavg;} qreal max() const {return _max;} - QString toolTip(Units units) const; + QString info() const; void setTimeType(TimeType type); diff --git a/src/GUI/temperaturegraphitem.cpp b/src/GUI/temperaturegraphitem.cpp index ecad7bfd..886ff5b7 100644 --- a/src/GUI/temperaturegraphitem.cpp +++ b/src/GUI/temperaturegraphitem.cpp @@ -12,12 +12,12 @@ TemperatureGraphItem::TemperatureGraphItem(const Graph &graph, GraphType type, _avg = GraphItem::avg(); } -QString TemperatureGraphItem::toolTip(Units units) const +QString TemperatureGraphItem::info() const { ToolTip tt; - qreal scale = (units == Metric) ? 1.0 : C2FS; - qreal offset = (units == Metric) ? 0 : C2FO; - QString su = (units == Metric) ? + qreal scale = (_units == Metric) ? 1.0 : C2FS; + qreal offset = (_units == Metric) ? 0 : C2FO; + QString su = (_units == Metric) ? QChar(0x00B0) + tr("C") : QChar(0x00B0) + tr("F"); QLocale l(QLocale::system()); diff --git a/src/GUI/temperaturegraphitem.h b/src/GUI/temperaturegraphitem.h index 15c08ab4..516af4d2 100644 --- a/src/GUI/temperaturegraphitem.h +++ b/src/GUI/temperaturegraphitem.h @@ -15,7 +15,7 @@ public: qreal min() const {return _min;} qreal avg() const {return _avg;} - QString toolTip(Units units) const; + QString info() const; private: qreal _min, _max, _avg; diff --git a/src/GUI/trackitem.cpp b/src/GUI/trackitem.cpp index e6437b90..63097ba0 100644 --- a/src/GUI/trackitem.cpp +++ b/src/GUI/trackitem.cpp @@ -5,7 +5,7 @@ #include "trackitem.h" -QString TrackItem::toolTip(Units units) const +QString TrackItem::info() const { ToolTip tt; @@ -14,7 +14,7 @@ QString TrackItem::toolTip(Units units) const if (!_desc.isEmpty()) tt.insert(tr("Description"), _desc); tt.insert(tr("Distance"), Format::distance(path().last().last().distance(), - units)); + _units)); if (_time > 0) tt.insert(tr("Total time"), Format::timeSpan(_time)); if (_movingTime > 0) diff --git a/src/GUI/trackitem.h b/src/GUI/trackitem.h index 6ef42976..41f01863 100644 --- a/src/GUI/trackitem.h +++ b/src/GUI/trackitem.h @@ -6,6 +6,7 @@ #include "data/track.h" #include "pathitem.h" #include "units.h" +#include "graphicsscene.h" class Map; @@ -16,7 +17,7 @@ class TrackItem : public PathItem public: TrackItem(const Track &track, Map *map, QGraphicsItem *parent = 0); - QString toolTip(Units units) const; + QString info() const; private: QString _name; diff --git a/src/GUI/waypointitem.cpp b/src/GUI/waypointitem.cpp index 7dd4d0c3..0692a00c 100644 --- a/src/GUI/waypointitem.cpp +++ b/src/GUI/waypointitem.cpp @@ -13,17 +13,17 @@ #define FS(size) \ ((int)((qreal)size * 1.41)) -ToolTip WaypointItem::toolTip(Units units, CoordinatesFormat format) +QString WaypointItem::info() const { ToolTip tt; if (!_waypoint.name().isEmpty()) tt.insert(qApp->translate("WaypointItem", "Name"), _waypoint.name()); tt.insert(qApp->translate("WaypointItem", "Coordinates"), - Format::coordinates(_waypoint.coordinates(), format)); + Format::coordinates(_waypoint.coordinates(), _format)); if (_waypoint.hasElevation()) tt.insert(qApp->translate("WaypointItem", "Elevation"), - Format::elevation(_waypoint.elevation(), units)); + Format::elevation(_waypoint.elevation(), _units)); if (_waypoint.timestamp().isValid()) tt.insert(qApp->translate("WaypointItem", "Date"), _waypoint.timestamp().toString(Qt::SystemLocaleShortDate)); @@ -40,11 +40,11 @@ ToolTip WaypointItem::toolTip(Units units, CoordinatesFormat format) } tt.setImage(_waypoint.image()); - return tt; + return tt.toString(); } WaypointItem::WaypointItem(const Waypoint &waypoint, Map *map, - QGraphicsItem *parent) : QGraphicsItem(parent) + QGraphicsItem *parent) : GraphicsItem(parent) { _waypoint = waypoint; _showLabel = true; @@ -165,8 +165,7 @@ void WaypointItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) void WaypointItem::mousePressEvent(QGraphicsSceneMouseEvent *event) { - ToolTip tt(toolTip(_units, _format)); - Popup::show(event->screenPos(), tt.toString(), event->widget()); + Popup::show(event->screenPos(), info(), event->widget()); /* Do not propagate the event any further as lower stacked items (path items) would replace the popup with their own popup */ } diff --git a/src/GUI/waypointitem.h b/src/GUI/waypointitem.h index 4829d121..9646553b 100644 --- a/src/GUI/waypointitem.h +++ b/src/GUI/waypointitem.h @@ -3,14 +3,15 @@ #include #include +#include #include "data/waypoint.h" #include "map/map.h" #include "units.h" +#include "graphicsscene.h" #include "format.h" -#include "tooltip.h" -class WaypointItem : public QGraphicsItem +class WaypointItem : public GraphicsItem { public: WaypointItem(const Waypoint &waypoint, Map *map, QGraphicsItem *parent = 0); @@ -29,6 +30,8 @@ public: void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); + QString info() const; + protected: void hoverEnterEvent(QGraphicsSceneHoverEvent *event); void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); @@ -36,7 +39,6 @@ protected: private: void updateCache(); - ToolTip toolTip(Units units, CoordinatesFormat format); Waypoint _waypoint; QPainterPath _shape;