X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=pv%2Fview%2Fcursorpair.cpp;h=0fb0d8d19ac681d1f1a44ec642730c769863528d;hb=0f1f98fe5b6ccc7add3cedc035b0df5d8e5431eb;hp=d8af3d76f319e19596e406f2b4aa9deca1f24685;hpb=5139748b422db3a22ceed92894596873e868d676;p=pulseview.git diff --git a/pv/view/cursorpair.cpp b/pv/view/cursorpair.cpp index d8af3d76..0fb0d8d1 100644 --- a/pv/view/cursorpair.cpp +++ b/pv/view/cursorpair.cpp @@ -18,52 +18,47 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "cursorpair.h" +#include "cursorpair.hpp" -#include "ruler.h" -#include "view.h" +#include "view.hpp" +#include "pv/util.hpp" +#include #include -using namespace std; +using std::max; +using std::make_pair; +using std::min; +using std::shared_ptr; +using std::pair; namespace pv { namespace view { const int CursorPair::DeltaPadding = 8; -CursorPair::CursorPair(const View &view) : - _first(view, 0.0, _second), - _second(view, 1.0, _first), - _view(view) +CursorPair::CursorPair(View &view) : + first_(new Cursor(view, 0.0)), + second_(new Cursor(view, 1.0)), + view_(view) { } -const Cursor& CursorPair::first() const +shared_ptr CursorPair::first() const { - return _first; + return first_; } -Cursor& CursorPair::first() +shared_ptr CursorPair::second() const { - return _first; -} - -const Cursor& CursorPair::second() const -{ - return _second; -} - -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); + text_size_.width() + View::LabelPadding.width() * 2, + text_size_.height() + View::LabelPadding.height() * 2); const pair offsets(get_cursor_offsets()); const pair normal_offsets( (offsets.first < offsets.second) ? offsets : @@ -82,13 +77,16 @@ QRectF CursorPair::get_label_rect(const QRect &rect) const void CursorPair::draw_markers(QPainter &p, const QRect &rect, unsigned int prefix) { + 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()) + if(text_rect.width() >= text_size_.width()) { const int highlight_radius = delta_rect.height() / 2 - 2; @@ -102,12 +100,12 @@ void CursorPair::draw_markers(QPainter &p, p.setPen(Cursor::TextColour); p.drawText(text_rect, Qt::AlignCenter | Qt::AlignVCenter, - Ruler::format_time(_second.time() - _first.time(), prefix, 2)); + 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); + first_->paint_label(p, rect, prefix); + second_->paint_label(p, rect, prefix); } void CursorPair::draw_viewport_background(QPainter &p, @@ -128,21 +126,30 @@ void CursorPair::draw_viewport_background(QPainter &p, void CursorPair::draw_viewport_foreground(QPainter &p, const QRect &rect) { - _first.paint(p, rect); - _second.paint(p, rect); + assert(first_); + assert(second_); + + first_->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(); + assert(first_); + assert(second_); + + text_size_ = p.boundingRect(QRectF(), 0, pv::util::format_time( + second_->time() - first_->time(), prefix, 2)).size(); } pair CursorPair::get_cursor_offsets() const { + assert(first_); + assert(second_); + return pair( - (_first.time() - _view.offset()) / _view.scale(), - (_second.time() - _view.offset()) / _view.scale()); + (first_->time() - view_.offset()) / view_.scale(), + (second_->time() - view_.offset()) / view_.scale()); } } // namespace view