3 #include "sliderinfoitem.h"
8 SliderInfoItem::SliderInfoItem(QGraphicsItem
*parent
) : QGraphicsItem(parent
)
13 _font
.setPixelSize(FONT_SIZE
);
14 _font
.setFamily(FONT_FAMILY
);
17 void SliderInfoItem::updateBoundingRect()
19 QFontMetrics
fm(_font
);
21 qreal width
= qMax(fm
.boundingRect(_x
).width(), fm
.boundingRect(_y
).width());
22 qreal height
= 2 * fm
.height() - 2*fm
.descent();
24 _boundingRect
= (_side
== Right
)
25 ? QRectF(-SIZE
/2, -height
/2, width
+ 1.5*SIZE
, height
)
26 : QRectF(-(width
+ SIZE
), -height
/2, width
+ 1.5*SIZE
, height
);
29 void SliderInfoItem::paint(QPainter
*painter
, const QStyleOptionGraphicsItem
30 *option
, QWidget
*widget
)
34 QFontMetrics
fm(_font
);
38 qreal width
= qMax(fm
.boundingRect(_x
).width(), fm
.boundingRect(_y
).width());
40 ry
= QRectF(SIZE
, -fm
.height() + fm
.descent(), fm
.boundingRect(_y
).width(),
41 fm
.height() - fm
.descent());
42 rx
= QRectF(SIZE
, 0, fm
.boundingRect(_x
).width(), fm
.height()
45 ry
= QRectF(-(width
+ SIZE
), -fm
.height() + fm
.descent(),
46 fm
.boundingRect(_y
).width(), fm
.height() - fm
.descent());
47 rx
= QRectF(-(width
+ SIZE
), 0, fm
.boundingRect(_x
).width(), fm
.height()
51 painter
->setPen(Qt::NoPen
);
52 QColor
bc(painter
->background().color());
54 painter
->setBrush(QBrush(bc
));
55 painter
->drawRect(ry
);
56 painter
->drawRect(rx
);
57 painter
->setBrush(Qt::NoBrush
);
59 painter
->setFont(_font
);
60 painter
->setRenderHint(QPainter::Antialiasing
, false);
61 painter
->setPen(_color
);
64 painter
->drawText(SIZE
, -fm
.descent()/2, _y
);
65 painter
->drawText(SIZE
, fm
.height() - fm
.descent()*1.5, _x
);
67 painter
->drawText(-(width
+ SIZE
), -fm
.descent()/2, _y
);
68 painter
->drawText(-(width
+ SIZE
), fm
.height() - fm
.descent()*1.5, _x
);
70 painter
->drawLine(QPointF(-SIZE
/2, 0), QPointF(SIZE
/2, 0));
72 //painter->drawRect(boundingRect());
75 void SliderInfoItem::setText(const QString
&x
, const QString
&y
)
77 prepareGeometryChange();
82 void SliderInfoItem::setSide(Side side
)
87 prepareGeometryChange();
92 void SliderInfoItem::setColor(const QColor
&color
)