1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-10-07 07:13:21 +02:00
GPXSee/src/sliderinfoitem.cpp

64 lines
1.3 KiB
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)
{
_side = Right;
2015-10-17 01:33:02 +02:00
}
void SliderInfoItem::updateBoundingRect()
{
QFont font;
font.setPixelSize(FONT_SIZE);
font.setFamily(FONT_FAMILY);
QFontMetrics fm(font);
_boundingRect = (_side == Right)
? QRectF(-SIZE/2, 0, fm.width(_text) + SIZE, fm.height())
: QRectF(-(fm.width(_text) + 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);
if (_side == Right)
painter->drawText(SIZE, fm.height() - fm.descent(), _text);
else
painter->drawText(-(fm.width(_text) + SIZE/2),
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)
{
2016-04-01 21:20:23 +02:00
prepareGeometryChange();
2015-10-17 01:33:02 +02:00
_text = text;
updateBoundingRect();
}
void SliderInfoItem::setSide(Side side)
{
if (side == _side)
return;
2016-04-01 21:20:23 +02:00
prepareGeometryChange();
_side = side;
updateBoundingRect();
}