From: Soeren Apel Date: Mon, 28 Dec 2015 14:13:42 +0000 (+0100) Subject: Use channel color as the trace background color X-Git-Tag: pulseview-0.3.0~28 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=99af6802961b0a5ec7ec7d3ff2215c8eb6925ca3;p=pulseview.git Use channel color as the trace background color --- diff --git a/pv/view/analogsignal.cpp b/pv/view/analogsignal.cpp index 683757d1..2597a8f3 100644 --- a/pv/view/analogsignal.cpp +++ b/pv/view/analogsignal.cpp @@ -63,7 +63,7 @@ AnalogSignal::AnalogSignal( scale_index_(0), scale_index_drag_offset_(0) { - colour_ = SignalColours[channel_->index() % countof(SignalColours)]; + set_colour(SignalColours[channel_->index() % countof(SignalColours)]); } AnalogSignal::~AnalogSignal() @@ -105,8 +105,10 @@ void AnalogSignal::scale_handle_drag_release() void AnalogSignal::paint_back(QPainter &p, const ViewItemPaintParams &pp) { - if (channel_->enabled()) + if (channel_->enabled()) { + Trace::paint_back(p, pp); paint_axis(p, pp, get_visual_y()); + } } void AnalogSignal::paint_mid(QPainter &p, const ViewItemPaintParams &pp) diff --git a/pv/view/logicsignal.cpp b/pv/view/logicsignal.cpp index 63d15314..5d3ac102 100644 --- a/pv/view/logicsignal.cpp +++ b/pv/view/logicsignal.cpp @@ -113,7 +113,7 @@ LogicSignal::LogicSignal( { shared_ptr trigger; - colour_ = SignalColours[channel->index() % countof(SignalColours)]; + set_colour(SignalColours[channel->index() % countof(SignalColours)]); /* Populate this channel's trigger setting with whatever we * find in the current session trigger, if anything. */ @@ -163,12 +163,6 @@ void LogicSignal::scale_handle_dragged(int offset) signal_height_ = ((units < 1) ? 1 : units) * font_height; } -void LogicSignal::paint_back(QPainter &p, const ViewItemPaintParams &pp) -{ - if (channel_->enabled()) - paint_axis(p, pp, get_visual_y()); -} - void LogicSignal::paint_mid(QPainter &p, const ViewItemPaintParams &pp) { QLineF *line; diff --git a/pv/view/logicsignal.hpp b/pv/view/logicsignal.hpp index d7c4cb64..8c3525e6 100644 --- a/pv/view/logicsignal.hpp +++ b/pv/view/logicsignal.hpp @@ -94,13 +94,6 @@ public: */ void scale_handle_dragged(int offset); - /** - * Paints the background layer of the signal 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); - /** * Paints the mid-layer of the signal with a QPainter * @param p the QPainter to paint into. diff --git a/pv/view/signal.cpp b/pv/view/signal.cpp index 47e91f4b..09a6da8f 100644 --- a/pv/view/signal.cpp +++ b/pv/view/signal.cpp @@ -107,6 +107,12 @@ const ViewItemOwner::item_list& Signal::child_items() const return items_; } +void Signal::paint_back(QPainter &p, const ViewItemPaintParams &pp) +{ + if (channel_->enabled()) + Trace::paint_back(p, pp); +} + void Signal::populate_popup_form(QWidget *parent, QFormLayout *form) { name_widget_ = new QComboBox(parent); diff --git a/pv/view/signal.hpp b/pv/view/signal.hpp index db328652..bcd4e2eb 100644 --- a/pv/view/signal.hpp +++ b/pv/view/signal.hpp @@ -76,6 +76,8 @@ public: */ const item_list& child_items() const; + void paint_back(QPainter &p, const ViewItemPaintParams &pp); + virtual void populate_popup_form(QWidget *parent, QFormLayout *form); QMenu* create_context_menu(QWidget *parent); diff --git a/pv/view/trace.cpp b/pv/view/trace.cpp index 2e15ca95..05054d49 100644 --- a/pv/view/trace.cpp +++ b/pv/view/trace.cpp @@ -66,6 +66,9 @@ QColor Trace::colour() const void Trace::set_colour(QColor colour) { colour_ = colour; + + bgcolour_ = colour; + bgcolour_.setAlpha(20); } void Trace::paint_label(QPainter &p, const QRect &rect, bool hover) @@ -170,6 +173,21 @@ QRectF Trace::hit_box_rect(const ViewItemPaintParams &pp) const pp.width(), h); } +void Trace::paint_back(QPainter &p, const ViewItemPaintParams &pp) +{ + p.setPen(QPen(Qt::NoPen)); + p.setBrush(bgcolour_); + + const std::pair extents = v_extents(); + + const int x = 0; + const int y = get_visual_y() + extents.first; + const int w = pp.right() - pp.left(); + const int h = extents.second - extents.first; + + p.drawRect(x, y, w, h); +} + void Trace::paint_axis(QPainter &p, const ViewItemPaintParams &pp, int y) { p.setPen(AxisPen); @@ -236,7 +254,7 @@ void Trace::on_colour_changed(const QColor &colour) set_colour(colour); if (owner_) - owner_->row_item_appearance_changed(true, false); + owner_->row_item_appearance_changed(true, true); } } // namespace view diff --git a/pv/view/trace.hpp b/pv/view/trace.hpp index 677f366b..dce9fcc9 100644 --- a/pv/view/trace.hpp +++ b/pv/view/trace.hpp @@ -100,6 +100,13 @@ public: QRectF label_rect(const QRectF &rect) const; protected: + /** + * Paints the background layer of the signal with a QPainter + * @param p the QPainter to paint into. + * @param pp the painting parameters object to paint with.. + */ + virtual void paint_back(QPainter &p, const ViewItemPaintParams &pp); + /** * Paints a zero axis across the viewport. * @param p the QPainter to paint into. @@ -123,7 +130,7 @@ private Q_SLOTS: protected: QString name_; - QColor colour_; + QColor colour_, bgcolour_; private: pv::widgets::Popup *popup_;