From: Soeren Apel Date: Sun, 12 Mar 2017 20:32:35 +0000 (+0100) Subject: Tie the "sticky scrolling" setting in with the settings mgmt X-Git-Tag: pulseview-0.4.0~153 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=87a97d8aa169936ec2dcd229df88b8c5b4a1411c;p=pulseview.git Tie the "sticky scrolling" setting in with the settings mgmt --- diff --git a/pv/dialogs/settings.cpp b/pv/dialogs/settings.cpp index 5346e5c9..a3738b73 100644 --- a/pv/dialogs/settings.cpp +++ b/pv/dialogs/settings.cpp @@ -125,7 +125,12 @@ QWidget *Settings::get_view_settings_form(QWidget *parent) const QCheckBox *always_zoom_to_fit_cb = new QCheckBox(); always_zoom_to_fit_cb->setChecked(settings.value(GlobalSettings::Key_View_AlwaysZoomToFit).toBool()); connect(always_zoom_to_fit_cb, SIGNAL(stateChanged(int)), this, SLOT(on_view_alwaysZoomToFit_changed(int))); - trace_view_layout->addRow(tr("&Always zoom-to-fit during capture"), always_zoom_to_fit_cb); + trace_view_layout->addRow(tr("Constantly perform &zoom-to-fit during capture"), always_zoom_to_fit_cb); + + QCheckBox *sticky_scrolling_cb = new QCheckBox(); + sticky_scrolling_cb->setChecked(settings.value(GlobalSettings::Key_View_StickyScrolling).toBool()); + connect(sticky_scrolling_cb, SIGNAL(stateChanged(int)), this, SLOT(on_view_stickyScrolling_changed(int))); + trace_view_layout->addRow(tr("Always keep &newest samples at the right edge during capture"), sticky_scrolling_cb); return form; } @@ -248,5 +253,12 @@ void Settings::on_view_colouredBG_changed(int state) settings.setValue(GlobalSettings::Key_View_ColouredBG, state ? true : false); } +void Settings::on_view_stickyScrolling_changed(int state) +{ + GlobalSettings settings; + settings.setValue(GlobalSettings::Key_View_StickyScrolling, state ? true : false); +} + + } // namespace dialogs } // namespace pv diff --git a/pv/dialogs/settings.hpp b/pv/dialogs/settings.hpp index f0501120..b204d683 100644 --- a/pv/dialogs/settings.hpp +++ b/pv/dialogs/settings.hpp @@ -49,6 +49,7 @@ private Q_SLOTS: void on_page_changed(QListWidgetItem *current, QListWidgetItem *previous); void on_view_alwaysZoomToFit_changed(int state); void on_view_colouredBG_changed(int state); + void on_view_stickyScrolling_changed(int state); private: DeviceManager &device_manager_; diff --git a/pv/globalsettings.cpp b/pv/globalsettings.cpp index d2482241..2e29a171 100644 --- a/pv/globalsettings.cpp +++ b/pv/globalsettings.cpp @@ -23,6 +23,7 @@ namespace pv { const QString GlobalSettings::Key_View_AlwaysZoomToFit = "View_AlwaysZoomToFit"; const QString GlobalSettings::Key_View_ColouredBG = "View_ColouredBG"; +const QString GlobalSettings::Key_View_StickyScrolling = "View_StickyScrolling"; std::multimap< QString, std::function > GlobalSettings::callbacks_; bool GlobalSettings::tracking_ = false; diff --git a/pv/globalsettings.hpp b/pv/globalsettings.hpp index 9581e294..ba0e2803 100644 --- a/pv/globalsettings.hpp +++ b/pv/globalsettings.hpp @@ -36,6 +36,7 @@ class GlobalSettings : public QSettings public: static const QString Key_View_AlwaysZoomToFit; static const QString Key_View_ColouredBG; + static const QString Key_View_StickyScrolling; public: GlobalSettings(); diff --git a/pv/mainwindow.cpp b/pv/mainwindow.cpp index d8247825..9164c6e8 100644 --- a/pv/mainwindow.cpp +++ b/pv/mainwindow.cpp @@ -86,6 +86,8 @@ MainWindow::MainWindow(DeviceManager &device_manager, GlobalSettings::register_change_handler(GlobalSettings::Key_View_ColouredBG, bind(&MainWindow::on_settingViewColouredBg_changed, this, _1)); + GlobalSettings::register_change_handler(GlobalSettings::Key_View_StickyScrolling, + bind(&MainWindow::on_settingViewStickyScrolling_changed, this, _1)); setup_ui(); restore_ui_settings(); @@ -717,15 +719,6 @@ void MainWindow::on_tab_close_requested(int index) remove_session(session); } -void MainWindow::on_view_sticky_scrolling_shortcut() -{ - shared_ptr viewbase = get_active_view(); - views::TraceView::View* view = - qobject_cast(viewbase.get()); - if (view) - view->toggle_sticky_scrolling(); -} - void MainWindow::on_view_coloured_bg_shortcut() { GlobalSettings settings; @@ -734,6 +727,14 @@ void MainWindow::on_view_coloured_bg_shortcut() settings.setValue(GlobalSettings::Key_View_ColouredBG, !state); } +void MainWindow::on_view_sticky_scrolling_shortcut() +{ + GlobalSettings settings; + + bool state = settings.value(GlobalSettings::Key_View_StickyScrolling).toBool(); + settings.setValue(GlobalSettings::Key_View_StickyScrolling, !state); +} + void MainWindow::on_settingViewColouredBg_changed(const QVariant new_value) { bool state = new_value.toBool(); @@ -749,6 +750,21 @@ void MainWindow::on_settingViewColouredBg_changed(const QVariant new_value) } } +void MainWindow::on_settingViewStickyScrolling_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_sticky_scrolling(state); + } +} + void MainWindow::on_close_current_tab() { int tab = session_selector_.currentIndex(); diff --git a/pv/mainwindow.hpp b/pv/mainwindow.hpp index e3a51c6d..50708c20 100644 --- a/pv/mainwindow.hpp +++ b/pv/mainwindow.hpp @@ -121,10 +121,11 @@ private Q_SLOTS: void on_tab_changed(int index); void on_tab_close_requested(int index); - void on_view_sticky_scrolling_shortcut(); void on_view_coloured_bg_shortcut(); + void on_view_sticky_scrolling_shortcut(); void on_settingViewColouredBg_changed(const QVariant new_value); + void on_settingViewStickyScrolling_changed(const QVariant new_value); void on_close_current_tab(); diff --git a/pv/view/view.cpp b/pv/view/view.cpp index cc0ceb79..d47b4fd1 100644 --- a/pv/view/view.cpp +++ b/pv/view/view.cpp @@ -567,11 +567,6 @@ void View::enable_sticky_scrolling(bool state) sticky_scrolling_ = state; } -void View::toggle_sticky_scrolling() -{ - sticky_scrolling_ = !sticky_scrolling_; -} - void View::enable_coloured_bg(bool state) { const vector> items( diff --git a/pv/view/view.hpp b/pv/view/view.hpp index c289cfcb..930f6cd2 100644 --- a/pv/view/view.hpp +++ b/pv/view/view.hpp @@ -205,11 +205,6 @@ public: */ void enable_sticky_scrolling(bool state); - /** - * Toggle sticky scrolling. - */ - void toggle_sticky_scrolling(void); - /** * Enables or disables coloured trace backgrounds. If they're not * coloured then they will use alternating colors.