mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-03-21 17:34:57 -05:00
Add option to run "else" actions using the "Run macros" button
If there are else actions to run holding control and clicking the "Run macros" button will allow you to test them.
This commit is contained in:
parent
0c8135078d
commit
d6e4ee0203
|
|
@ -268,6 +268,8 @@ target_sources(
|
|||
src/utils/macro-export-import-dialog.hpp
|
||||
src/utils/macro-list.cpp
|
||||
src/utils/macro-list.hpp
|
||||
src/utils/macro-run-button.cpp
|
||||
src/utils/macro-run-button.hpp
|
||||
src/utils/macro-segment-selection.cpp
|
||||
src/utils/macro-segment-selection.hpp
|
||||
src/utils/math-helpers.cpp
|
||||
|
|
|
|||
|
|
@ -79,6 +79,7 @@ AdvSceneSwitcher.macroTab.edit.action="Action type:"
|
|||
AdvSceneSwitcher.macroTab.add="Add new macro"
|
||||
AdvSceneSwitcher.macroTab.name="Name:"
|
||||
AdvSceneSwitcher.macroTab.run="Run macro"
|
||||
AdvSceneSwitcher.macroTab.runElse="Run macro (else)"
|
||||
AdvSceneSwitcher.macroTab.runFail="Running \"%1\" failed!\nEither one of the actions failed or the macro is running already."
|
||||
AdvSceneSwitcher.macroTab.runInParallel="Run macro in parallel to other macros"
|
||||
AdvSceneSwitcher.macroTab.onChange="Perform actions only on condition change"
|
||||
|
|
|
|||
|
|
@ -843,7 +843,7 @@
|
|||
<widget class="QLineEdit" name="macroName"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="runMacro">
|
||||
<widget class="advss::MacroRunButton" name="runMacro">
|
||||
<property name="text">
|
||||
<string>AdvSceneSwitcher.macroTab.run</string>
|
||||
</property>
|
||||
|
|
@ -4849,6 +4849,11 @@
|
|||
<header>macro-segment-list.hpp</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>advss::MacroRunButton</class>
|
||||
<extends>QPushButton</extends>
|
||||
<header>macro-run-button.hpp</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
|
|
|
|||
|
|
@ -101,7 +101,6 @@ public slots:
|
|||
void on_macroUp_clicked();
|
||||
void on_macroDown_clicked();
|
||||
void on_macroName_editingFinished();
|
||||
void on_runMacro_clicked();
|
||||
void on_runMacroInParallel_stateChanged(int value);
|
||||
void on_runMacroOnChange_stateChanged(int value);
|
||||
void on_conditionAdd_clicked();
|
||||
|
|
|
|||
|
|
@ -451,21 +451,6 @@ void AdvSceneSwitcher::on_macroName_editingFinished()
|
|||
RenameMacro(macro, newName);
|
||||
}
|
||||
|
||||
void AdvSceneSwitcher::on_runMacro_clicked()
|
||||
{
|
||||
auto macro = GetSelectedMacro();
|
||||
if (!macro) {
|
||||
return;
|
||||
}
|
||||
|
||||
bool ret = macro->PerformActions(true, true, true);
|
||||
if (!ret) {
|
||||
QString err =
|
||||
obs_module_text("AdvSceneSwitcher.macroTab.runFail");
|
||||
DisplayMessage(err.arg(QString::fromStdString(macro->Name())));
|
||||
}
|
||||
}
|
||||
|
||||
void AdvSceneSwitcher::on_runMacroInParallel_stateChanged(int value)
|
||||
{
|
||||
auto macro = GetSelectedMacro();
|
||||
|
|
@ -792,6 +777,7 @@ void AdvSceneSwitcher::SetupMacroTab()
|
|||
SLOT(MacroSelectionAboutToChange()));
|
||||
connect(ui->macros, SIGNAL(MacroSelectionChanged()), this,
|
||||
SLOT(MacroSelectionChanged()));
|
||||
ui->runMacro->SetMacroTree(ui->macros);
|
||||
|
||||
ui->conditionsList->SetHelpMsg(
|
||||
obs_module_text("AdvSceneSwitcher.macroTab.editConditionHelp"));
|
||||
|
|
|
|||
82
src/utils/macro-run-button.cpp
Normal file
82
src/utils/macro-run-button.cpp
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
#include "macro-run-button.hpp"
|
||||
#include "macro-tree.hpp"
|
||||
#include "macro.hpp"
|
||||
#include "obs-module-helper.hpp"
|
||||
#include "utility.hpp"
|
||||
|
||||
#include <QKeyEvent>
|
||||
|
||||
namespace advss {
|
||||
|
||||
MacroRunButton::MacroRunButton(QWidget *parent) : QPushButton(parent)
|
||||
{
|
||||
if (window()) {
|
||||
window()->installEventFilter(this);
|
||||
}
|
||||
QWidget::connect(this, SIGNAL(pressed()), this, SLOT(Pressed()));
|
||||
}
|
||||
|
||||
void MacroRunButton::SetMacroTree(MacroTree *macros)
|
||||
{
|
||||
_macros = macros;
|
||||
QWidget::connect(macros, SIGNAL(MacroSelectionChanged()), this,
|
||||
SLOT(MacroSelectionChanged()));
|
||||
QWidget::connect(&_timer, &QTimer::timeout, this,
|
||||
[this]() { MacroSelectionChanged(); });
|
||||
_timer.start(1000);
|
||||
}
|
||||
|
||||
void MacroRunButton::MacroSelectionChanged()
|
||||
{
|
||||
auto macro = _macros->GetCurrentMacro();
|
||||
if (!macro) {
|
||||
_macroHasElseActions = false;
|
||||
return;
|
||||
}
|
||||
_macroHasElseActions = macro->ElseActions().size() > 0;
|
||||
}
|
||||
|
||||
bool MacroRunButton::eventFilter(QObject *obj, QEvent *event)
|
||||
{
|
||||
if (!_macroHasElseActions) {
|
||||
setText(obs_module_text("AdvSceneSwitcher.macroTab.run"));
|
||||
_runElseActionsKeyHeld = false;
|
||||
return QPushButton::eventFilter(obj, event);
|
||||
}
|
||||
|
||||
if (event->type() == QEvent::KeyPress) {
|
||||
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
|
||||
if (keyEvent->key() == Qt::Key_Control) {
|
||||
setText(obs_module_text(
|
||||
"AdvSceneSwitcher.macroTab.runElse"));
|
||||
_runElseActionsKeyHeld = true;
|
||||
}
|
||||
} else if (event->type() == QEvent::KeyRelease) {
|
||||
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
|
||||
if (keyEvent->key() == Qt::Key_Control) {
|
||||
setText(obs_module_text(
|
||||
"AdvSceneSwitcher.macroTab.run"));
|
||||
_runElseActionsKeyHeld = false;
|
||||
}
|
||||
}
|
||||
return QPushButton::eventFilter(obj, event);
|
||||
}
|
||||
|
||||
void MacroRunButton::Pressed()
|
||||
{
|
||||
auto macro = _macros->GetCurrentMacro();
|
||||
if (!macro) {
|
||||
return;
|
||||
}
|
||||
|
||||
bool ret = _runElseActionsKeyHeld
|
||||
? macro->PerformActions(false, true, true)
|
||||
: macro->PerformActions(true, true, true);
|
||||
if (!ret) {
|
||||
QString err =
|
||||
obs_module_text("AdvSceneSwitcher.macroTab.runFail");
|
||||
DisplayMessage(err.arg(QString::fromStdString(macro->Name())));
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace advss
|
||||
29
src/utils/macro-run-button.hpp
Normal file
29
src/utils/macro-run-button.hpp
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
#pragma once
|
||||
#include <QPushButton>
|
||||
#include <QTimer>
|
||||
|
||||
namespace advss {
|
||||
|
||||
class MacroTree;
|
||||
|
||||
class MacroRunButton : public QPushButton {
|
||||
Q_OBJECT
|
||||
public:
|
||||
MacroRunButton(QWidget *parent = nullptr);
|
||||
void SetMacroTree(MacroTree *);
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject *obj, QEvent *event) override;
|
||||
|
||||
private slots:
|
||||
void MacroSelectionChanged();
|
||||
void Pressed();
|
||||
|
||||
private:
|
||||
MacroTree *_macros = nullptr;
|
||||
bool _macroHasElseActions = false;
|
||||
bool _runElseActionsKeyHeld = false;
|
||||
QTimer _timer;
|
||||
};
|
||||
|
||||
} // namespace advss
|
||||
Loading…
Reference in New Issue
Block a user