1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-10-07 07:13:21 +02:00
GPXSee/src/waypointitem.cpp

70 lines
1.8 KiB
C++
Raw Normal View History

2015-10-05 01:43:48 +02:00
#include <QPainter>
2015-10-17 01:33:02 +02:00
#include "config.h"
#include "ll.h"
#include "misc.h"
2016-02-19 21:34:55 +01:00
#include "waypointitem.h"
2015-10-05 01:43:48 +02:00
#define POINT_SIZE 8
static QString tt(const Waypoint &waypoint)
{
QString date = waypoint.timestamp().toString(Qt::SystemLocaleShortDate);
return "<b>" + QObject::tr("Coordinates:") + "</b> "
+ coordinates(waypoint.coordinates()) + "<br><b>"
+ QObject::tr("Description:") + "</b> " + waypoint.description()
+ "<br><b>" + QObject::tr("Elevation:") + "</b> "
+ QString::number(waypoint.elevation() - waypoint.geoidHeight())
+ "<br><b>" + QObject::tr("Date:") + "</b> " + date;
}
WaypointItem::WaypointItem(const Waypoint &waypoint, QGraphicsItem *parent)
2015-10-17 01:33:02 +02:00
: QGraphicsItem(parent)
2015-10-05 01:43:48 +02:00
{
_label = waypoint.name();
_coordinates = ll2mercator(QPointF(waypoint.coordinates().x(),
-waypoint.coordinates().y()));
2015-10-05 01:43:48 +02:00
updateBoundingRect();
2016-07-25 19:32:36 +02:00
setToolTip(tt(waypoint));
setCursor(Qt::ArrowCursor);
2015-10-05 01:43:48 +02:00
}
2016-02-19 21:42:54 +01:00
void WaypointItem::updateBoundingRect()
2015-10-05 01:43:48 +02:00
{
QFont font;
font.setPixelSize(FONT_SIZE);
font.setFamily(FONT_FAMILY);
QFontMetrics fm(font);
QRect ts = fm.tightBoundingRect(_label);
2015-10-05 01:43:48 +02:00
_boundingRect = QRectF(-POINT_SIZE/2, -POINT_SIZE/2, ts.width()
+ POINT_SIZE, ts.height() + fm.descent() + POINT_SIZE);
2015-10-05 01:43:48 +02:00
}
2016-07-25 19:32:36 +02:00
void WaypointItem::paint(QPainter *painter,
const QStyleOptionGraphicsItem *option, QWidget *widget)
2015-10-05 01:43:48 +02:00
{
Q_UNUSED(option);
Q_UNUSED(widget);
QFont font;
font.setPixelSize(FONT_SIZE);
font.setFamily(FONT_FAMILY);
QFontMetrics fm(font);
QRect ts = fm.tightBoundingRect(_label);
2015-10-05 01:43:48 +02:00
painter->setFont(font);
painter->drawText(POINT_SIZE/2 - qMax(ts.x(), 0), POINT_SIZE/2 + ts.height(),
_label);
2015-10-05 01:43:48 +02:00
painter->setBrush(Qt::SolidPattern);
painter->drawEllipse(-POINT_SIZE/2, -POINT_SIZE/2, POINT_SIZE, POINT_SIZE);
2015-10-05 01:43:48 +02:00
/*
painter->setPen(Qt::red);
painter->setBrush(Qt::NoBrush);
painter->drawRect(boundingRect());
*/
}