From ced0548eac9932f80994bde76c3c2bb7a14a4b54 Mon Sep 17 00:00:00 2001 From: Joel Holdsworth Date: Sun, 30 Nov 2014 13:48:37 +0000 Subject: [PATCH] TimeMarker: Added default get_label_rect implementation --- pv/view/timemarker.cpp | 21 +++++++++++++++++++++ pv/view/timemarker.hpp | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/pv/view/timemarker.cpp b/pv/view/timemarker.cpp index 9d6e7fd..d4bd714 100644 --- a/pv/view/timemarker.cpp +++ b/pv/view/timemarker.cpp @@ -26,7 +26,9 @@ #include "view.hpp" +#include #include +#include #include #include @@ -86,6 +88,25 @@ void TimeMarker::paint(QPainter &p, const QRect &rect) p.drawLine(QPointF(x, rect.top()), QPointF(x, rect.bottom())); } +QRectF TimeMarker::get_label_rect(const QRect &rect) const +{ + const float x = (time_ - view_.offset()) / view_.scale(); + + QFontMetrics m(QApplication::font()); + QSize text_size = m.boundingRect( + pv::util::format_time(time_, view_.tick_prefix(), 2)).size(); + + const QSizeF label_size( + text_size.width() + View::LabelPadding.width() * 2, + text_size.height() + View::LabelPadding.height() * 2); + const float top = rect.height() - label_size.height() - + TimeMarker::Offset - TimeMarker::ArrowSize - 0.5f; + const float height = label_size.height(); + + return QRectF(x - label_size.width() / 2 - 0.5f, top, + label_size.width(), height); +} + void TimeMarker::paint_label(QPainter &p, const QRect &rect) { const qreal x = (time_ - view_.offset()) / view_.scale(); diff --git a/pv/view/timemarker.hpp b/pv/view/timemarker.hpp index 21de262..ae54749 100644 --- a/pv/view/timemarker.hpp +++ b/pv/view/timemarker.hpp @@ -84,7 +84,7 @@ public: * @param rect The rectangle of the ruler client area. * @return Returns the label rectangle. */ - virtual QRectF get_label_rect(const QRect &rect) const = 0; + virtual QRectF get_label_rect(const QRect &rect) const; /** * Paints the marker's label to the ruler. -- 2.30.2