From: Joel Holdsworth Date: Sat, 20 Apr 2013 12:01:03 +0000 (+0100) Subject: Added CursorPair::get_cursor_offsets() X-Git-Tag: pulseview-0.1.0~32 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=199441e4fe68f1ee45f3d4b7617a7166a87c7926;p=pulseview.git Added CursorPair::get_cursor_offsets() --- diff --git a/pv/view/cursor.cpp b/pv/view/cursor.cpp index 855bfa01..809a0501 100644 --- a/pv/view/cursor.cpp +++ b/pv/view/cursor.cpp @@ -58,9 +58,15 @@ QRectF Cursor::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); - return QRectF(x - label_size.width() / 2 - 0.5f, - rect.height() - label_size.height() - Offset - ArrowSize - 0.5f, - label_size.width() + 1, label_size.height() + 1); + const float top = rect.height() - label_size.height() - + Cursor::Offset - Cursor::ArrowSize - 0.5f; + const float height = label_size.height() + 1; + + if (_time > _other.time()) + return QRectF(x, top, label_size.width(), height); + else + return QRectF(x - label_size.width(), top, + label_size.width(), height); } void Cursor::paint_label(QPainter &p, const QRect &rect, diff --git a/pv/view/cursorpair.cpp b/pv/view/cursorpair.cpp index feac91d2..5ce398a0 100644 --- a/pv/view/cursorpair.cpp +++ b/pv/view/cursorpair.cpp @@ -69,10 +69,11 @@ void CursorPair::draw_viewport_background(QPainter &p, 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 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()); } @@ -84,5 +85,12 @@ void CursorPair::draw_viewport_foreground(QPainter &p, _second.paint(p, rect); } +pair CursorPair::get_cursor_offsets() const +{ + return pair( + (_first.time() - _view.offset()) / _view.scale(), + (_second.time() - _view.offset()) / _view.scale()); +} + } // namespace view } // namespace pv diff --git a/pv/view/cursorpair.h b/pv/view/cursorpair.h index 05035cc2..b152b808 100644 --- a/pv/view/cursorpair.h +++ b/pv/view/cursorpair.h @@ -67,6 +67,8 @@ public: void draw_viewport_foreground(QPainter &p, const QRect &rect); + std::pair get_cursor_offsets() const; + private: Cursor _first, _second; const View &_view;