]> sigrok.org Git - pulseview.git/commitdiff
Added Cursors Delta display
authorJoel Holdsworth <redacted>
Sat, 20 Apr 2013 13:25:46 +0000 (14:25 +0100)
committerJoel Holdsworth <redacted>
Sat, 20 Apr 2013 13:25:46 +0000 (14:25 +0100)
pv/view/cursor.cpp
pv/view/cursor.h
pv/view/cursorpair.cpp
pv/view/cursorpair.h

index 809a0501b20da1a4be759451fb0d51b717a4dff6..b55d11e016c3b96123b4eb287f44534c51c99034 100644 (file)
@@ -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;
                _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);
 
        if (_time > _other.time())
                return QRectF(x, top, label_size.width(), height);
index 4c0c35dd85de81d8372d0804f090ac9230df3257..48bf7a0ee930ab49a7975af25d0ed8ba38588afc 100644 (file)
@@ -34,7 +34,7 @@ class Cursor : public TimeMarker
 {
        Q_OBJECT
 
 {
        Q_OBJECT
 
-private:
+public:
        static const QColor LineColour;
        static const QColor FillColour;
        static const QColor HighlightColour;
        static const QColor LineColour;
        static const QColor FillColour;
        static const QColor HighlightColour;
index 5ce398a0ff3f764e9b0e6d6914bf9f258254bce0..d8af3d76f319e19596e406f2b4aa9deca1f24685 100644 (file)
@@ -20,6 +20,7 @@
 
 #include "cursorpair.h"
 
 
 #include "cursorpair.h"
 
+#include "ruler.h"
 #include "view.h"
 
 #include <algorithm>
 #include "view.h"
 
 #include <algorithm>
@@ -29,6 +30,8 @@ using namespace std;
 namespace pv {
 namespace view {
 
 namespace pv {
 namespace view {
 
+const int CursorPair::DeltaPadding = 8;
+
 CursorPair::CursorPair(const View &view) :
        _first(view, 0.0, _second),
        _second(view, 1.0, _first),
 CursorPair::CursorPair(const View &view) :
        _first(view, 0.0, _second),
        _second(view, 1.0, _first),
@@ -56,9 +59,53 @@ Cursor& CursorPair::second()
        return _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<float, float> offsets(get_cursor_offsets());
+       const pair<float, float> 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)
 {
 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);
 }
        _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);
 }
 
        _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<float, float> CursorPair::get_cursor_offsets() const
 {
        return pair<float, float>(
 pair<float, float> CursorPair::get_cursor_offsets() const
 {
        return pair<float, float>(
index b152b8083a2db4ff0db7932569e7ae08c836abc3..42e6e51fa32ca3c764ac521b1d16318983e56825 100644 (file)
@@ -32,6 +32,9 @@ namespace view {
 
 class CursorPair
 {
 
 class CursorPair
 {
+private:
+       static const int DeltaPadding;
+
 public:
        /**
         * Constructor.
 public:
        /**
         * Constructor.
@@ -60,6 +63,8 @@ public:
        const Cursor& second() const;
 
 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);
 
        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 draw_viewport_foreground(QPainter &p, const QRect &rect);
 
+       void compute_text_size(QPainter &p, unsigned int prefix);
+
        std::pair<float, float> get_cursor_offsets() const;
 
 private:
        Cursor _first, _second;
        const View &_view;
        std::pair<float, float> get_cursor_offsets() const;
 
 private:
        Cursor _first, _second;
        const View &_view;
+
+       QSizeF _text_size;
 };
 
 } // namespace view
 };
 
 } // namespace view