mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-03-21 17:34:57 -05:00
Enable grouping of macros
Based on OBS's source-tree model/view implementation
This commit is contained in:
parent
2116bd7a78
commit
a80af327d7
|
|
@ -217,8 +217,6 @@ target_sources(
|
|||
src/macro-core/macro-condition-window.hpp
|
||||
src/macro-core/macro-condition.cpp
|
||||
src/macro-core/macro-condition.hpp
|
||||
src/macro-core/macro-list-entry-widget.cpp
|
||||
src/macro-core/macro-list-entry-widget.hpp
|
||||
src/macro-core/macro-properties.cpp
|
||||
src/macro-core/macro-properties.hpp
|
||||
src/macro-core/macro-ref.cpp
|
||||
|
|
@ -230,6 +228,8 @@ target_sources(
|
|||
src/macro-core/macro-selection.cpp
|
||||
src/macro-core/macro-selection.hpp
|
||||
src/macro-core/macro-tab.cpp
|
||||
src/macro-core/macro-tree.cpp
|
||||
src/macro-core/macro-tree.hpp
|
||||
src/macro-core/macro.cpp
|
||||
src/macro-core/macro.hpp)
|
||||
|
||||
|
|
|
|||
|
|
@ -79,8 +79,12 @@ AdvSceneSwitcher.macroTab.runFail="Running \"%1\" failed!\nEither one of the act
|
|||
AdvSceneSwitcher.macroTab.runInParallel="Run macro in parallel to other macros"
|
||||
AdvSceneSwitcher.macroTab.onChange="Perform actions only on condition change"
|
||||
AdvSceneSwitcher.macroTab.defaultname="Macro %1"
|
||||
AdvSceneSwitcher.macroTab.defaultGroupName="Group %1"
|
||||
AdvSceneSwitcher.macroTab.exists="Macro name exists already"
|
||||
AdvSceneSwitcher.macroTab.copy="Create copy"
|
||||
AdvSceneSwitcher.macroTab.groupDeleteConfirm="Are you sure you want to delete \"%1\" and all its elements?"
|
||||
AdvSceneSwitcher.macroTab.copy="Create copy of current macro"
|
||||
AdvSceneSwitcher.macroTab.group="Group selected items"
|
||||
AdvSceneSwitcher.macroTab.ungroup="Ungroup selected groups"
|
||||
AdvSceneSwitcher.macroTab.expandAll="Expand all"
|
||||
AdvSceneSwitcher.macroTab.collapseAll="Collapse all"
|
||||
AdvSceneSwitcher.macroTab.maximize="Maximize"
|
||||
|
|
|
|||
|
|
@ -634,49 +634,26 @@
|
|||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QGridLayout" name="gridLayout_26">
|
||||
<item row="0" column="0">
|
||||
<widget class="QListWidget" name="macros">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="dragEnabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="dragDropMode">
|
||||
<enum>QAbstractItemView::InternalMove</enum>
|
||||
</property>
|
||||
<property name="defaultDropAction">
|
||||
<enum>Qt::MoveAction</enum>
|
||||
</property>
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="sortingEnabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="macroHelp">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>AdvSceneSwitcher.macroTab.help</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
<widget class="MacroTree" name="macros">
|
||||
<property name="showDropIndicator" stdset="0">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="dragEnabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="dragDropMode">
|
||||
<enum>QAbstractItemView::InternalMove</enum>
|
||||
</property>
|
||||
<property name="defaultDropAction">
|
||||
<enum>Qt::TargetMoveAction</enum>
|
||||
</property>
|
||||
<property name="selectionMode">
|
||||
<enum>QAbstractItemView::ExtendedSelection</enum>
|
||||
</property>
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_61">
|
||||
|
|
@ -4560,6 +4537,13 @@
|
|||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>MacroTree</class>
|
||||
<extends>QListView</extends>
|
||||
<header>macro-tree.hpp</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
|
|
|||
|
|
@ -44,8 +44,9 @@ public:
|
|||
void OpenSequenceExtendEdit(SequenceWidget *sw);
|
||||
void SetEditSceneGroup(SceneGroup &sg);
|
||||
|
||||
bool addNewMacro(std::string &name, std::string format = "");
|
||||
Macro *getSelectedMacro();
|
||||
bool addNewMacro(std::shared_ptr<Macro> &res, std::string &name,
|
||||
std::string format = "");
|
||||
std::shared_ptr<Macro> getSelectedMacro();
|
||||
void SetEditMacro(Macro &m);
|
||||
void SetMacroEditAreaDisabled(bool);
|
||||
void HighlightAction(int idx);
|
||||
|
|
@ -126,7 +127,6 @@ public slots:
|
|||
void on_runMacro_clicked();
|
||||
void on_runMacroInParallel_stateChanged(int value);
|
||||
void on_runMacroOnChange_stateChanged(int value);
|
||||
void on_macros_currentRowChanged(int idx);
|
||||
void on_conditionAdd_clicked();
|
||||
void on_conditionRemove_clicked();
|
||||
void on_conditionUp_clicked();
|
||||
|
|
@ -135,6 +135,8 @@ public slots:
|
|||
void on_actionRemove_clicked();
|
||||
void on_actionUp_clicked();
|
||||
void on_actionDown_clicked();
|
||||
void MacroSelectionChanged(const QItemSelection &,
|
||||
const QItemSelection &);
|
||||
void UpMacroSegementHotkey();
|
||||
void DownMacroSegementHotkey();
|
||||
void DeleteMacroSegementHotkey();
|
||||
|
|
@ -165,7 +167,6 @@ public slots:
|
|||
void ResetOpacityActionControls();
|
||||
void ResetOpacityConditionControls();
|
||||
void HighlightControls();
|
||||
void MacroDragDropReorder(QModelIndex, int, int, QModelIndex, int);
|
||||
void HighlightOnChange();
|
||||
void on_macroProperties_clicked();
|
||||
|
||||
|
|
|
|||
|
|
@ -172,8 +172,9 @@ void AdvSceneSwitcher::AddMacroAction(int idx)
|
|||
}
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(switcher->m);
|
||||
macro->Actions().emplace(macro->Actions().begin() + idx,
|
||||
MacroActionFactory::Create(id, macro));
|
||||
macro->Actions().emplace(
|
||||
macro->Actions().begin() + idx,
|
||||
MacroActionFactory::Create(id, macro.get()));
|
||||
if (idx - 1 >= 0) {
|
||||
auto data = obs_data_create();
|
||||
macro->Actions().at(idx - 1)->Save(data);
|
||||
|
|
@ -298,7 +299,7 @@ void AdvSceneSwitcher::MoveMacroActionUp(int idx)
|
|||
return;
|
||||
}
|
||||
|
||||
SwapActions(macro, idx, idx - 1);
|
||||
SwapActions(macro.get(), idx, idx - 1);
|
||||
HighlightAction(idx - 1);
|
||||
}
|
||||
|
||||
|
|
@ -313,7 +314,7 @@ void AdvSceneSwitcher::MoveMacroActionDown(int idx)
|
|||
return;
|
||||
}
|
||||
|
||||
SwapActions(macro, idx, idx + 1);
|
||||
SwapActions(macro.get(), idx, idx + 1);
|
||||
HighlightAction(idx + 1);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -380,7 +380,7 @@ void AdvSceneSwitcher::AddMacroCondition(int idx)
|
|||
logic = macro->Conditions().at(idx - 1)->GetLogicType();
|
||||
}
|
||||
} else {
|
||||
MacroConditionScene temp(macro);
|
||||
MacroConditionScene temp(macro.get());
|
||||
id = temp.GetId();
|
||||
logic = LogicType::ROOT_NONE;
|
||||
}
|
||||
|
|
@ -388,7 +388,7 @@ void AdvSceneSwitcher::AddMacroCondition(int idx)
|
|||
std::lock_guard<std::mutex> lock(switcher->m);
|
||||
auto cond = macro->Conditions().emplace(
|
||||
macro->Conditions().begin() + idx,
|
||||
MacroConditionFactory::Create(id, macro));
|
||||
MacroConditionFactory::Create(id, macro.get()));
|
||||
if (idx - 1 >= 0) {
|
||||
auto data = obs_data_create();
|
||||
macro->Conditions().at(idx - 1)->Save(data);
|
||||
|
|
@ -535,7 +535,7 @@ void AdvSceneSwitcher::MoveMacroConditionUp(int idx)
|
|||
return;
|
||||
}
|
||||
|
||||
SwapConditions(macro, idx, idx - 1);
|
||||
SwapConditions(macro.get(), idx, idx - 1);
|
||||
HighlightCondition(idx - 1);
|
||||
}
|
||||
|
||||
|
|
@ -550,7 +550,7 @@ void AdvSceneSwitcher::MoveMacroConditionDown(int idx)
|
|||
return;
|
||||
}
|
||||
|
||||
SwapConditions(macro, idx, idx + 1);
|
||||
SwapConditions(macro.get(), idx, idx + 1);
|
||||
HighlightCondition(idx + 1);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,72 +0,0 @@
|
|||
#include "macro-list-entry-widget.hpp"
|
||||
#include "macro.hpp"
|
||||
#include "utility.hpp"
|
||||
|
||||
MacroListEntryWidget::MacroListEntryWidget(std::shared_ptr<Macro> macro,
|
||||
bool highlight, QWidget *parent)
|
||||
: QWidget(parent),
|
||||
_name(new QLabel(QString::fromStdString(macro->Name()))),
|
||||
_running(new QCheckBox),
|
||||
_macro(macro),
|
||||
_highlightExecutedMacros(highlight)
|
||||
{
|
||||
_running->setChecked(!macro->Paused());
|
||||
|
||||
setStyleSheet("\
|
||||
QCheckBox { background-color: rgba(0,0,0,0); }\
|
||||
QLabel { background-color: rgba(0,0,0,0); }");
|
||||
|
||||
auto layout = new QHBoxLayout;
|
||||
layout->setContentsMargins(0, 0, 0, 0);
|
||||
layout->addWidget(_running);
|
||||
layout->addWidget(_name);
|
||||
layout->addStretch();
|
||||
layout->setSizeConstraint(QLayout::SetFixedSize);
|
||||
setLayout(layout);
|
||||
|
||||
connect(_running, SIGNAL(stateChanged(int)), this,
|
||||
SLOT(PauseChanged(int)));
|
||||
connect(window(), SIGNAL(HighlightMacrosChanged(bool)), this,
|
||||
SLOT(EnableHighlight(bool)));
|
||||
_timer.setInterval(1500);
|
||||
connect(&_timer, SIGNAL(timeout()), this, SLOT(HighlightExecuted()));
|
||||
connect(&_timer, SIGNAL(timeout()), this, SLOT(UpdatePaused()));
|
||||
_timer.start();
|
||||
}
|
||||
|
||||
void MacroListEntryWidget::PauseChanged(int state)
|
||||
{
|
||||
_macro->SetPaused(!state);
|
||||
}
|
||||
|
||||
void MacroListEntryWidget::SetName(const QString &name)
|
||||
{
|
||||
_name->setText(name);
|
||||
}
|
||||
|
||||
void MacroListEntryWidget::SetMacro(std::shared_ptr<Macro> &m)
|
||||
{
|
||||
_macro = m;
|
||||
}
|
||||
|
||||
void MacroListEntryWidget::EnableHighlight(bool value)
|
||||
{
|
||||
_highlightExecutedMacros = value;
|
||||
}
|
||||
|
||||
void MacroListEntryWidget::HighlightExecuted()
|
||||
{
|
||||
if (!_highlightExecutedMacros) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (_macro && _macro->WasExecutedRecently()) {
|
||||
PulseWidget(this, Qt::green, QColor(0, 0, 0, 0), true);
|
||||
}
|
||||
}
|
||||
|
||||
void MacroListEntryWidget::UpdatePaused()
|
||||
{
|
||||
const QSignalBlocker b(_running);
|
||||
_running->setChecked(!_macro->Paused());
|
||||
}
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <QLabel>
|
||||
#include <QCheckBox>
|
||||
#include <QTimer>
|
||||
#include <memory>
|
||||
|
||||
class Macro;
|
||||
|
||||
class MacroListEntryWidget : public QWidget {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
MacroListEntryWidget(std::shared_ptr<Macro>, bool highlight,
|
||||
QWidget *parent);
|
||||
void SetName(const QString &);
|
||||
void SetMacro(std::shared_ptr<Macro> &);
|
||||
|
||||
private slots:
|
||||
void PauseChanged(int);
|
||||
void HighlightExecuted();
|
||||
void UpdatePaused();
|
||||
void EnableHighlight(bool);
|
||||
|
||||
private:
|
||||
QTimer _timer;
|
||||
QLabel *_name;
|
||||
QCheckBox *_running;
|
||||
std::shared_ptr<Macro> _macro;
|
||||
|
||||
bool _highlightExecutedMacros = false;
|
||||
};
|
||||
|
|
@ -17,7 +17,10 @@ MacroSelection::MacroSelection(QWidget *parent) : QComboBox(parent)
|
|||
firstItem->setSelectable(false);
|
||||
firstItem->setEnabled(false);
|
||||
|
||||
for (auto &m : switcher->macros) {
|
||||
for (const auto &m : switcher->macros) {
|
||||
if (m->IsGroup()) {
|
||||
continue;
|
||||
}
|
||||
addItem(QString::fromStdString(m->Name()));
|
||||
}
|
||||
|
||||
|
|
@ -51,7 +54,12 @@ void MacroSelection::HideSelectedMacro()
|
|||
if (!ssWindow) {
|
||||
return;
|
||||
}
|
||||
int idx = ssWindow->ui->macros->currentRow();
|
||||
|
||||
const auto m = ssWindow->ui->macros->GetCurrentMacro();
|
||||
if (!m) {
|
||||
return;
|
||||
}
|
||||
int idx = findText(QString::fromStdString(m->Name()));
|
||||
if (idx == -1) {
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
#include "macro.hpp"
|
||||
#include "macro-list-entry-widget.hpp"
|
||||
#include "macro-tree.hpp"
|
||||
#include "macro-action-edit.hpp"
|
||||
#include "macro-condition-edit.hpp"
|
||||
#include "advanced-scene-switcher.hpp"
|
||||
|
|
@ -20,7 +20,8 @@ bool macroNameExists(std::string name)
|
|||
return !!GetMacroByName(name.c_str());
|
||||
}
|
||||
|
||||
bool AdvSceneSwitcher::addNewMacro(std::string &name, std::string format)
|
||||
bool AdvSceneSwitcher::addNewMacro(std::shared_ptr<Macro> &res,
|
||||
std::string &name, std::string format)
|
||||
{
|
||||
QString fmt;
|
||||
int i = 1;
|
||||
|
|
@ -58,116 +59,78 @@ bool AdvSceneSwitcher::addNewMacro(std::string &name, std::string format)
|
|||
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(switcher->m);
|
||||
switcher->macros.emplace_back(std::make_shared<Macro>(
|
||||
res = std::make_shared<Macro>(
|
||||
name,
|
||||
switcher->macroProperties._newMacroRegisterHotkeys));
|
||||
switcher->macroProperties._newMacroRegisterHotkeys);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
QListWidgetItem *AddNewMacroListEntry(QListWidget *list,
|
||||
std::shared_ptr<Macro> ¯o)
|
||||
{
|
||||
QListWidgetItem *item = new QListWidgetItem(list);
|
||||
item->setData(Qt::UserRole, QString::fromStdString(macro->Name()));
|
||||
auto listEntry = new MacroListEntryWidget(
|
||||
macro, switcher->macroProperties._highlightExecuted, list);
|
||||
list->setItemWidget(item, listEntry);
|
||||
return item;
|
||||
}
|
||||
|
||||
void AdvSceneSwitcher::on_macroAdd_clicked()
|
||||
{
|
||||
std::string name;
|
||||
if (!addNewMacro(name)) {
|
||||
std::shared_ptr<Macro> newMacro;
|
||||
if (!addNewMacro(newMacro, name)) {
|
||||
return;
|
||||
}
|
||||
QString text = QString::fromStdString(name);
|
||||
|
||||
auto item = AddNewMacroListEntry(ui->macros, switcher->macros.back());
|
||||
ui->macros->setCurrentItem(item);
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(switcher->m);
|
||||
ui->macros->Add(newMacro);
|
||||
}
|
||||
|
||||
ui->macroAdd->disconnect(addPulse);
|
||||
ui->macroHelp->setVisible(false);
|
||||
|
||||
emit MacroAdded(QString::fromStdString(name));
|
||||
}
|
||||
|
||||
void AdvSceneSwitcher::on_macroRemove_clicked()
|
||||
{
|
||||
QListWidgetItem *item = ui->macros->currentItem();
|
||||
if (!item) {
|
||||
auto macro = getSelectedMacro();
|
||||
if (!macro) {
|
||||
return;
|
||||
}
|
||||
int idx = ui->macros->currentRow();
|
||||
delete item;
|
||||
QString name;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(switcher->m);
|
||||
switcher->abortMacroWait = true;
|
||||
switcher->macroWaitCv.notify_all();
|
||||
name = QString::fromStdString(switcher->macros[idx]->Name());
|
||||
switcher->macros.erase(switcher->macros.begin() + idx);
|
||||
for (auto &m : switcher->macros) {
|
||||
m->ResolveMacroRef();
|
||||
auto name = QString::fromStdString(macro->Name());
|
||||
if (macro->IsGroup()) {
|
||||
QString deleteWarning = obs_module_text(
|
||||
"AdvSceneSwitcher.macroTab.groupDeleteConfirm");
|
||||
if (!DisplayMessage(deleteWarning.arg(name), true)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (ui->macros->count() == 0) {
|
||||
ui->macroHelp->setVisible(true);
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(switcher->m);
|
||||
ui->macros->Remove(macro);
|
||||
}
|
||||
|
||||
emit MacroRemoved(name);
|
||||
}
|
||||
|
||||
void AdvSceneSwitcher::on_macroUp_clicked()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(switcher->m);
|
||||
if (!listMoveUp(ui->macros)) {
|
||||
auto macro = getSelectedMacro();
|
||||
if (!macro) {
|
||||
return;
|
||||
}
|
||||
|
||||
int index = ui->macros->currentRow() + 1;
|
||||
auto *entry1 = static_cast<MacroListEntryWidget *>(
|
||||
ui->macros->itemWidget(ui->macros->item(index)));
|
||||
auto *entry2 = static_cast<MacroListEntryWidget *>(
|
||||
ui->macros->itemWidget(ui->macros->item(index - 1)));
|
||||
entry1->SetMacro(*(switcher->macros.begin() + index - 1));
|
||||
entry2->SetMacro(*(switcher->macros.begin() + index));
|
||||
iter_swap(switcher->macros.begin() + index,
|
||||
switcher->macros.begin() + index - 1);
|
||||
|
||||
for (auto &m : switcher->macros) {
|
||||
m->ResolveMacroRef();
|
||||
}
|
||||
ui->macros->Up(macro);
|
||||
}
|
||||
|
||||
void AdvSceneSwitcher::on_macroDown_clicked()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(switcher->m);
|
||||
if (!listMoveDown(ui->macros)) {
|
||||
auto macro = getSelectedMacro();
|
||||
if (!macro) {
|
||||
return;
|
||||
}
|
||||
|
||||
int index = ui->macros->currentRow() - 1;
|
||||
auto *entry1 = static_cast<MacroListEntryWidget *>(
|
||||
ui->macros->itemWidget(ui->macros->item(index)));
|
||||
auto *entry2 = static_cast<MacroListEntryWidget *>(
|
||||
ui->macros->itemWidget(ui->macros->item(index + 1)));
|
||||
entry1->SetMacro(*(switcher->macros.begin() + index + 1));
|
||||
entry2->SetMacro(*(switcher->macros.begin() + index));
|
||||
iter_swap(switcher->macros.begin() + index,
|
||||
switcher->macros.begin() + index + 1);
|
||||
|
||||
for (auto &m : switcher->macros) {
|
||||
m->ResolveMacroRef();
|
||||
}
|
||||
ui->macros->Down(macro);
|
||||
}
|
||||
|
||||
void AdvSceneSwitcher::on_macroName_editingFinished()
|
||||
{
|
||||
bool nameValid = true;
|
||||
|
||||
Macro *macro = getSelectedMacro();
|
||||
auto macro = getSelectedMacro();
|
||||
if (!macro) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -189,22 +152,24 @@ void AdvSceneSwitcher::on_macroName_editingFinished()
|
|||
std::lock_guard<std::mutex> lock(switcher->m);
|
||||
if (nameValid) {
|
||||
macro->SetName(newName.toUtf8().constData());
|
||||
QListWidgetItem *item = ui->macros->currentItem();
|
||||
item->setData(Qt::UserRole, newName);
|
||||
auto listEntry = static_cast<MacroListEntryWidget *>(
|
||||
ui->macros->itemWidget(item));
|
||||
listEntry->SetName(newName);
|
||||
auto macro = getSelectedMacro();
|
||||
if (!macro) {
|
||||
return;
|
||||
}
|
||||
macro->SetName(newName.toStdString());
|
||||
} else {
|
||||
ui->macroName->setText(oldName);
|
||||
}
|
||||
}
|
||||
|
||||
emit MacroRenamed(oldName, newName);
|
||||
if (nameValid) {
|
||||
emit MacroRenamed(oldName, newName);
|
||||
}
|
||||
}
|
||||
|
||||
void AdvSceneSwitcher::on_runMacro_clicked()
|
||||
{
|
||||
Macro *macro = getSelectedMacro();
|
||||
auto macro = getSelectedMacro();
|
||||
if (!macro) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -219,7 +184,7 @@ void AdvSceneSwitcher::on_runMacro_clicked()
|
|||
|
||||
void AdvSceneSwitcher::on_runMacroInParallel_stateChanged(int value)
|
||||
{
|
||||
Macro *macro = getSelectedMacro();
|
||||
auto macro = getSelectedMacro();
|
||||
if (!macro) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -229,7 +194,7 @@ void AdvSceneSwitcher::on_runMacroInParallel_stateChanged(int value)
|
|||
|
||||
void AdvSceneSwitcher::on_runMacroOnChange_stateChanged(int value)
|
||||
{
|
||||
Macro *macro = getSelectedMacro();
|
||||
auto macro = getSelectedMacro();
|
||||
if (!macro) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -313,6 +278,10 @@ void AdvSceneSwitcher::SetEditMacro(Macro &m)
|
|||
PopulateMacroConditions(m);
|
||||
PopulateMacroActions(m);
|
||||
SetMacroEditAreaDisabled(false);
|
||||
if (m.IsGroup()) {
|
||||
SetMacroEditAreaDisabled(true);
|
||||
ui->macroName->setEnabled(true);
|
||||
}
|
||||
|
||||
currentActionIdx = -1;
|
||||
currentConditionIdx = -1;
|
||||
|
|
@ -340,25 +309,20 @@ void AdvSceneSwitcher::HighlightCondition(int idx)
|
|||
conditionsList->Highlight(idx);
|
||||
}
|
||||
|
||||
Macro *AdvSceneSwitcher::getSelectedMacro()
|
||||
std::shared_ptr<Macro> AdvSceneSwitcher::getSelectedMacro()
|
||||
{
|
||||
QListWidgetItem *item = ui->macros->currentItem();
|
||||
|
||||
if (!item) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
QString name = item->data(Qt::UserRole).toString();
|
||||
return GetMacroByQString(name);
|
||||
return ui->macros->GetCurrentMacro();
|
||||
}
|
||||
|
||||
void AdvSceneSwitcher::on_macros_currentRowChanged(int idx)
|
||||
void AdvSceneSwitcher::MacroSelectionChanged(const QItemSelection &,
|
||||
const QItemSelection &)
|
||||
{
|
||||
if (loading) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (idx == -1) {
|
||||
auto macro = getSelectedMacro();
|
||||
if (!macro) {
|
||||
SetMacroEditAreaDisabled(true);
|
||||
conditionsList->Clear();
|
||||
actionsList->Clear();
|
||||
|
|
@ -366,44 +330,21 @@ void AdvSceneSwitcher::on_macros_currentRowChanged(int idx)
|
|||
actionsList->SetHelpMsgVisible(true);
|
||||
return;
|
||||
}
|
||||
|
||||
QListWidgetItem *item = ui->macros->item(idx);
|
||||
QString macroName = item->data(Qt::UserRole).toString();
|
||||
|
||||
auto macro = GetMacroByQString(macroName);
|
||||
if (macro) {
|
||||
SetEditMacro(*macro);
|
||||
}
|
||||
}
|
||||
|
||||
void AdvSceneSwitcher::MacroDragDropReorder(QModelIndex, int from, int,
|
||||
QModelIndex, int to)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(switcher->m);
|
||||
if (from > to) {
|
||||
std::rotate(switcher->macros.rend() - from - 1,
|
||||
switcher->macros.rend() - from,
|
||||
switcher->macros.rend() - to);
|
||||
} else {
|
||||
std::rotate(switcher->macros.begin() + from,
|
||||
switcher->macros.begin() + from + 1,
|
||||
switcher->macros.begin() + to);
|
||||
}
|
||||
|
||||
for (auto &m : switcher->macros) {
|
||||
m->ResolveMacroRef();
|
||||
}
|
||||
SetEditMacro(*macro);
|
||||
}
|
||||
|
||||
void AdvSceneSwitcher::HighlightOnChange()
|
||||
{
|
||||
if (!switcher->macroProperties._highlightExecuted) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto macro = getSelectedMacro();
|
||||
if (!macro) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (switcher->macroProperties._highlightExecuted &&
|
||||
macro->OnChangePreventedActionsRecently()) {
|
||||
if (macro->OnChangePreventedActionsRecently()) {
|
||||
PulseWidget(ui->runMacroOnChange, Qt::yellow, Qt::transparent,
|
||||
true);
|
||||
}
|
||||
|
|
@ -413,7 +354,7 @@ void AdvSceneSwitcher::on_macroProperties_clicked()
|
|||
{
|
||||
MacroProperties prop = switcher->macroProperties;
|
||||
bool accepted = MacroPropertiesDialog::AskForSettings(
|
||||
this, prop, getSelectedMacro());
|
||||
this, prop, getSelectedMacro().get());
|
||||
if (!accepted) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -440,26 +381,17 @@ bool shouldResotreSplitterPos(const QList<int> &pos)
|
|||
|
||||
void AdvSceneSwitcher::setupMacroTab()
|
||||
{
|
||||
const QSignalBlocker signalBlocker(ui->macros);
|
||||
ui->macros->clear();
|
||||
for (auto &m : switcher->macros) {
|
||||
AddNewMacroListEntry(ui->macros, m);
|
||||
if (switcher->macros.size() == 0 && !switcher->disableHints) {
|
||||
addPulse = PulseWidget(ui->macroAdd, QColor(Qt::green));
|
||||
}
|
||||
|
||||
if (switcher->macros.size() == 0) {
|
||||
if (!switcher->disableHints) {
|
||||
addPulse = PulseWidget(ui->macroAdd, QColor(Qt::green));
|
||||
}
|
||||
ui->macroHelp->setVisible(true);
|
||||
} else {
|
||||
ui->macroHelp->setVisible(false);
|
||||
}
|
||||
|
||||
connect(ui->macros->model(),
|
||||
SIGNAL(rowsMoved(QModelIndex, int, int, QModelIndex, int)),
|
||||
ui->macros->Reset(switcher->macros,
|
||||
switcher->macroProperties._highlightExecuted);
|
||||
connect(ui->macros->selectionModel(),
|
||||
SIGNAL(selectionChanged(const QItemSelection &,
|
||||
const QItemSelection &)),
|
||||
this,
|
||||
SLOT(MacroDragDropReorder(QModelIndex, int, int, QModelIndex,
|
||||
int)));
|
||||
SLOT(MacroSelectionChanged(const QItemSelection &,
|
||||
const QItemSelection &)));
|
||||
|
||||
delete conditionsList;
|
||||
conditionsList = new MacroSegmentList(this);
|
||||
|
|
@ -531,42 +463,56 @@ void AdvSceneSwitcher::setupMacroTab()
|
|||
void AdvSceneSwitcher::ShowMacroContextMenu(const QPoint &pos)
|
||||
{
|
||||
QPoint globalPos = ui->macros->mapToGlobal(pos);
|
||||
QMenu myMenu;
|
||||
myMenu.addAction(obs_module_text("AdvSceneSwitcher.macroTab.copy"),
|
||||
this, &AdvSceneSwitcher::CopyMacro);
|
||||
myMenu.exec(globalPos);
|
||||
QMenu menu;
|
||||
auto copy = menu.addAction(
|
||||
obs_module_text("AdvSceneSwitcher.macroTab.copy"), this,
|
||||
&AdvSceneSwitcher::CopyMacro);
|
||||
copy->setDisabled(ui->macros->GroupsSelected());
|
||||
|
||||
auto group = menu.addAction(
|
||||
obs_module_text("AdvSceneSwitcher.macroTab.group"), ui->macros,
|
||||
&MacroTree::GroupSelectedItems);
|
||||
// Nested groups are not supported
|
||||
group->setDisabled(ui->macros->GroupedItemsSelected() ||
|
||||
ui->macros->GroupsSelected() ||
|
||||
ui->macros->SelectionEmpty());
|
||||
|
||||
auto ungroup = menu.addAction(
|
||||
obs_module_text("AdvSceneSwitcher.macroTab.ungroup"),
|
||||
ui->macros, &MacroTree::UngroupSelectedGroups);
|
||||
ungroup->setEnabled(ui->macros->GroupsSelected());
|
||||
|
||||
menu.exec(globalPos);
|
||||
}
|
||||
|
||||
void AdvSceneSwitcher::ShowMacroActionsContextMenu(const QPoint &pos)
|
||||
{
|
||||
QPoint globalPos = actionsList->mapToGlobal(pos);
|
||||
QMenu myMenu;
|
||||
myMenu.addAction(obs_module_text("AdvSceneSwitcher.macroTab.expandAll"),
|
||||
this, &AdvSceneSwitcher::ExpandAllActions);
|
||||
myMenu.addAction(
|
||||
obs_module_text("AdvSceneSwitcher.macroTab.collapseAll"), this,
|
||||
&AdvSceneSwitcher::CollapseAllActions);
|
||||
myMenu.addAction(obs_module_text("AdvSceneSwitcher.macroTab.maximize"),
|
||||
this, &AdvSceneSwitcher::MinimizeConditions);
|
||||
myMenu.addAction(obs_module_text("AdvSceneSwitcher.macroTab.minimize"),
|
||||
this, &AdvSceneSwitcher::MinimizeActions);
|
||||
myMenu.exec(globalPos);
|
||||
QMenu menu;
|
||||
menu.addAction(obs_module_text("AdvSceneSwitcher.macroTab.expandAll"),
|
||||
this, &AdvSceneSwitcher::ExpandAllActions);
|
||||
menu.addAction(obs_module_text("AdvSceneSwitcher.macroTab.collapseAll"),
|
||||
this, &AdvSceneSwitcher::CollapseAllActions);
|
||||
menu.addAction(obs_module_text("AdvSceneSwitcher.macroTab.maximize"),
|
||||
this, &AdvSceneSwitcher::MinimizeConditions);
|
||||
menu.addAction(obs_module_text("AdvSceneSwitcher.macroTab.minimize"),
|
||||
this, &AdvSceneSwitcher::MinimizeActions);
|
||||
menu.exec(globalPos);
|
||||
}
|
||||
|
||||
void AdvSceneSwitcher::ShowMacroConditionsContextMenu(const QPoint &pos)
|
||||
{
|
||||
QPoint globalPos = conditionsList->mapToGlobal(pos);
|
||||
QMenu myMenu;
|
||||
myMenu.addAction(obs_module_text("AdvSceneSwitcher.macroTab.expandAll"),
|
||||
this, &AdvSceneSwitcher::ExpandAllConditions);
|
||||
myMenu.addAction(
|
||||
obs_module_text("AdvSceneSwitcher.macroTab.collapseAll"), this,
|
||||
&AdvSceneSwitcher::CollapseAllConditions);
|
||||
myMenu.addAction(obs_module_text("AdvSceneSwitcher.macroTab.maximize"),
|
||||
this, &AdvSceneSwitcher::MinimizeActions);
|
||||
myMenu.addAction(obs_module_text("AdvSceneSwitcher.macroTab.minimize"),
|
||||
this, &AdvSceneSwitcher::MinimizeConditions);
|
||||
myMenu.exec(globalPos);
|
||||
QMenu menu;
|
||||
menu.addAction(obs_module_text("AdvSceneSwitcher.macroTab.expandAll"),
|
||||
this, &AdvSceneSwitcher::ExpandAllConditions);
|
||||
menu.addAction(obs_module_text("AdvSceneSwitcher.macroTab.collapseAll"),
|
||||
this, &AdvSceneSwitcher::CollapseAllConditions);
|
||||
menu.addAction(obs_module_text("AdvSceneSwitcher.macroTab.maximize"),
|
||||
this, &AdvSceneSwitcher::MinimizeActions);
|
||||
menu.addAction(obs_module_text("AdvSceneSwitcher.macroTab.minimize"),
|
||||
this, &AdvSceneSwitcher::MinimizeConditions);
|
||||
menu.exec(globalPos);
|
||||
}
|
||||
|
||||
void AdvSceneSwitcher::CopyMacro()
|
||||
|
|
@ -578,18 +524,20 @@ void AdvSceneSwitcher::CopyMacro()
|
|||
|
||||
std::string format = macro->Name() + " %1";
|
||||
std::string name;
|
||||
if (!addNewMacro(name, format)) {
|
||||
std::shared_ptr<Macro> newMacro;
|
||||
if (!addNewMacro(newMacro, name, format)) {
|
||||
return;
|
||||
}
|
||||
|
||||
obs_data_t *data = obs_data_create();
|
||||
macro->Save(data);
|
||||
switcher->macros.back()->Load(data);
|
||||
switcher->macros.back()->SetName(name);
|
||||
newMacro->Load(data);
|
||||
newMacro->SetName(name);
|
||||
obs_data_release(data);
|
||||
|
||||
auto item = AddNewMacroListEntry(ui->macros, switcher->macros.back());
|
||||
ui->macros->setCurrentItem(item);
|
||||
ui->macros->Add(newMacro);
|
||||
ui->macroAdd->disconnect(addPulse);
|
||||
emit MacroAdded(QString::fromStdString(name));
|
||||
}
|
||||
|
||||
void AdvSceneSwitcher::ExpandAllActions()
|
||||
|
|
|
|||
1201
src/macro-core/macro-tree.cpp
Normal file
1201
src/macro-core/macro-tree.cpp
Normal file
File diff suppressed because it is too large
Load Diff
160
src/macro-core/macro-tree.hpp
Normal file
160
src/macro-core/macro-tree.hpp
Normal file
|
|
@ -0,0 +1,160 @@
|
|||
#pragma once
|
||||
|
||||
#include <QTimer>
|
||||
#include <QLabel>
|
||||
#include <QCheckBox>
|
||||
#include <QListView>
|
||||
#include <QStaticText>
|
||||
#include <QAbstractListModel>
|
||||
#include <QStyledItemDelegate>
|
||||
|
||||
#include <memory>
|
||||
#include <deque>
|
||||
|
||||
class Macro;
|
||||
|
||||
class QLabel;
|
||||
class MacroTree;
|
||||
class QSpacerItem;
|
||||
class QHBoxLayout;
|
||||
|
||||
class MacroTreeItem : public QFrame {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit MacroTreeItem(MacroTree *tree, std::shared_ptr<Macro> macro,
|
||||
bool highlight);
|
||||
|
||||
private slots:
|
||||
void ExpandClicked(bool checked);
|
||||
void EnableHighlight(bool enable);
|
||||
void UpdatePaused();
|
||||
void HighlightIfExecuted();
|
||||
void MacroRenamed(const QString &, const QString &);
|
||||
|
||||
private:
|
||||
virtual void paintEvent(QPaintEvent *event) override;
|
||||
void mouseDoubleClickEvent(QMouseEvent *event) override;
|
||||
void Update(bool force);
|
||||
|
||||
enum class Type {
|
||||
Unknown,
|
||||
Item,
|
||||
Group,
|
||||
SubItem,
|
||||
};
|
||||
|
||||
Type _type = Type::Unknown;
|
||||
|
||||
QSpacerItem *_spacer = nullptr;
|
||||
QCheckBox *_expand = nullptr;
|
||||
QLabel *_iconLabel = nullptr;
|
||||
QCheckBox *_running = nullptr;
|
||||
QHBoxLayout *_boxLayout = nullptr;
|
||||
QLabel *_label = nullptr;
|
||||
MacroTree *_tree;
|
||||
bool _highlight;
|
||||
QTimer _timer;
|
||||
std::shared_ptr<Macro> _macro;
|
||||
|
||||
friend class MacroTree;
|
||||
friend class MacroTreeModel;
|
||||
};
|
||||
|
||||
// Only used to enable applying "SourceTreeSubItemCheckBox" stylesheet
|
||||
class SourceTreeSubItemCheckBox : public QCheckBox {
|
||||
Q_OBJECT
|
||||
};
|
||||
|
||||
class MacroTreeModel : public QAbstractListModel {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit MacroTreeModel(MacroTree *st,
|
||||
std::deque<std::shared_ptr<Macro>> ¯os);
|
||||
~MacroTreeModel() = default;
|
||||
virtual int rowCount(const QModelIndex &parent) const override;
|
||||
virtual QVariant data(const QModelIndex &index,
|
||||
int role) const override;
|
||||
virtual Qt::ItemFlags flags(const QModelIndex &index) const override;
|
||||
virtual Qt::DropActions supportedDropActions() const override;
|
||||
|
||||
private:
|
||||
void Reset(std::deque<std::shared_ptr<Macro>> &);
|
||||
void MoveItemBefore(const std::shared_ptr<Macro> &item,
|
||||
const std::shared_ptr<Macro> &before);
|
||||
void MoveItemAfter(const std::shared_ptr<Macro> &item,
|
||||
const std::shared_ptr<Macro> &after);
|
||||
void Add(std::shared_ptr<Macro> item);
|
||||
void Remove(std::shared_ptr<Macro> item);
|
||||
std::shared_ptr<Macro> Neighbor(const std::shared_ptr<Macro> &m,
|
||||
bool above) const;
|
||||
std::shared_ptr<Macro> FindEndOfGroup(const std::shared_ptr<Macro> &m,
|
||||
bool above) const;
|
||||
std::shared_ptr<Macro> GetCurrentMacro() const;
|
||||
QString GetNewGroupName();
|
||||
void GroupSelectedItems(QModelIndexList &indices);
|
||||
void UngroupSelectedGroups(QModelIndexList &indices);
|
||||
void ExpandGroup(std::shared_ptr<Macro> item);
|
||||
void CollapseGroup(std::shared_ptr<Macro> item);
|
||||
void UpdateGroupState(bool update);
|
||||
int GetItemMacroIndex(const std::shared_ptr<Macro> &item) const;
|
||||
int GetItemModelIndex(const std::shared_ptr<Macro> &item) const;
|
||||
bool IsLastItem(std::shared_ptr<Macro> item) const;
|
||||
|
||||
MacroTree *_mt;
|
||||
std::deque<std::shared_ptr<Macro>> &_macros;
|
||||
bool _hasGroups = false;
|
||||
|
||||
friend class MacroTree;
|
||||
friend class MacroTreeItem;
|
||||
};
|
||||
|
||||
class MacroTree : public QListView {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit MacroTree(QWidget *parent = nullptr);
|
||||
void Reset(std::deque<std::shared_ptr<Macro>> &, bool highlight);
|
||||
void Add(std::shared_ptr<Macro> item) const;
|
||||
void Remove(std::shared_ptr<Macro> item) const;
|
||||
void Up(std::shared_ptr<Macro> item) const;
|
||||
void Down(std::shared_ptr<Macro> item) const;
|
||||
std::shared_ptr<Macro> GetCurrentMacro() const;
|
||||
bool GroupsSelected() const;
|
||||
bool GroupedItemsSelected() const;
|
||||
bool SelectionEmpty() const;
|
||||
|
||||
public slots:
|
||||
void GroupSelectedItems();
|
||||
void UngroupSelectedGroups();
|
||||
|
||||
protected:
|
||||
virtual void dropEvent(QDropEvent *event) override;
|
||||
virtual void paintEvent(QPaintEvent *event) override;
|
||||
|
||||
private:
|
||||
MacroTreeItem *GetItemWidget(int idx) const;
|
||||
void ResetWidgets();
|
||||
void UpdateWidget(const QModelIndex &idx, std::shared_ptr<Macro> item);
|
||||
void UpdateWidgets(bool force = false);
|
||||
void MoveItemBefore(const std::shared_ptr<Macro> &item,
|
||||
const std::shared_ptr<Macro> &after) const;
|
||||
void MoveItemAfter(const std::shared_ptr<Macro> &item,
|
||||
const std::shared_ptr<Macro> &after) const;
|
||||
MacroTreeModel *GetModel() const;
|
||||
|
||||
bool _highlight = false;
|
||||
|
||||
friend class MacroTreeModel;
|
||||
friend class MacroTreeItem;
|
||||
};
|
||||
|
||||
class MacroTreeDelegate : public QStyledItemDelegate {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
MacroTreeDelegate(QObject *parent);
|
||||
virtual QSize sizeHint(const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index) const override;
|
||||
};
|
||||
|
|
@ -28,8 +28,72 @@ Macro::~Macro()
|
|||
ClearHotkeys();
|
||||
}
|
||||
|
||||
std::shared_ptr<Macro>
|
||||
Macro::CreateGroup(const std::string &name,
|
||||
std::vector<std::shared_ptr<Macro>> &children)
|
||||
{
|
||||
auto group = std::make_shared<Macro>(name, false);
|
||||
for (auto &c : children) {
|
||||
c->SetParent(group.get());
|
||||
}
|
||||
group->_isGroup = true;
|
||||
group->_groupSize = children.size();
|
||||
return group;
|
||||
}
|
||||
|
||||
void Macro::RemoveGroup(std::shared_ptr<Macro> group)
|
||||
{
|
||||
auto it = std::find(switcher->macros.begin(), switcher->macros.end(),
|
||||
group);
|
||||
if (it == switcher->macros.end()) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto size = group->GroupSize();
|
||||
for (uint32_t i = 1; i <= size; i++) {
|
||||
auto m = std::next(it, i);
|
||||
(*m)->SetParent(nullptr);
|
||||
}
|
||||
|
||||
switcher->macros.erase(it);
|
||||
}
|
||||
|
||||
void Macro::PrepareMoveToGroup(Macro *group, std::shared_ptr<Macro> item)
|
||||
{
|
||||
for (auto &m : switcher->macros) {
|
||||
if (m.get() == group) {
|
||||
PrepareMoveToGroup(m, item);
|
||||
return;
|
||||
}
|
||||
}
|
||||
PrepareMoveToGroup(std::shared_ptr<Macro>(), item);
|
||||
}
|
||||
|
||||
void Macro::PrepareMoveToGroup(std::shared_ptr<Macro> group,
|
||||
std::shared_ptr<Macro> item)
|
||||
{
|
||||
if (!item) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Potentially remove from old group
|
||||
auto oldGroup = item->Parent();
|
||||
if (oldGroup) {
|
||||
oldGroup->_groupSize--;
|
||||
}
|
||||
|
||||
item->SetParent(group.get());
|
||||
if (group) {
|
||||
group->_groupSize++;
|
||||
}
|
||||
}
|
||||
|
||||
bool Macro::CeckMatch()
|
||||
{
|
||||
if (_isGroup) {
|
||||
return false;
|
||||
}
|
||||
|
||||
_matched = false;
|
||||
for (auto &c : _conditions) {
|
||||
if (_paused) {
|
||||
|
|
@ -140,6 +204,9 @@ bool Macro::PerformActions(bool forceParallel, bool ignorePause)
|
|||
RunActions(ret, ignorePause);
|
||||
}
|
||||
_wasExecutedRecently = true;
|
||||
if (_parent) {
|
||||
_parent->_wasExecutedRecently = true;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
@ -253,6 +320,16 @@ bool Macro::Save(obs_data_t *obj) const
|
|||
obs_data_set_bool(obj, "parallel", _runInParallel);
|
||||
obs_data_set_bool(obj, "onChange", _matchOnChange);
|
||||
|
||||
obs_data_set_bool(obj, "group", _isGroup);
|
||||
if (_isGroup) {
|
||||
auto groupData = obs_data_create();
|
||||
obs_data_set_bool(groupData, "collapsed", _isCollapsed);
|
||||
obs_data_set_int(groupData, "size", _groupSize);
|
||||
obs_data_set_obj(obj, "groupData", groupData);
|
||||
obs_data_release(groupData);
|
||||
return true;
|
||||
}
|
||||
|
||||
obs_data_set_bool(obj, "registerHotkeys", _registerHotkeys);
|
||||
obs_data_array_t *pauseHotkey = obs_hotkey_save(_pauseHotkey);
|
||||
obs_data_set_array(obj, "pauseHotkey", pauseHotkey);
|
||||
|
|
@ -333,6 +410,15 @@ bool Macro::Load(obs_data_t *obj)
|
|||
_runInParallel = obs_data_get_bool(obj, "parallel");
|
||||
_matchOnChange = obs_data_get_bool(obj, "onChange");
|
||||
|
||||
_isGroup = obs_data_get_bool(obj, "group");
|
||||
if (_isGroup) {
|
||||
auto groupData = obs_data_get_obj(obj, "groupData");
|
||||
_isCollapsed = obs_data_get_bool(groupData, "collapsed");
|
||||
_groupSize = obs_data_get_int(groupData, "size");
|
||||
obs_data_release(groupData);
|
||||
return true;
|
||||
}
|
||||
|
||||
obs_data_set_default_bool(obj, "registerHotkeys", true);
|
||||
_registerHotkeys = obs_data_get_bool(obj, "registerHotkeys");
|
||||
if (_registerHotkeys) {
|
||||
|
|
@ -610,8 +696,18 @@ void SwitcherData::loadMacros(obs_data_t *obj)
|
|||
}
|
||||
obs_data_array_release(macroArray);
|
||||
|
||||
int groupCount = 0;
|
||||
Macro *group = nullptr;
|
||||
for (auto &m : macros) {
|
||||
m->ResolveMacroRef();
|
||||
if (groupCount) {
|
||||
m->SetParent(group);
|
||||
groupCount--;
|
||||
}
|
||||
if (m->IsGroup()) {
|
||||
groupCount = m->GroupSize();
|
||||
group = m.get();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ class Macro {
|
|||
public:
|
||||
Macro(const std::string &name = "", const bool addHotkey = false);
|
||||
virtual ~Macro();
|
||||
|
||||
bool CeckMatch();
|
||||
bool PerformActions(bool forceParallel = false,
|
||||
bool ignorePause = false);
|
||||
|
|
@ -41,9 +40,26 @@ public:
|
|||
{
|
||||
return _conditions;
|
||||
}
|
||||
std::deque<std::shared_ptr<MacroAction>> &Actions() { return _actions; }
|
||||
void UpdateActionIndices();
|
||||
void UpdateConditionIndices();
|
||||
std::deque<std::shared_ptr<MacroAction>> &Actions() { return _actions; }
|
||||
|
||||
// Group controls
|
||||
static std::shared_ptr<Macro>
|
||||
CreateGroup(const std::string &name,
|
||||
std::vector<std::shared_ptr<Macro>> &children);
|
||||
static void RemoveGroup(std::shared_ptr<Macro>);
|
||||
static void PrepareMoveToGroup(Macro *group,
|
||||
std::shared_ptr<Macro> item);
|
||||
static void PrepareMoveToGroup(std::shared_ptr<Macro> group,
|
||||
std::shared_ptr<Macro> item);
|
||||
bool IsGroup() { return _isGroup; }
|
||||
uint32_t GroupSize() { return _groupSize; }
|
||||
bool IsSubitem() { return !!_parent; }
|
||||
void SetCollapsed(bool val) { _isCollapsed = val; }
|
||||
bool IsCollapsed() { return _isCollapsed; }
|
||||
void SetParent(Macro *m) { _parent = m; }
|
||||
Macro *Parent() { return _parent; }
|
||||
|
||||
bool Save(obs_data_t *obj) const;
|
||||
bool Load(obs_data_t *obj);
|
||||
|
|
@ -75,6 +91,10 @@ private:
|
|||
std::string _name = "";
|
||||
std::deque<std::shared_ptr<MacroCondition>> _conditions;
|
||||
std::deque<std::shared_ptr<MacroAction>> _actions;
|
||||
|
||||
Macro *_parent = nullptr;
|
||||
uint32_t _groupSize = 0;
|
||||
|
||||
bool _runInParallel = false;
|
||||
bool _matched = false;
|
||||
bool _lastMatched = false;
|
||||
|
|
@ -87,6 +107,8 @@ private:
|
|||
obs_hotkey_id _togglePauseHotkey = OBS_INVALID_HOTKEY_ID;
|
||||
|
||||
// UI helpers for the macro tab
|
||||
bool _isGroup = false;
|
||||
bool _isCollapsed = false;
|
||||
bool _wasExecutedRecently = false;
|
||||
bool _onChangeTriggered = false;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user