2 #include <QFontMetrics>
4 #include "axislabelitem.h"
7 AxisLabelItem::AxisLabelItem(Type type
, QGraphicsItem
*parent
)
8 : QGraphicsItem(parent
), _type(type
)
10 _font
.setPixelSize(FONT_SIZE
);
11 _font
.setFamily(FONT_FAMILY
);
14 void AxisLabelItem::setLabel(const QString
& label
, const QString
&units
)
16 prepareGeometryChange();
17 QFontMetrics
fm(_font
);
18 _label
= QString("%1 [%2]").arg(label
, units
.isEmpty() ? "-" : units
);
19 _labelBB
= fm
.tightBoundingRect(_label
);
24 void AxisLabelItem::updateBoundingRect()
26 QFontMetrics
fm(_font
);
29 _boundingRect
= QRectF(0, 0, _labelBB
.width(), fm
.height());
31 _boundingRect
= QRectF(0, 0, fm
.height(), _labelBB
.width());
34 void AxisLabelItem::paint(QPainter
*painter
, const QStyleOptionGraphicsItem
*option
,
39 QFontMetrics
fm(_font
);
41 painter
->setFont(_font
);
44 painter
->drawText(0, fm
.height() - fm
.descent(), _label
);
47 painter
->drawText(-_labelBB
.width(), fm
.height() - fm
.descent(), _label
);
51 //painter->setRenderHint(QPainter::Antialiasing, false);
52 //painter->setPen(Qt::red);
53 //painter->drawRect(boundingRect());