From: Joel Holdsworth Date: Sat, 13 Dec 2014 12:13:43 +0000 (+0000) Subject: CursorPair: Paint with ViewItem::paint_fore/paint_back X-Git-Tag: pulseview-0.3.0~350 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=beb897c6c32c8e8dd9eb34d91100ab0569fca5f6;p=pulseview.git CursorPair: Paint with ViewItem::paint_fore/paint_back --- diff --git a/pv/view/cursorpair.cpp b/pv/view/cursorpair.cpp index 8432a24b..859f6fde 100644 --- a/pv/view/cursorpair.cpp +++ b/pv/view/cursorpair.cpp @@ -142,9 +142,10 @@ void CursorPair::paint_label(QPainter &p, const QRect &rect) } } -void CursorPair::draw_viewport_background(QPainter &p, - const QRect &rect) -{ +void CursorPair::paint_back(QPainter &p, const ViewItemPaintParams &pp) { + if (!enabled()) + return; + p.setPen(Qt::NoPen); p.setBrush(QBrush(View::CursorAreaColour)); @@ -152,19 +153,9 @@ void CursorPair::draw_viewport_background(QPainter &p, 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_); + offsets.first, offsets.second), (float)pp.width()); - first_->paint(p, rect); - second_->paint(p, rect); + p.drawRect(l, pp.top(), r - l, pp.height()); } void CursorPair::compute_text_size(QPainter &p, unsigned int prefix) diff --git a/pv/view/cursorpair.hpp b/pv/view/cursorpair.hpp index 47ca694b..af7f5556 100644 --- a/pv/view/cursorpair.hpp +++ b/pv/view/cursorpair.hpp @@ -76,9 +76,12 @@ public: void paint_label(QPainter &p, const QRect &rect); - void draw_viewport_background(QPainter &p, const QRect &rect); - - void draw_viewport_foreground(QPainter &p, const QRect &rect); + /** + * Paints the background layer of the item with a QPainter + * @param p the QPainter to paint into. + * @param pp the painting parameters object to paint with. + **/ + void paint_back(QPainter &p, const ViewItemPaintParams &pp); void compute_text_size(QPainter &p, unsigned int prefix); diff --git a/pv/view/timemarker.cpp b/pv/view/timemarker.cpp index eebac024..ad383059 100644 --- a/pv/view/timemarker.cpp +++ b/pv/view/timemarker.cpp @@ -80,13 +80,6 @@ void TimeMarker::set_time(double time) time_changed(); } -void TimeMarker::paint(QPainter &p, const QRect &rect) -{ - const float x = get_x(); - p.setPen(colour_.darker()); - p.drawLine(QPointF(x, rect.top()), QPointF(x, rect.bottom())); -} - QRectF TimeMarker::label_rect(const QRectF &rect) const { const float x = (time_ - view_.offset()) / view_.scale(); @@ -158,6 +151,16 @@ void TimeMarker::paint_label(QPainter &p, const QRect &rect) p.drawText(r, Qt::AlignCenter | Qt::AlignVCenter, get_text()); } +void TimeMarker::paint_fore(QPainter &p, const ViewItemPaintParams &pp) +{ + if (!enabled()) + return; + + const float x = get_x(); + p.setPen(colour_.darker()); + p.drawLine(QPointF(x, pp.top()), QPointF(x, pp.bottom())); +} + pv::widgets::Popup* TimeMarker::create_popup(QWidget *parent) { using pv::widgets::Popup; diff --git a/pv/view/timemarker.hpp b/pv/view/timemarker.hpp index 38dfa18e..7534dbd7 100644 --- a/pv/view/timemarker.hpp +++ b/pv/view/timemarker.hpp @@ -72,13 +72,6 @@ public: */ QPoint point() const; - /** - * Paints the marker to the viewport. - * @param p The painter to draw with. - * @param rect The rectangle of the viewport client area. - */ - virtual void paint(QPainter &p, const QRect &rect); - /** * Computes the outline rectangle of a label. * @param rect the rectangle of the header area. @@ -98,6 +91,13 @@ public: */ void paint_label(QPainter &p, const QRect &rect); + /** + * Paints the foreground layer of the item with a QPainter + * @param p the QPainter to paint into. + * @param pp the painting parameters object to paint with. + **/ + void paint_fore(QPainter &p, const ViewItemPaintParams &pp); + pv::widgets::Popup* create_popup(QWidget *parent); private Q_SLOTS: diff --git a/pv/view/viewport.cpp b/pv/view/viewport.cpp index 84092ee4..feb880e9 100644 --- a/pv/view/viewport.cpp +++ b/pv/view/viewport.cpp @@ -34,6 +34,7 @@ using std::abs; using std::max; using std::min; +using std::none_of; using std::shared_ptr; using std::stable_sort; using std::vector; @@ -60,33 +61,36 @@ Viewport::Viewport(View &parent) : void Viewport::paintEvent(QPaintEvent*) { vector< shared_ptr > row_items(view_.begin(), view_.end()); + assert(none_of(row_items.begin(), row_items.end(), + [](const shared_ptr &r) { return !r; })); + stable_sort(row_items.begin(), row_items.end(), [](const shared_ptr &a, const shared_ptr &b) { return a->visual_v_offset() < b->visual_v_offset(); }); + const vector< shared_ptr > time_items(view_.time_items()); + assert(none_of(time_items.begin(), time_items.end(), + [](const shared_ptr &t) { return !t; })); + QPainter p(this); p.setRenderHint(QPainter::Antialiasing); - if (view_.cursors_shown()) - view_.cursors()->draw_viewport_background(p, rect()); - const ViewItemPaintParams pp(rect(), view_.scale(), view_.offset()); - // Plot the signal + for (const shared_ptr t : time_items) + t->paint_back(p, pp); for (const shared_ptr r : row_items) - { - assert(r); r->paint_back(p, pp); - } + for (const shared_ptr t : time_items) + t->paint_mid(p, pp); for (const shared_ptr r : row_items) r->paint_mid(p, pp); for (const shared_ptr r : row_items) r->paint_fore(p, pp); - - if (view_.cursors_shown()) - view_.cursors()->draw_viewport_foreground(p, rect()); + for (const shared_ptr t : time_items) + t->paint_fore(p, pp); p.end(); }