Removed unneeded Cursor::Size constant
[pulseview.git] / pv / view / cursor.cpp
index 35c2ed45fc0d564486140a91d8fb63225ae19bb2..1ec3b37a9948cf31d4d492c2af80973685d615b9 100644 (file)
@@ -20,6 +20,7 @@
 
 #include "cursor.h"
 
+#include "ruler.h"
 #include "view.h"
 
 #include <QBrush>
@@ -40,7 +41,6 @@ const QColor Cursor::FillColour(52, 101, 164);
 const QColor Cursor::HighlightColour(83, 130, 186);
 const QColor Cursor::TextColour(Qt::white);
 
-const int Cursor::Size = 12;
 const int Cursor::Offset = 1;
 
 const int Cursor::ArrowSize = 4;
@@ -62,9 +62,10 @@ QRectF Cursor::get_label_rect(const QRect &rect) const
                label_size.width() + 1, label_size.height() + 1);
 }
 
-void Cursor::paint_label(QPainter &p, const QRect &rect)
+void Cursor::paint_label(QPainter &p, const QRect &rect,
+       unsigned int prefix)
 {
-       compute_text_size(p);
+       compute_text_size(p, prefix);
        const QRectF r(get_label_rect(rect));
 
        const float h_centre = (r.left() + r.right()) / 2;
@@ -88,9 +89,6 @@ void Cursor::paint_label(QPainter &p, const QRect &rect)
                QPointF(r.left() + 1, r.top() + 1),
        };
 
-       char text[16];
-       format_text(text);
-
        p.setPen(Qt::transparent);
        p.setBrush(FillColour);
        p.drawPolygon(points, countof(points));
@@ -104,19 +102,14 @@ void Cursor::paint_label(QPainter &p, const QRect &rect)
        p.drawPolygon(points, countof(points));
 
        p.setPen(TextColour);
-       p.drawText(r, Qt::AlignCenter | Qt::AlignVCenter, text);
-}
-
-void Cursor::compute_text_size(QPainter &p)
-{
-       char text[16];
-       format_text(text);
-       _text_size = p.boundingRect(QRectF(), 0, text).size();
+       p.drawText(r, Qt::AlignCenter | Qt::AlignVCenter,
+               Ruler::format_time(_time, prefix, 2));
 }
 
-void Cursor::format_text(char *text)
+void Cursor::compute_text_size(QPainter &p, unsigned int prefix)
 {
-       sprintf(text, "%gs", _time);
+       _text_size = p.boundingRect(QRectF(), 0,
+               Ruler::format_time(_time, prefix, 2)).size();
 }
 
 } // namespace view