diff --git a/src/GUI/pathitem.cpp b/src/GUI/pathitem.cpp index d1e888b4..3cbea450 100644 --- a/src/GUI/pathitem.cpp +++ b/src/GUI/pathitem.cpp @@ -325,20 +325,15 @@ void PathItem::updateTicks() return; int ts = tickSize(); - qreal f = xInM(); - int tc = (int)_path.last().last().distance() / (ts * f); - - QFontMetrics fm(PathTickItem::font()); - QRect tr = fm.boundingRect(QRect(), Qt::AlignCenter, - QString::number(qMax(ts * (tc - 1), 10))) - .adjusted(-2, 0, 2, 0); + int tc = _path.last().last().distance() / (ts * xInM()); + QRect tr = PathTickItem::tickRect(ts * (tc - 1)); _ticks.resize(tc); for (int i = 0; i < tc; i++) { - QPoint pos(position((i + 1) * ts * xInM()).toPoint()); _ticks[i] = new PathTickItem(tr, (i + 1) * ts, this); - _ticks[i]->setPos(QPointF(pos.x() - 0.5, pos.y() - 0.5)); + _ticks[i]->setPos(position((i + 1) * ts * xInM())); _ticks[i]->setColor(_pen.color()); + _ticks[i]->setToolTip(toolTip()); } } diff --git a/src/GUI/pathtickitem.cpp b/src/GUI/pathtickitem.cpp index 46f7c119..4c5c4b51 100644 --- a/src/GUI/pathtickitem.cpp +++ b/src/GUI/pathtickitem.cpp @@ -54,3 +54,18 @@ void PathTickItem::paint(QPainter *painter, painter->drawRect(boundingRect()); */ } + +void PathTickItem::setPos(const QPointF &pos) +{ + /* For propper rounded rect rendering, the item must be positioned in the + middle of a pixel */ + QPoint p(pos.toPoint()); + QGraphicsItem::setPos(QPointF(p.x() - 0.5, p.y() - 0.5)); +} + +QRect PathTickItem::tickRect(int value) +{ + QFontMetrics fm(_font); + return fm.boundingRect(QRect(), Qt::AlignCenter, + QString::number(qMax(value, 10))).adjusted(-2, 0, 2, 0); +} diff --git a/src/GUI/pathtickitem.h b/src/GUI/pathtickitem.h index 9c428a36..1deb4a7e 100644 --- a/src/GUI/pathtickitem.h +++ b/src/GUI/pathtickitem.h @@ -13,9 +13,10 @@ public: void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); + void setPos(const QPointF &pos); void setColor(const QColor &color) {_brush = QBrush(color);} - static const QFont &font() {return _font;} + static QRect tickRect(int value); private: QRectF _tickRect;