Add VariableSelectionDialog

This commit is contained in:
WarmUpTill 2024-05-31 23:00:06 +02:00 committed by WarmUpTill
parent 235b31fccc
commit d72a0c0d38
5 changed files with 65 additions and 2 deletions

View File

@ -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"

View File

@ -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;

View File

@ -268,6 +268,53 @@ void VariableSelection::SetVariable(const std::weak_ptr<Variable> &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)
{
}

View File

@ -82,6 +82,17 @@ public:
void SetVariable(const std::weak_ptr<Variable> &);
};
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:

View File

@ -35,4 +35,9 @@ std::string GetThemeTypeName()
void QeueUITask(void (*task)(void *param), void *) {}
QWidget *GetSettingsWindow()
{
return nullptr;
}
} // namespace advss