diff --git a/gpxsee.pro b/gpxsee.pro index a3f359ee..915248e8 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/popup.h \ src/common/staticassert.h \ src/common/coordinates.h \ src/common/range.h \ @@ -185,6 +186,7 @@ HEADERS += src/common/config.h \ src/data/csv.h \ src/data/cupparser.h SOURCES += src/main.cpp \ + src/GUI/popup.cpp \ src/common/coordinates.cpp \ src/common/rectc.cpp \ src/common/range.cpp \ diff --git a/src/GUI/cadencegraphitem.cpp b/src/GUI/cadencegraphitem.cpp index 335972dc..29ba0c49 100644 --- a/src/GUI/cadencegraphitem.cpp +++ b/src/GUI/cadencegraphitem.cpp @@ -7,11 +7,11 @@ CadenceGraphItem::CadenceGraphItem(const Graph &graph, GraphType type, int width, const QColor &color, QGraphicsItem *parent) : GraphItem(graph, type, width, color, parent) { - setToolTip(toolTip()); } -QString CadenceGraphItem::toolTip() const +QString CadenceGraphItem::toolTip(Units units) const { + Q_UNUSED(units); ToolTip tt; QLocale l(QLocale::system()); diff --git a/src/GUI/cadencegraphitem.h b/src/GUI/cadencegraphitem.h index c39b80ff..03cd2bae 100644 --- a/src/GUI/cadencegraphitem.h +++ b/src/GUI/cadencegraphitem.h @@ -11,8 +11,7 @@ public: CadenceGraphItem(const Graph &graph, GraphType type, int width, const QColor &color, QGraphicsItem *parent = 0); -private: - QString toolTip() const; + QString toolTip(Units units) const; }; #endif // CADENCEGRAPHITEM_H diff --git a/src/GUI/elevationgraphitem.cpp b/src/GUI/elevationgraphitem.cpp index 09ca7c65..359b542b 100644 --- a/src/GUI/elevationgraphitem.cpp +++ b/src/GUI/elevationgraphitem.cpp @@ -24,8 +24,6 @@ ElevationGraphItem::ElevationGraphItem(const Graph &graph, GraphType type, _descent += prev - cur; } } - - setToolTip(toolTip(Metric)); } QString ElevationGraphItem::toolTip(Units units) const @@ -46,8 +44,3 @@ QString ElevationGraphItem::toolTip(Units units) const return tt.toString(); } - -void ElevationGraphItem::setUnits(Units units) -{ - setToolTip(toolTip(units)); -} diff --git a/src/GUI/elevationgraphitem.h b/src/GUI/elevationgraphitem.h index 40294269..665e5344 100644 --- a/src/GUI/elevationgraphitem.h +++ b/src/GUI/elevationgraphitem.h @@ -16,11 +16,9 @@ public: qreal max() const {return _max;} qreal min() const {return _min;} - void setUnits(Units units); - -private: QString toolTip(Units units) const; +private: qreal _ascent, _descent, _min, _max; }; diff --git a/src/GUI/gearratiographitem.cpp b/src/GUI/gearratiographitem.cpp index e9f61688..42ff04b8 100644 --- a/src/GUI/gearratiographitem.cpp +++ b/src/GUI/gearratiographitem.cpp @@ -25,12 +25,11 @@ GearRatioGraphItem::GearRatioGraphItem(const Graph &graph, GraphType type, } } _top = key; - - setToolTip(toolTip()); } -QString GearRatioGraphItem::toolTip() const +QString GearRatioGraphItem::toolTip(Units units) const { + Q_UNUSED(units); ToolTip tt; QLocale l(QLocale::system()); diff --git a/src/GUI/gearratiographitem.h b/src/GUI/gearratiographitem.h index f13eb859..b507c704 100644 --- a/src/GUI/gearratiographitem.h +++ b/src/GUI/gearratiographitem.h @@ -13,12 +13,11 @@ public: const QColor &color, QGraphicsItem *parent = 0); qreal top() const {return _top;} - const QMap &map() const {return _map;} -private: - QString toolTip() const; + QString toolTip(Units units) const; +private: QMap _map; qreal _top; }; diff --git a/src/GUI/graphitem.cpp b/src/GUI/graphitem.cpp index bebaa1ed..d36f01f8 100644 --- a/src/GUI/graphitem.cpp +++ b/src/GUI/graphitem.cpp @@ -1,4 +1,6 @@ #include +#include +#include "popup.h" #include "graphitem.h" @@ -8,6 +10,7 @@ GraphItem::GraphItem(const Graph &graph, GraphType type, int width, { Q_ASSERT(_graph.isValid()); + _units = Metric; _pen = QPen(color, width); _sx = 0; _sy = 0; _time = _graph.hasTime(); @@ -303,3 +306,9 @@ void GraphItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) emit selected(false); } + +void GraphItem::mousePressEvent(QGraphicsSceneMouseEvent *event) +{ + Popup::show(event->screenPos(), toolTip(_units), event->widget()); + QGraphicsObject::mousePressEvent(event); +} diff --git a/src/GUI/graphitem.h b/src/GUI/graphitem.h index cce77bfb..7d698455 100644 --- a/src/GUI/graphitem.h +++ b/src/GUI/graphitem.h @@ -15,6 +15,8 @@ public: QGraphicsItem *parent = 0); virtual ~GraphItem() {} + 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, @@ -30,7 +32,7 @@ public: void setGraphType(GraphType type); void setColor(const QColor &color); void setWidth(int width); - virtual void setUnits(Units units) {Q_UNUSED(units);} + void setUnits(Units units) {_units = units;} qreal yAtX(qreal x); qreal distanceAtTime(qreal time); @@ -45,10 +47,12 @@ public slots: void emitSliderPositionChanged(qreal); void hover(bool hover); -private: +protected: void hoverEnterEvent(QGraphicsSceneHoverEvent *event); void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); + void mousePressEvent(QGraphicsSceneMouseEvent *event); +private: const GraphSegment *segment(qreal x, GraphType type) const; void updatePath(); void updateShape(); @@ -56,6 +60,7 @@ private: Graph _graph; GraphType _type; + Units _units; QPainterPath _path; QPainterPath _shape; QRectF _bounds; diff --git a/src/GUI/graphview.cpp b/src/GUI/graphview.cpp index 9e0a68a7..65dc3261 100644 --- a/src/GUI/graphview.cpp +++ b/src/GUI/graphview.cpp @@ -357,13 +357,13 @@ void GraphView::wheelEvent(QWheelEvent *e) QGraphicsView::wheelEvent(e); } -void GraphView::paintEvent(QPaintEvent *event) +void GraphView::paintEvent(QPaintEvent *e) { QRectF viewRect(mapToScene(rect()).boundingRect()); _info->setPos(QPointF(viewRect.left() + (viewRect.width() - _info->boundingRect().width())/2.0, _info->pos().y())); - QGraphicsView::paintEvent(event); + QGraphicsView::paintEvent(e); } void GraphView::plot(QPainter *painter, const QRectF &target, qreal scale) diff --git a/src/GUI/graphview.h b/src/GUI/graphview.h index 5829cb60..a29c1be2 100644 --- a/src/GUI/graphview.h +++ b/src/GUI/graphview.h @@ -48,10 +48,15 @@ signals: protected: void addGraph(GraphItem *graph); void removeGraph(GraphItem *graph); - void setGraphType(GraphType type); void setUnits(Units units); + void resizeEvent(QResizeEvent *e); + void mousePressEvent(QMouseEvent *e); + void wheelEvent(QWheelEvent *e); + void changeEvent(QEvent *e); + void paintEvent(QPaintEvent *e); + const QString &yLabel() const {return _yLabel;} const QString &yUnits() const {return _yUnits;} qreal yScale() const {return _yScale;} @@ -88,12 +93,6 @@ private: void removeItem(QGraphicsItem *item); void addItem(QGraphicsItem *item); - void resizeEvent(QResizeEvent *e); - void mousePressEvent(QMouseEvent *e); - void wheelEvent(QWheelEvent *e); - void changeEvent(QEvent *e); - void paintEvent(QPaintEvent *event); - QGraphicsScene *_scene; AxisItem *_xAxis, *_yAxis; diff --git a/src/GUI/gui.cpp b/src/GUI/gui.cpp index aa2f3d4d..6fd48f22 100644 --- a/src/GUI/gui.cpp +++ b/src/GUI/gui.cpp @@ -1580,7 +1580,6 @@ void GUI::keyPressEvent(QKeyEvent *event) else _movingTimeAction->trigger(); break; - case Qt::Key_Escape: if (_fullscreenAction->isChecked()) { _fullscreenAction->setChecked(false); diff --git a/src/GUI/heartrategraphitem.cpp b/src/GUI/heartrategraphitem.cpp index ff383ca2..ee983da9 100644 --- a/src/GUI/heartrategraphitem.cpp +++ b/src/GUI/heartrategraphitem.cpp @@ -7,11 +7,11 @@ HeartRateGraphItem::HeartRateGraphItem(const Graph &graph, GraphType type, int width, const QColor &color, QGraphicsItem *parent) : GraphItem(graph, type, width, color, parent) { - setToolTip(toolTip()); } -QString HeartRateGraphItem::toolTip() const +QString HeartRateGraphItem::toolTip(Units units) const { + Q_UNUSED(units); ToolTip tt; QLocale l(QLocale::system()); diff --git a/src/GUI/heartrategraphitem.h b/src/GUI/heartrategraphitem.h index 4ab97607..41a0f2c2 100644 --- a/src/GUI/heartrategraphitem.h +++ b/src/GUI/heartrategraphitem.h @@ -11,8 +11,7 @@ public: HeartRateGraphItem(const Graph &graph, GraphType type, int width, const QColor &color, QGraphicsItem *parent = 0); -private: - QString toolTip() const; + QString toolTip(Units units) const; }; #endif // HEARTRATEGRAPHITEM_H diff --git a/src/GUI/pathitem.cpp b/src/GUI/pathitem.cpp index f8a5188e..5d25deb1 100644 --- a/src/GUI/pathitem.cpp +++ b/src/GUI/pathitem.cpp @@ -1,9 +1,11 @@ #include #include #include +#include #include "common/greatcircle.h" #include "map/map.h" #include "pathtickitem.h" +#include "popup.h" #include "pathitem.h" @@ -336,7 +338,6 @@ void PathItem::updateTicks() _ticks[i] = new PathTickItem(tr, (i + 1) * ts, this); _ticks[i]->setPos(position((i + 1) * ts * xInM())); _ticks[i]->setColor(_pen.color()); - _ticks[i]->setToolTip(toolTip()); } } @@ -381,3 +382,9 @@ void PathItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) emit selected(false); } + +void PathItem::mousePressEvent(QGraphicsSceneMouseEvent *event) +{ + Popup::show(event->screenPos(), toolTip(_units), event->widget()); + QGraphicsObject::mousePressEvent(event); +} diff --git a/src/GUI/pathitem.h b/src/GUI/pathitem.h index 27508b13..b01cfdec 100644 --- a/src/GUI/pathitem.h +++ b/src/GUI/pathitem.h @@ -16,6 +16,9 @@ class PathItem : public QGraphicsObject 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();} @@ -44,6 +47,11 @@ public slots: signals: void selected(bool); +protected: + void hoverEnterEvent(QGraphicsSceneHoverEvent *event); + void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); + void mousePressEvent(QGraphicsSceneMouseEvent *event); + private: const PathSegment *segment(qreal x) const; QPointF position(qreal distance) const; @@ -55,9 +63,6 @@ private: unsigned tickSize() const; void updateTicks(); - void hoverEnterEvent(QGraphicsSceneHoverEvent *event); - void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); - Path _path; Map *_map; qreal _markerDistance; diff --git a/src/GUI/pathtickitem.cpp b/src/GUI/pathtickitem.cpp index 4c5c4b51..56fe850e 100644 --- a/src/GUI/pathtickitem.cpp +++ b/src/GUI/pathtickitem.cpp @@ -1,6 +1,9 @@ #include #include +#include #include "font.h" +#include "popup.h" +#include "pathitem.h" #include "pathtickitem.h" @@ -69,3 +72,10 @@ QRect PathTickItem::tickRect(int value) return fm.boundingRect(QRect(), Qt::AlignCenter, QString::number(qMax(value, 10))).adjusted(-2, 0, 2, 0); } + +void PathTickItem::mousePressEvent(QGraphicsSceneMouseEvent *event) +{ + const PathItem *pi = static_cast(parentItem()); + Popup::show(event->screenPos(), pi->toolTip(pi->units()), event->widget()); + QGraphicsItem::mousePressEvent(event); +} diff --git a/src/GUI/pathtickitem.h b/src/GUI/pathtickitem.h index 1deb4a7e..d24d31ee 100644 --- a/src/GUI/pathtickitem.h +++ b/src/GUI/pathtickitem.h @@ -18,6 +18,9 @@ public: static QRect tickRect(int value); +protected: + void mousePressEvent(QGraphicsSceneMouseEvent *event); + private: QRectF _tickRect; QString _text; diff --git a/src/GUI/popup.cpp b/src/GUI/popup.cpp new file mode 100644 index 00000000..72dc43f1 --- /dev/null +++ b/src/GUI/popup.cpp @@ -0,0 +1,162 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "popup.h" + +#include + + +class Label : public QLabel +{ +public: + Label(const QString &text, QWidget *parent = 0); + ~Label(); + + bool eventFilter(QObject *o, QEvent *ev); + void place(const QPoint &pos, QWidget *w); + void deleteAfterTimer(); + void stopTimer() {_timer.stop();} + + static Label *_instance; + +protected: + void paintEvent(QPaintEvent *event); + void timerEvent(QTimerEvent *event); + +private: + QBasicTimer _timer; +}; + +Label *Label::_instance = 0; + +Label::Label(const QString &text, QWidget *parent) + : QLabel(text, parent, Qt::ToolTip | Qt::BypassGraphicsProxyWidget) +{ + delete _instance; + _instance = this; + + setForegroundRole(QPalette::ToolTipText); + setBackgroundRole(QPalette::ToolTipBase); + setPalette(QToolTip::palette()); + ensurePolished(); + setMargin(1 + style()->pixelMetric(QStyle::PM_ToolTipLabelFrameWidth, 0, + this)); + setFrameStyle(QFrame::NoFrame); + setAlignment(Qt::AlignLeft); + setIndent(1); + setWindowOpacity(style()->styleHint(QStyle::SH_ToolTipLabel_Opacity, 0, + this) / 255.0); + + setTextInteractionFlags(Qt::TextBrowserInteraction); + setOpenExternalLinks(true); + + setMouseTracking(true); + + qApp->installEventFilter(this); +} + +Label::~Label() +{ + _instance = 0; +} + +void Label::paintEvent(QPaintEvent *event) +{ + QStylePainter p(this); + QStyleOptionFrame opt; + opt.init(this); + p.drawPrimitive(QStyle::PE_PanelTipLabel, opt); + p.end(); + QLabel::paintEvent(event); +} + +void Label::timerEvent(QTimerEvent *event) +{ + if (event->timerId() == _timer.timerId()) { + _timer.stop(); + deleteLater(); + } +} + +bool Label::eventFilter(QObject *o, QEvent *ev) +{ + Q_UNUSED(o); + + switch (ev->type()) { + case QEvent::KeyPress: + case QEvent::KeyRelease: { + const int key = static_cast(ev)->key(); + if (key == Qt::Key_Escape) { + deleteLater(); + return true; + } + break; + } + case QEvent::FocusIn: + case QEvent::FocusOut: + case QEvent::WindowActivate: + case QEvent::WindowDeactivate: + case QEvent::Close: + deleteLater(); + break; + case QEvent::MouseMove: { + QRectF r(geometry().adjusted(-5, -20, 5, 20)); + QPointF p(static_cast(ev)->screenPos()); + if (!r.contains(p)) + deleteAfterTimer(); + break; + } + default: + break; + } + + return false; +} + +void Label::place(const QPoint &pos, QWidget *w) +{ + QRect screen = QApplication::desktop()->screenGeometry(w); + QPoint p(pos.x() + 2, pos.y() + 16); + + if (p.x() + width() > screen.x() + screen.width()) + p.rx() -= 4 + width(); + if (p.y() + height() > screen.y() + screen.height()) + p.ry() -= 24 + height(); + if (p.y() < screen.y()) + p.setY(screen.y()); + if (p.x() + width() > screen.x() + screen.width()) + p.setX(screen.x() + screen.width() - width()); + if (p.x() < screen.x()) + p.setX(screen.x()); + if (p.y() + height() > screen.y() + screen.height()) + p.setY(screen.y() + screen.height() - height()); + + this->move(p); +} + +void Label::deleteAfterTimer() +{ + if (!_timer.isActive()) + _timer.start(300, this); +} + + +void Popup::show(const QPoint &pos, const QString &text, QWidget *w) +{ + if (Label::_instance) { + Label::_instance->stopTimer(); + Label::_instance->setText(text); + Label::_instance->resize(Label::_instance->sizeHint()); + } else { + Label::_instance = new Label(text); + Label::_instance->showNormal(); + } + + Label::_instance->place(pos, w); +} diff --git a/src/GUI/popup.h b/src/GUI/popup.h new file mode 100644 index 00000000..22d51317 --- /dev/null +++ b/src/GUI/popup.h @@ -0,0 +1,14 @@ +#ifndef POPUP_H +#define POPUP_H + +class QPoint; +class QString; +class QWidget; + +class Popup +{ +public: + static void show(const QPoint &pos, const QString &text, QWidget *w); +}; + +#endif // POPUP_H diff --git a/src/GUI/powergraphitem.cpp b/src/GUI/powergraphitem.cpp index 20d6b4b8..bd5664cb 100644 --- a/src/GUI/powergraphitem.cpp +++ b/src/GUI/powergraphitem.cpp @@ -7,11 +7,11 @@ PowerGraphItem::PowerGraphItem(const Graph &graph, GraphType type, int width, const QColor &color, QGraphicsItem *parent) : GraphItem(graph, type, width, color, parent) { - setToolTip(toolTip()); } -QString PowerGraphItem::toolTip() const +QString PowerGraphItem::toolTip(Units units) const { + Q_UNUSED(units); ToolTip tt; QLocale l(QLocale::system()); diff --git a/src/GUI/powergraphitem.h b/src/GUI/powergraphitem.h index ba2c7fc4..4f040c71 100644 --- a/src/GUI/powergraphitem.h +++ b/src/GUI/powergraphitem.h @@ -11,8 +11,7 @@ public: PowerGraphItem(const Graph &graph, GraphType type, int width, const QColor &color, QGraphicsItem *parent = 0); -private: - QString toolTip() const; + QString toolTip(Units units) const; }; #endif // POWERGRAPHITEM_H diff --git a/src/GUI/routeitem.cpp b/src/GUI/routeitem.cpp index 90e6df99..8005c230 100644 --- a/src/GUI/routeitem.cpp +++ b/src/GUI/routeitem.cpp @@ -33,8 +33,6 @@ RouteItem::RouteItem(const Route &route, Map *map, QGraphicsItem *parent) _name = route.name(); _desc = route.description(); _coordinatesFormat = DecimalDegrees; - - setToolTip(toolTip(Metric)); } void RouteItem::setMap(Map *map) @@ -50,9 +48,8 @@ void RouteItem::setUnits(Units u) if (units() == u) return; - setToolTip(toolTip(units())); for (int i = 0; i < _waypoints.count(); i++) - _waypoints[i]->setToolTipFormat(units(), _coordinatesFormat); + _waypoints[i]->setToolTipFormat(u, _coordinatesFormat); PathItem::setUnits(u); } diff --git a/src/GUI/routeitem.h b/src/GUI/routeitem.h index 882e68ae..32e2dfec 100644 --- a/src/GUI/routeitem.h +++ b/src/GUI/routeitem.h @@ -23,9 +23,9 @@ public: void showWaypoints(bool show); void showWaypointLabels(bool show); -private: QString toolTip(Units units) const; +private: QString _name; QString _desc; CoordinatesFormat _coordinatesFormat; diff --git a/src/GUI/speedgraphitem.cpp b/src/GUI/speedgraphitem.cpp index 85d1343e..b92d03d3 100644 --- a/src/GUI/speedgraphitem.cpp +++ b/src/GUI/speedgraphitem.cpp @@ -8,26 +8,23 @@ SpeedGraphItem::SpeedGraphItem(const Graph &graph, GraphType type, int width, const QColor &color, qreal movingTime, QGraphicsItem *parent) : GraphItem(graph, type, width, color, parent) { - _units = Metric; _timeType = Total; _max = GraphItem::max(); _avg = graph.last().last().s() / graph.last().last().t(); _mavg = graph.last().last().s() / movingTime; - - setToolTip(toolTip()); } -QString SpeedGraphItem::toolTip() const +QString SpeedGraphItem::toolTip(Units units) 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()); @@ -40,14 +37,7 @@ QString SpeedGraphItem::toolTip() const return tt.toString(); } -void SpeedGraphItem::setUnits(Units units) -{ - _units = units; - setToolTip(toolTip()); -} - void SpeedGraphItem::setTimeType(TimeType type) { _timeType = type; - setToolTip(toolTip()); } diff --git a/src/GUI/speedgraphitem.h b/src/GUI/speedgraphitem.h index c39048be..6bc79ade 100644 --- a/src/GUI/speedgraphitem.h +++ b/src/GUI/speedgraphitem.h @@ -16,15 +16,13 @@ public: qreal mavg() const {return _mavg;} qreal max() const {return _max;} - void setUnits(Units units); + QString toolTip(Units units) const; + void setTimeType(TimeType type); private: - QString toolTip() const; - qreal _avg, _mavg, _max; TimeType _timeType; - Units _units; }; #endif // SPEEDGRAPHITEM_H diff --git a/src/GUI/temperaturegraphitem.cpp b/src/GUI/temperaturegraphitem.cpp index 10b20ae5..ecad7bfd 100644 --- a/src/GUI/temperaturegraphitem.cpp +++ b/src/GUI/temperaturegraphitem.cpp @@ -10,8 +10,6 @@ TemperatureGraphItem::TemperatureGraphItem(const Graph &graph, GraphType type, _min = GraphItem::min(); _max = GraphItem::max(); _avg = GraphItem::avg(); - - setToolTip(toolTip(Metric)); } QString TemperatureGraphItem::toolTip(Units units) const @@ -32,8 +30,3 @@ QString TemperatureGraphItem::toolTip(Units units) const return tt.toString(); } - -void TemperatureGraphItem::setUnits(Units units) -{ - setToolTip(toolTip(units)); -} diff --git a/src/GUI/temperaturegraphitem.h b/src/GUI/temperaturegraphitem.h index 11931c62..15c08ab4 100644 --- a/src/GUI/temperaturegraphitem.h +++ b/src/GUI/temperaturegraphitem.h @@ -15,11 +15,9 @@ public: qreal min() const {return _min;} qreal avg() const {return _avg;} - void setUnits(Units units); - -private: QString toolTip(Units units) const; +private: qreal _min, _max, _avg; }; diff --git a/src/GUI/tooltip.cpp b/src/GUI/tooltip.cpp index 8e573c50..d96270cc 100644 --- a/src/GUI/tooltip.cpp +++ b/src/GUI/tooltip.cpp @@ -1,4 +1,6 @@ #include +#include +#include "popup.h" #include "tooltip.h" @@ -26,7 +28,8 @@ QString ToolTip::toString() const } html += "
"; - html += QString("") + html += QString("" + "") .arg(_img.path(), QString::number(width), QString::number(height)); html += "
"; } diff --git a/src/GUI/trackitem.cpp b/src/GUI/trackitem.cpp index 0ee8a828..217e6281 100644 --- a/src/GUI/trackitem.cpp +++ b/src/GUI/trackitem.cpp @@ -33,12 +33,4 @@ TrackItem::TrackItem(const Track &track, Map *map, QGraphicsItem *parent) _date = track.date(); _time = track.time(); _movingTime = track.movingTime(); - - setToolTip(toolTip(Metric)); -} - -void TrackItem::setUnits(Units units) -{ - setToolTip(toolTip(units)); - PathItem::setUnits(units); } diff --git a/src/GUI/trackitem.h b/src/GUI/trackitem.h index 39a5d3e7..4e4bdbab 100644 --- a/src/GUI/trackitem.h +++ b/src/GUI/trackitem.h @@ -16,11 +16,9 @@ class TrackItem : public PathItem public: TrackItem(const Track &track, Map *map, QGraphicsItem *parent = 0); - void setUnits(Units units); - -private: QString toolTip(Units units) const; +private: QString _name; QString _desc; QDateTime _date; diff --git a/src/GUI/waypointitem.cpp b/src/GUI/waypointitem.cpp index 83c5b781..30f3b726 100644 --- a/src/GUI/waypointitem.cpp +++ b/src/GUI/waypointitem.cpp @@ -1,7 +1,10 @@ #include #include +#include +#include #include "font.h" #include "tooltip.h" +#include "popup.h" #include "waypointitem.h" @@ -10,7 +13,7 @@ #define FS(size) \ ((int)((qreal)size * 1.41)) -QString WaypointItem::toolTip(Units units, CoordinatesFormat format) +ToolTip WaypointItem::toolTip(Units units, CoordinatesFormat format) { ToolTip tt; @@ -29,7 +32,7 @@ QString WaypointItem::toolTip(Units units, CoordinatesFormat format) _waypoint.description()); tt.setImage(_waypoint.image()); - return tt.toString(); + return tt; } WaypointItem::WaypointItem(const Waypoint &waypoint, Map *map, @@ -43,10 +46,12 @@ WaypointItem::WaypointItem(const Waypoint &waypoint, Map *map, _font.setPixelSize(FS(_size)); _font.setFamily(FONT_FAMILY); + _units = Metric; + _format = DecimalDegrees; + updateCache(); setPos(map->ll2xy(waypoint.coordinates())); - setToolTip(toolTip(Metric, DecimalDegrees)); setCursor(Qt::ArrowCursor); setAcceptHoverEvents(true); } @@ -116,7 +121,8 @@ void WaypointItem::setColor(const QColor &color) void WaypointItem::setToolTipFormat(Units units, CoordinatesFormat format) { - setToolTip(toolTip(units, format)); + _units = units; + _format = format; } void WaypointItem::showLabel(bool show) @@ -148,3 +154,10 @@ void WaypointItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) updateCache(); setZValue(zValue() - 1.0); } + +void WaypointItem::mousePressEvent(QGraphicsSceneMouseEvent *event) +{ + ToolTip tt(toolTip(_units, _format)); + Popup::show(event->screenPos(), tt.toString(), event->widget()); + QGraphicsItem::mousePressEvent(event); +} diff --git a/src/GUI/waypointitem.h b/src/GUI/waypointitem.h index 77b96d08..4829d121 100644 --- a/src/GUI/waypointitem.h +++ b/src/GUI/waypointitem.h @@ -7,6 +7,8 @@ #include "map/map.h" #include "units.h" #include "format.h" +#include "tooltip.h" + class WaypointItem : public QGraphicsItem { @@ -16,23 +18,25 @@ public: const Waypoint &waypoint() const {return _waypoint;} void setMap(Map *map) {setPos(map->ll2xy(_waypoint.coordinates()));} - void setToolTipFormat(Units units, CoordinatesFormat format); void setSize(int size); void setColor(const QColor &color); void showLabel(bool show); void setDigitalZoom(int zoom) {setScale(pow(2, -zoom));} + void setToolTipFormat(Units units, CoordinatesFormat format); QPainterPath shape() const {return _shape;} QRectF boundingRect() const {return _shape.boundingRect();} void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); -private: +protected: void hoverEnterEvent(QGraphicsSceneHoverEvent *event); void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); + void mousePressEvent(QGraphicsSceneMouseEvent *event); +private: void updateCache(); - QString toolTip(Units units, CoordinatesFormat format); + ToolTip toolTip(Units units, CoordinatesFormat format); Waypoint _waypoint; QPainterPath _shape; @@ -41,6 +45,9 @@ private: bool _showLabel; QFont _font; QRect _labelBB; + + Units _units; + CoordinatesFormat _format; }; #endif // WAYPOINTITEM_H