Added CursorPair::get_cursor_offsets()
[pulseview.git] / pv / view / cursorpair.cpp
index a677c50347a75ed4c57ff2d5bfcb891314be7ed5..5ce398a0ff3f764e9b0e6d6914bf9f258254bce0 100644 (file)
@@ -30,8 +30,8 @@ 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)
 {
 }
@@ -56,16 +56,24 @@ 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());
+       const pair<float, float> offsets(get_cursor_offsets());
+       const int l = (int)max(min(
+               offsets.first, offsets.second), 0.0f);
+       const int r = (int)min(max(
+               offsets.first, offsets.second), (float)rect.width());
 
        p.drawRect(l, 0, r - l, rect.height());
 }
@@ -77,5 +85,12 @@ void CursorPair::draw_viewport_foreground(QPainter &p,
        _second.paint(p, rect);
 }
 
+pair<float, float> CursorPair::get_cursor_offsets() const
+{
+       return pair<float, float>(
+               (_first.time() - _view.offset()) / _view.scale(),
+               (_second.time() - _view.offset()) / _view.scale());
+}
+
 } // namespace view
 } // namespace pv