From: Soeren Apel Date: Sun, 5 Mar 2017 18:58:37 +0000 (+0100) Subject: Tie the "use coloured bg" setting in with the settings mgmt X-Git-Tag: pulseview-0.4.0~171 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=24c29d4f917ffac5a280d572cc04d1edb66a81b9;p=pulseview.git Tie the "use coloured bg" setting in with the settings mgmt --- diff --git a/pv/mainwindow.cpp b/pv/mainwindow.cpp index 8b650e1c..879c8a52 100644 --- a/pv/mainwindow.cpp +++ b/pv/mainwindow.cpp @@ -87,6 +87,9 @@ MainWindow::MainWindow(DeviceManager &device_manager, qRegisterMetaType("util::Timestamp"); qRegisterMetaType("uint64_t"); + GlobalSettings::register_change_handler(GlobalSettings::Key_View_ColouredBG, + bind(&MainWindow::on_settingViewColouredBg_changed, this, _1)); + setup_ui(); restore_ui_settings(); @@ -155,6 +158,8 @@ shared_ptr MainWindow::get_active_view() const shared_ptr 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) @@ -195,7 +200,7 @@ shared_ptr 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 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() { - shared_ptr viewbase = get_active_view(); - views::TraceView::View* view = - qobject_cast(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 viewbase = entry.second; + + // Only trace views have this setting + views::TraceView::View* view = + qobject_cast(viewbase.get()); + if (view) + view->enable_coloured_bg(state); + } } void MainWindow::on_actionAbout_triggered() diff --git a/pv/mainwindow.hpp b/pv/mainwindow.hpp index f38ee447..fdb3c888 100644 --- a/pv/mainwindow.hpp +++ b/pv/mainwindow.hpp @@ -124,9 +124,10 @@ private Q_SLOTS: void on_tab_close_requested(int index); void on_view_sticky_scrolling_shortcut(); - void on_view_coloured_bg_shortcut(); + void on_settingViewColouredBg_changed(const QVariant new_value); + void on_actionAbout_triggered(); void on_close_current_tab(); diff --git a/pv/view/trace.cpp b/pv/view/trace.cpp index e481f2a0..978f3dc8 100644 --- a/pv/view/trace.cpp +++ b/pv/view/trace.cpp @@ -31,8 +31,9 @@ #include "tracepalette.hpp" #include "view.hpp" -#include -#include +#include "pv/globalsettings.hpp" +#include "pv/widgets/colourbutton.hpp" +#include "pv/widgets/popup.hpp" namespace pv { namespace views { @@ -46,10 +47,12 @@ const QColor Trace::DarkGrayBGColour = QColor(0, 0, 0, 15*255/100); Trace::Trace(std::shared_ptr channel) : base_(channel), - coloured_bg_(true), // Default setting is set in MainWindow::setup_ui() 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&)), diff --git a/pv/view/view.cpp b/pv/view/view.cpp index e8774f33..f6048f04 100644 --- a/pv/view/view.cpp +++ b/pv/view/view.cpp @@ -57,6 +57,7 @@ #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" @@ -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() - coloured_bg_(false), 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) { + 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)), @@ -569,18 +572,11 @@ void View::toggle_sticky_scrolling(void) sticky_scrolling_ = !sticky_scrolling_; } -bool View::get_coloured_bg(void) -{ - return coloured_bg_; -} - void View::enable_coloured_bg(bool state) { const vector> items( list_by_type()); - coloured_bg_ = state; - for (shared_ptr 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(); } -void View::toggle_coloured_bg(void) -{ - enable_coloured_bg(!coloured_bg_); -} - bool View::cursors_shown() const { return show_cursors_; diff --git a/pv/view/view.hpp b/pv/view/view.hpp index 5981f57a..0e1a5443 100644 --- a/pv/view/view.hpp +++ b/pv/view/view.hpp @@ -210,22 +210,12 @@ public: */ 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); - /** - * Toggle coloured backgrounds. - */ - void toggle_coloured_bg(void); - /** * Returns true if cursors are displayed. false otherwise. */