mirror of
https://github.com/tumic0/GPXSee.git
synced 2025-07-25 07:54:24 +02:00
Initial commit
This commit is contained in:
51
src/poiitem.cpp
Normal file
51
src/poiitem.cpp
Normal file
@ -0,0 +1,51 @@
|
||||
#include <QPainter>
|
||||
#include "poiitem.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
#define FONT_FAMILY "Arial"
|
||||
#define FONT_SIZE 12
|
||||
#define POINT_SIZE 8
|
||||
|
||||
|
||||
POIItem::POIItem(const QString &text)
|
||||
{
|
||||
_text = text;
|
||||
updateBoundingRect();
|
||||
}
|
||||
|
||||
void POIItem::updateBoundingRect()
|
||||
{
|
||||
QFont font;
|
||||
font.setPixelSize(FONT_SIZE);
|
||||
font.setFamily(FONT_FAMILY);
|
||||
QFontMetrics fm(font);
|
||||
QRect ts = fm.tightBoundingRect(_text);
|
||||
|
||||
_boundingRect = QRectF(0, 0, ts.width() + POINT_SIZE,
|
||||
ts.height() + fm.descent() + POINT_SIZE);
|
||||
}
|
||||
|
||||
void POIItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
||||
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(_text);
|
||||
|
||||
painter->setFont(font);
|
||||
painter->drawText(POINT_SIZE - qMax(ts.x(), 0), POINT_SIZE + ts.height(),
|
||||
_text);
|
||||
painter->setBrush(Qt::SolidPattern);
|
||||
painter->drawEllipse(0, 0, POINT_SIZE, POINT_SIZE);
|
||||
|
||||
/*
|
||||
painter->setPen(Qt::red);
|
||||
painter->setBrush(Qt::NoBrush);
|
||||
painter->drawRect(boundingRect());
|
||||
*/
|
||||
}
|
Reference in New Issue
Block a user