2015-10-05 01:43:48 +02:00
|
|
|
#include <QPainter>
|
2015-10-17 01:33:02 +02:00
|
|
|
#include "config.h"
|
2016-07-28 00:23:22 +02:00
|
|
|
#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
|
|
|
|
|
2016-07-28 00:23:22 +02:00
|
|
|
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
|
|
|
{
|
2016-07-28 00:23:22 +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
|
|
|
|
2016-07-28 00:23:22 +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);
|
2016-07-28 00:23:22 +02:00
|
|
|
QRect ts = fm.tightBoundingRect(_label);
|
2015-10-05 01:43:48 +02:00
|
|
|
|
2016-03-13 17:44:25 +01: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);
|
2016-07-28 00:23:22 +02:00
|
|
|
QRect ts = fm.tightBoundingRect(_label);
|
2015-10-05 01:43:48 +02:00
|
|
|
|
|
|
|
painter->setFont(font);
|
2016-03-13 17:44:25 +01:00
|
|
|
painter->drawText(POINT_SIZE/2 - qMax(ts.x(), 0), POINT_SIZE/2 + ts.height(),
|
2016-07-28 00:23:22 +02:00
|
|
|
_label);
|
2015-10-05 01:43:48 +02:00
|
|
|
painter->setBrush(Qt::SolidPattern);
|
2016-03-13 17:44:25 +01:00
|
|
|
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());
|
|
|
|
*/
|
|
|
|
}
|