From: Joel Holdsworth Date: Sun, 30 Nov 2014 15:31:10 +0000 (+0000) Subject: TimeMarker: Added get_text X-Git-Tag: pulseview-0.3.0~388 X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=commitdiff_plain;h=3b84fd6d59b10053d5ffba90f8e66324f49841a3 TimeMarker: Added get_text --- diff --git a/pv/view/cursor.cpp b/pv/view/cursor.cpp index d5b0a641..6a473311 100644 --- a/pv/view/cursor.cpp +++ b/pv/view/cursor.cpp @@ -45,6 +45,11 @@ Cursor::Cursor(View &view, double time) : { } +QString Cursor::get_text() const +{ + return pv::util::format_time(time_, view_.tick_prefix(), 2); +} + QRectF Cursor::get_label_rect(const QRect &rect) const { const shared_ptr other(get_other_cursor()); @@ -53,8 +58,7 @@ QRectF Cursor::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(); + QSize text_size = m.boundingRect(get_text()).size(); const QSizeF label_size( text_size.width() + View::LabelPadding.width() * 2, diff --git a/pv/view/cursor.hpp b/pv/view/cursor.hpp index 9f0adedd..fab7497e 100644 --- a/pv/view/cursor.hpp +++ b/pv/view/cursor.hpp @@ -48,6 +48,11 @@ public: Cursor(View &view, double time); public: + /** + * Gets the text to show in the marker. + */ + QString get_text() const; + /** * Gets the marker label rectangle. * @param rect The rectangle of the ruler client area. diff --git a/pv/view/logicsignal.cpp b/pv/view/logicsignal.cpp index 48d2debc..4a8939d1 100644 --- a/pv/view/logicsignal.cpp +++ b/pv/view/logicsignal.cpp @@ -246,15 +246,15 @@ void LogicSignal::paint_fore(QPainter &p, const RowItemPaintParams &pp) if (!pixmap) continue; - const int pad = TriggerMarkerPadding; + const float pad = TriggerMarkerPadding - 0.5f; const QSize size = pixmap->size(); const QPoint point( pp.right() - size.width() - pad * 2, y - (SignalHeight + size.height()) / 2); - p.setPen(QPen(Qt::NoPen)); + p.setPen(QPen(TriggerMarkerBackgroundColour.darker())); p.setBrush(TriggerMarkerBackgroundColour); - p.drawRoundedRect(QRect(point, size).adjusted( + p.drawRoundedRect(QRectF(point, size).adjusted( -pad, -pad, pad, pad), pad, pad); p.drawPixmap(point, *pixmap); diff --git a/pv/view/timemarker.cpp b/pv/view/timemarker.cpp index d4bd7140..7e238068 100644 --- a/pv/view/timemarker.cpp +++ b/pv/view/timemarker.cpp @@ -31,7 +31,6 @@ #include #include -#include #include using std::max; @@ -93,8 +92,7 @@ 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(); + QSize text_size = m.boundingRect(get_text()).size(); const QSizeF label_size( text_size.width() + View::LabelPadding.width() * 2, @@ -152,8 +150,7 @@ void TimeMarker::paint_label(QPainter &p, const QRect &rect) p.drawPolygon(points, countof(points)); p.setPen(select_text_colour(colour_)); - p.drawText(r, Qt::AlignCenter | Qt::AlignVCenter, - pv::util::format_time(time_, view_.tick_prefix(), 2)); + p.drawText(r, Qt::AlignCenter | Qt::AlignVCenter, get_text()); } pv::widgets::Popup* TimeMarker::create_popup(QWidget *parent) diff --git a/pv/view/timemarker.hpp b/pv/view/timemarker.hpp index ae54749e..93c7dc90 100644 --- a/pv/view/timemarker.hpp +++ b/pv/view/timemarker.hpp @@ -79,6 +79,11 @@ public: */ virtual void paint(QPainter &p, const QRect &rect); + /** + * Gets the text to show in the marker. + */ + virtual QString get_text() const = 0; + /** * Gets the marker label rectangle. * @param rect The rectangle of the ruler client area.