Use the canonical file name also for the "already open" check
[GPXSee.git] / src / GUI / axislabelitem.cpp
blob9e7a42b5db0250a2ccfa588313c4dfd6978de096
1 #include <QPainter>
2 #include <QFontMetrics>
3 #include "font.h"
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);
20 updateBoundingRect();
21 update();
24 void AxisLabelItem::updateBoundingRect()
26 QFontMetrics fm(_font);
28 if (_type == X)
29 _boundingRect = QRectF(0, 0, _labelBB.width(), fm.height());
30 else
31 _boundingRect = QRectF(0, 0, fm.height(), _labelBB.width());
34 void AxisLabelItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
35 QWidget *widget)
37 Q_UNUSED(option);
38 Q_UNUSED(widget);
39 QFontMetrics fm(_font);
41 painter->setFont(_font);
43 if (_type == X) {
44 painter->drawText(0, fm.height() - fm.descent(), _label);
45 } else {
46 painter->rotate(-90);
47 painter->drawText(-_labelBB.width(), fm.height() - fm.descent(), _label);
48 painter->rotate(90);
51 //painter->setRenderHint(QPainter::Antialiasing, false);
52 //painter->setPen(Qt::red);
53 //painter->drawRect(boundingRect());