Use the canonical file name also for the "already open" check
[GPXSee.git] / src / GUI / sliderinfoitem.cpp
blobd19c54a2ecbc716822122aebc66bb9750e7a5f19
1 #include <QPainter>
2 #include "font.h"
3 #include "sliderinfoitem.h"
6 #define SIZE 5
8 SliderInfoItem::SliderInfoItem(QGraphicsItem *parent) : QGraphicsItem(parent)
10 _side = Right;
11 _color = Qt::red;
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)
32 Q_UNUSED(option);
33 Q_UNUSED(widget);
34 QFontMetrics fm(_font);
35 QRectF rx, ry;
38 qreal width = qMax(fm.boundingRect(_x).width(), fm.boundingRect(_y).width());
39 if (_side == Right) {
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()
43 - fm.descent());
44 } else {
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()
48 - fm.descent());
51 painter->setPen(Qt::NoPen);
52 QColor bc(painter->background().color());
53 bc.setAlpha(196);
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);
63 if (_side == Right) {
64 painter->drawText(SIZE, -fm.descent()/2, _y);
65 painter->drawText(SIZE, fm.height() - fm.descent()*1.5, _x);
66 } else {
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();
78 _x = x; _y = y;
79 updateBoundingRect();
82 void SliderInfoItem::setSide(Side side)
84 if (side == _side)
85 return;
87 prepareGeometryChange();
88 _side = side;
89 updateBoundingRect();
92 void SliderInfoItem::setColor(const QColor &color)
94 _color = color;
95 update();