diff --git a/data/locale/en-US.ini b/data/locale/en-US.ini index 73085e89..6736b24d 100644 --- a/data/locale/en-US.ini +++ b/data/locale/en-US.ini @@ -1123,6 +1123,7 @@ AdvSceneSwitcher.variable.save="Save / load behavior" AdvSceneSwitcher.variable.save.dontSave="Don't save variable value" AdvSceneSwitcher.variable.save.save="Save variable value" AdvSceneSwitcher.variable.save.default="Set to value" +AdvSceneSwitcher.variable.selectionDialog="Select variable:" AdvSceneSwitcher.tooltip.availableVariables="Variables are supported, use ${VarName} to retrieve the value of VarName" diff --git a/lib/utils/item-selection-helpers.hpp b/lib/utils/item-selection-helpers.hpp index 95b1e2ca..b3517bec 100644 --- a/lib/utils/item-selection-helpers.hpp +++ b/lib/utils/item-selection-helpers.hpp @@ -81,6 +81,7 @@ public: "AdvSceneSwitcher.item.nameNotAvailable", std::string_view configureTooltip = "", QWidget *parent = 0); virtual ~ItemSelection() = default; + Item *GetCurrentItem(); void SetItem(const std::string &); void ShowRenameContextMenu(bool value); @@ -99,8 +100,6 @@ signals: void ItemRenamed(const QString &oldName, const QString &name); private: - Item *GetCurrentItem(); - FilterComboBox *_selection; QPushButton *_modify; CreateItemFunc _create; diff --git a/lib/variables/variable.cpp b/lib/variables/variable.cpp index d6c43e3c..44cf5358 100644 --- a/lib/variables/variable.cpp +++ b/lib/variables/variable.cpp @@ -268,6 +268,53 @@ void VariableSelection::SetVariable(const std::weak_ptr &variable_) } } +VariableSelectionDialog::VariableSelectionDialog(QWidget *parent) + : QDialog(parent), + _variableSelection(new VariableSelection(this)) +{ + setModal(true); + setWindowModality(Qt::WindowModality::ApplicationModal); + setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); + setMinimumWidth(350); + setMinimumHeight(70); + + auto buttonbox = new QDialogButtonBox(QDialogButtonBox::Ok | + QDialogButtonBox::Cancel); + + buttonbox->setCenterButtons(true); + connect(buttonbox, &QDialogButtonBox::accepted, this, &QDialog::accept); + connect(buttonbox, &QDialogButtonBox::rejected, this, &QDialog::reject); + + auto selectionLayout = new QHBoxLayout(); + selectionLayout->addWidget(new QLabel( + obs_module_text("AdvSceneSwitcher.variable.selectionDialog"))); + selectionLayout->addWidget(_variableSelection); + selectionLayout->addStretch(); + auto layout = new QVBoxLayout(); + layout->addLayout(selectionLayout); + layout->addWidget(buttonbox); + setLayout(layout); +} + +QWidget *GetSettingsWindow(); + +bool VariableSelectionDialog::AskForVariable(QWidget *parent, + std::string &varName) +{ + VariableSelectionDialog dialog(GetSettingsWindow()); + dialog.setWindowTitle(obs_module_text("AdvSceneSwitcher.windowTitle")); + + if (dialog.exec() != DialogCode::Accepted) { + return false; + } + auto item = dialog._variableSelection->GetCurrentItem(); + if (!item) { + return false; + } + varName = item->Name(); + return true; +} + VariableSignalManager::VariableSignalManager(QObject *parent) : QObject(parent) { } diff --git a/lib/variables/variable.hpp b/lib/variables/variable.hpp index fa673781..4bdf1c91 100644 --- a/lib/variables/variable.hpp +++ b/lib/variables/variable.hpp @@ -82,6 +82,17 @@ public: void SetVariable(const std::weak_ptr &); }; +class VariableSelectionDialog : public QDialog { + Q_OBJECT + +public: + VariableSelectionDialog(QWidget *parent); + static bool AskForVariable(QWidget *parent, std::string &variableName); + +private: + VariableSelection *_variableSelection; +}; + class ADVSS_EXPORT VariableSignalManager : public QObject { Q_OBJECT public: diff --git a/tests/mocks/ui-helpers.cpp b/tests/mocks/ui-helpers.cpp index 8dd3ac85..84a4750e 100644 --- a/tests/mocks/ui-helpers.cpp +++ b/tests/mocks/ui-helpers.cpp @@ -35,4 +35,9 @@ std::string GetThemeTypeName() void QeueUITask(void (*task)(void *param), void *) {} +QWidget *GetSettingsWindow() +{ + return nullptr; +} + } // namespace advss