1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-10-06 23:03:22 +02:00
GPXSee/src/sliderinfoitem.cpp

47 lines
968 B
C++
Raw Normal View History

2015-10-17 01:33:02 +02:00
#include <QPainter>
#include "config.h"
#include "sliderinfoitem.h"
#define SIZE 5
SliderInfoItem::SliderInfoItem(QGraphicsItem *parent) : QGraphicsItem(parent)
{
}
void SliderInfoItem::updateBoundingRect()
{
QFont font;
font.setPixelSize(FONT_SIZE);
font.setFamily(FONT_FAMILY);
QFontMetrics fm(font);
2015-10-19 23:57:45 +02:00
_boundingRect = QRectF(-SIZE/2, 0, fm.width(_text) + SIZE, fm.height());
2015-10-17 01:33:02 +02:00
}
void SliderInfoItem::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);
painter->setFont(font);
painter->setPen(Qt::red);
painter->drawText(SIZE, fm.height() - fm.descent(), _text);
2015-10-19 23:57:45 +02:00
painter->drawLine(QPointF(-SIZE/2, 0), QPointF(SIZE/2, 0));
2015-10-17 01:33:02 +02:00
2015-10-19 23:57:45 +02:00
//painter->drawRect(boundingRect());
2015-10-17 01:33:02 +02:00
}
void SliderInfoItem::setText(const QString &text)
{
_text = text;
updateBoundingRect();
prepareGeometryChange();
}