]> sigrok.org Git - pulseview.git/commitdiff
TimeMarker: Added default get_label_rect implementation
authorJoel Holdsworth <redacted>
Sun, 30 Nov 2014 13:48:37 +0000 (13:48 +0000)
committerUwe Hermann <redacted>
Wed, 10 Dec 2014 17:06:15 +0000 (18:06 +0100)
pv/view/timemarker.cpp
pv/view/timemarker.hpp

index 9d6e7fde6b126e547af4184b27f1542ed6faaf2e..d4bd7140e92fba17cdf300495c35331cfa24ac1f 100644 (file)
@@ -26,7 +26,9 @@
 
 #include "view.hpp"
 
+#include <QApplication>
 #include <QFormLayout>
+#include <QFontMetrics>
 #include <QPainter>
 
 #include <pv/util.hpp>
@@ -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();
index 21de26258f4b4153ce4e970236ded0e2511360e7..ae54749e4e58055e5c73db88cbf0b28526f4511b 100644 (file)
@@ -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.