]> sigrok.org Git - pulseview.git/commitdiff
Tie the "use coloured bg" setting in with the settings mgmt
authorSoeren Apel <redacted>
Sun, 5 Mar 2017 18:58:37 +0000 (19:58 +0100)
committerUwe Hermann <redacted>
Tue, 7 Mar 2017 21:59:36 +0000 (22:59 +0100)
pv/mainwindow.cpp
pv/mainwindow.hpp
pv/view/trace.cpp
pv/view/view.cpp
pv/view/view.hpp

index 8b650e1ca00067b0d406b6387a3eab657a2dfae4..879c8a522d9121f8c27a907a9d1fc2bf78717dc4 100644 (file)
@@ -87,6 +87,9 @@ MainWindow::MainWindow(DeviceManager &device_manager,
        qRegisterMetaType<util::Timestamp>("util::Timestamp");
        qRegisterMetaType<uint64_t>("uint64_t");
 
        qRegisterMetaType<util::Timestamp>("util::Timestamp");
        qRegisterMetaType<uint64_t>("uint64_t");
 
+       GlobalSettings::register_change_handler(GlobalSettings::Key_View_ColouredBG,
+               bind(&MainWindow::on_settingViewColouredBg_changed, this, _1));
+
        setup_ui();
        restore_ui_settings();
 
        setup_ui();
        restore_ui_settings();
 
@@ -155,6 +158,8 @@ shared_ptr<views::ViewBase> MainWindow::get_active_view() const
 shared_ptr<views::ViewBase> MainWindow::add_view(const QString &title,
        views::ViewType type, Session &session)
 {
 shared_ptr<views::ViewBase> MainWindow::add_view(const QString &title,
        views::ViewType type, Session &session)
 {
+       GlobalSettings settings;
+
        QMainWindow *main_window = nullptr;
        for (auto entry : session_windows_)
                if (entry.first.get() == &session)
        QMainWindow *main_window = nullptr;
        for (auto entry : session_windows_)
                if (entry.first.get() == &session)
@@ -195,7 +200,7 @@ shared_ptr<views::ViewBase> MainWindow::add_view(const QString &title,
                                SLOT(trigger_event(util::Timestamp)));
 
                        v->enable_sticky_scrolling(true);
                                SLOT(trigger_event(util::Timestamp)));
 
                        v->enable_sticky_scrolling(true);
-                       v->enable_coloured_bg(true);
+                       v->enable_coloured_bg(settings.value(GlobalSettings::Key_View_ColouredBG).toBool());
 
                        shared_ptr<MainBar> main_bar = session.main_bar();
                        if (!main_bar) {
 
                        shared_ptr<MainBar> main_bar = session.main_bar();
                        if (!main_bar) {
@@ -727,11 +732,25 @@ void MainWindow::on_view_sticky_scrolling_shortcut()
 
 void MainWindow::on_view_coloured_bg_shortcut()
 {
 
 void MainWindow::on_view_coloured_bg_shortcut()
 {
-       shared_ptr<views::ViewBase> viewbase = get_active_view();
-       views::TraceView::View* view =
-                       qobject_cast<views::TraceView::View*>(viewbase.get());
-       if (view)
-               view->toggle_coloured_bg();
+       GlobalSettings settings;
+
+       bool state = settings.value(GlobalSettings::Key_View_ColouredBG).toBool();
+       settings.setValue(GlobalSettings::Key_View_ColouredBG, !state);
+}
+
+void MainWindow::on_settingViewColouredBg_changed(const QVariant new_value)
+{
+       bool state = new_value.toBool();
+
+       for (auto entry : view_docks_) {
+               shared_ptr<views::ViewBase> viewbase = entry.second;
+
+               // Only trace views have this setting
+               views::TraceView::View* view =
+                               qobject_cast<views::TraceView::View*>(viewbase.get());
+               if (view)
+                       view->enable_coloured_bg(state);
+       }
 }
 
 void MainWindow::on_actionAbout_triggered()
 }
 
 void MainWindow::on_actionAbout_triggered()
index f38ee44781632521cba1ee31402cc68af1a2bbfd..fdb3c88886d2ce05c0816e437ef4fbdb41f2983d 100644 (file)
@@ -124,9 +124,10 @@ private Q_SLOTS:
        void on_tab_close_requested(int index);
 
        void on_view_sticky_scrolling_shortcut();
        void on_tab_close_requested(int index);
 
        void on_view_sticky_scrolling_shortcut();
-
        void on_view_coloured_bg_shortcut();
 
        void on_view_coloured_bg_shortcut();
 
+       void on_settingViewColouredBg_changed(const QVariant new_value);
+
        void on_actionAbout_triggered();
 
        void on_close_current_tab();
        void on_actionAbout_triggered();
 
        void on_close_current_tab();
index e481f2a009753aacd2a82a15eca93bb5a3895761..978f3dc84137d467fcc0d0dee4288710fb280838 100644 (file)
@@ -31,8 +31,9 @@
 #include "tracepalette.hpp"
 #include "view.hpp"
 
 #include "tracepalette.hpp"
 #include "view.hpp"
 
-#include <pv/widgets/colourbutton.hpp>
-#include <pv/widgets/popup.hpp>
+#include "pv/globalsettings.hpp"
+#include "pv/widgets/colourbutton.hpp"
+#include "pv/widgets/popup.hpp"
 
 namespace pv {
 namespace views {
 
 namespace pv {
 namespace views {
@@ -46,10 +47,12 @@ const QColor Trace::DarkGrayBGColour = QColor(0, 0, 0, 15*255/100);
 
 Trace::Trace(std::shared_ptr<data::SignalBase> channel) :
        base_(channel),
 
 Trace::Trace(std::shared_ptr<data::SignalBase> channel) :
        base_(channel),
-       coloured_bg_(true), // Default setting is set in MainWindow::setup_ui()
        popup_(nullptr),
        popup_form_(nullptr)
 {
        popup_(nullptr),
        popup_form_(nullptr)
 {
+       GlobalSettings settings;
+       coloured_bg_ = settings.value(GlobalSettings::Key_View_ColouredBG).toBool();
+
        connect(channel.get(), SIGNAL(name_changed(const QString&)),
                this, SLOT(on_name_changed(const QString&)));
        connect(channel.get(), SIGNAL(colour_changed(const QColor&)),
        connect(channel.get(), SIGNAL(name_changed(const QString&)),
                this, SLOT(on_name_changed(const QString&)));
        connect(channel.get(), SIGNAL(colour_changed(const QColor&)),
index e8774f332b235dfa20222c4cd5da09202a0b1371..f6048f0401c3c8a16826307528f2861b2fbb31db 100644 (file)
@@ -57,6 +57,7 @@
 #include "viewport.hpp"
 
 #include "pv/session.hpp"
 #include "viewport.hpp"
 
 #include "pv/session.hpp"
+#include "pv/globalsettings.hpp"
 #include "pv/devices/device.hpp"
 #include "pv/data/logic.hpp"
 #include "pv/data/logicsegment.hpp"
 #include "pv/devices/device.hpp"
 #include "pv/data/logic.hpp"
 #include "pv/data/logicsegment.hpp"
@@ -145,7 +146,6 @@ View::View(Session &session, QWidget *parent) :
        offset_(0),
        updating_scroll_(false),
        sticky_scrolling_(false), // Default setting is set in MainWindow::setup_ui()
        offset_(0),
        updating_scroll_(false),
        sticky_scrolling_(false), // Default setting is set in MainWindow::setup_ui()
-       coloured_bg_(false),
        always_zoom_to_fit_(false),
        tick_period_(0),
        tick_prefix_(pv::util::SIPrefix::yocto),
        always_zoom_to_fit_(false),
        tick_period_(0),
        tick_prefix_(pv::util::SIPrefix::yocto),
@@ -160,6 +160,9 @@ View::View(Session &session, QWidget *parent) :
        saved_v_offset_(0),
        size_finalized_(false)
 {
        saved_v_offset_(0),
        size_finalized_(false)
 {
+       GlobalSettings settings;
+       coloured_bg_ = settings.value(GlobalSettings::Key_View_ColouredBG).toBool();
+
        connect(scrollarea_.horizontalScrollBar(), SIGNAL(valueChanged(int)),
                this, SLOT(h_scroll_value_changed(int)));
        connect(scrollarea_.verticalScrollBar(), SIGNAL(valueChanged(int)),
        connect(scrollarea_.horizontalScrollBar(), SIGNAL(valueChanged(int)),
                this, SLOT(h_scroll_value_changed(int)));
        connect(scrollarea_.verticalScrollBar(), SIGNAL(valueChanged(int)),
@@ -569,18 +572,11 @@ void View::toggle_sticky_scrolling(void)
        sticky_scrolling_ = !sticky_scrolling_;
 }
 
        sticky_scrolling_ = !sticky_scrolling_;
 }
 
-bool View::get_coloured_bg(void)
-{
-       return coloured_bg_;
-}
-
 void View::enable_coloured_bg(bool state)
 {
        const vector<shared_ptr<TraceTreeItem>> items(
                list_by_type<TraceTreeItem>());
 
 void View::enable_coloured_bg(bool state)
 {
        const vector<shared_ptr<TraceTreeItem>> items(
                list_by_type<TraceTreeItem>());
 
-       coloured_bg_ = state;
-
        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
        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
@@ -603,11 +599,6 @@ void View::enable_coloured_bg(bool state)
        viewport_->update();
 }
 
        viewport_->update();
 }
 
-void View::toggle_coloured_bg(void)
-{
-       enable_coloured_bg(!coloured_bg_);
-}
-
 bool View::cursors_shown() const
 {
        return show_cursors_;
 bool View::cursors_shown() const
 {
        return show_cursors_;
index 5981f57a036c92a986710e4cf1520eec649ffe8c..0e1a54438a4206f00254453e26f4565c270de3bb 100644 (file)
@@ -210,22 +210,12 @@ public:
         */
        void toggle_sticky_scrolling(void);
 
         */
        void toggle_sticky_scrolling(void);
 
-       /**
-        * Get current coloured_bg state. Returns true if coloured backgrounds are enabled.
-        */
-       bool get_coloured_bg(void);
-
        /**
         * Enables or disables coloured trace backgrounds. If they're not
         * coloured then they will use alternating colors.
         */
        void enable_coloured_bg(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);
 
-       /**
-        * Toggle coloured backgrounds.
-        */
-       void toggle_coloured_bg(void);
-
        /**
         * Returns true if cursors are displayed. false otherwise.
         */
        /**
         * Returns true if cursors are displayed. false otherwise.
         */