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

Hyperlink + copy&paste enabled tool tips

This commit is contained in:
Martin Tůma 2019-10-13 20:20:32 +02:00
parent de9bae9d66
commit a9ce6f54c7
33 changed files with 286 additions and 96 deletions

View File

@ -19,6 +19,7 @@ equals(QT_MAJOR_VERSION, 5) : lessThan(QT_MINOR_VERSION, 4) {QT += opengl}
INCLUDEPATH += ./src INCLUDEPATH += ./src
HEADERS += src/common/config.h \ HEADERS += src/common/config.h \
src/GUI/popup.h \
src/common/staticassert.h \ src/common/staticassert.h \
src/common/coordinates.h \ src/common/coordinates.h \
src/common/range.h \ src/common/range.h \
@ -185,6 +186,7 @@ HEADERS += src/common/config.h \
src/data/csv.h \ src/data/csv.h \
src/data/cupparser.h src/data/cupparser.h
SOURCES += src/main.cpp \ SOURCES += src/main.cpp \
src/GUI/popup.cpp \
src/common/coordinates.cpp \ src/common/coordinates.cpp \
src/common/rectc.cpp \ src/common/rectc.cpp \
src/common/range.cpp \ src/common/range.cpp \

View File

@ -7,11 +7,11 @@ CadenceGraphItem::CadenceGraphItem(const Graph &graph, GraphType type,
int width, const QColor &color, QGraphicsItem *parent) int width, const QColor &color, QGraphicsItem *parent)
: GraphItem(graph, type, width, color, parent) : GraphItem(graph, type, width, color, parent)
{ {
setToolTip(toolTip());
} }
QString CadenceGraphItem::toolTip() const QString CadenceGraphItem::toolTip(Units units) const
{ {
Q_UNUSED(units);
ToolTip tt; ToolTip tt;
QLocale l(QLocale::system()); QLocale l(QLocale::system());

View File

@ -11,8 +11,7 @@ public:
CadenceGraphItem(const Graph &graph, GraphType type, int width, CadenceGraphItem(const Graph &graph, GraphType type, int width,
const QColor &color, QGraphicsItem *parent = 0); const QColor &color, QGraphicsItem *parent = 0);
private: QString toolTip(Units units) const;
QString toolTip() const;
}; };
#endif // CADENCEGRAPHITEM_H #endif // CADENCEGRAPHITEM_H

View File

@ -24,8 +24,6 @@ ElevationGraphItem::ElevationGraphItem(const Graph &graph, GraphType type,
_descent += prev - cur; _descent += prev - cur;
} }
} }
setToolTip(toolTip(Metric));
} }
QString ElevationGraphItem::toolTip(Units units) const QString ElevationGraphItem::toolTip(Units units) const
@ -46,8 +44,3 @@ QString ElevationGraphItem::toolTip(Units units) const
return tt.toString(); return tt.toString();
} }
void ElevationGraphItem::setUnits(Units units)
{
setToolTip(toolTip(units));
}

View File

@ -16,11 +16,9 @@ public:
qreal max() const {return _max;} qreal max() const {return _max;}
qreal min() const {return _min;} qreal min() const {return _min;}
void setUnits(Units units);
private:
QString toolTip(Units units) const; QString toolTip(Units units) const;
private:
qreal _ascent, _descent, _min, _max; qreal _ascent, _descent, _min, _max;
}; };

View File

@ -25,12 +25,11 @@ GearRatioGraphItem::GearRatioGraphItem(const Graph &graph, GraphType type,
} }
} }
_top = key; _top = key;
setToolTip(toolTip());
} }
QString GearRatioGraphItem::toolTip() const QString GearRatioGraphItem::toolTip(Units units) const
{ {
Q_UNUSED(units);
ToolTip tt; ToolTip tt;
QLocale l(QLocale::system()); QLocale l(QLocale::system());

View File

@ -13,12 +13,11 @@ public:
const QColor &color, QGraphicsItem *parent = 0); const QColor &color, QGraphicsItem *parent = 0);
qreal top() const {return _top;} qreal top() const {return _top;}
const QMap<qreal, qreal> &map() const {return _map;} const QMap<qreal, qreal> &map() const {return _map;}
private: QString toolTip(Units units) const;
QString toolTip() const;
private:
QMap<qreal, qreal> _map; QMap<qreal, qreal> _map;
qreal _top; qreal _top;
}; };

View File

@ -1,4 +1,6 @@
#include <QPainter> #include <QPainter>
#include <QGraphicsSceneMouseEvent>
#include "popup.h"
#include "graphitem.h" #include "graphitem.h"
@ -8,6 +10,7 @@ GraphItem::GraphItem(const Graph &graph, GraphType type, int width,
{ {
Q_ASSERT(_graph.isValid()); Q_ASSERT(_graph.isValid());
_units = Metric;
_pen = QPen(color, width); _pen = QPen(color, width);
_sx = 0; _sy = 0; _sx = 0; _sy = 0;
_time = _graph.hasTime(); _time = _graph.hasTime();
@ -303,3 +306,9 @@ void GraphItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
emit selected(false); emit selected(false);
} }
void GraphItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
Popup::show(event->screenPos(), toolTip(_units), event->widget());
QGraphicsObject::mousePressEvent(event);
}

View File

@ -15,6 +15,8 @@ public:
QGraphicsItem *parent = 0); QGraphicsItem *parent = 0);
virtual ~GraphItem() {} virtual ~GraphItem() {}
virtual QString toolTip(Units units) const = 0;
QPainterPath shape() const {return _shape;} QPainterPath shape() const {return _shape;}
QRectF boundingRect() const {return _shape.boundingRect();} QRectF boundingRect() const {return _shape.boundingRect();}
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
@ -30,7 +32,7 @@ public:
void setGraphType(GraphType type); void setGraphType(GraphType type);
void setColor(const QColor &color); void setColor(const QColor &color);
void setWidth(int width); void setWidth(int width);
virtual void setUnits(Units units) {Q_UNUSED(units);} void setUnits(Units units) {_units = units;}
qreal yAtX(qreal x); qreal yAtX(qreal x);
qreal distanceAtTime(qreal time); qreal distanceAtTime(qreal time);
@ -45,10 +47,12 @@ public slots:
void emitSliderPositionChanged(qreal); void emitSliderPositionChanged(qreal);
void hover(bool hover); void hover(bool hover);
private: protected:
void hoverEnterEvent(QGraphicsSceneHoverEvent *event); void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
void mousePressEvent(QGraphicsSceneMouseEvent *event);
private:
const GraphSegment *segment(qreal x, GraphType type) const; const GraphSegment *segment(qreal x, GraphType type) const;
void updatePath(); void updatePath();
void updateShape(); void updateShape();
@ -56,6 +60,7 @@ private:
Graph _graph; Graph _graph;
GraphType _type; GraphType _type;
Units _units;
QPainterPath _path; QPainterPath _path;
QPainterPath _shape; QPainterPath _shape;
QRectF _bounds; QRectF _bounds;

View File

@ -357,13 +357,13 @@ void GraphView::wheelEvent(QWheelEvent *e)
QGraphicsView::wheelEvent(e); QGraphicsView::wheelEvent(e);
} }
void GraphView::paintEvent(QPaintEvent *event) void GraphView::paintEvent(QPaintEvent *e)
{ {
QRectF viewRect(mapToScene(rect()).boundingRect()); QRectF viewRect(mapToScene(rect()).boundingRect());
_info->setPos(QPointF(viewRect.left() + (viewRect.width() _info->setPos(QPointF(viewRect.left() + (viewRect.width()
- _info->boundingRect().width())/2.0, _info->pos().y())); - _info->boundingRect().width())/2.0, _info->pos().y()));
QGraphicsView::paintEvent(event); QGraphicsView::paintEvent(e);
} }
void GraphView::plot(QPainter *painter, const QRectF &target, qreal scale) void GraphView::plot(QPainter *painter, const QRectF &target, qreal scale)

View File

@ -48,10 +48,15 @@ signals:
protected: protected:
void addGraph(GraphItem *graph); void addGraph(GraphItem *graph);
void removeGraph(GraphItem *graph); void removeGraph(GraphItem *graph);
void setGraphType(GraphType type); void setGraphType(GraphType type);
void setUnits(Units units); 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 &yLabel() const {return _yLabel;}
const QString &yUnits() const {return _yUnits;} const QString &yUnits() const {return _yUnits;}
qreal yScale() const {return _yScale;} qreal yScale() const {return _yScale;}
@ -88,12 +93,6 @@ private:
void removeItem(QGraphicsItem *item); void removeItem(QGraphicsItem *item);
void addItem(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; QGraphicsScene *_scene;
AxisItem *_xAxis, *_yAxis; AxisItem *_xAxis, *_yAxis;

View File

@ -1580,7 +1580,6 @@ void GUI::keyPressEvent(QKeyEvent *event)
else else
_movingTimeAction->trigger(); _movingTimeAction->trigger();
break; break;
case Qt::Key_Escape: case Qt::Key_Escape:
if (_fullscreenAction->isChecked()) { if (_fullscreenAction->isChecked()) {
_fullscreenAction->setChecked(false); _fullscreenAction->setChecked(false);

View File

@ -7,11 +7,11 @@ HeartRateGraphItem::HeartRateGraphItem(const Graph &graph, GraphType type,
int width, const QColor &color, QGraphicsItem *parent) int width, const QColor &color, QGraphicsItem *parent)
: GraphItem(graph, type, width, color, parent) : GraphItem(graph, type, width, color, parent)
{ {
setToolTip(toolTip());
} }
QString HeartRateGraphItem::toolTip() const QString HeartRateGraphItem::toolTip(Units units) const
{ {
Q_UNUSED(units);
ToolTip tt; ToolTip tt;
QLocale l(QLocale::system()); QLocale l(QLocale::system());

View File

@ -11,8 +11,7 @@ public:
HeartRateGraphItem(const Graph &graph, GraphType type, int width, HeartRateGraphItem(const Graph &graph, GraphType type, int width,
const QColor &color, QGraphicsItem *parent = 0); const QColor &color, QGraphicsItem *parent = 0);
private: QString toolTip(Units units) const;
QString toolTip() const;
}; };
#endif // HEARTRATEGRAPHITEM_H #endif // HEARTRATEGRAPHITEM_H

View File

@ -1,9 +1,11 @@
#include <cmath> #include <cmath>
#include <QCursor> #include <QCursor>
#include <QPainter> #include <QPainter>
#include <QGraphicsSceneMouseEvent>
#include "common/greatcircle.h" #include "common/greatcircle.h"
#include "map/map.h" #include "map/map.h"
#include "pathtickitem.h" #include "pathtickitem.h"
#include "popup.h"
#include "pathitem.h" #include "pathitem.h"
@ -336,7 +338,6 @@ void PathItem::updateTicks()
_ticks[i] = new PathTickItem(tr, (i + 1) * ts, this); _ticks[i] = new PathTickItem(tr, (i + 1) * ts, this);
_ticks[i]->setPos(position((i + 1) * ts * xInM())); _ticks[i]->setPos(position((i + 1) * ts * xInM()));
_ticks[i]->setColor(_pen.color()); _ticks[i]->setColor(_pen.color());
_ticks[i]->setToolTip(toolTip());
} }
} }
@ -381,3 +382,9 @@ void PathItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
emit selected(false); emit selected(false);
} }
void PathItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
Popup::show(event->screenPos(), toolTip(_units), event->widget());
QGraphicsObject::mousePressEvent(event);
}

View File

@ -16,6 +16,9 @@ class PathItem : public QGraphicsObject
public: public:
PathItem(const Path &path, Map *map, QGraphicsItem *parent = 0); PathItem(const Path &path, Map *map, QGraphicsItem *parent = 0);
virtual ~PathItem() {}
virtual QString toolTip(Units units) const = 0;
QPainterPath shape() const {return _shape;} QPainterPath shape() const {return _shape;}
QRectF boundingRect() const {return _shape.boundingRect();} QRectF boundingRect() const {return _shape.boundingRect();}
@ -44,6 +47,11 @@ public slots:
signals: signals:
void selected(bool); void selected(bool);
protected:
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
void mousePressEvent(QGraphicsSceneMouseEvent *event);
private: private:
const PathSegment *segment(qreal x) const; const PathSegment *segment(qreal x) const;
QPointF position(qreal distance) const; QPointF position(qreal distance) const;
@ -55,9 +63,6 @@ private:
unsigned tickSize() const; unsigned tickSize() const;
void updateTicks(); void updateTicks();
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
Path _path; Path _path;
Map *_map; Map *_map;
qreal _markerDistance; qreal _markerDistance;

View File

@ -1,6 +1,9 @@
#include <QPainter> #include <QPainter>
#include <QCursor> #include <QCursor>
#include <QGraphicsSceneMouseEvent>
#include "font.h" #include "font.h"
#include "popup.h"
#include "pathitem.h"
#include "pathtickitem.h" #include "pathtickitem.h"
@ -69,3 +72,10 @@ QRect PathTickItem::tickRect(int value)
return fm.boundingRect(QRect(), Qt::AlignCenter, return fm.boundingRect(QRect(), Qt::AlignCenter,
QString::number(qMax(value, 10))).adjusted(-2, 0, 2, 0); QString::number(qMax(value, 10))).adjusted(-2, 0, 2, 0);
} }
void PathTickItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
const PathItem *pi = static_cast<PathItem*>(parentItem());
Popup::show(event->screenPos(), pi->toolTip(pi->units()), event->widget());
QGraphicsItem::mousePressEvent(event);
}

View File

@ -18,6 +18,9 @@ public:
static QRect tickRect(int value); static QRect tickRect(int value);
protected:
void mousePressEvent(QGraphicsSceneMouseEvent *event);
private: private:
QRectF _tickRect; QRectF _tickRect;
QString _text; QString _text;

162
src/GUI/popup.cpp Normal file
View File

@ -0,0 +1,162 @@
#include <QToolTip>
#include <QStyle>
#include <QStylePainter>
#include <QStyleOptionFrame>
#include <QLabel>
#include <QMouseEvent>
#include <QApplication>
#include <QDesktopWidget>
#include <QBasicTimer>
#include "popup.h"
#include <QDebug>
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<QKeyEvent *>(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<QMouseEvent*>(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);
}

14
src/GUI/popup.h Normal file
View File

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

View File

@ -7,11 +7,11 @@ PowerGraphItem::PowerGraphItem(const Graph &graph, GraphType type, int width,
const QColor &color, QGraphicsItem *parent) const QColor &color, QGraphicsItem *parent)
: GraphItem(graph, type, width, color, parent) : GraphItem(graph, type, width, color, parent)
{ {
setToolTip(toolTip());
} }
QString PowerGraphItem::toolTip() const QString PowerGraphItem::toolTip(Units units) const
{ {
Q_UNUSED(units);
ToolTip tt; ToolTip tt;
QLocale l(QLocale::system()); QLocale l(QLocale::system());

View File

@ -11,8 +11,7 @@ public:
PowerGraphItem(const Graph &graph, GraphType type, int width, PowerGraphItem(const Graph &graph, GraphType type, int width,
const QColor &color, QGraphicsItem *parent = 0); const QColor &color, QGraphicsItem *parent = 0);
private: QString toolTip(Units units) const;
QString toolTip() const;
}; };
#endif // POWERGRAPHITEM_H #endif // POWERGRAPHITEM_H

View File

@ -33,8 +33,6 @@ RouteItem::RouteItem(const Route &route, Map *map, QGraphicsItem *parent)
_name = route.name(); _name = route.name();
_desc = route.description(); _desc = route.description();
_coordinatesFormat = DecimalDegrees; _coordinatesFormat = DecimalDegrees;
setToolTip(toolTip(Metric));
} }
void RouteItem::setMap(Map *map) void RouteItem::setMap(Map *map)
@ -50,9 +48,8 @@ void RouteItem::setUnits(Units u)
if (units() == u) if (units() == u)
return; return;
setToolTip(toolTip(units()));
for (int i = 0; i < _waypoints.count(); i++) for (int i = 0; i < _waypoints.count(); i++)
_waypoints[i]->setToolTipFormat(units(), _coordinatesFormat); _waypoints[i]->setToolTipFormat(u, _coordinatesFormat);
PathItem::setUnits(u); PathItem::setUnits(u);
} }

View File

@ -23,9 +23,9 @@ public:
void showWaypoints(bool show); void showWaypoints(bool show);
void showWaypointLabels(bool show); void showWaypointLabels(bool show);
private:
QString toolTip(Units units) const; QString toolTip(Units units) const;
private:
QString _name; QString _name;
QString _desc; QString _desc;
CoordinatesFormat _coordinatesFormat; CoordinatesFormat _coordinatesFormat;

View File

@ -8,26 +8,23 @@ SpeedGraphItem::SpeedGraphItem(const Graph &graph, GraphType type, int width,
const QColor &color, qreal movingTime, QGraphicsItem *parent) const QColor &color, qreal movingTime, QGraphicsItem *parent)
: GraphItem(graph, type, width, color, parent) : GraphItem(graph, type, width, color, parent)
{ {
_units = Metric;
_timeType = Total; _timeType = Total;
_max = GraphItem::max(); _max = GraphItem::max();
_avg = graph.last().last().s() / graph.last().last().t(); _avg = graph.last().last().s() / graph.last().last().t();
_mavg = graph.last().last().s() / movingTime; _mavg = graph.last().last().s() / movingTime;
setToolTip(toolTip());
} }
QString SpeedGraphItem::toolTip() const QString SpeedGraphItem::toolTip(Units units) const
{ {
ToolTip tt; ToolTip tt;
qreal scale = (_units == Imperial) ? MS2MIH : (_units == Nautical) qreal scale = (units == Imperial) ? MS2MIH : (units == Nautical)
? MS2KN : MS2KMH; ? 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"); ? tr("kn") : tr("km/h");
QString pace = Format::timeSpan((3600.0 / ((_timeType == Total) QString pace = Format::timeSpan((3600.0 / ((_timeType == Total)
? avg() * scale : mavg() * scale)), false); ? 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"); tr("min/mi") : tr("min/nmi");
QLocale l(QLocale::system()); QLocale l(QLocale::system());
@ -40,14 +37,7 @@ QString SpeedGraphItem::toolTip() const
return tt.toString(); return tt.toString();
} }
void SpeedGraphItem::setUnits(Units units)
{
_units = units;
setToolTip(toolTip());
}
void SpeedGraphItem::setTimeType(TimeType type) void SpeedGraphItem::setTimeType(TimeType type)
{ {
_timeType = type; _timeType = type;
setToolTip(toolTip());
} }

View File

@ -16,15 +16,13 @@ public:
qreal mavg() const {return _mavg;} qreal mavg() const {return _mavg;}
qreal max() const {return _max;} qreal max() const {return _max;}
void setUnits(Units units); QString toolTip(Units units) const;
void setTimeType(TimeType type); void setTimeType(TimeType type);
private: private:
QString toolTip() const;
qreal _avg, _mavg, _max; qreal _avg, _mavg, _max;
TimeType _timeType; TimeType _timeType;
Units _units;
}; };
#endif // SPEEDGRAPHITEM_H #endif // SPEEDGRAPHITEM_H

View File

@ -10,8 +10,6 @@ TemperatureGraphItem::TemperatureGraphItem(const Graph &graph, GraphType type,
_min = GraphItem::min(); _min = GraphItem::min();
_max = GraphItem::max(); _max = GraphItem::max();
_avg = GraphItem::avg(); _avg = GraphItem::avg();
setToolTip(toolTip(Metric));
} }
QString TemperatureGraphItem::toolTip(Units units) const QString TemperatureGraphItem::toolTip(Units units) const
@ -32,8 +30,3 @@ QString TemperatureGraphItem::toolTip(Units units) const
return tt.toString(); return tt.toString();
} }
void TemperatureGraphItem::setUnits(Units units)
{
setToolTip(toolTip(units));
}

View File

@ -15,11 +15,9 @@ public:
qreal min() const {return _min;} qreal min() const {return _min;}
qreal avg() const {return _avg;} qreal avg() const {return _avg;}
void setUnits(Units units);
private:
QString toolTip(Units units) const; QString toolTip(Units units) const;
private:
qreal _min, _max, _avg; qreal _min, _max, _avg;
}; };

View File

@ -1,4 +1,6 @@
#include <QImageReader> #include <QImageReader>
#include <QLabel>
#include "popup.h"
#include "tooltip.h" #include "tooltip.h"
@ -26,7 +28,8 @@ QString ToolTip::toString() const
} }
html += "<div align=\"center\">"; html += "<div align=\"center\">";
html += QString("<img src=\"file:%0\" width=\"%1\" height=\"%2\"/>") html += QString("<a href=\"file:%0\">"
"<img src=\"file:%0\" width=\"%1\" height=\"%2\"/></a>")
.arg(_img.path(), QString::number(width), QString::number(height)); .arg(_img.path(), QString::number(width), QString::number(height));
html += "</div>"; html += "</div>";
} }

View File

@ -33,12 +33,4 @@ TrackItem::TrackItem(const Track &track, Map *map, QGraphicsItem *parent)
_date = track.date(); _date = track.date();
_time = track.time(); _time = track.time();
_movingTime = track.movingTime(); _movingTime = track.movingTime();
setToolTip(toolTip(Metric));
}
void TrackItem::setUnits(Units units)
{
setToolTip(toolTip(units));
PathItem::setUnits(units);
} }

View File

@ -16,11 +16,9 @@ class TrackItem : public PathItem
public: public:
TrackItem(const Track &track, Map *map, QGraphicsItem *parent = 0); TrackItem(const Track &track, Map *map, QGraphicsItem *parent = 0);
void setUnits(Units units);
private:
QString toolTip(Units units) const; QString toolTip(Units units) const;
private:
QString _name; QString _name;
QString _desc; QString _desc;
QDateTime _date; QDateTime _date;

View File

@ -1,7 +1,10 @@
#include <QApplication> #include <QApplication>
#include <QPainter> #include <QPainter>
#include <QGraphicsSceneMouseEvent>
#include <QLabel>
#include "font.h" #include "font.h"
#include "tooltip.h" #include "tooltip.h"
#include "popup.h"
#include "waypointitem.h" #include "waypointitem.h"
@ -10,7 +13,7 @@
#define FS(size) \ #define FS(size) \
((int)((qreal)size * 1.41)) ((int)((qreal)size * 1.41))
QString WaypointItem::toolTip(Units units, CoordinatesFormat format) ToolTip WaypointItem::toolTip(Units units, CoordinatesFormat format)
{ {
ToolTip tt; ToolTip tt;
@ -29,7 +32,7 @@ QString WaypointItem::toolTip(Units units, CoordinatesFormat format)
_waypoint.description()); _waypoint.description());
tt.setImage(_waypoint.image()); tt.setImage(_waypoint.image());
return tt.toString(); return tt;
} }
WaypointItem::WaypointItem(const Waypoint &waypoint, Map *map, WaypointItem::WaypointItem(const Waypoint &waypoint, Map *map,
@ -43,10 +46,12 @@ WaypointItem::WaypointItem(const Waypoint &waypoint, Map *map,
_font.setPixelSize(FS(_size)); _font.setPixelSize(FS(_size));
_font.setFamily(FONT_FAMILY); _font.setFamily(FONT_FAMILY);
_units = Metric;
_format = DecimalDegrees;
updateCache(); updateCache();
setPos(map->ll2xy(waypoint.coordinates())); setPos(map->ll2xy(waypoint.coordinates()));
setToolTip(toolTip(Metric, DecimalDegrees));
setCursor(Qt::ArrowCursor); setCursor(Qt::ArrowCursor);
setAcceptHoverEvents(true); setAcceptHoverEvents(true);
} }
@ -116,7 +121,8 @@ void WaypointItem::setColor(const QColor &color)
void WaypointItem::setToolTipFormat(Units units, CoordinatesFormat format) void WaypointItem::setToolTipFormat(Units units, CoordinatesFormat format)
{ {
setToolTip(toolTip(units, format)); _units = units;
_format = format;
} }
void WaypointItem::showLabel(bool show) void WaypointItem::showLabel(bool show)
@ -148,3 +154,10 @@ void WaypointItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
updateCache(); updateCache();
setZValue(zValue() - 1.0); 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);
}

View File

@ -7,6 +7,8 @@
#include "map/map.h" #include "map/map.h"
#include "units.h" #include "units.h"
#include "format.h" #include "format.h"
#include "tooltip.h"
class WaypointItem : public QGraphicsItem class WaypointItem : public QGraphicsItem
{ {
@ -16,23 +18,25 @@ public:
const Waypoint &waypoint() const {return _waypoint;} const Waypoint &waypoint() const {return _waypoint;}
void setMap(Map *map) {setPos(map->ll2xy(_waypoint.coordinates()));} void setMap(Map *map) {setPos(map->ll2xy(_waypoint.coordinates()));}
void setToolTipFormat(Units units, CoordinatesFormat format);
void setSize(int size); void setSize(int size);
void setColor(const QColor &color); void setColor(const QColor &color);
void showLabel(bool show); void showLabel(bool show);
void setDigitalZoom(int zoom) {setScale(pow(2, -zoom));} void setDigitalZoom(int zoom) {setScale(pow(2, -zoom));}
void setToolTipFormat(Units units, CoordinatesFormat format);
QPainterPath shape() const {return _shape;} QPainterPath shape() const {return _shape;}
QRectF boundingRect() const {return _shape.boundingRect();} QRectF boundingRect() const {return _shape.boundingRect();}
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget); QWidget *widget);
private: protected:
void hoverEnterEvent(QGraphicsSceneHoverEvent *event); void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
void mousePressEvent(QGraphicsSceneMouseEvent *event);
private:
void updateCache(); void updateCache();
QString toolTip(Units units, CoordinatesFormat format); ToolTip toolTip(Units units, CoordinatesFormat format);
Waypoint _waypoint; Waypoint _waypoint;
QPainterPath _shape; QPainterPath _shape;
@ -41,6 +45,9 @@ private:
bool _showLabel; bool _showLabel;
QFont _font; QFont _font;
QRect _labelBB; QRect _labelBB;
Units _units;
CoordinatesFormat _format;
}; };
#endif // WAYPOINTITEM_H #endif // WAYPOINTITEM_H