From: Soeren Apel Date: Mon, 28 Dec 2015 20:16:33 +0000 (+0100) Subject: Implement "use coloured background" functionality X-Git-Tag: pulseview-0.3.0~25 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=574c568d184240cd87be1b57fc00d60a4eac7566;p=pulseview.git Implement "use coloured background" functionality --- diff --git a/pv/mainwindow.cpp b/pv/mainwindow.cpp index 272dac23..3c5af937 100644 --- a/pv/mainwindow.cpp +++ b/pv/mainwindow.cpp @@ -476,12 +476,14 @@ void MainWindow::setup_ui() action_view_coloured_bg_->setCheckable(true); action_view_coloured_bg_->setChecked(true); - action_view_coloured_bg_->setShortcut(QKeySequence(Qt::Key_S)); + action_view_coloured_bg_->setShortcut(QKeySequence(Qt::Key_B)); action_view_coloured_bg_->setObjectName( QString::fromUtf8("actionViewColouredBg")); action_view_coloured_bg_->setText(tr("Use &coloured backgrounds")); menu_view->addAction(action_view_coloured_bg_); + view_->enable_coloured_bg(action_view_coloured_bg_->isChecked()); + menu_view->addSeparator(); action_view_show_cursors_->setCheckable(true); @@ -807,6 +809,7 @@ void MainWindow::on_actionViewStickyScrolling_triggered() void MainWindow::on_actionViewColouredBg_triggered() { + view_->enable_coloured_bg(action_view_coloured_bg_->isChecked()); } void MainWindow::on_actionViewShowCursors_triggered() diff --git a/pv/view/trace.cpp b/pv/view/trace.cpp index 05054d49..3727afa2 100644 --- a/pv/view/trace.cpp +++ b/pv/view/trace.cpp @@ -43,6 +43,7 @@ const int Trace::LabelHitPadding = 2; Trace::Trace(QString name) : name_(name), + coloured_bg_(true), // Default setting is set in MainWindow::setup_ui() popup_(nullptr), popup_form_(nullptr) { @@ -71,6 +72,11 @@ void Trace::set_colour(QColor colour) bgcolour_.setAlpha(20); } +void Trace::set_coloured_bg(bool state) +{ + coloured_bg_ = state; +} + void Trace::paint_label(QPainter &p, const QRect &rect, bool hover) { const int y = get_visual_y(); @@ -175,17 +181,19 @@ QRectF Trace::hit_box_rect(const ViewItemPaintParams &pp) const void Trace::paint_back(QPainter &p, const ViewItemPaintParams &pp) { - p.setPen(QPen(Qt::NoPen)); - p.setBrush(bgcolour_); + if (coloured_bg_) { + p.setPen(QPen(Qt::NoPen)); + p.setBrush(bgcolour_); - const std::pair extents = v_extents(); + 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; + 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); + p.drawRect(x, y, w, h); + } } void Trace::paint_axis(QPainter &p, const ViewItemPaintParams &pp, int y) diff --git a/pv/view/trace.hpp b/pv/view/trace.hpp index dce9fcc9..74daf4a5 100644 --- a/pv/view/trace.hpp +++ b/pv/view/trace.hpp @@ -73,6 +73,11 @@ public: */ void set_colour(QColor colour); + /** + * Enables or disables the coloured background for this trace. + */ + void set_coloured_bg(bool state); + /** * Computes the outline rectangle of the viewport hit-box. * @param rect the rectangle of the viewport area. @@ -131,6 +136,7 @@ private Q_SLOTS: protected: QString name_; QColor colour_, bgcolour_; + bool coloured_bg_; private: pv::widgets::Popup *popup_; diff --git a/pv/view/view.cpp b/pv/view/view.cpp index c6a6afd3..eeb8afd2 100644 --- a/pv/view/view.cpp +++ b/pv/view/view.cpp @@ -42,6 +42,7 @@ #include +#include "analogsignal.hpp" #include "decodetrace.hpp" #include "header.hpp" #include "logicsignal.hpp" @@ -437,6 +438,31 @@ void View::enable_sticky_scrolling(bool state) sticky_scrolling_ = state; } +void View::enable_coloured_bg(bool state) +{ + const vector> items( + list_by_type()); + + for (shared_ptr i : items) { + // Can't cast to Trace because it's abstract, so we need to + // check for any derived classes individually + + shared_ptr a = dynamic_pointer_cast(i); + if (a) + a->set_coloured_bg(state); + + shared_ptr l = dynamic_pointer_cast(i); + if (l) + l->set_coloured_bg(state); + + shared_ptr d = dynamic_pointer_cast(i); + if (d) + d->set_coloured_bg(state); + } + + viewport_->update(); +} + bool View::cursors_shown() const { return show_cursors_; diff --git a/pv/view/view.hpp b/pv/view/view.hpp index 66d31a22..635273da 100644 --- a/pv/view/view.hpp +++ b/pv/view/view.hpp @@ -171,6 +171,12 @@ public: */ void enable_sticky_scrolling(bool state); + /** + * Enables or disables coloured trace backgrounds. If they're not + * coloured then they will use alternating colors. + */ + void enable_coloured_bg(bool state); + /** * Returns true if cursors are displayed. false otherwise. */