From: Joel Holdsworth Date: Wed, 4 Sep 2013 22:48:11 +0000 (+0100) Subject: Split signal painting into 3 layers X-Git-Tag: pulseview-0.2.0~297 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=fe08b6e8a85c80ae738757f7d85aa38ef7c4bdc3;p=pulseview.git Split signal painting into 3 layers --- diff --git a/pv/view/analogsignal.cpp b/pv/view/analogsignal.cpp index 681386ff..a4474dac 100644 --- a/pv/view/analogsignal.cpp +++ b/pv/view/analogsignal.cpp @@ -67,7 +67,13 @@ void AnalogSignal::set_scale(float 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); @@ -83,8 +89,6 @@ void AnalogSignal::paint(QPainter &p, int left, int right) if (!_probe->enabled) return; - paint_axis(p, y, left, right); - const deque< shared_ptr > &snapshots = _data->get_snapshots(); if (snapshots.empty()) diff --git a/pv/view/analogsignal.h b/pv/view/analogsignal.h index 002076a2..3b92455c 100644 --- a/pv/view/analogsignal.h +++ b/pv/view/analogsignal.h @@ -52,12 +52,20 @@ public: 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. **/ - 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, diff --git a/pv/view/decodesignal.cpp b/pv/view/decodesignal.cpp index 33ea33f3..bc37b201 100644 --- a/pv/view/decodesignal.cpp +++ b/pv/view/decodesignal.cpp @@ -60,12 +60,17 @@ void DecodeSignal::set_view(pv::view::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); - const int y = _v_offset - _view->v_offset(); + const int y = get_y(); const double scale = _view->scale(); assert(scale > 0); diff --git a/pv/view/decodesignal.h b/pv/view/decodesignal.h index 95459d68..271937b8 100644 --- a/pv/view/decodesignal.h +++ b/pv/view/decodesignal.h @@ -48,12 +48,20 @@ public: 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 **/ - void paint(QPainter &p, int left, int right); + void paint_mid(QPainter &p, int left, int right); const std::list get_context_bar_actions(); diff --git a/pv/view/logicsignal.cpp b/pv/view/logicsignal.cpp index bc4f5311..19522fb2 100644 --- a/pv/view/logicsignal.cpp +++ b/pv/view/logicsignal.cpp @@ -162,7 +162,13 @@ const list LogicSignal::get_context_bar_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; @@ -185,8 +191,6 @@ void LogicSignal::paint(QPainter &p, int left, int right) 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; diff --git a/pv/view/logicsignal.h b/pv/view/logicsignal.h index 02378757..18b54981 100644 --- a/pv/view/logicsignal.h +++ b/pv/view/logicsignal.h @@ -59,12 +59,20 @@ public: const std::list 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. **/ - 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: diff --git a/pv/view/signal.cpp b/pv/view/signal.cpp index 45a8cd30..d61ccd83 100644 --- a/pv/view/signal.cpp +++ b/pv/view/signal.cpp @@ -31,8 +31,6 @@ namespace pv { namespace view { -const QPen Signal::SignalAxisPen(QColor(128, 128, 128, 64)); - const char *const ProbeNames[] = { "CLK", "DATA", @@ -94,12 +92,6 @@ const sr_probe* Signal::probe() const 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); diff --git a/pv/view/signal.h b/pv/view/signal.h index 96172d77..d55bcf1f 100644 --- a/pv/view/signal.h +++ b/pv/view/signal.h @@ -22,7 +22,6 @@ #define PULSEVIEW_PV_SIGNAL_H #include -#include #include #include @@ -43,9 +42,6 @@ class Signal : public Trace { Q_OBJECT -private: - static const QPen SignalAxisPen; - protected: Signal(pv::SigSession &session, const sr_probe *const probe); @@ -64,17 +60,6 @@ public: 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); diff --git a/pv/view/trace.cpp b/pv/view/trace.cpp index 6c43c4c2..ff1fbddb 100644 --- a/pv/view/trace.cpp +++ b/pv/view/trace.cpp @@ -29,6 +29,7 @@ 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) : @@ -74,6 +75,27 @@ void Trace::set_view(pv::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); @@ -141,6 +163,17 @@ bool Trace::pt_in_label_rect(int left, int right, const QPoint &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( diff --git a/pv/view/trace.h b/pv/view/trace.h index ffd87fa4..07f90f4c 100644 --- a/pv/view/trace.h +++ b/pv/view/trace.h @@ -23,6 +23,7 @@ #include #include +#include #include #include @@ -43,6 +44,7 @@ class Trace : public SelectableItem Q_OBJECT private: + static const QPen AxisPen; static const int LabelHitPadding; protected: @@ -87,12 +89,28 @@ public: 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 **/ - 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. @@ -113,6 +131,21 @@ public: */ 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: /** diff --git a/pv/view/viewport.cpp b/pv/view/viewport.cpp index 06fab904..8cf97ff5 100644 --- a/pv/view/viewport.cpp +++ b/pv/view/viewport.cpp @@ -72,9 +72,15 @@ void Viewport::paintEvent(QPaintEvent*) BOOST_FOREACH(const shared_ptr t, traces) { assert(t); - t->paint(p, 0, width()); + t->paint_back(p, 0, width()); } + BOOST_FOREACH(const shared_ptr t, traces) + t->paint_mid(p, 0, width()); + + BOOST_FOREACH(const shared_ptr t, traces) + t->paint_fore(p, 0, width()); + if (_view.cursors_shown()) _view.cursors().draw_viewport_foreground(p, rect());