From f2bfc72648ee11bf1efd33f5f57b78f05a59b52e Mon Sep 17 00:00:00 2001 From: "Lubomir I. Ivanov" Date: Wed, 12 Mar 2014 00:09:53 +0200 Subject: Ruler: change how the ruler text drawing works A couple of problems with the ruler: - the rotated text doesn't look very well at all and interpolation doesn't help it much - measuring towards the right most part of the profile makes the text go out of the screen To solve these issues and attempt to improve the ruler this patch does the following: - place the text at the bottom of the lowest of the start and end points. this way the line will never intersect with the text - clamp the x position, so that the text doesn't ever leave the screen horizontally - place a white background behind the text so that it will cover text and graphics under the ruler item (TODO: place the ruler on top of everything else) Signed-off-by: Lubomir I. Ivanov Signed-off-by: Dirk Hohndel --- qt-ui/profile/ruleritem.cpp | 31 ++++++++++++++++++++----------- qt-ui/profile/ruleritem.h | 3 ++- 2 files changed, 22 insertions(+), 12 deletions(-) (limited to 'qt-ui/profile') diff --git a/qt-ui/profile/ruleritem.cpp b/qt-ui/profile/ruleritem.cpp index 66fb67a0b..627958e37 100644 --- a/qt-ui/profile/ruleritem.cpp +++ b/qt-ui/profile/ruleritem.cpp @@ -68,12 +68,15 @@ RulerItem2::RulerItem2() : source(new RulerNodeItem2()), dest(new RulerNodeItem2()), timeAxis(NULL), depthAxis(NULL), + textItemBack(new QGraphicsRectItem(this)), textItem(new QGraphicsSimpleTextItem(this)) { memset(&pInfo, 0, sizeof(pInfo)); source->setRuler(this); dest->setRuler(this); textItem->setFlag(QGraphicsItem::ItemIgnoresTransformations); + textItemBack->setBrush(QColor(0xff, 0xff, 0xff, 190)); + textItemBack->setPen(QColor(Qt::white)); } void RulerItem2::recalculate() @@ -100,20 +103,26 @@ void RulerItem2::recalculate() compare_samples(source->entry, dest->entry, buffer, 500, 1); text = QString(buffer); - //Draw Text - // This text item ignores transformations, so we cant use - // the line.angle(), we need to calculate the angle based - // on the view. - + // draw text QGraphicsView *view = scene()->views().first(); QPoint begin = view->mapFromScene(mapToScene(startPoint)); - QPoint end = view->mapFromScene(mapToScene(endPoint)); - QLineF globalLine(begin, end); textItem->setText(text); - textItem->resetMatrix(); - textItem->resetTransform(); - textItem->setPos(startPoint); - textItem->rotate(globalLine.angle() * -1); + qreal tgtX = startPoint.x(); + const qreal diff = begin.x() + textItem->boundingRect().width(); + // clamp so that the text doesn't go out of the screen to the right + if (diff > view->width()) { + begin.setX(begin.x() - (diff - view->width())); + tgtX = mapFromScene(view->mapToScene(begin)).x(); + } + // always show the text bellow the lowest of the start and end points + qreal tgtY = (startPoint.y() >= endPoint.y()) ? startPoint.y() : endPoint.y(); + textItem->setPos(tgtX - 1, tgtY + 4); + + // setup the text background + textItemBack->setVisible(startPoint.x() != endPoint.x()); + QPointF wh = mapFromScene(view->mapToScene(QPoint(textItem->boundingRect().width(), + textItem->boundingRect().height()))); + textItemBack->setRect(tgtX - 2, tgtY + 3, wh.x() + 2, wh.y() + 3); } RulerNodeItem2 *RulerItem2::sourceNode() const diff --git a/qt-ui/profile/ruleritem.h b/qt-ui/profile/ruleritem.h index 6ab86f44b..7bfc63eee 100644 --- a/qt-ui/profile/ruleritem.h +++ b/qt-ui/profile/ruleritem.h @@ -50,6 +50,7 @@ private: int paint_direction; DiveCartesianAxis *timeAxis; DiveCartesianAxis *depthAxis; + QGraphicsRectItem *textItemBack; QGraphicsSimpleTextItem *textItem; }; -#endif \ No newline at end of file +#endif -- cgit v1.2.3-70-g09d2