]> sigrok.org Git - pulseview.git/commitdiff
Split signal painting into 3 layers
authorJoel Holdsworth <redacted>
Wed, 4 Sep 2013 22:48:11 +0000 (23:48 +0100)
committerJoel Holdsworth <redacted>
Sun, 29 Sep 2013 14:55:48 +0000 (23:55 +0900)
pv/view/analogsignal.cpp
pv/view/analogsignal.h
pv/view/decodesignal.cpp
pv/view/decodesignal.h
pv/view/logicsignal.cpp
pv/view/logicsignal.h
pv/view/signal.cpp
pv/view/signal.h
pv/view/trace.cpp
pv/view/trace.h
pv/view/viewport.cpp

index 681386ff6b91f9c69e4f1a84f350b08675551b43..a4474dac8e06a0026b40da41e53b15b3cc7e8bc9 100644 (file)
@@ -67,7 +67,13 @@ void AnalogSignal::set_scale(float scale)
        _scale = scale;
 }
 
        _scale = scale;
 }
 
-void AnalogSignal::paint(QPainter &p, int left, int right)
+void AnalogSignal::paint_back(QPainter &p, int left, int right)
+{
+       if (_probe->enabled)
+               paint_axis(p, get_y(), left, right);
+}
+
+void AnalogSignal::paint_mid(QPainter &p, int left, int right)
 {
        assert(_data);
        assert(right >= left);
 {
        assert(_data);
        assert(right >= left);
@@ -83,8 +89,6 @@ void AnalogSignal::paint(QPainter &p, int left, int right)
        if (!_probe->enabled)
                return;
 
        if (!_probe->enabled)
                return;
 
-       paint_axis(p, y, left, right);
-
        const deque< shared_ptr<pv::data::AnalogSnapshot> > &snapshots =
                _data->get_snapshots();
        if (snapshots.empty())
        const deque< shared_ptr<pv::data::AnalogSnapshot> > &snapshots =
                _data->get_snapshots();
        if (snapshots.empty())
index 002076a2cc5c8f95729dc70a31058b41a2e3f10b..3b92455cb706a587815b2ada7d3728f5bb202977 100644 (file)
@@ -52,12 +52,20 @@ public:
        void set_scale(float scale);
 
        /**
        void set_scale(float scale);
 
        /**
-        * Paints the signal with a QPainter
+        * Paints the background layer of the signal with a QPainter
         * @param p the QPainter to paint into.
         * @param left the x-coordinate of the left edge of the signal.
         * @param right the x-coordinate of the right edge of the signal.
         **/
         * @param p the QPainter to paint into.
         * @param left the x-coordinate of the left edge of the signal.
         * @param right the x-coordinate of the right edge of the signal.
         **/
-       void paint(QPainter &p, int left, int right);
+       void paint_back(QPainter &p, int left, int right);
+
+       /**
+        * Paints the mid-layer of the signal with a QPainter
+        * @param p the QPainter to paint into.
+        * @param left the x-coordinate of the left edge of the signal.
+        * @param right the x-coordinate of the right edge of the signal.
+        **/
+       void paint_mid(QPainter &p, int left, int right);
 
 private:
        void paint_trace(QPainter &p,
 
 private:
        void paint_trace(QPainter &p,
index 33ea33f381e484391c82ec7cb83427b45d3a252f..bc37b2019819c8c54b046467da6fc1a239b24a8e 100644 (file)
@@ -60,12 +60,17 @@ void DecodeSignal::set_view(pv::view::View *view)
        Trace::set_view(view);
 }
 
        Trace::set_view(view);
 }
 
-void DecodeSignal::paint(QPainter &p, int left, int right)
+void DecodeSignal::paint_back(QPainter &p, int left, int right)
+{
+       paint_axis(p, get_y(), left, right);
+}
+
+void DecodeSignal::paint_mid(QPainter &p, int left, int right)
 {
        using namespace pv::view::decode;
 
        assert(_view);
 {
        using namespace pv::view::decode;
 
        assert(_view);
-       const int y = _v_offset - _view->v_offset();
+       const int y = get_y();
 
        const double scale = _view->scale();
        assert(scale > 0);
 
        const double scale = _view->scale();
        assert(scale > 0);
index 95459d68fd7da43faa97474610f94a6a89d0aa7b..271937b831d87410d202776f83bfd5c6bc0e0033 100644 (file)
@@ -48,12 +48,20 @@ public:
        void set_view(pv::view::View *view);
 
        /**
        void set_view(pv::view::View *view);
 
        /**
-        * Paints the trace with a QPainter
+        * Paints the background layer of the trace with a QPainter
+        * @param p the QPainter to paint into.
+        * @param left the x-coordinate of the left edge of the signal.
+        * @param right the x-coordinate of the right edge of the signal.
+        **/
+       void paint_back(QPainter &p, int left, int right);
+
+       /**
+        * Paints the mid-layer of the trace with a QPainter
         * @param p the QPainter to paint into.
         * @param left the x-coordinate of the left edge of the signal
         * @param right the x-coordinate of the right edge of the signal
         **/
         * @param p the QPainter to paint into.
         * @param left the x-coordinate of the left edge of the signal
         * @param right the x-coordinate of the right edge of the signal
         **/
-       void paint(QPainter &p, int left, int right);
+       void paint_mid(QPainter &p, int left, int right);
 
        const std::list<QAction*> get_context_bar_actions();
 
 
        const std::list<QAction*> get_context_bar_actions();
 
index bc4f5311b1fecb6200b85f7773ea0df3245c4090..19522fb27f0187d05fd3b27dfd5c705045445162 100644 (file)
@@ -162,7 +162,13 @@ const list<QAction*> LogicSignal::get_context_bar_actions()
        return actions;
 }
 
        return actions;
 }
 
-void LogicSignal::paint(QPainter &p, int left, int right)
+void LogicSignal::paint_back(QPainter &p, int left, int right)
+{
+       if (_probe->enabled)
+               paint_axis(p, get_y(), left, right);
+}
+
+void LogicSignal::paint_mid(QPainter &p, int left, int right)
 {
        using pv::view::View;
 
 {
        using pv::view::View;
 
@@ -185,8 +191,6 @@ void LogicSignal::paint(QPainter &p, int left, int right)
        if (!_probe->enabled)
                return;
 
        if (!_probe->enabled)
                return;
 
-       paint_axis(p, y, left, right);
-
        const float high_offset = y - View::SignalHeight + 0.5f;
        const float low_offset = y + 0.5f;
 
        const float high_offset = y - View::SignalHeight + 0.5f;
        const float low_offset = y + 0.5f;
 
index 023787573c243ad334008f1a18481999ebdb3fa9..18b549811e604665fda5133bb3078c4e9c596954 100644 (file)
@@ -59,12 +59,20 @@ public:
        const std::list<QAction*> get_context_bar_actions();
 
        /**
        const std::list<QAction*> get_context_bar_actions();
 
        /**
-        * Paints the signal with a QPainter
+        * Paints the background layer of the signal with a QPainter
         * @param p the QPainter to paint into.
         * @param left the x-coordinate of the left edge of the signal.
         * @param right the x-coordinate of the right edge of the signal.
         **/
         * @param p the QPainter to paint into.
         * @param left the x-coordinate of the left edge of the signal.
         * @param right the x-coordinate of the right edge of the signal.
         **/
-       void paint(QPainter &p, int left, int right);
+       void paint_back(QPainter &p, int left, int right);
+
+       /**
+        * Paints the mid-layer of the signal with a QPainter
+        * @param p the QPainter to paint into.
+        * @param left the x-coordinate of the left edge of the signal.
+        * @param right the x-coordinate of the right edge of the signal.
+        **/
+       void paint_mid(QPainter &p, int left, int right);
 
 private:
 
 
 private:
 
index 45a8cd30726f43e64fa681c85427464c7d2ad415..d61ccd8368ec8cce971a4735459353b7429d16a4 100644 (file)
@@ -31,8 +31,6 @@
 namespace pv {
 namespace view {
 
 namespace pv {
 namespace view {
 
-const QPen Signal::SignalAxisPen(QColor(128, 128, 128, 64));
-
 const char *const ProbeNames[] = {
        "CLK",
        "DATA",
 const char *const ProbeNames[] = {
        "CLK",
        "DATA",
@@ -94,12 +92,6 @@ const sr_probe* Signal::probe() const
        return _probe;
 }
 
        return _probe;
 }
 
-void Signal::paint_axis(QPainter &p, int y, int left, int right)
-{
-       p.setPen(SignalAxisPen);
-       p.drawLine(QPointF(left, y + 0.5f), QPointF(right, y + 0.5f));
-}
-
 void Signal::on_text_changed(const QString &text)
 {
        Trace::set_name(text);
 void Signal::on_text_changed(const QString &text)
 {
        Trace::set_name(text);
index 96172d77b3a439b761ccdf93e2de2d34cc14bb11..d55bcf1fe5205386ef8165be34b020232d496def 100644 (file)
@@ -22,7 +22,6 @@
 #define PULSEVIEW_PV_SIGNAL_H
 
 #include <QComboBox>
 #define PULSEVIEW_PV_SIGNAL_H
 
 #include <QComboBox>
-#include <QPen>
 #include <QWidgetAction>
 
 #include <stdint.h>
 #include <QWidgetAction>
 
 #include <stdint.h>
@@ -43,9 +42,6 @@ class Signal : public Trace
 {
        Q_OBJECT
 
 {
        Q_OBJECT
 
-private:
-       static const QPen SignalAxisPen;
-
 protected:
        Signal(pv::SigSession &session, const sr_probe *const probe);
 
 protected:
        Signal(pv::SigSession &session, const sr_probe *const probe);
 
@@ -64,17 +60,6 @@ public:
 
        const sr_probe* probe() const;
 
 
        const sr_probe* probe() const;
 
-protected:
-
-       /**
-        * Paints a zero axis across the viewport.
-        * @param p the QPainter to paint into.
-        * @param y the y-offset of the axis.
-        * @param left the x-coordinate of the left edge of the view.
-        * @param right the x-coordinate of the right edge of the view.
-        */
-       void paint_axis(QPainter &p, int y, int left, int right);
-
 private slots:
        void on_text_changed(const QString &text);
 
 private slots:
        void on_text_changed(const QString &text);
 
index 6c43c4c2238044c572fbe0edc4e7343449c06ba7..ff1fbddbcb5305185ec1abba301cc5e3857b7c19 100644 (file)
@@ -29,6 +29,7 @@
 namespace pv {
 namespace view {
 
 namespace pv {
 namespace view {
 
+const QPen Trace::AxisPen(QColor(128, 128, 128, 64));
 const int Trace::LabelHitPadding = 2;
 
 Trace::Trace(pv::SigSession &session, QString name) :
 const int Trace::LabelHitPadding = 2;
 
 Trace::Trace(pv::SigSession &session, QString name) :
@@ -74,6 +75,27 @@ void Trace::set_view(pv::view::View *view)
        _view = view;
 }
 
        _view = view;
 }
 
+void Trace::paint_back(QPainter &p, int left, int right)
+{
+       (void)p;
+       (void)left;
+       (void)right;
+}
+
+void Trace::paint_mid(QPainter &p, int left, int right)
+{
+       (void)p;
+       (void)left;
+       (void)right;
+}
+
+void Trace::paint_fore(QPainter &p, int left, int right)
+{
+       (void)p;
+       (void)left;
+       (void)right;
+}
+
 void Trace::paint_label(QPainter &p, int right, bool hover)
 {
        assert(_view);
 void Trace::paint_label(QPainter &p, int right, bool hover)
 {
        assert(_view);
@@ -141,6 +163,17 @@ bool Trace::pt_in_label_rect(int left, int right, const QPoint &point)
                        ).contains(point);
 }
 
                        ).contains(point);
 }
 
+int Trace::get_y() const
+{
+       return _v_offset - _view->v_offset();
+}
+
+void Trace::paint_axis(QPainter &p, int y, int left, int right)
+{
+       p.setPen(AxisPen);
+       p.drawLine(QPointF(left, y + 0.5f), QPointF(right, y + 0.5f));
+}
+
 void Trace::compute_text_size(QPainter &p)
 {
        _text_size = QSize(
 void Trace::compute_text_size(QPainter &p)
 {
        _text_size = QSize(
index ffd87fa45524feae6e5d2cade3d3ef86cdb368da..07f90f4c92734e718f085f7b9b0bc0fc1d913564 100644 (file)
@@ -23,6 +23,7 @@
 
 #include <QColor>
 #include <QPainter>
 
 #include <QColor>
 #include <QPainter>
+#include <QPen>
 #include <QRect>
 #include <QString>
 
 #include <QRect>
 #include <QString>
 
@@ -43,6 +44,7 @@ class Trace : public SelectableItem
        Q_OBJECT
 
 private:
        Q_OBJECT
 
 private:
+       static const QPen AxisPen;
        static const int LabelHitPadding;
 
 protected:
        static const int LabelHitPadding;
 
 protected:
@@ -87,12 +89,28 @@ public:
        virtual void set_view(pv::view::View *view);
 
        /**
        virtual void set_view(pv::view::View *view);
 
        /**
-        * Paints the trace with a QPainter
+        * Paints the background layer of the trace with a QPainter
         * @param p the QPainter to paint into.
         * @param left the x-coordinate of the left edge of the signal
         * @param right the x-coordinate of the right edge of the signal
         **/
         * @param p the QPainter to paint into.
         * @param left the x-coordinate of the left edge of the signal
         * @param right the x-coordinate of the right edge of the signal
         **/
-       virtual void paint(QPainter &p, int left, int right) = 0;
+       virtual void paint_back(QPainter &p, int left, int right);
+
+       /**
+        * Paints the mid-layer of the trace with a QPainter
+        * @param p the QPainter to paint into.
+        * @param left the x-coordinate of the left edge of the signal
+        * @param right the x-coordinate of the right edge of the signal
+        **/
+       virtual void paint_mid(QPainter &p, int left, int right);
+
+       /**
+        * Paints the foreground layer of the trace with a QPainter
+        * @param p the QPainter to paint into.
+        * @param left the x-coordinate of the left edge of the signal
+        * @param right the x-coordinate of the right edge of the signal
+        **/
+       virtual void paint_fore(QPainter &p, int left, int right);
 
        /**
         * Paints the signal label into a QGLWidget.
 
        /**
         * Paints the signal label into a QGLWidget.
@@ -113,6 +131,21 @@ public:
         */
        bool pt_in_label_rect(int left, int right, const QPoint &point);
 
         */
        bool pt_in_label_rect(int left, int right, const QPoint &point);
 
+protected:
+       /**
+        * Gets the y-offset of the axis.
+        */
+       int get_y() const;
+
+       /**
+        * Paints a zero axis across the viewport.
+        * @param p the QPainter to paint into.
+        * @param y the y-offset of the axis.
+        * @param left the x-coordinate of the left edge of the view.
+        * @param right the x-coordinate of the right edge of the view.
+        */
+       void paint_axis(QPainter &p, int y, int left, int right);
+
 private:
 
        /**
 private:
 
        /**
index 06fab904e75168fab06a9499574446959c93e9a3..8cf97ff58020594b2e6c82290589a70112b260e0 100644 (file)
@@ -72,9 +72,15 @@ void Viewport::paintEvent(QPaintEvent*)
        BOOST_FOREACH(const shared_ptr<Trace> t, traces)
        {
                assert(t);
        BOOST_FOREACH(const shared_ptr<Trace> t, traces)
        {
                assert(t);
-               t->paint(p, 0, width());
+               t->paint_back(p, 0, width());
        }
 
        }
 
+       BOOST_FOREACH(const shared_ptr<Trace> t, traces)
+               t->paint_mid(p, 0, width());
+
+       BOOST_FOREACH(const shared_ptr<Trace> t, traces)
+               t->paint_fore(p, 0, width());
+
        if (_view.cursors_shown())
                _view.cursors().draw_viewport_foreground(p, rect());
 
        if (_view.cursors_shown())
                _view.cursors().draw_viewport_foreground(p, rect());