Moved Cursor markers to the outside
[pulseview.git] / pv / view / cursorpair.cpp
index 7fe90c7b6ef11ccb12d3a91d8a3bb05c53334ee9..feac91d20d47a513c60f0a294c97b4f4fbda65cb 100644 (file)
 
 #include "view.h"
 
+#include <algorithm>
+
+using namespace std;
+
 namespace pv {
 namespace view {
 
 CursorPair::CursorPair(const View &view) :
-       _first(view, 0.0),
-       _second(view, 1.0),
+       _first(view, 0.0, _second),
+       _second(view, 1.0, _first),
        _view(view)
 {
 }
@@ -52,5 +56,33 @@ Cursor& CursorPair::second()
        return _second;
 }
 
+void CursorPair::draw_markers(QPainter &p,
+       const QRect &rect, unsigned int prefix)
+{
+       _first.paint_label(p, rect, prefix);
+       _second.paint_label(p, rect, prefix);
+}
+
+void CursorPair::draw_viewport_background(QPainter &p,
+       const QRect &rect)
+{
+       p.setPen(Qt::NoPen);
+       p.setBrush(QBrush(View::CursorAreaColour));
+
+       const float x1 = (_first.time() - _view.offset()) / _view.scale();
+       const float x2 = (_second.time() - _view.offset()) / _view.scale();
+       const int l = (int)max(min(x1, x2), 0.0f);
+       const int r = (int)min(max(x1, x2), (float)rect.width());
+
+       p.drawRect(l, 0, r - l, rect.height());
+}
+
+void CursorPair::draw_viewport_foreground(QPainter &p,
+       const QRect &rect)
+{
+       _first.paint(p, rect);
+       _second.paint(p, rect);
+}
+
 } // namespace view
 } // namespace pv