diff options
Diffstat (limited to 'qt-ui/profile/ruleritem.cpp')
-rw-r--r-- | qt-ui/profile/ruleritem.cpp | 31 |
1 files changed, 20 insertions, 11 deletions
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 |