mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-04-21 01:27:24 -05:00
Add tooltip for run button explaining else (#931)
* Add tooltip for run button explaining else * Switch run button modifier to Shift * Toggle button label only when hovering over it
This commit is contained in:
parent
99a0118d31
commit
845c12c01c
|
|
@ -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.run.tooltip="Run all macro actions regardless of condition.\nIf else actions are available, hold Shift and click the button to execute them instead."
|
||||
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"
|
||||
|
|
|
|||
|
|
@ -10,19 +10,26 @@ namespace advss {
|
|||
|
||||
MacroRunButton::MacroRunButton(QWidget *parent) : QPushButton(parent)
|
||||
{
|
||||
if (window()) {
|
||||
window()->installEventFilter(this);
|
||||
installEventFilter(this);
|
||||
auto parentWindow = window();
|
||||
if (parentWindow) {
|
||||
parentWindow->installEventFilter(this);
|
||||
}
|
||||
|
||||
setToolTip(obs_module_text("AdvSceneSwitcher.macroTab.run.tooltip"));
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
@ -33,35 +40,53 @@ void MacroRunButton::MacroSelectionChanged()
|
|||
_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;
|
||||
DeactivateElseState();
|
||||
return QPushButton::eventFilter(obj, event);
|
||||
}
|
||||
|
||||
if (event->type() == QEvent::KeyPress) {
|
||||
auto eventType = event->type();
|
||||
if (eventType == QEvent::KeyPress) {
|
||||
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
|
||||
if (keyEvent->key() == Qt::Key_Control) {
|
||||
setText(obs_module_text(
|
||||
"AdvSceneSwitcher.macroTab.runElse"));
|
||||
_runElseActionsKeyHeld = true;
|
||||
if (keyEvent->key() == Qt::Key_Shift) {
|
||||
if (underMouse()) {
|
||||
ActivateElseState();
|
||||
}
|
||||
_shiftHeld = true;
|
||||
}
|
||||
} else if (event->type() == QEvent::KeyRelease) {
|
||||
} else if (eventType == QEvent::KeyRelease) {
|
||||
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
|
||||
if (keyEvent->key() == Qt::Key_Control) {
|
||||
setText(obs_module_text(
|
||||
"AdvSceneSwitcher.macroTab.run"));
|
||||
_runElseActionsKeyHeld = false;
|
||||
if (keyEvent->key() == Qt::Key_Shift) {
|
||||
DeactivateElseState();
|
||||
_shiftHeld = false;
|
||||
}
|
||||
} else if (_shiftHeld && obj == this && eventType == QEvent::Enter) {
|
||||
ActivateElseState();
|
||||
} else if (obj == this && eventType == QEvent::Leave) {
|
||||
DeactivateElseState();
|
||||
}
|
||||
|
||||
return QPushButton::eventFilter(obj, event);
|
||||
}
|
||||
|
||||
void MacroRunButton::ActivateElseState()
|
||||
{
|
||||
setText(obs_module_text("AdvSceneSwitcher.macroTab.runElse"));
|
||||
_elseStateActive = true;
|
||||
}
|
||||
|
||||
void MacroRunButton::DeactivateElseState()
|
||||
{
|
||||
setText(obs_module_text("AdvSceneSwitcher.macroTab.run"));
|
||||
_elseStateActive = false;
|
||||
}
|
||||
|
||||
void MacroRunButton::Pressed()
|
||||
{
|
||||
auto macro = _macros->GetCurrentMacro();
|
||||
|
|
@ -69,9 +94,9 @@ void MacroRunButton::Pressed()
|
|||
return;
|
||||
}
|
||||
|
||||
bool ret = _runElseActionsKeyHeld
|
||||
? macro->PerformActions(false, true, true)
|
||||
: macro->PerformActions(true, true, true);
|
||||
bool ret = _elseStateActive ? macro->PerformActions(false, true, true)
|
||||
: macro->PerformActions(true, true, true);
|
||||
|
||||
if (!ret) {
|
||||
QString err =
|
||||
obs_module_text("AdvSceneSwitcher.macroTab.runFail");
|
||||
|
|
|
|||
|
|
@ -20,9 +20,13 @@ private slots:
|
|||
void Pressed();
|
||||
|
||||
private:
|
||||
MacroTree *_macros = nullptr;
|
||||
void ActivateElseState();
|
||||
void DeactivateElseState();
|
||||
|
||||
bool _macroHasElseActions = false;
|
||||
bool _runElseActionsKeyHeld = false;
|
||||
bool _elseStateActive = false;
|
||||
bool _shiftHeld = false;
|
||||
MacroTree *_macros = nullptr;
|
||||
QTimer _timer;
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user