]> sigrok.org Git - pulseview.git/commitdiff
Implement "use coloured background" functionality
authorSoeren Apel <redacted>
Mon, 28 Dec 2015 20:16:33 +0000 (21:16 +0100)
committerSoeren Apel <redacted>
Mon, 28 Dec 2015 20:16:33 +0000 (21:16 +0100)
pv/mainwindow.cpp
pv/view/trace.cpp
pv/view/trace.hpp
pv/view/view.cpp
pv/view/view.hpp

index 272dac234374c9f4e69e825100520e81010644d4..3c5af937fda9546eaf67e84b08a04eb819e41861 100644 (file)
@@ -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()
index 05054d4927001c260d271d713ba88bbc14433029..3727afa2de246912c8834dc0f3977d5131ec25bc 100644 (file)
@@ -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<int, int> extents = v_extents();
+               const std::pair<int, int> 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)
index dce9fcc920c4ab856a5bb60663b1cb50146a3538..74daf4a53cd69d8303709b0ae3a57da92830cab2 100644 (file)
@@ -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_;
index c6a6afd323dcccac191061bfac65c640bac36c68..eeb8afd236529e442bac91d6f4eeae6b5a065f05 100644 (file)
@@ -42,6 +42,7 @@
 
 #include <libsigrokcxx/libsigrokcxx.hpp>
 
+#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<shared_ptr<TraceTreeItem>> items(
+               list_by_type<TraceTreeItem>());
+
+       for (shared_ptr<TraceTreeItem> i : items) {
+               // Can't cast to Trace because it's abstract, so we need to
+               // check for any derived classes individually
+
+               shared_ptr<AnalogSignal> a = dynamic_pointer_cast<AnalogSignal>(i);
+               if (a)
+                       a->set_coloured_bg(state);
+
+               shared_ptr<LogicSignal> l = dynamic_pointer_cast<LogicSignal>(i);
+               if (l)
+                       l->set_coloured_bg(state);
+
+               shared_ptr<DecodeTrace> d = dynamic_pointer_cast<DecodeTrace>(i);
+               if (d)
+                       d->set_coloured_bg(state);
+       }
+
+       viewport_->update();
+}
+
 bool View::cursors_shown() const
 {
        return show_cursors_;
index 66d31a225bf7b28806da3b28e87465ce5349daa7..635273dae74ad6e1131a592da699beba6a8e76e7 100644 (file)
@@ -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.
         */