From: Joel Holdsworth Date: Sun, 30 Nov 2014 13:48:37 +0000 (+0000) Subject: TimeMarker: Added default get_label_rect implementation X-Git-Tag: pulseview-0.3.0~389 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=ced0548eac9932f80994bde76c3c2bb7a14a4b54;p=pulseview.git TimeMarker: Added default get_label_rect implementation --- diff --git a/pv/view/timemarker.cpp b/pv/view/timemarker.cpp index 9d6e7fde..d4bd7140 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 21de2625..ae54749e 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.