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)
|
|
|
|
{
|
2016-03-30 01:48:48 +02:00
|
|
|
_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);
|
|
|
|
|
2016-03-30 01:48:48 +02:00
|
|
|
_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);
|
2016-03-30 01:48:48 +02:00
|
|
|
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();
|
|
|
|
}
|
2016-03-30 01:48:48 +02:00
|
|
|
|
|
|
|
void SliderInfoItem::setSide(Side side)
|
|
|
|
{
|
|
|
|
if (side == _side)
|
|
|
|
return;
|
|
|
|
|
2016-04-01 21:20:23 +02:00
|
|
|
prepareGeometryChange();
|
2016-03-30 01:48:48 +02:00
|
|
|
_side = side;
|
|
|
|
updateBoundingRect();
|
|
|
|
}
|