SceneSwitcher/src/macro-core/macro-properties.cpp
WarmUpTill 2c5caabab0 Add advss namespace
Fixes name conflict with "Duration" class and typedef of the same name
on MacOS
2023-04-17 11:33:24 -07:00

154 lines
5.6 KiB
C++

#include "macro-properties.hpp"
#include <QVBoxLayout>
#include <QDialogButtonBox>
#include <obs-module.h>
namespace advss {
void MacroProperties::Save(obs_data_t *obj) const
{
auto data = obs_data_create();
obs_data_set_bool(data, "highlightExecuted", _highlightExecuted);
obs_data_set_bool(data, "highlightConditions", _highlightConditions);
obs_data_set_bool(data, "highlightActions", _highlightActions);
obs_data_set_bool(data, "newMacroRegisterHotkey",
_newMacroRegisterHotkeys);
obs_data_set_obj(obj, "macroProperties", data);
obs_data_release(data);
}
void MacroProperties::Load(obs_data_t *obj)
{
auto data = obs_data_get_obj(obj, "macroProperties");
_highlightExecuted = obs_data_get_bool(data, "highlightExecuted");
_highlightConditions = obs_data_get_bool(data, "highlightConditions");
_highlightActions = obs_data_get_bool(data, "highlightActions");
_newMacroRegisterHotkeys =
obs_data_get_bool(data, "newMacroRegisterHotkey");
obs_data_release(data);
}
MacroPropertiesDialog::MacroPropertiesDialog(QWidget *parent,
const MacroProperties &prop,
Macro *macro)
: QDialog(parent),
_executed(new QCheckBox(obs_module_text(
"AdvSceneSwitcher.macroTab.highlightExecutedMacros"))),
_conditions(new QCheckBox(obs_module_text(
"AdvSceneSwitcher.macroTab.highlightTrueConditions"))),
_actions(new QCheckBox(obs_module_text(
"AdvSceneSwitcher.macroTab.highlightPerformedActions"))),
_newMacroRegisterHotkeys(new QCheckBox(obs_module_text(
"AdvSceneSwitcher.macroTab.newMacroRegisterHotkey"))),
_currentMacroRegisterHotkeys(new QCheckBox(obs_module_text(
"AdvSceneSwitcher.macroTab.currentDisableHotkeys"))),
_currentMacroRegisterDock(new QCheckBox(obs_module_text(
"AdvSceneSwitcher.macroTab.currentRegisterDock"))),
_currentMacroDockAddRunButton(new QCheckBox(obs_module_text(
"AdvSceneSwitcher.macroTab.currentDockAddRunButton"))),
_currentMacroDockAddPauseButton(new QCheckBox(obs_module_text(
"AdvSceneSwitcher.macroTab.currentDockAddPauseButton")))
{
setModal(true);
setWindowModality(Qt::WindowModality::WindowModal);
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
auto highlightOptions = new QGroupBox(
obs_module_text("AdvSceneSwitcher.macroTab.highlightSettings"));
QVBoxLayout *highlightLayout = new QVBoxLayout;
highlightLayout->addWidget(_executed);
highlightLayout->addWidget(_conditions);
highlightLayout->addWidget(_actions);
highlightOptions->setLayout(highlightLayout);
auto hotkeyOptions = new QGroupBox(
obs_module_text("AdvSceneSwitcher.macroTab.hotkeySettings"));
QVBoxLayout *hotkeyLayout = new QVBoxLayout;
hotkeyLayout->addWidget(_newMacroRegisterHotkeys);
hotkeyLayout->addWidget(_currentMacroRegisterHotkeys);
hotkeyOptions->setLayout(hotkeyLayout);
_dockOptions = new QGroupBox(
obs_module_text("AdvSceneSwitcher.macroTab.dockSettings"));
QVBoxLayout *dockLayout = new QVBoxLayout;
dockLayout->addWidget(_currentMacroRegisterDock);
dockLayout->addWidget(_currentMacroDockAddRunButton);
dockLayout->addWidget(_currentMacroDockAddPauseButton);
_dockOptions->setLayout(dockLayout);
QDialogButtonBox *buttonbox = new QDialogButtonBox(
QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
buttonbox->setCenterButtons(true);
connect(buttonbox, &QDialogButtonBox::accepted, this, &QDialog::accept);
connect(buttonbox, &QDialogButtonBox::rejected, this, &QDialog::reject);
connect(_currentMacroRegisterDock, &QCheckBox::stateChanged, this,
&MacroPropertiesDialog::DockEnableChanged);
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(highlightOptions);
layout->addWidget(hotkeyOptions);
layout->addWidget(_dockOptions);
layout->addWidget(buttonbox);
setLayout(layout);
_executed->setChecked(prop._highlightExecuted);
_conditions->setChecked(prop._highlightConditions);
_actions->setChecked(prop._highlightActions);
_newMacroRegisterHotkeys->setChecked(prop._newMacroRegisterHotkeys);
if (!macro || macro->IsGroup()) {
hotkeyOptions->hide();
_dockOptions->hide();
return;
}
_currentMacroRegisterHotkeys->setChecked(macro->PauseHotkeysEnabled());
const bool dockEnabled = macro->DockEnabled();
_currentMacroRegisterDock->setChecked(dockEnabled);
_currentMacroDockAddRunButton->setChecked(macro->DockHasRunButton());
_currentMacroDockAddPauseButton->setChecked(
macro->DockHasPauseButton());
_currentMacroDockAddRunButton->setVisible(dockEnabled);
_currentMacroDockAddPauseButton->setVisible(dockEnabled);
}
void MacroPropertiesDialog::DockEnableChanged(int enabled)
{
_currentMacroDockAddRunButton->setVisible(enabled);
_currentMacroDockAddPauseButton->setVisible(enabled);
_dockOptions->adjustSize();
_dockOptions->updateGeometry();
adjustSize();
updateGeometry();
}
bool MacroPropertiesDialog::AskForSettings(QWidget *parent,
MacroProperties &userInput,
Macro *macro)
{
MacroPropertiesDialog dialog(parent, userInput, macro);
dialog.setWindowTitle(obs_module_text("AdvSceneSwitcher.windowTitle"));
if (dialog.exec() != DialogCode::Accepted) {
return false;
}
userInput._highlightExecuted = dialog._executed->isChecked();
userInput._highlightConditions = dialog._conditions->isChecked();
userInput._highlightActions = dialog._actions->isChecked();
userInput._newMacroRegisterHotkeys =
dialog._newMacroRegisterHotkeys->isChecked();
if (!macro) {
return true;
}
macro->EnablePauseHotkeys(
dialog._currentMacroRegisterHotkeys->isChecked());
macro->EnableDock(dialog._currentMacroRegisterDock->isChecked());
macro->SetDockHasRunButton(
dialog._currentMacroDockAddRunButton->isChecked());
macro->SetDockHasPauseButton(
dialog._currentMacroDockAddPauseButton->isChecked());
return true;
}
} // namespace advss