From 428e114a0ac1ee65b6102be43a2fc7a1b772525a Mon Sep 17 00:00:00 2001 From: WarmUpTill Date: Sun, 6 Mar 2022 19:57:23 +0100 Subject: [PATCH] Highlight recently executed action and true conditions --- src/headers/macro-segment.hpp | 14 +++++++++-- src/headers/macro.hpp | 1 + src/macro-action-edit.cpp | 5 ++-- src/macro-condition-edit.cpp | 6 +++-- src/macro-segment.cpp | 45 ++++++++++++++++++++++++++++++++--- src/macro-tab.cpp | 2 ++ src/macro.cpp | 31 ++++++++++++++++++++++-- 7 files changed, 93 insertions(+), 11 deletions(-) diff --git a/src/headers/macro-segment.hpp b/src/headers/macro-segment.hpp index eabefc64..4812fe28 100644 --- a/src/headers/macro-segment.hpp +++ b/src/headers/macro-segment.hpp @@ -2,6 +2,7 @@ #include #include #include +#include #include class Macro; @@ -18,10 +19,14 @@ public: virtual bool Load(obs_data_t *obj) = 0; virtual std::string GetShortDesc(); virtual std::string GetId() = 0; + void SetHighlight(); + bool Highlight(); protected: int _idx = 0; bool _collapsed = false; + // UI helper + bool _highlight = false; private: Macro *_macro = nullptr; @@ -34,7 +39,7 @@ class MacroSegmentEdit : public QWidget { Q_OBJECT public: - MacroSegmentEdit(QWidget *parent = nullptr); + MacroSegmentEdit(bool highlight, QWidget *parent = nullptr); // Use this function to avoid accidental edits when scrolling through // list of actions and conditions void SetFocusPolicyOfWidgets(); @@ -44,6 +49,8 @@ public: protected slots: void HeaderInfoChanged(const QString &); void Collapsed(bool); + void Highlight(); + void EnableHighlight(bool); signals: void MacroAdded(const QString &name); void MacroRemoved(const QString &name); @@ -59,10 +66,13 @@ protected: Section *_section; QLabel *_headerInfo; QFrame *_frame; - QVBoxLayout *_highLightFrameLayout; + QVBoxLayout *_selectionFrameLayout; private: virtual MacroSegment *Data() = 0; + + bool _showHighlight; + QTimer _timer; }; class MouseWheelWidgetAdjustmentGuard : public QObject { diff --git a/src/headers/macro.hpp b/src/headers/macro.hpp index a4fa0ada..18f31605 100644 --- a/src/headers/macro.hpp +++ b/src/headers/macro.hpp @@ -110,6 +110,7 @@ public: // UI helpers for the macro tab bool WasExecutedRecently(); + void ResetUIHelpers(); private: void SetupHotkeys(); diff --git a/src/macro-action-edit.cpp b/src/macro-action-edit.cpp index 1aa783c1..847c762f 100644 --- a/src/macro-action-edit.cpp +++ b/src/macro-action-edit.cpp @@ -63,7 +63,8 @@ static inline void populateActionSelection(QComboBox *list) MacroActionEdit::MacroActionEdit(QWidget *parent, std::shared_ptr *entryData, const std::string &id) - : MacroSegmentEdit(parent), _entryData(entryData) + : MacroSegmentEdit(switcher->highlightExecutedMacros, parent), + _entryData(entryData) { _actionSelection = new QComboBox(); @@ -80,7 +81,7 @@ MacroActionEdit::MacroActionEdit(QWidget *parent, actionLayout->setContentsMargins(0, 0, 0, 0); actionLayout->setSpacing(0); actionLayout->addWidget(_frame); - _highLightFrameLayout->addWidget(_section); + _selectionFrameLayout->addWidget(_section); QHBoxLayout *mainLayout = new QHBoxLayout; mainLayout->setContentsMargins(0, 0, 0, 0); diff --git a/src/macro-condition-edit.cpp b/src/macro-condition-edit.cpp index ce1676bf..e357a306 100644 --- a/src/macro-condition-edit.cpp +++ b/src/macro-condition-edit.cpp @@ -92,7 +92,9 @@ static inline void populateConditionSelection(QComboBox *list) MacroConditionEdit::MacroConditionEdit( QWidget *parent, std::shared_ptr *entryData, const std::string &id, bool root) - : MacroSegmentEdit(parent), _entryData(entryData), _isRoot(root) + : MacroSegmentEdit(switcher->highlightExecutedMacros, parent), + _entryData(entryData), + _isRoot(root) { _logicSelection = new QComboBox(); _conditionSelection = new QComboBox(); @@ -123,7 +125,7 @@ MacroConditionEdit::MacroConditionEdit( conditionLayout->setContentsMargins(0, 0, 0, 0); conditionLayout->setSpacing(0); conditionLayout->addWidget(_frame); - _highLightFrameLayout->addWidget(_section); + _selectionFrameLayout->addWidget(_section); QHBoxLayout *mainLayout = new QHBoxLayout; mainLayout->setContentsMargins(0, 0, 0, 0); diff --git a/src/macro-segment.cpp b/src/macro-segment.cpp index 71eec564..66fa4382 100644 --- a/src/macro-segment.cpp +++ b/src/macro-segment.cpp @@ -1,5 +1,6 @@ #include "headers/macro-segment.hpp" #include "headers/section.hpp" +#include "headers/utility.hpp" #include #include @@ -24,6 +25,20 @@ std::string MacroSegment::GetShortDesc() return ""; } +void MacroSegment::SetHighlight() +{ + _highlight = true; +} + +bool MacroSegment::Highlight() +{ + if (_highlight) { + _highlight = false; + return true; + } + return false; +} + MouseWheelWidgetAdjustmentGuard::MouseWheelWidgetAdjustmentGuard(QObject *parent) : QObject(parent) { @@ -40,16 +55,17 @@ bool MouseWheelWidgetAdjustmentGuard::eventFilter(QObject *o, QEvent *e) return QObject::eventFilter(o, e); } -MacroSegmentEdit::MacroSegmentEdit(QWidget *parent) : QWidget(parent) +MacroSegmentEdit::MacroSegmentEdit(bool highlight, QWidget *parent) + : QWidget(parent), _showHighlight(highlight) { _section = new Section(300); _headerInfo = new QLabel(); _frame = new QFrame; _frame->setObjectName("segmentFrame"); - _highLightFrameLayout = new QVBoxLayout; + _selectionFrameLayout = new QVBoxLayout; SetSelected(false); - _frame->setLayout(_highLightFrameLayout); + _frame->setLayout(_selectionFrameLayout); // Set background transparent to avoid blocking highlight frame setStyleSheet("QCheckBox { background-color: rgba(0,0,0,0); }" "QLabel { background-color: rgba(0,0,0,0); }" @@ -81,6 +97,13 @@ MacroSegmentEdit::MacroSegmentEdit(QWidget *parent) : QWidget(parent) parent, SIGNAL(SceneGroupRenamed(const QString &, const QString)), this, SIGNAL(SceneGroupRenamed(const QString &, const QString))); + + QWidget::connect(parent, SIGNAL(HighlightMacrosChanged(bool)), this, + SLOT(EnableHighlight(bool))); + + _timer.setInterval(1500); + connect(&_timer, SIGNAL(timeout()), this, SLOT(Highlight())); + _timer.start(); } void MacroSegmentEdit::HeaderInfoChanged(const QString &text) @@ -96,6 +119,22 @@ void MacroSegmentEdit::Collapsed(bool collapsed) } } +void MacroSegmentEdit::Highlight() +{ + if (!Data()) { + return; + } + + if (_showHighlight && Data()->Highlight()) { + PulseWidget(this, Qt::green, QColor(0, 0, 0, 0), true); + } +} + +void MacroSegmentEdit::EnableHighlight(bool value) +{ + _showHighlight = value; +} + void MacroSegmentEdit::mousePressEvent(QMouseEvent *event) { if (event->button() == Qt::LeftButton && Data()) { diff --git a/src/macro-tab.cpp b/src/macro-tab.cpp index 75e7209b..36b5763c 100644 --- a/src/macro-tab.cpp +++ b/src/macro-tab.cpp @@ -308,6 +308,8 @@ void AdvSceneSwitcher::SetEditMacro(Macro &m) clearLayout(conditionsList->ContentLayout()); clearLayout(actionsList->ContentLayout()); + m.ResetUIHelpers(); + PopulateMacroConditions(m); PopulateMacroActions(m); ui->macroEdit->setDisabled(false); diff --git a/src/macro.cpp b/src/macro.cpp index 214271fe..d09a5730 100644 --- a/src/macro.cpp +++ b/src/macro.cpp @@ -65,24 +65,40 @@ bool Macro::CeckMatch() "ignoring condition check 'none' for '%s'", _name.c_str()); continue; - break; case LogicType::AND: _matched = _matched && cond; + if (cond) { + c->SetHighlight(); + } break; case LogicType::OR: _matched = _matched || cond; + if (cond) { + c->SetHighlight(); + } break; case LogicType::AND_NOT: _matched = _matched && !cond; + if (!cond) { + c->SetHighlight(); + } break; case LogicType::OR_NOT: - _matched = _matched || !cond; + if (!cond) { + c->SetHighlight(); + } break; case LogicType::ROOT_NONE: _matched = cond; + if (cond) { + c->SetHighlight(); + } break; case LogicType::ROOT_NOT: _matched = !cond; + if (!cond) { + c->SetHighlight(); + } break; default: blog(LOG_WARNING, @@ -158,6 +174,7 @@ void Macro::RunActions(bool &retVal, bool ignorePause) retVal = ret; break; } + a->SetHighlight(); } _done = true; } @@ -414,6 +431,16 @@ bool Macro::WasExecutedRecently() return false; } +void Macro::ResetUIHelpers() +{ + for (auto c : _conditions) { + c->Highlight(); + } + for (auto a : _actions) { + a->Highlight(); + } +} + static void pauseCB(void *data, obs_hotkey_id, obs_hotkey_t *, bool pressed) { if (pressed) {