2015-10-17 01:33:02 +02:00
|
|
|
#include <QPainter>
|
2018-11-02 20:01:19 +01:00
|
|
|
#include "font.h"
|
2015-10-17 01:33:02 +02:00
|
|
|
#include "sliderinfoitem.h"
|
|
|
|
|
|
|
|
|
|
|
|
#define SIZE 5
|
|
|
|
|
|
|
|
SliderInfoItem::SliderInfoItem(QGraphicsItem *parent) : QGraphicsItem(parent)
|
|
|
|
{
|
2016-03-30 01:48:48 +02:00
|
|
|
_side = Right;
|
2017-12-03 00:36:52 +01:00
|
|
|
_color = Qt::red;
|
2018-05-18 01:38:33 +02:00
|
|
|
|
|
|
|
_font.setPixelSize(FONT_SIZE);
|
|
|
|
_font.setFamily(FONT_FAMILY);
|
2015-10-17 01:33:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void SliderInfoItem::updateBoundingRect()
|
|
|
|
{
|
2018-05-18 01:38:33 +02:00
|
|
|
QFontMetrics fm(_font);
|
2015-10-17 01:33:02 +02:00
|
|
|
|
2017-09-29 11:43:09 +02:00
|
|
|
qreal width = qMax(fm.width(_x), fm.width(_y));
|
|
|
|
qreal height = 2 * fm.height() - 2*fm.descent();
|
|
|
|
|
2016-03-30 01:48:48 +02:00
|
|
|
_boundingRect = (_side == Right)
|
2017-09-29 11:43:09 +02:00
|
|
|
? QRectF(-SIZE/2, -height/2, width + 1.5*SIZE, height)
|
|
|
|
: QRectF(-(width + SIZE), -height/2, width + 1.5*SIZE, 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);
|
2018-05-18 01:38:33 +02:00
|
|
|
QFontMetrics fm(_font);
|
2017-09-29 11:43:09 +02:00
|
|
|
QRectF rx, ry;
|
|
|
|
|
|
|
|
|
|
|
|
qreal width = qMax(fm.width(_x), fm.width(_y));
|
|
|
|
if (_side == Right) {
|
|
|
|
ry = QRectF(SIZE, -fm.height() + fm.descent(), fm.width(_y),
|
|
|
|
fm.height() - fm.descent());
|
|
|
|
rx = QRectF(SIZE, 0, fm.width(_x), fm.height()
|
|
|
|
- fm.descent());
|
|
|
|
} else {
|
|
|
|
ry = QRectF(-(width + SIZE), -fm.height() + fm.descent(), fm.width(_y),
|
|
|
|
fm.height() - fm.descent());
|
|
|
|
rx = QRectF(-(width + SIZE), 0, fm.width(_x), fm.height()
|
|
|
|
- fm.descent());
|
|
|
|
}
|
|
|
|
|
|
|
|
painter->setPen(Qt::NoPen);
|
2019-01-04 19:21:05 +01:00
|
|
|
QColor bc(painter->background().color());
|
|
|
|
bc.setAlpha(196);
|
|
|
|
painter->setBrush(QBrush(bc));
|
2017-09-29 11:43:09 +02:00
|
|
|
painter->drawRect(ry);
|
|
|
|
painter->drawRect(rx);
|
|
|
|
painter->setBrush(Qt::NoBrush);
|
2015-10-17 01:33:02 +02:00
|
|
|
|
2018-05-18 01:38:33 +02:00
|
|
|
painter->setFont(_font);
|
2016-12-06 01:48:26 +01:00
|
|
|
painter->setRenderHint(QPainter::Antialiasing, false);
|
2017-12-03 00:36:52 +01:00
|
|
|
painter->setPen(_color);
|
2016-12-06 01:48:26 +01:00
|
|
|
|
2017-09-29 11:43:09 +02:00
|
|
|
if (_side == Right) {
|
|
|
|
painter->drawText(SIZE, -fm.descent()/2, _y);
|
|
|
|
painter->drawText(SIZE, fm.height() - fm.descent()*1.5, _x);
|
|
|
|
} else {
|
|
|
|
painter->drawText(-(width + SIZE), -fm.descent()/2, _y);
|
|
|
|
painter->drawText(-(width + SIZE), fm.height() - fm.descent()*1.5, _x);
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2017-09-29 11:43:09 +02:00
|
|
|
void SliderInfoItem::setText(const QString &x, const QString &y)
|
2015-10-17 01:33:02 +02:00
|
|
|
{
|
2016-04-01 21:20:23 +02:00
|
|
|
prepareGeometryChange();
|
2017-09-29 11:43:09 +02:00
|
|
|
_x = x; _y = y;
|
2015-10-17 01:33:02 +02:00
|
|
|
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();
|
|
|
|
}
|
2017-12-03 00:36:52 +01:00
|
|
|
|
|
|
|
void SliderInfoItem::setColor(const QColor &color)
|
|
|
|
{
|
|
|
|
_color = color;
|
|
|
|
update();
|
|
|
|
}
|