From a0b4df574bf5b8700ddb1e14e18446a45f1261bf Mon Sep 17 00:00:00 2001 From: WarmUpTill Date: Sat, 12 Aug 2023 11:26:22 +0200 Subject: [PATCH] Add option to disable filtering by typing in FilterComboBox --- data/locale/en-US.ini | 1 + forms/advanced-scene-switcher.ui | 28 ++++++++++++++++++++++++++-- src/advanced-scene-switcher.hpp | 1 + src/general.cpp | 19 +++++++++++++++++++ src/switcher-data.hpp | 1 + src/utils/filter-combo-box.cpp | 18 ++++++++++++++++++ src/utils/filter-combo-box.hpp | 2 ++ 7 files changed, 68 insertions(+), 2 deletions(-) diff --git a/data/locale/en-US.ini b/data/locale/en-US.ini index 8900837c..07f6756b 100644 --- a/data/locale/en-US.ini +++ b/data/locale/en-US.ini @@ -30,6 +30,7 @@ AdvSceneSwitcher.generalTab.generalBehavior.verboseLogging="Enable verbose loggi AdvSceneSwitcher.generalTab.generalBehavior.saveWindowGeo="Save window position and size" AdvSceneSwitcher.generalTab.generalBehavior.showTrayNotifications="Show system tray notifications" AdvSceneSwitcher.generalTab.generalBehavior.disableUIHints="Disable UI hints" +AdvSceneSwitcher.generalTab.generalBehavior.comboBoxFilterDisable="Disable filtering by typing in drop down menus" AdvSceneSwitcher.generalTab.generalBehavior.warnPluginLoadFailure="Display warning if plugins cannot be loaded" AdvSceneSwitcher.generalTab.generalBehavior.warnPluginLoadFailureMessage="Loading of the following plugin libraries was unsuccessful, which could result in some Advanced Scene Switcher functions not being available:%1Check the OBS logs for details.
This message can be disabled on the General tab." AdvSceneSwitcher.generalTab.generalBehavior.hideLegacyTabs="Hide tabs which can be represented via macros" diff --git a/forms/advanced-scene-switcher.ui b/forms/advanced-scene-switcher.ui index 20749375..9e880f1a 100644 --- a/forms/advanced-scene-switcher.ui +++ b/forms/advanced-scene-switcher.ui @@ -67,8 +67,8 @@ 0 0 - 957 - 905 + 962 + 1033 @@ -256,6 +256,30 @@ + + + + + + AdvSceneSwitcher.generalTab.generalBehavior.comboBoxFilterDisable + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + diff --git a/src/advanced-scene-switcher.hpp b/src/advanced-scene-switcher.hpp index c62e562c..e6f497c9 100644 --- a/src/advanced-scene-switcher.hpp +++ b/src/advanced-scene-switcher.hpp @@ -63,6 +63,7 @@ public slots: void on_saveWindowGeo_stateChanged(int state); void on_showTrayNotifications_stateChanged(int state); void on_uiHintsDisable_stateChanged(int state); + void on_disableComboBoxFilter_stateChanged(int state); void on_warnPluginLoadFailure_stateChanged(int state); void on_hideLegacyTabs_stateChanged(int state); void on_priorityUp_clicked(); diff --git a/src/general.cpp b/src/general.cpp index 6beb274b..f67d6323 100644 --- a/src/general.cpp +++ b/src/general.cpp @@ -2,6 +2,7 @@ #include "switcher-data.hpp" #include "status-control.hpp" #include "file-selection.hpp" +#include "filter-combo-box.hpp" #include "utility.hpp" #include "version.h" @@ -175,6 +176,16 @@ void AdvSceneSwitcher::on_uiHintsDisable_stateChanged(int state) switcher->disableHints = state; } +void AdvSceneSwitcher::on_disableComboBoxFilter_stateChanged(int state) +{ + if (loading) { + return; + } + + switcher->disableFilterComboboxFilter = state; + FilterComboBox::SetFilterBehaviourEnabled(!state); +} + void AdvSceneSwitcher::on_warnPluginLoadFailure_stateChanged(int state) { if (loading) { @@ -575,6 +586,8 @@ void SwitcherData::SaveGeneralSettings(obs_data_t *obj) obs_data_set_bool(obj, "showSystemTrayNotifications", showSystemTrayNotifications); obs_data_set_bool(obj, "disableHints", disableHints); + obs_data_set_bool(obj, "disableFilterComboboxFilter", + disableFilterComboboxFilter); obs_data_set_bool(obj, "warnPluginLoadFailure", warnPluginLoadFailure); obs_data_set_bool(obj, "hideLegacyTabs", hideLegacyTabs); @@ -623,6 +636,8 @@ void SwitcherData::LoadGeneralSettings(obs_data_t *obj) showSystemTrayNotifications = obs_data_get_bool(obj, "showSystemTrayNotifications"); disableHints = obs_data_get_bool(obj, "disableHints"); + disableFilterComboboxFilter = + obs_data_get_bool(obj, "disableFilterComboboxFilter"); obs_data_set_default_bool(obj, "warnPluginLoadFailure", true); warnPluginLoadFailure = obs_data_get_bool(obj, "warnPluginLoadFailure"); obs_data_set_default_bool(obj, "hideLegacyTabs", true); @@ -997,6 +1012,10 @@ void AdvSceneSwitcher::SetupGeneralTab() ui->showTrayNotifications->setChecked( switcher->showSystemTrayNotifications); ui->uiHintsDisable->setChecked(switcher->disableHints); + ui->disableComboBoxFilter->setChecked( + switcher->disableFilterComboboxFilter); + FilterComboBox::SetFilterBehaviourEnabled( + !switcher->disableFilterComboboxFilter); ui->warnPluginLoadFailure->setChecked(switcher->warnPluginLoadFailure); ui->hideLegacyTabs->setChecked(switcher->hideLegacyTabs); diff --git a/src/switcher-data.hpp b/src/switcher-data.hpp index c37d49a9..55fd95fd 100644 --- a/src/switcher-data.hpp +++ b/src/switcher-data.hpp @@ -204,6 +204,7 @@ public: QStringList loadFailureLibs; bool warnPluginLoadFailure = true; bool disableHints = false; + bool disableFilterComboboxFilter = false; bool hideLegacyTabs = true; std::vector tabOrder = std::vector(tab_count); bool saveWindowGeo = false; diff --git a/src/utils/filter-combo-box.cpp b/src/utils/filter-combo-box.cpp index 4871df4f..2529c8ca 100644 --- a/src/utils/filter-combo-box.cpp +++ b/src/utils/filter-combo-box.cpp @@ -7,9 +7,22 @@ namespace advss { +bool FilterComboBox::_filteringEnabled = false; + FilterComboBox::FilterComboBox(QWidget *parent, const QString &placehodler) : QComboBox(parent) { + // If the filtering behaviour of the FilterComboBox is disabled it is + // just a regular QComboBox with the option to set a placeholder so exit + // the constructor early. + + if (!_filteringEnabled) { + if (!placehodler.isEmpty()) { + setPlaceholderText(placehodler); + } + return; + } + // Allow edit for completer but don't add new entries on pressing enter setEditable(true); setInsertPolicy(InsertPolicy::NoInsert); @@ -31,6 +44,11 @@ FilterComboBox::FilterComboBox(QWidget *parent, const QString &placehodler) &FilterComboBox::TextChagned); } +void FilterComboBox::SetFilterBehaviourEnabled(bool value) +{ + FilterComboBox::_filteringEnabled = value; +} + void FilterComboBox::focusOutEvent(QFocusEvent *event) { // Reset on invalid selection diff --git a/src/utils/filter-combo-box.hpp b/src/utils/filter-combo-box.hpp index 8e35498c..126d6d9e 100644 --- a/src/utils/filter-combo-box.hpp +++ b/src/utils/filter-combo-box.hpp @@ -10,6 +10,7 @@ class FilterComboBox : public QComboBox { public: FilterComboBox(QWidget *parent = nullptr, const QString &placehodler = ""); + static void SetFilterBehaviourEnabled(bool); protected: void focusOutEvent(QFocusEvent *event) override; @@ -20,6 +21,7 @@ private slots: private: int _lastCompleterHighlightRow = -1; + static bool _filteringEnabled; }; } // namespace advss