1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-24 11:45:53 +01:00

Propper path tick tooltip

+ code cleanup
This commit is contained in:
Martin Tůma 2019-05-28 07:24:39 +02:00
parent a16354a6ba
commit 48674bb50b
3 changed files with 21 additions and 10 deletions

View File

@ -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());
}
}

View File

@ -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);
}

View File

@ -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;