]> sigrok.org Git - pulseview.git/commitdiff
CursorPair: Paint with ViewItem::paint_fore/paint_back
authorJoel Holdsworth <redacted>
Sat, 13 Dec 2014 12:13:43 +0000 (12:13 +0000)
committerJoel Holdsworth <redacted>
Sun, 28 Dec 2014 18:52:53 +0000 (18:52 +0000)
pv/view/cursorpair.cpp
pv/view/cursorpair.hpp
pv/view/timemarker.cpp
pv/view/timemarker.hpp
pv/view/viewport.cpp

index 8432a24b47cfba4fb8ce692ff075925161d7912f..859f6fdef4e129336b23cc038cddf6e31b107e73 100644 (file)
@@ -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)
index 47ca694bc07b622fdad6dcdcef17a7222651496d..af7f5556c722bc83609e72664a5b610858072d08 100644 (file)
@@ -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);
 
index eebac024cca0c81608d5452a560544e235081813..ad3830590a8b059a1d3006275c3e812f0dff2e8e 100644 (file)
@@ -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;
index 38dfa18e61d69a6b1e679c8ffd1b1498bbf22231..7534dbd7c2708c615b9d36179806ec521facac9b 100644 (file)
@@ -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:
index 84092ee451ba77caea5a9661687ff2a8befd9ad5..feb880e94a0bd0ea477ed225bdae4642c5cef767 100644 (file)
@@ -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<RowItem> > row_items(view_.begin(), view_.end());
+       assert(none_of(row_items.begin(), row_items.end(),
+               [](const shared_ptr<RowItem> &r) { return !r; }));
+
        stable_sort(row_items.begin(), row_items.end(),
                [](const shared_ptr<RowItem> &a, const shared_ptr<RowItem> &b) {
                        return a->visual_v_offset() < b->visual_v_offset(); });
 
+       const vector< shared_ptr<TimeItem> > time_items(view_.time_items());
+       assert(none_of(time_items.begin(), time_items.end(),
+               [](const shared_ptr<TimeItem> &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<TimeItem> t : time_items)
+               t->paint_back(p, pp);
        for (const shared_ptr<RowItem> r : row_items)
-       {
-               assert(r);
                r->paint_back(p, pp);
-       }
 
+       for (const shared_ptr<TimeItem> t : time_items)
+               t->paint_mid(p, pp);
        for (const shared_ptr<RowItem> r : row_items)
                r->paint_mid(p, pp);
 
        for (const shared_ptr<RowItem> r : row_items)
                r->paint_fore(p, pp);
-
-       if (view_.cursors_shown())
-               view_.cursors()->draw_viewport_foreground(p, rect());
+       for (const shared_ptr<TimeItem> t : time_items)
+               t->paint_fore(p, pp);
 
        p.end();
 }