2016-08-02 20:46:22 +02:00
|
|
|
#include <QApplication>
|
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-08-02 00:28:56 +02:00
|
|
|
#include "tooltip.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-08-02 00:28:56 +02:00
|
|
|
QString WaypointItem::toolTip()
|
2016-07-28 00:23:22 +02:00
|
|
|
{
|
2016-08-02 00:28:56 +02:00
|
|
|
ToolTip tt;
|
|
|
|
|
2016-08-09 01:16:19 +02:00
|
|
|
if (!_waypoint.name().isEmpty() && !_showLabel)
|
|
|
|
tt.insert(qApp->translate("WaypointItem", "Name"), _waypoint.name());
|
2016-08-02 20:46:22 +02:00
|
|
|
tt.insert(qApp->translate("WaypointItem", "Coordinates"),
|
|
|
|
::coordinates(_waypoint.coordinates()));
|
|
|
|
if (!std::isnan(_waypoint.elevation()))
|
|
|
|
tt.insert(qApp->translate("WaypointItem", "Elevation"),
|
|
|
|
::elevation(_waypoint.elevation() - _waypoint.geoidHeight(), _units));
|
|
|
|
if (!_waypoint.timestamp().isNull())
|
|
|
|
tt.insert(qApp->translate("WaypointItem", "Date"),
|
|
|
|
_waypoint.timestamp().toString(Qt::SystemLocaleShortDate));
|
|
|
|
if (!_waypoint.description().isNull())
|
|
|
|
tt.insert(qApp->translate("WaypointItem", "Description"),
|
|
|
|
_waypoint.description());
|
2016-08-02 00:28:56 +02:00
|
|
|
|
|
|
|
return tt.toString();
|
2016-07-28 00:23:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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-08-02 00:28:56 +02:00
|
|
|
_units = Metric;
|
2016-08-09 01:16:19 +02:00
|
|
|
_showLabel = true;
|
2016-08-02 00:28:56 +02:00
|
|
|
|
2016-08-02 20:46:22 +02:00
|
|
|
_waypoint = waypoint;
|
2016-07-28 00:23:22 +02:00
|
|
|
_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-08-02 20:46:22 +02:00
|
|
|
setPos(_coordinates);
|
2016-08-02 00:28:56 +02:00
|
|
|
setToolTip(toolTip());
|
2016-07-28 00:23:22 +02:00
|
|
|
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
|
|
|
{
|
2016-08-09 01:16:19 +02:00
|
|
|
if (_showLabel) {
|
|
|
|
QFont font;
|
|
|
|
font.setPixelSize(FONT_SIZE);
|
|
|
|
font.setFamily(FONT_FAMILY);
|
|
|
|
QFontMetrics fm(font);
|
|
|
|
QRect ts = fm.tightBoundingRect(_waypoint.name());
|
|
|
|
|
|
|
|
_boundingRect = QRectF(-POINT_SIZE/2, -POINT_SIZE/2, ts.width()
|
|
|
|
+ POINT_SIZE, ts.height() + fm.descent() + POINT_SIZE);
|
|
|
|
} else
|
|
|
|
_boundingRect = QRectF(-POINT_SIZE/2, -POINT_SIZE/2, POINT_SIZE,
|
|
|
|
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);
|
2016-08-09 01:16:19 +02:00
|
|
|
|
|
|
|
if (_showLabel) {
|
|
|
|
QFont font;
|
|
|
|
font.setPixelSize(FONT_SIZE);
|
|
|
|
font.setFamily(FONT_FAMILY);
|
|
|
|
QFontMetrics fm(font);
|
|
|
|
QRect ts = fm.tightBoundingRect(_waypoint.name());
|
|
|
|
|
|
|
|
painter->setFont(font);
|
|
|
|
painter->drawText(POINT_SIZE/2 - qMax(ts.x(), 0), POINT_SIZE/2
|
|
|
|
+ ts.height(), _waypoint.name());
|
|
|
|
}
|
|
|
|
|
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());
|
|
|
|
*/
|
|
|
|
}
|
2016-08-02 00:28:56 +02:00
|
|
|
|
|
|
|
void WaypointItem::setScale(qreal scale)
|
|
|
|
{
|
|
|
|
setPos(_coordinates * scale);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WaypointItem::setUnits(enum Units units)
|
|
|
|
{
|
|
|
|
_units = units;
|
|
|
|
setToolTip(toolTip());
|
|
|
|
}
|
2016-08-09 01:16:19 +02:00
|
|
|
|
|
|
|
void WaypointItem::showLabel(bool show)
|
|
|
|
{
|
|
|
|
prepareGeometryChange();
|
|
|
|
_showLabel = show;
|
|
|
|
updateBoundingRect();
|
|
|
|
setToolTip(toolTip());
|
|
|
|
}
|