diff --git a/lib/advanced-scene-switcher.hpp b/lib/advanced-scene-switcher.hpp index e618957d..3650d0c1 100644 --- a/lib/advanced-scene-switcher.hpp +++ b/lib/advanced-scene-switcher.hpp @@ -189,9 +189,6 @@ signals: void MacroSegmentOrderChanged(); void SegmentTempVarsChanged(); void HighlightMacrosChanged(bool value); - void HighlightActionsChanged(bool value); - void HighlightElseActionsChanged(bool value); - void HighlightConditionsChanged(bool value); void ConnectionAdded(const QString &); void ConnectionRenamed(const QString &oldName, const QString &newName); diff --git a/lib/macro/macro-action-edit.cpp b/lib/macro/macro-action-edit.cpp index 007bd737..4fa0d422 100644 --- a/lib/macro/macro-action-edit.cpp +++ b/lib/macro/macro-action-edit.cpp @@ -29,8 +29,7 @@ static inline void populateActionSelection(QComboBox *list) MacroActionEdit::MacroActionEdit(QWidget *parent, std::shared_ptr *entryData, const std::string &id) - : MacroSegmentEdit(GetGlobalMacroProperties()._highlightActions, - parent), + : MacroSegmentEdit(parent), _actionSelection(new FilterComboBox()), _enable(new SwitchButton()), _entryData(entryData) @@ -40,8 +39,6 @@ MacroActionEdit::MacroActionEdit(QWidget *parent, SLOT(ActionSelectionChanged(const QString &))); QWidget::connect(_enable, SIGNAL(checked(bool)), this, SLOT(ActionEnableChanged(bool))); - QWidget::connect(window(), SIGNAL(HighlightActionsChanged(bool)), this, - SLOT(EnableHighlight(bool))); QWidget::connect(&_actionStateTimer, SIGNAL(timeout()), this, SLOT(UpdateActionState())); diff --git a/lib/macro/macro-condition-edit.cpp b/lib/macro/macro-condition-edit.cpp index 307c6a30..f5825a6e 100644 --- a/lib/macro/macro-condition-edit.cpp +++ b/lib/macro/macro-condition-edit.cpp @@ -121,8 +121,7 @@ void DurationModifierEdit::Collapse(bool collapse) MacroConditionEdit::MacroConditionEdit( QWidget *parent, std::shared_ptr *entryData, const std::string &id, bool root) - : MacroSegmentEdit(GetGlobalMacroProperties()._highlightConditions, - parent), + : MacroSegmentEdit(parent), _logicSelection(new QComboBox()), _conditionSelection(new FilterComboBox()), _dur(new DurationModifierEdit()), @@ -139,8 +138,6 @@ MacroConditionEdit::MacroConditionEdit( QWidget::connect(_dur, SIGNAL(ModifierChanged(DurationModifier::Type)), this, SLOT(DurationModifierChanged(DurationModifier::Type))); - QWidget::connect(window(), SIGNAL(HighlightConditionsChanged(bool)), - this, SLOT(EnableHighlight(bool))); populateLogicSelection(_logicSelection, root); populateConditionSelection(_conditionSelection); diff --git a/lib/macro/macro-segment.cpp b/lib/macro/macro-segment.cpp index 2f4e41b9..ce719ef6 100644 --- a/lib/macro/macro-segment.cpp +++ b/lib/macro/macro-segment.cpp @@ -59,12 +59,12 @@ std::string MacroSegment::GetShortDesc() const return ""; } -void MacroSegment::SetHighlight() +void MacroSegment::EnableHighlight() { _highlight = true; } -bool MacroSegment::Highlight() +bool MacroSegment::GetHighlightAndReset() { if (_highlight) { _highlight = false; @@ -194,7 +194,7 @@ void DecrementVariableRef(MacroSegment *segment) segment->_variableRefs--; } -MacroSegmentEdit::MacroSegmentEdit(bool highlight, QWidget *parent) +MacroSegmentEdit::MacroSegmentEdit(QWidget *parent) : QWidget(parent), _section(new Section(300)), _headerInfo(new QLabel()), @@ -203,8 +203,7 @@ MacroSegmentEdit::MacroSegmentEdit(bool highlight, QWidget *parent) _noBorderframe(new QFrame), _borderFrame(new QFrame), _dropLineAbove(new QFrame), - _dropLineBelow(new QFrame), - _showHighlight(highlight) + _dropLineBelow(new QFrame) { _dropLineAbove->setLineWidth(3); _dropLineAbove->setFixedHeight(11); @@ -282,10 +281,6 @@ MacroSegmentEdit::MacroSegmentEdit(bool highlight, QWidget *parent) // Enable dragging while clicking on the header text _headerInfo->installEventFilter(this); - - _timer.setInterval(1500); - connect(&_timer, SIGNAL(timeout()), this, SLOT(Highlight())); - _timer.start(); } bool MacroSegmentEdit::eventFilter(QObject *obj, QEvent *ev) @@ -330,22 +325,6 @@ 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::SetFocusPolicyOfWidgets() { QList widgets = this->findChildren(); diff --git a/lib/macro/macro-segment.hpp b/lib/macro/macro-segment.hpp index c16e7133..f0d1f751 100644 --- a/lib/macro/macro-segment.hpp +++ b/lib/macro/macro-segment.hpp @@ -37,8 +37,8 @@ public: virtual bool PostLoad(); virtual std::string GetShortDesc() const; virtual std::string GetId() const = 0; - void SetHighlight(); - bool Highlight(); + void EnableHighlight(); + bool GetHighlightAndReset(); virtual std::string GetVariableValue() const; protected: @@ -87,7 +87,7 @@ class MacroSegmentEdit : public QWidget { Q_OBJECT public: - MacroSegmentEdit(bool highlight, QWidget *parent = nullptr); + MacroSegmentEdit(QWidget *parent = nullptr); // Use this function to avoid accidental edits when scrolling through // list of actions and conditions void SetFocusPolicyOfWidgets(); @@ -100,8 +100,6 @@ public slots: protected slots: void Collapsed(bool); - void Highlight(); - void EnableHighlight(bool); signals: void MacroAdded(const QString &name); void MacroRemoved(const QString &name); @@ -143,9 +141,6 @@ private: QFrame *_dropLineAbove; QFrame *_dropLineBelow; - bool _showHighlight; - QTimer _timer; - friend class MacroSegmentList; }; diff --git a/lib/macro/macro-tab.cpp b/lib/macro/macro-tab.cpp index 4cc0a310..0cb1fb9a 100644 --- a/lib/macro/macro-tab.cpp +++ b/lib/macro/macro-tab.cpp @@ -768,8 +768,6 @@ void AdvSceneSwitcher::on_macroProperties_clicked() } GetGlobalMacroProperties() = prop; emit HighlightMacrosChanged(prop._highlightExecuted); - emit HighlightActionsChanged(prop._highlightActions); - emit HighlightConditionsChanged(prop._highlightConditions); } static void moveControlsToSplitter(QSplitter *splitter, int idx, @@ -784,7 +782,7 @@ static void moveControlsToSplitter(QSplitter *splitter, int idx, splitter->setStyleSheet("QSplitter::handle {background: transparent;}"); } -bool shouldRestoreSplitter(const QList &pos) +static bool shouldRestoreSplitter(const QList &pos) { if (pos.size() == 0) { return false; @@ -798,6 +796,36 @@ bool shouldRestoreSplitter(const QList &pos) return true; } +static void runSegmentHighligtChecksHelper(MacroSegmentList *list) +{ + MacroSegmentEdit *widget = nullptr; + for (int i = 0; (widget = list->WidgetAt(i)); i++) { + if (widget->Data() && widget->Data()->GetHighlightAndReset()) { + list->Highlight(i); + } + } +} + +static void runSegmentHighligtChecks(AdvSceneSwitcher *ss) +{ + if (!ss || !HighlightUIElementsEnabled()) { + return; + } + auto macro = ss->GetSelectedMacro(); + if (!macro) { + return; + } + + const auto &properties = GetGlobalMacroProperties(); + if (properties._highlightConditions) { + runSegmentHighligtChecksHelper(ss->ui->conditionsList); + } + if (properties._highlightActions) { + runSegmentHighligtChecksHelper(ss->ui->actionsList); + runSegmentHighligtChecksHelper(ss->ui->elseActionsList); + } +} + void AdvSceneSwitcher::SetupMacroTab() { ui->macroElseActions->installEventFilter(this); @@ -894,6 +922,12 @@ void AdvSceneSwitcher::SetupMacroTab() } SetupSegmentCopyPasteShortcutHandlers(this); + + // Macro segment highlight + auto timer = new QTimer(this); + connect(timer, &QTimer::timeout, + [this]() { runSegmentHighligtChecks(this); }); + timer->start(1500); } void AdvSceneSwitcher::ShowMacroContextMenu(const QPoint &pos) diff --git a/lib/macro/macro.cpp b/lib/macro/macro.cpp index b8874441..49e30592 100644 --- a/lib/macro/macro.cpp +++ b/lib/macro/macro.cpp @@ -137,37 +137,37 @@ bool Macro::CeckMatch() case LogicType::AND: _matched = _matched && cond; if (cond) { - c->SetHighlight(); + c->EnableHighlight(); } break; case LogicType::OR: _matched = _matched || cond; if (cond) { - c->SetHighlight(); + c->EnableHighlight(); } break; case LogicType::AND_NOT: _matched = _matched && !cond; if (!cond) { - c->SetHighlight(); + c->EnableHighlight(); } break; case LogicType::OR_NOT: _matched = _matched || !cond; if (!cond) { - c->SetHighlight(); + c->EnableHighlight(); } break; case LogicType::ROOT_NONE: _matched = cond; if (cond) { - c->SetHighlight(); + c->EnableHighlight(); } break; case LogicType::ROOT_NOT: _matched = !cond; if (!cond) { - c->SetHighlight(); + c->EnableHighlight(); } break; default: @@ -313,7 +313,7 @@ bool Macro::RunActionsHelper( break; } if (action->Enabled()) { - action->SetHighlight(); + action->EnableHighlight(); } } _done = true; @@ -819,10 +819,10 @@ void Macro::ResetUIHelpers() { _onPreventedActionExecution = false; for (auto c : _conditions) { - c->Highlight(); + c->GetHighlightAndReset(); } for (auto a : _actions) { - a->Highlight(); + a->GetHighlightAndReset(); } }