mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-09-14 12:36:09 -05:00
Add option to set placeholder text when asking for input
This commit is contained in:
@@ -751,7 +751,8 @@ AdvSceneSwitcher.action.variable.entry="{{actions}}{{variables}}{{variables2}}{{
|
|||||||
AdvSceneSwitcher.action.variable.entry.substringIndex="Substring start:{{subStringStart}}Substring size:{{subStringSize}}"
|
AdvSceneSwitcher.action.variable.entry.substringIndex="Substring start:{{subStringStart}}Substring size:{{subStringSize}}"
|
||||||
AdvSceneSwitcher.action.variable.entry.substringRegex="Assign value of{{regexMatchIdx}}match using regular expression:"
|
AdvSceneSwitcher.action.variable.entry.substringRegex="Assign value of{{regexMatchIdx}}match using regular expression:"
|
||||||
AdvSceneSwitcher.action.variable.entry.findAndReplace="{{findStr}}{{replaceStr}}"
|
AdvSceneSwitcher.action.variable.entry.findAndReplace="{{findStr}}{{replaceStr}}"
|
||||||
AdvSceneSwitcher.action.variable.entry.userInput="{{useCustomPrompt}}Use custom prompt{{inputPrompt}}"
|
AdvSceneSwitcher.action.variable.entry.userInput.customPrompt="{{useCustomPrompt}}Use custom prompt{{inputPrompt}}"
|
||||||
|
AdvSceneSwitcher.action.variable.entry.userInput.placeholder="{{useInputPlaceholder}}Fill with placeholder{{inputPlaceholder}}"
|
||||||
AdvSceneSwitcher.action.projector="Projector"
|
AdvSceneSwitcher.action.projector="Projector"
|
||||||
AdvSceneSwitcher.action.projector.type.source="Source"
|
AdvSceneSwitcher.action.projector.type.source="Source"
|
||||||
AdvSceneSwitcher.action.projector.type.scene="Scene"
|
AdvSceneSwitcher.action.projector.type.scene="Scene"
|
||||||
|
|||||||
@@ -126,6 +126,7 @@ void MacroActionVariable::HandleMathExpression(Variable *var)
|
|||||||
|
|
||||||
struct AskForInputParams {
|
struct AskForInputParams {
|
||||||
QString prompt;
|
QString prompt;
|
||||||
|
QString placeholder;
|
||||||
std::optional<std::string> result;
|
std::optional<std::string> result;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -134,6 +135,7 @@ static void askForInput(void *param)
|
|||||||
auto parameters = static_cast<AskForInputParams *>(param);
|
auto parameters = static_cast<AskForInputParams *>(param);
|
||||||
auto dialog = new NonModalMessageDialog(
|
auto dialog = new NonModalMessageDialog(
|
||||||
parameters->prompt, NonModalMessageDialog::Type::INPUT);
|
parameters->prompt, NonModalMessageDialog::Type::INPUT);
|
||||||
|
dialog->SetInput(parameters->placeholder);
|
||||||
parameters->result = dialog->GetInput();
|
parameters->result = dialog->GetInput();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -213,6 +215,9 @@ bool MacroActionVariable::PerformAction()
|
|||||||
"AdvSceneSwitcher.action.variable.askForValuePromptDefault"))
|
"AdvSceneSwitcher.action.variable.askForValuePromptDefault"))
|
||||||
.arg(QString::fromStdString(
|
.arg(QString::fromStdString(
|
||||||
var->Name())),
|
var->Name())),
|
||||||
|
_useCustomPrompt && _useInputPlaceholder
|
||||||
|
? QString::fromStdString(_inputPlaceholder)
|
||||||
|
: "",
|
||||||
{}};
|
{}};
|
||||||
obs_queue_task(OBS_TASK_UI, askForInput, ¶ms, true);
|
obs_queue_task(OBS_TASK_UI, askForInput, ¶ms, true);
|
||||||
if (!params.result.has_value()) {
|
if (!params.result.has_value()) {
|
||||||
@@ -247,6 +252,8 @@ bool MacroActionVariable::Save(obs_data_t *obj) const
|
|||||||
_mathExpression.Save(obj, "mathExpression");
|
_mathExpression.Save(obj, "mathExpression");
|
||||||
obs_data_set_bool(obj, "useCustomPrompt", _useCustomPrompt);
|
obs_data_set_bool(obj, "useCustomPrompt", _useCustomPrompt);
|
||||||
_inputPrompt.Save(obj, "inputPrompt");
|
_inputPrompt.Save(obj, "inputPrompt");
|
||||||
|
obs_data_set_bool(obj, "useInputPlaceholder", _useInputPlaceholder);
|
||||||
|
_inputPlaceholder.Save(obj, "inputPlaceholder");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -271,6 +278,8 @@ bool MacroActionVariable::Load(obs_data_t *obj)
|
|||||||
_mathExpression.Load(obj, "mathExpression");
|
_mathExpression.Load(obj, "mathExpression");
|
||||||
_useCustomPrompt = obs_data_get_bool(obj, "useCustomPrompt");
|
_useCustomPrompt = obs_data_get_bool(obj, "useCustomPrompt");
|
||||||
_inputPrompt.Load(obj, "inputPrompt");
|
_inputPrompt.Load(obj, "inputPrompt");
|
||||||
|
_useInputPlaceholder = obs_data_get_bool(obj, "useInputPlaceholder");
|
||||||
|
_inputPlaceholder.Load(obj, "inputPlaceholder");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -392,7 +401,10 @@ MacroActionVariableEdit::MacroActionVariableEdit(
|
|||||||
_mathExpressionResult(new QLabel()),
|
_mathExpressionResult(new QLabel()),
|
||||||
_promptLayout(new QHBoxLayout()),
|
_promptLayout(new QHBoxLayout()),
|
||||||
_useCustomPrompt(new QCheckBox()),
|
_useCustomPrompt(new QCheckBox()),
|
||||||
_inputPrompt(new VariableLineEdit(this))
|
_inputPrompt(new VariableLineEdit(this)),
|
||||||
|
_placeholderLayout(new QHBoxLayout()),
|
||||||
|
_useInputPlaceholder(new QCheckBox()),
|
||||||
|
_inputPlaceholder(new VariableLineEdit(this))
|
||||||
{
|
{
|
||||||
_numValue->setMinimum(-9999999999);
|
_numValue->setMinimum(-9999999999);
|
||||||
_numValue->setMaximum(9999999999);
|
_numValue->setMaximum(9999999999);
|
||||||
@@ -447,6 +459,10 @@ MacroActionVariableEdit::MacroActionVariableEdit(
|
|||||||
SLOT(UseCustomPromptChanged(int)));
|
SLOT(UseCustomPromptChanged(int)));
|
||||||
QWidget::connect(_inputPrompt, SIGNAL(editingFinished()), this,
|
QWidget::connect(_inputPrompt, SIGNAL(editingFinished()), this,
|
||||||
SLOT(InputPromptChanged()));
|
SLOT(InputPromptChanged()));
|
||||||
|
QWidget::connect(_useInputPlaceholder, SIGNAL(stateChanged(int)), this,
|
||||||
|
SLOT(UseInputPlaceholderChanged(int)));
|
||||||
|
QWidget::connect(_inputPlaceholder, SIGNAL(editingFinished()), this,
|
||||||
|
SLOT(InputPlaceholderChanged()));
|
||||||
|
|
||||||
std::unordered_map<std::string, QWidget *> widgetPlaceholders = {
|
std::unordered_map<std::string, QWidget *> widgetPlaceholders = {
|
||||||
{"{{variables}}", _variables},
|
{"{{variables}}", _variables},
|
||||||
@@ -463,6 +479,8 @@ MacroActionVariableEdit::MacroActionVariableEdit(
|
|||||||
{"{{mathExpression}}", _mathExpression},
|
{"{{mathExpression}}", _mathExpression},
|
||||||
{"{{useCustomPrompt}}", _useCustomPrompt},
|
{"{{useCustomPrompt}}", _useCustomPrompt},
|
||||||
{"{{inputPrompt}}", _inputPrompt},
|
{"{{inputPrompt}}", _inputPrompt},
|
||||||
|
{"{{useInputPlaceholder}}", _useInputPlaceholder},
|
||||||
|
{"{{inputPlaceholder}}", _inputPlaceholder},
|
||||||
};
|
};
|
||||||
auto entryLayout = new QHBoxLayout;
|
auto entryLayout = new QHBoxLayout;
|
||||||
PlaceWidgets(obs_module_text("AdvSceneSwitcher.action.variable.entry"),
|
PlaceWidgets(obs_module_text("AdvSceneSwitcher.action.variable.entry"),
|
||||||
@@ -485,8 +503,12 @@ MacroActionVariableEdit::MacroActionVariableEdit(
|
|||||||
|
|
||||||
PlaceWidgets(
|
PlaceWidgets(
|
||||||
obs_module_text(
|
obs_module_text(
|
||||||
"AdvSceneSwitcher.action.variable.entry.userInput"),
|
"AdvSceneSwitcher.action.variable.entry.userInput.customPrompt"),
|
||||||
_promptLayout, widgetPlaceholders);
|
_promptLayout, widgetPlaceholders);
|
||||||
|
PlaceWidgets(
|
||||||
|
obs_module_text(
|
||||||
|
"AdvSceneSwitcher.action.variable.entry.userInput.placeholder"),
|
||||||
|
_placeholderLayout, widgetPlaceholders);
|
||||||
|
|
||||||
auto regexConfigLayout = new QHBoxLayout;
|
auto regexConfigLayout = new QHBoxLayout;
|
||||||
regexConfigLayout->addWidget(_regex);
|
regexConfigLayout->addWidget(_regex);
|
||||||
@@ -505,6 +527,7 @@ MacroActionVariableEdit::MacroActionVariableEdit(
|
|||||||
layout->addLayout(_findReplaceLayout);
|
layout->addLayout(_findReplaceLayout);
|
||||||
layout->addWidget(_mathExpressionResult);
|
layout->addWidget(_mathExpressionResult);
|
||||||
layout->addLayout(_promptLayout);
|
layout->addLayout(_promptLayout);
|
||||||
|
layout->addLayout(_placeholderLayout);
|
||||||
setLayout(layout);
|
setLayout(layout);
|
||||||
|
|
||||||
_entryData = entryData;
|
_entryData = entryData;
|
||||||
@@ -547,6 +570,8 @@ void MacroActionVariableEdit::UpdateEntryData()
|
|||||||
_mathExpression->setText(_entryData->_mathExpression);
|
_mathExpression->setText(_entryData->_mathExpression);
|
||||||
_useCustomPrompt->setChecked(_entryData->_useCustomPrompt);
|
_useCustomPrompt->setChecked(_entryData->_useCustomPrompt);
|
||||||
_inputPrompt->setText(_entryData->_inputPrompt);
|
_inputPrompt->setText(_entryData->_inputPrompt);
|
||||||
|
_useInputPlaceholder->setChecked(_entryData->_useInputPlaceholder);
|
||||||
|
_inputPlaceholder->setText(_entryData->_inputPlaceholder);
|
||||||
SetWidgetVisibility();
|
SetWidgetVisibility();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -818,15 +843,9 @@ void MacroActionVariableEdit::UseCustomPromptChanged(int value)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_inputPrompt->setVisible(value);
|
|
||||||
if (value) {
|
|
||||||
RemoveStretchIfPresent(_promptLayout);
|
|
||||||
} else {
|
|
||||||
AddStretchIfNecessary(_promptLayout);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto lock = LockContext();
|
auto lock = LockContext();
|
||||||
_entryData->_useCustomPrompt = value;
|
_entryData->_useCustomPrompt = value;
|
||||||
|
SetWidgetVisibility();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MacroActionVariableEdit::InputPromptChanged()
|
void MacroActionVariableEdit::InputPromptChanged()
|
||||||
@@ -839,6 +858,27 @@ void MacroActionVariableEdit::InputPromptChanged()
|
|||||||
_entryData->_inputPrompt = _inputPrompt->text().toStdString();
|
_entryData->_inputPrompt = _inputPrompt->text().toStdString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MacroActionVariableEdit::UseInputPlaceholderChanged(int value)
|
||||||
|
{
|
||||||
|
if (_loading || !_entryData) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto lock = LockContext();
|
||||||
|
_entryData->_useInputPlaceholder = value;
|
||||||
|
SetWidgetVisibility();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MacroActionVariableEdit::InputPlaceholderChanged()
|
||||||
|
{
|
||||||
|
if (_loading || !_entryData) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto lock = LockContext();
|
||||||
|
_entryData->_inputPlaceholder = _inputPlaceholder->text().toStdString();
|
||||||
|
}
|
||||||
|
|
||||||
void MacroActionVariableEdit::SetWidgetVisibility()
|
void MacroActionVariableEdit::SetWidgetVisibility()
|
||||||
{
|
{
|
||||||
if (!_entryData) {
|
if (!_entryData) {
|
||||||
@@ -887,7 +927,30 @@ void MacroActionVariableEdit::SetWidgetVisibility()
|
|||||||
SetLayoutVisible(_promptLayout,
|
SetLayoutVisible(_promptLayout,
|
||||||
_entryData->_type ==
|
_entryData->_type ==
|
||||||
MacroActionVariable::Type::USER_INPUT);
|
MacroActionVariable::Type::USER_INPUT);
|
||||||
_inputPrompt->setVisible(_entryData->_useCustomPrompt);
|
_inputPrompt->setVisible(
|
||||||
|
_entryData->_type == MacroActionVariable::Type::USER_INPUT &&
|
||||||
|
_entryData->_useCustomPrompt);
|
||||||
|
if (_entryData->_useCustomPrompt) {
|
||||||
|
RemoveStretchIfPresent(_promptLayout);
|
||||||
|
} else {
|
||||||
|
AddStretchIfNecessary(_promptLayout);
|
||||||
|
}
|
||||||
|
SetLayoutVisible(
|
||||||
|
_placeholderLayout,
|
||||||
|
_entryData->_type == MacroActionVariable::Type::USER_INPUT &&
|
||||||
|
_entryData->_useCustomPrompt);
|
||||||
|
_useInputPlaceholder->setVisible(
|
||||||
|
_entryData->_type == MacroActionVariable::Type::USER_INPUT &&
|
||||||
|
_entryData->_useCustomPrompt);
|
||||||
|
_inputPlaceholder->setVisible(
|
||||||
|
_entryData->_type == MacroActionVariable::Type::USER_INPUT &&
|
||||||
|
_entryData->_useCustomPrompt &&
|
||||||
|
_entryData->_useInputPlaceholder);
|
||||||
|
if (_entryData->_useInputPlaceholder) {
|
||||||
|
RemoveStretchIfPresent(_placeholderLayout);
|
||||||
|
} else {
|
||||||
|
AddStretchIfNecessary(_placeholderLayout);
|
||||||
|
}
|
||||||
adjustSize();
|
adjustSize();
|
||||||
updateGeometry();
|
updateGeometry();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,6 +58,9 @@ public:
|
|||||||
bool _useCustomPrompt = false;
|
bool _useCustomPrompt = false;
|
||||||
StringVariable _inputPrompt = obs_module_text(
|
StringVariable _inputPrompt = obs_module_text(
|
||||||
"AdvSceneSwitcher.action.variable.askForValuePrompt");
|
"AdvSceneSwitcher.action.variable.askForValuePrompt");
|
||||||
|
bool _useInputPlaceholder = false;
|
||||||
|
StringVariable _inputPlaceholder =
|
||||||
|
obs_module_text("AdvSceneSwitcher.enterText");
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void DecrementCurrentSegmentVariableRef();
|
void DecrementCurrentSegmentVariableRef();
|
||||||
@@ -107,11 +110,16 @@ private slots:
|
|||||||
void MathExpressionChanged();
|
void MathExpressionChanged();
|
||||||
void UseCustomPromptChanged(int);
|
void UseCustomPromptChanged(int);
|
||||||
void InputPromptChanged();
|
void InputPromptChanged();
|
||||||
|
void UseInputPlaceholderChanged(int);
|
||||||
|
void InputPlaceholderChanged();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void HeaderInfoChanged(const QString &);
|
void HeaderInfoChanged(const QString &);
|
||||||
|
|
||||||
protected:
|
private:
|
||||||
|
void SetWidgetVisibility();
|
||||||
|
void SetSegmentValueError(const QString &);
|
||||||
|
|
||||||
VariableSelection *_variables;
|
VariableSelection *_variables;
|
||||||
VariableSelection *_variables2;
|
VariableSelection *_variables2;
|
||||||
QComboBox *_actions;
|
QComboBox *_actions;
|
||||||
@@ -136,12 +144,11 @@ protected:
|
|||||||
QHBoxLayout *_promptLayout;
|
QHBoxLayout *_promptLayout;
|
||||||
QCheckBox *_useCustomPrompt;
|
QCheckBox *_useCustomPrompt;
|
||||||
VariableLineEdit *_inputPrompt;
|
VariableLineEdit *_inputPrompt;
|
||||||
|
QHBoxLayout *_placeholderLayout;
|
||||||
|
QCheckBox *_useInputPlaceholder;
|
||||||
|
VariableLineEdit *_inputPlaceholder;
|
||||||
|
|
||||||
std::shared_ptr<MacroActionVariable> _entryData;
|
std::shared_ptr<MacroActionVariable> _entryData;
|
||||||
|
|
||||||
private:
|
|
||||||
void SetWidgetVisibility();
|
|
||||||
void SetSegmentValueError(const QString &);
|
|
||||||
|
|
||||||
QTimer _timer;
|
QTimer _timer;
|
||||||
bool _loading = true;
|
bool _loading = true;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ std::optional<std::string> NonModalMessageDialog::GetInput()
|
|||||||
show();
|
show();
|
||||||
|
|
||||||
// Trigger resize
|
// Trigger resize
|
||||||
_inputEdit->setPlainText("");
|
_inputEdit->setPlainText(_inputEdit->toPlainText());
|
||||||
|
|
||||||
exec();
|
exec();
|
||||||
this->deleteLater();
|
this->deleteLater();
|
||||||
@@ -85,6 +85,12 @@ std::optional<std::string> NonModalMessageDialog::GetInput()
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NonModalMessageDialog::SetInput(const QString &input)
|
||||||
|
{
|
||||||
|
assert(_type == Type::INPUT);
|
||||||
|
_inputEdit->setPlainText(input);
|
||||||
|
}
|
||||||
|
|
||||||
void NonModalMessageDialog::YesClicked()
|
void NonModalMessageDialog::YesClicked()
|
||||||
{
|
{
|
||||||
_answer = QMessageBox::Yes;
|
_answer = QMessageBox::Yes;
|
||||||
|
|||||||
@@ -19,7 +19,8 @@ public:
|
|||||||
NonModalMessageDialog(const QString &message, bool question);
|
NonModalMessageDialog(const QString &message, bool question);
|
||||||
QMessageBox::StandardButton ShowMessage();
|
QMessageBox::StandardButton ShowMessage();
|
||||||
std::optional<std::string> GetInput();
|
std::optional<std::string> GetInput();
|
||||||
Type GetType() { return _type; }
|
Type GetType() const { return _type; }
|
||||||
|
void SetInput(const QString &);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void YesClicked();
|
void YesClicked();
|
||||||
|
|||||||
Reference in New Issue
Block a user