From a8d483f5a76318257f364fcd8428d5251fd3c1f8 Mon Sep 17 00:00:00 2001 From: WarmUpTill <19472752+WarmUpTill@users.noreply.github.com> Date: Fri, 9 Jan 2026 20:25:58 +0100 Subject: [PATCH] Enable un-/pausing all macros in a group --- lib/macro/macro-tree.cpp | 122 ++++++++++++++++++++++++++++----------- lib/macro/macro-tree.hpp | 5 +- 2 files changed, 90 insertions(+), 37 deletions(-) diff --git a/lib/macro/macro-tree.cpp b/lib/macro/macro-tree.cpp index f0685ec3..278e85ad 100644 --- a/lib/macro/macro-tree.cpp +++ b/lib/macro/macro-tree.cpp @@ -62,12 +62,11 @@ MacroTreeItem::MacroTreeItem(MacroTree *tree, std::shared_ptr macroItem, _boxLayout = new QHBoxLayout(); _boxLayout->setContentsMargins(0, 0, 0, 0); - _boxLayout->addWidget(_running); if (isGroup) { _boxLayout->addWidget(_iconLabel); _boxLayout->addSpacing(2); - _running->hide(); } + _boxLayout->addWidget(_running); _boxLayout->addWidget(_label); #ifdef __APPLE__ /* Hack: Fixes a bug where scrollbars would be above the lock icon */ @@ -77,17 +76,17 @@ MacroTreeItem::MacroTreeItem(MacroTree *tree, std::shared_ptr macroItem, Update(true); setLayout(_boxLayout); - auto setRunning = [this](bool val) { - _macro->SetPaused(!val); - }; - connect(_running, &QAbstractButton::clicked, setRunning); + connect(_running, SIGNAL(clicked(bool)), this, + SLOT(RunningClicked(bool))); connect(MacroSignalManager::Instance(), SIGNAL(HighlightChanged(bool)), this, SLOT(EnableHighlight(bool))); connect(MacroSignalManager::Instance(), SIGNAL(Rename(const QString &, const QString &)), this, SLOT(MacroRenamed(const QString &, const QString &))); connect(&_timer, SIGNAL(timeout()), this, SLOT(HighlightIfExecuted())); - connect(&_timer, SIGNAL(timeout()), this, SLOT(UpdatePaused())); + connect(&_timer, SIGNAL(timeout()), this, SLOT(UpdateRunning())); + + UpdateRunning(); _timer.start(1500); } @@ -96,10 +95,90 @@ void MacroTreeItem::EnableHighlight(bool enable) _highlight = enable; } -void MacroTreeItem::UpdatePaused() +void MacroTreeItem::RunningClicked(bool running) +{ + const auto updateWidget = [this](Macro *macro) { + if (!macro) { + return; + } + + const auto ¯os = GetTopLevelMacros(); + + bool found = false; + int idx = 0; + for (const auto &m : macros) { + if (m.get() == macro) { + found = true; + break; + } + idx++; + } + + if (!found) { + return; + } + + const auto widget = _tree->GetItemWidget(idx); + if (widget) { + widget->UpdateRunning(); + } + }; + + if (!_macro->IsGroup()) { + _macro->SetPaused(!running); + if (!_macro->IsSubitem()) { + return; + } + + const auto group = _macro->Parent(); + updateWidget(group.get()); + return; + } + + const auto macros = GetGroupMacroEntries(_macro.get()); + for (const auto ¯o : macros) { + macro->SetPaused(!running); + } + + // Update backend values before updating UI to prevent flickering in + // running state of the group + for (const auto ¯o : macros) { + updateWidget(macro.get()); + } + UpdateRunning(); +} + +void MacroTreeItem::UpdateRunning() { const QSignalBlocker blocker(_running); - _running->setChecked(!_macro->Paused()); + + if (!_macro->IsGroup()) { + _running->setChecked(!_macro->Paused()); + return; + } + + const auto macros = GetGroupMacroEntries(_macro.get()); + bool allRunning = true; + bool allPaused = true; + for (const auto ¯o : macros) { + if (macro->Paused()) { + allRunning = false; + } else { + allPaused = false; + } + } + + if (allRunning) { + _running->setCheckState(Qt::Checked); + return; + } + + if (allPaused) { + _running->setCheckState(Qt::Unchecked); + return; + } + + _running->setCheckState(Qt::PartiallyChecked); } void MacroTreeItem::HighlightIfExecuted() @@ -214,7 +293,6 @@ void MacroTreeModel::Reset(std::deque> &newItems) _macros = newItems; endResetModel(); - UpdateGroupState(false); _mt->ResetWidgets(); } @@ -459,9 +537,6 @@ void MacroTreeModel::Remove(std::shared_ptr item) _mt->selectionModel()->clear(); - if (isGroup) { - UpdateGroupState(true); - } assert(IsInValidState()); } @@ -550,7 +625,6 @@ MacroTreeModel::MacroTreeModel(MacroTree *st_, _mt(st_), _macros(macros) { - UpdateGroupState(false); } int MacroTreeModel::rowCount(const QModelIndex &parent) const @@ -704,7 +778,6 @@ void MacroTreeModel::GroupSelectedItems(QModelIndexList &indices) offset++; } - _hasGroups = true; _mt->selectionModel()->clear(); Reset(_macros); @@ -762,24 +835,6 @@ void MacroTreeModel::CollapseGroup(std::shared_ptr item) assert(IsInValidState()); } -void MacroTreeModel::UpdateGroupState(bool update) -{ - bool nowHasGroups = false; - for (auto &item : _macros) { - if (item->IsGroup()) { - nowHasGroups = true; - break; - } - } - - if (nowHasGroups != _hasGroups) { - _hasGroups = nowHasGroups; - if (update) { - _mt->UpdateWidgets(true); - } - } -} - void MacroTree::Reset(std::deque> ¯os, bool highlight) { @@ -842,7 +897,6 @@ MacroTree::MacroTree(QWidget *parent_) : QListView(parent_) void MacroTree::ResetWidgets() { MacroTreeModel *mtm = GetModel(); - mtm->UpdateGroupState(false); int modelIdx = 0; for (int i = 0; i < (int)mtm->_macros.size(); i++) { QModelIndex index = mtm->createIndex(modelIdx, 0, nullptr); diff --git a/lib/macro/macro-tree.hpp b/lib/macro/macro-tree.hpp index 2b0ca6f6..52ed28da 100644 --- a/lib/macro/macro-tree.hpp +++ b/lib/macro/macro-tree.hpp @@ -37,7 +37,8 @@ public: private slots: void ExpandClicked(bool checked); void EnableHighlight(bool enable); - void UpdatePaused(); + void RunningClicked(bool); + void UpdateRunning(); void HighlightIfExecuted(); void MacroRenamed(const QString &, const QString &); @@ -106,7 +107,6 @@ private: void UngroupSelectedGroups(QModelIndexList &indices); void ExpandGroup(std::shared_ptr item); void CollapseGroup(std::shared_ptr item); - void UpdateGroupState(bool update); int GetItemMacroIndex(const std::shared_ptr &item) const; int GetItemModelIndex(const std::shared_ptr &item) const; bool IsLastItem(std::shared_ptr item) const; @@ -114,7 +114,6 @@ private: MacroTree *_mt; std::deque> &_macros; - bool _hasGroups = false; friend class MacroTree; friend class MacroTreeItem;