1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-28 05:34:47 +01:00
GPXSee/src/waypointitem.cpp

50 lines
1.1 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"
2016-02-19 21:34:55 +01:00
#include "waypointitem.h"
2015-10-05 01:43:48 +02:00
#define POINT_SIZE 8
2016-02-19 21:42:54 +01:00
WaypointItem::WaypointItem(const Waypoint &entry, QGraphicsItem *parent)
2015-10-17 01:33:02 +02:00
: QGraphicsItem(parent)
2015-10-05 01:43:48 +02:00
{
2015-11-23 02:37:08 +01:00
_entry = entry;
2015-10-05 01:43:48 +02:00
updateBoundingRect();
}
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(_entry.description());
2015-10-05 01:43:48 +02:00
_boundingRect = QRectF(0, 0, ts.width() + POINT_SIZE,
ts.height() + fm.descent() + POINT_SIZE);
}
2016-02-19 21:42:54 +01:00
void WaypointItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
2015-10-05 01:43:48 +02:00
QWidget *widget)
{
Q_UNUSED(option);
Q_UNUSED(widget);
QFont font;
font.setPixelSize(FONT_SIZE);
font.setFamily(FONT_FAMILY);
QFontMetrics fm(font);
QRect ts = fm.tightBoundingRect(_entry.description());
2015-10-05 01:43:48 +02:00
painter->setFont(font);
painter->drawText(POINT_SIZE - qMax(ts.x(), 0), POINT_SIZE + ts.height(),
_entry.description());
2015-10-05 01:43:48 +02:00
painter->setBrush(Qt::SolidPattern);
painter->drawEllipse(0, 0, POINT_SIZE, POINT_SIZE);
/*
painter->setPen(Qt::red);
painter->setBrush(Qt::NoBrush);
painter->drawRect(boundingRect());
*/
}