+ assert(_first);
+ assert(_second);
+
+ 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,
+ pv::util::format_time(_second->time() - _first->time(), prefix, 2));
+ }
+
+ // Paint the cursor markers
+ _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 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());
+}
+
+void CursorPair::draw_viewport_foreground(QPainter &p,
+ const QRect &rect)
+{
+ assert(_first);
+ assert(_second);
+
+ _first->paint(p, rect);
+ _second->paint(p, rect);
+}
+
+void CursorPair::compute_text_size(QPainter &p, unsigned int prefix)
+{
+ assert(_first);
+ assert(_second);
+
+ _text_size = p.boundingRect(QRectF(), 0, pv::util::format_time(
+ _second->time() - _first->time(), prefix, 2)).size();
+}
+
+pair<float, float> CursorPair::get_cursor_offsets() const
+{
+ assert(_first);
+ assert(_second);
+
+ return pair<float, float>(
+ (_first->time() - _view.offset()) / _view.scale(),
+ (_second->time() - _view.offset()) / _view.scale());