From: Joel Holdsworth Date: Sat, 20 Apr 2013 13:25:46 +0000 (+0100) Subject: Added Cursors Delta display X-Git-Tag: pulseview-0.1.0~31 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=5139748b422db3a22ceed92894596873e868d676;p=pulseview.git Added Cursors Delta display --- diff --git a/pv/view/cursor.cpp b/pv/view/cursor.cpp index 809a0501..b55d11e0 100644 --- a/pv/view/cursor.cpp +++ b/pv/view/cursor.cpp @@ -60,7 +60,7 @@ QRectF Cursor::get_label_rect(const QRect &rect) const _text_size.height() + View::LabelPadding.height() * 2); const float top = rect.height() - label_size.height() - Cursor::Offset - Cursor::ArrowSize - 0.5f; - const float height = label_size.height() + 1; + const float height = label_size.height(); if (_time > _other.time()) return QRectF(x, top, label_size.width(), height); diff --git a/pv/view/cursor.h b/pv/view/cursor.h index 4c0c35dd..48bf7a0e 100644 --- a/pv/view/cursor.h +++ b/pv/view/cursor.h @@ -34,7 +34,7 @@ class Cursor : public TimeMarker { Q_OBJECT -private: +public: static const QColor LineColour; static const QColor FillColour; static const QColor HighlightColour; diff --git a/pv/view/cursorpair.cpp b/pv/view/cursorpair.cpp index 5ce398a0..d8af3d76 100644 --- a/pv/view/cursorpair.cpp +++ b/pv/view/cursorpair.cpp @@ -20,6 +20,7 @@ #include "cursorpair.h" +#include "ruler.h" #include "view.h" #include @@ -29,6 +30,8 @@ using namespace std; namespace pv { namespace view { +const int CursorPair::DeltaPadding = 8; + CursorPair::CursorPair(const View &view) : _first(view, 0.0, _second), _second(view, 1.0, _first), @@ -56,9 +59,53 @@ Cursor& CursorPair::second() return _second; } +QRectF CursorPair::get_label_rect(const QRect &rect) const +{ + const QSizeF label_size( + _text_size.width() + View::LabelPadding.width() * 2, + _text_size.height() + View::LabelPadding.height() * 2); + const pair offsets(get_cursor_offsets()); + const pair normal_offsets( + (offsets.first < offsets.second) ? offsets : + make_pair(offsets.second, offsets.first)); + + const float height = label_size.height(); + const float left = max(normal_offsets.first + DeltaPadding, -height); + const float right = min(normal_offsets.second - DeltaPadding, + (float)rect.width() + height); + + return QRectF(left, rect.height() - label_size.height() - + Cursor::ArrowSize - Cursor::Offset - 0.5f, + right - left, height); +} + void CursorPair::draw_markers(QPainter &p, const QRect &rect, unsigned int prefix) { + compute_text_size(p, prefix); + QRectF delta_rect(get_label_rect(rect)); + + const int radius = delta_rect.height() / 2; + const QRectF text_rect(delta_rect.intersected( + rect).adjusted(radius, 0, -radius, 0)); + if(text_rect.width() >= _text_size.width()) + { + const int highlight_radius = delta_rect.height() / 2 - 2; + + p.setBrush(Cursor::FillColour); + p.setPen(Cursor::LineColour); + p.drawRoundedRect(delta_rect, radius, radius); + + delta_rect.adjust(1, 1, -1, -1); + p.setPen(Cursor::HighlightColour); + p.drawRoundedRect(delta_rect, highlight_radius, highlight_radius); + + p.setPen(Cursor::TextColour); + p.drawText(text_rect, Qt::AlignCenter | Qt::AlignVCenter, + Ruler::format_time(_second.time() - _first.time(), prefix, 2)); + } + + // Paint the cursor markers _first.paint_label(p, rect, prefix); _second.paint_label(p, rect, prefix); } @@ -85,6 +132,12 @@ void CursorPair::draw_viewport_foreground(QPainter &p, _second.paint(p, rect); } +void CursorPair::compute_text_size(QPainter &p, unsigned int prefix) +{ + _text_size = p.boundingRect(QRectF(), 0, Ruler::format_time( + _second.time() - _first.time(), prefix, 2)).size(); +} + pair CursorPair::get_cursor_offsets() const { return pair( diff --git a/pv/view/cursorpair.h b/pv/view/cursorpair.h index b152b808..42e6e51f 100644 --- a/pv/view/cursorpair.h +++ b/pv/view/cursorpair.h @@ -32,6 +32,9 @@ namespace view { class CursorPair { +private: + static const int DeltaPadding; + public: /** * Constructor. @@ -60,6 +63,8 @@ public: const Cursor& second() const; public: + QRectF get_label_rect(const QRect &rect) const; + void draw_markers(QPainter &p, const QRect &rect, unsigned int prefix); @@ -67,11 +72,15 @@ public: void draw_viewport_foreground(QPainter &p, const QRect &rect); + void compute_text_size(QPainter &p, unsigned int prefix); + std::pair get_cursor_offsets() const; private: Cursor _first, _second; const View &_view; + + QSizeF _text_size; }; } // namespace view