From 3ff7a848b141bd7654d662285c4e676ca2d61867 Mon Sep 17 00:00:00 2001 From: WarmUpTill Date: Sat, 10 Oct 2020 00:17:19 +0200 Subject: [PATCH] add option to add 'select ...' entry to populate functions --- src/advanced-scene-switcher.cpp | 38 +++++++++++++++++++++---- src/headers/advanced-scene-switcher.hpp | 15 ++++++---- 2 files changed, 43 insertions(+), 10 deletions(-) diff --git a/src/advanced-scene-switcher.cpp b/src/advanced-scene-switcher.cpp index 8fc3da57..03759fef 100644 --- a/src/advanced-scene-switcher.cpp +++ b/src/advanced-scene-switcher.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include @@ -304,8 +305,23 @@ void SwitcherData::Stop() } } -void SceneSwitcher::populateSceneSelection(QComboBox *sel, bool addPrevious) +void addSelectionEntry(QComboBox *sel, const char *description) { + sel->addItem(description); + QStandardItemModel *model = + qobject_cast(sel->model()); + QModelIndex firstIndex = + model->index(0, sel->modelColumn(), sel->rootModelIndex()); + QStandardItem *firstItem = model->itemFromIndex(firstIndex); + firstItem->setSelectable(false); +} + +void SceneSwitcher::populateSceneSelection(QComboBox *sel, bool addPrevious, + bool addSelect) +{ + if (addSelect) + addSelectionEntry(sel, "--select scene--"); + BPtr scenes = obs_frontend_get_scene_names(); char **temp = scenes; while (*temp) { @@ -318,8 +334,11 @@ void SceneSwitcher::populateSceneSelection(QComboBox *sel, bool addPrevious) sel->addItem(previous_scene_name); } -void SceneSwitcher::populateTransitionSelection(QComboBox *sel) +void SceneSwitcher::populateTransitionSelection(QComboBox *sel, bool addSelect) { + if (addSelect) + addSelectionEntry(sel, "--select transition--"); + obs_frontend_source_list *transitions = new obs_frontend_source_list(); obs_frontend_get_transitions(transitions); @@ -332,8 +351,11 @@ void SceneSwitcher::populateTransitionSelection(QComboBox *sel) obs_frontend_source_list_free(transitions); } -void SceneSwitcher::populateWindowSelection(QComboBox *sel) +void SceneSwitcher::populateWindowSelection(QComboBox *sel, bool addSelect) { + if (addSelect) + addSelectionEntry(sel, "--select window--"); + std::vector windows; GetWindowList(windows); sort(windows.begin(), windows.end()); @@ -343,8 +365,11 @@ void SceneSwitcher::populateWindowSelection(QComboBox *sel) } } -void SceneSwitcher::populateAudioSelection(QComboBox *sel) +void SceneSwitcher::populateAudioSelection(QComboBox *sel, bool addSelect) { + if (addSelect) + addSelectionEntry(sel, "--select audio source--"); + auto sourceEnum = [](void *data, obs_source_t *source) -> bool /* -- */ { QComboBox *combo = reinterpret_cast(data); @@ -360,8 +385,11 @@ void SceneSwitcher::populateAudioSelection(QComboBox *sel) obs_enum_sources(sourceEnum, sel); } -void SceneSwitcher::populateMediaSelection(QComboBox *sel) +void SceneSwitcher::populateMediaSelection(QComboBox *sel, bool addSelect) { + if (addSelect) + addSelectionEntry(sel, "--select media source--"); + auto sourceEnum = [](void *data, obs_source_t *source) -> bool /* -- */ { QComboBox *combo = reinterpret_cast(data); diff --git a/src/headers/advanced-scene-switcher.hpp b/src/headers/advanced-scene-switcher.hpp index 509ca26d..50b8d3c6 100644 --- a/src/headers/advanced-scene-switcher.hpp +++ b/src/headers/advanced-scene-switcher.hpp @@ -71,11 +71,16 @@ public: void setTabOrder(); static void populateSceneSelection(QComboBox *sel, - bool addPrevious = false); - static void populateTransitionSelection(QComboBox *sel); - static void populateWindowSelection(QComboBox *sel); - static void populateAudioSelection(QComboBox *sel); - static void populateMediaSelection(QComboBox *sel); + bool addPrevious = false, + bool addSelect = true); + static void populateTransitionSelection(QComboBox *sel, + bool addSelect = true); + static void populateWindowSelection(QComboBox *sel, + bool addSelect = true); + static void populateAudioSelection(QComboBox *sel, + bool addSelect = true); + static void populateMediaSelection(QComboBox *sel, + bool addSelect = true); public slots: void on_switches_currentRowChanged(int idx);