Tie the "use coloured bg" setting in with the settings mgmt
[pulseview.git] / pv / mainwindow.cpp
index 33ebdd648e84e09fd6c6614eeb6a6511ce413047..879c8a522d9121f8c27a907a9d1fc2bf78717dc4 100644 (file)
 #include "mainwindow.hpp"
 
 #include "devicemanager.hpp"
+#include "globalsettings.hpp"
 #include "util.hpp"
 #include "devices/hardwaredevice.hpp"
 #include "dialogs/about.hpp"
+#include "dialogs/settings.hpp"
 #include "toolbars/mainbar.hpp"
 #include "view/view.hpp"
 #include "views/trace/standardbar.hpp"
@@ -65,6 +67,9 @@ class ViewItem;
 
 using toolbars::MainBar;
 
+using std::bind;
+using std::placeholders::_1;
+
 const QString MainWindow::WindowTitle = tr("PulseView");
 
 MainWindow::MainWindow(DeviceManager &device_manager,
@@ -82,6 +87,9 @@ MainWindow::MainWindow(DeviceManager &device_manager,
        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();
 
@@ -150,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)
 {
+       GlobalSettings settings;
+
        QMainWindow *main_window = nullptr;
        for (auto entry : session_windows_)
                if (entry.first.get() == &session)
@@ -190,7 +200,7 @@ shared_ptr<views::ViewBase> MainWindow::add_view(const QString &title,
                                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) {
@@ -392,6 +402,8 @@ void MainWindow::setup_ui()
                this, SLOT(on_run_stop_clicked()));
        connect(&session_state_mapper_, SIGNAL(mapped(QObject*)),
                this, SLOT(on_capture_state_changed(QObject*)));
+       connect(settings_button_, SIGNAL(clicked(bool)),
+               this, SLOT(on_settings_clicked()));
 
        connect(&session_selector_, SIGNAL(tabCloseRequested(int)),
                this, SLOT(on_tab_close_requested(int)));
@@ -591,6 +603,12 @@ void MainWindow::on_run_stop_clicked()
        }
 }
 
+void MainWindow::on_settings_clicked()
+{
+       dialogs::Settings dlg;
+       dlg.exec();
+}
+
 void MainWindow::on_session_name_changed()
 {
        // Update the corresponding dock widget's name(s)
@@ -714,11 +732,25 @@ void MainWindow::on_view_sticky_scrolling_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()