From: Joel Holdsworth Date: Tue, 30 Dec 2014 11:43:47 +0000 (+0000) Subject: CursorPair: Added frequency indication X-Git-Tag: pulseview-0.3.0~287 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=3204525355165f3d5994a5d17d044da19e29e1c5;p=pulseview.git CursorPair: Added frequency indication This fixes #502 --- diff --git a/pv/view/cursorpair.cpp b/pv/view/cursorpair.cpp index ea60b6ce..4f4d3975 100644 --- a/pv/view/cursorpair.cpp +++ b/pv/view/cursorpair.cpp @@ -108,12 +108,11 @@ void CursorPair::paint_label(QPainter &p, const QRect &rect, bool hover) if (!enabled()) return; - const unsigned int prefix = view_.tick_prefix(); const QColor text_colour = ViewItem::select_text_colour(Cursor::FillColour); p.setPen(text_colour); - compute_text_size(p, prefix); + compute_text_size(p); QRectF delta_rect(label_rect(rect)); const int radius = delta_rect.height() / 2; @@ -140,7 +139,7 @@ void CursorPair::paint_label(QPainter &p, const QRect &rect, bool hover) p.setPen(text_colour); p.drawText(text_rect, Qt::AlignCenter | Qt::AlignVCenter, - pv::util::format_time(second_->time() - first_->time(), prefix, 2)); + format_string()); } } @@ -160,13 +159,21 @@ void CursorPair::paint_back(QPainter &p, const ViewItemPaintParams &pp) { p.drawRect(l, pp.top(), r - l, pp.height()); } -void CursorPair::compute_text_size(QPainter &p, unsigned int prefix) +QString CursorPair::format_string() +{ + const unsigned int prefix = view_.tick_prefix(); + const double delta = second_->time() - first_->time(); + return QString("%1 / %2"). + arg(util::format_time(delta, prefix, 2)). + arg(util::format_si_value(1.0 / fabs(delta), "Hz", -1, 4)); +} + +void CursorPair::compute_text_size(QPainter &p) { assert(first_); assert(second_); - text_size_ = p.boundingRect(QRectF(), 0, pv::util::format_time( - second_->time() - first_->time(), prefix, 2)).size(); + text_size_ = p.boundingRect(QRectF(), 0, format_string()).size(); } pair CursorPair::get_cursor_offsets() const diff --git a/pv/view/cursorpair.hpp b/pv/view/cursorpair.hpp index 4361784a..aacc7d8c 100644 --- a/pv/view/cursorpair.hpp +++ b/pv/view/cursorpair.hpp @@ -90,7 +90,12 @@ public: **/ void paint_back(QPainter &p, const ViewItemPaintParams &pp); - void compute_text_size(QPainter &p, unsigned int prefix); + /** + * Constructs the string to display. + */ + QString format_string(); + + void compute_text_size(QPainter &p); std::pair get_cursor_offsets() const;