From 2dd912026596800431a5082075164c6fa99b363b Mon Sep 17 00:00:00 2001 From: WarmUpTill <19472752+WarmUpTill@users.noreply.github.com> Date: Sun, 1 Feb 2026 00:31:42 +0100 Subject: [PATCH] Add tooltip for last execution time of macro in macro list --- data/locale/en-US.ini | 2 ++ lib/macro/macro-tree.cpp | 34 +++++++++++++++++++++++++++++++--- lib/macro/macro-tree.hpp | 3 +++ lib/macro/macro.cpp | 5 +++++ lib/macro/macro.hpp | 1 + 5 files changed, 42 insertions(+), 3 deletions(-) diff --git a/data/locale/en-US.ini b/data/locale/en-US.ini index c1c4dd9f..4d0913fe 100644 --- a/data/locale/en-US.ini +++ b/data/locale/en-US.ini @@ -160,6 +160,8 @@ AdvSceneSwitcher.macroTab.title="Macro" AdvSceneSwitcher.macroTab.macros="Macros" AdvSceneSwitcher.macroTab.priorityWarning="Note: It is recommended to configure macros to be the highest priority functionality.\nThis setting can be changed on the General tab." AdvSceneSwitcher.macroTab.help="Macros allow you to execute a string of actions depending on multiple conditions.\n\nClick on the highlighted plus symbol to add a new Macro." +AdvSceneSwitcher.macroTab.macroLastExecutedTooltip="Was last executed %1 seconds ago." +AdvSceneSwitcher.macroTab.macroNotYetExecutedTooltip="Was not yet executed." AdvSceneSwitcher.macroTab.editConditionHelp="This section allows you to define macro conditions.\n\nSelect an existing or add a new macro on the left.\nThen click the plus button below to add a new condition." AdvSceneSwitcher.macroTab.editActionHelp="This section allows you to define macro actions.\nThe actions in this section will be performed when the conditions are met.\n\nSelect an existing or add a new macro on the left.\nThen click the plus button below to add a new action." AdvSceneSwitcher.macroTab.editElseActionHelp="This section allows you to define macro actions.\nThe actions in this section will be performed when the conditions are *not* met.\n\nSelect an existing or add a new macro on the left.\nThen click the plus button below to add a new action." diff --git a/lib/macro/macro-tree.cpp b/lib/macro/macro-tree.cpp index ed780822..169f1963 100644 --- a/lib/macro/macro-tree.cpp +++ b/lib/macro/macro-tree.cpp @@ -5,18 +5,17 @@ #include "path-helpers.hpp" #include "sync-helpers.hpp" #include "ui-helpers.hpp" -#include "utility.hpp" #include #include #include #include #include -#include #include #include #include #include +#include Q_DECLARE_METATYPE(std::shared_ptr); @@ -90,6 +89,35 @@ MacroTreeItem::MacroTreeItem(MacroTree *tree, std::shared_ptr macroItem, _timer.start(1500); } +bool MacroTreeItem::event(QEvent *event) +{ + if (event->type() != QEvent::ToolTip) { + return QFrame::event(event); + } + + if (_macro->IsGroup()) { + return true; + } + + QString text; + if (!_macro->WasExecutedSince({})) { + text = obs_module_text( + "AdvSceneSwitcher.macroTab.macroNotYetExecutedTooltip"); + } else { + const QString formatStr = obs_module_text( + "AdvSceneSwitcher.macroTab.macroLastExecutedTooltip"); + const auto secondsSinceLastRun = + std::chrono::duration_cast( + std::chrono::high_resolution_clock::now() - + _macro->GetLastExecutionTime()); + text = formatStr.arg(secondsSinceLastRun.count()); + } + + auto helpEvent = static_cast(event); + QToolTip::showText(helpEvent->globalPos(), text, this); + return true; +} + void MacroTreeItem::EnableHighlight(bool enable) { _highlight = enable; @@ -276,7 +304,7 @@ void MacroTreeItem::Update(bool force) _expand->blockSignals(true); _expand->setChecked(_macro->IsCollapsed()); _expand->blockSignals(false); - connect(_expand, &QPushButton::toggled, this, + connect(_expand, &QCheckBox::toggled, this, &MacroTreeItem::ExpandClicked); } else { _spacer = new QSpacerItem(3, 1); diff --git a/lib/macro/macro-tree.hpp b/lib/macro/macro-tree.hpp index 52ed28da..ca764528 100644 --- a/lib/macro/macro-tree.hpp +++ b/lib/macro/macro-tree.hpp @@ -34,6 +34,9 @@ public: explicit MacroTreeItem(MacroTree *tree, std::shared_ptr macro, bool highlight); +protected: + bool event(QEvent *) override; + private slots: void ExpandClicked(bool checked); void EnableHighlight(bool enable); diff --git a/lib/macro/macro.cpp b/lib/macro/macro.cpp index f772c1aa..439989e0 100644 --- a/lib/macro/macro.cpp +++ b/lib/macro/macro.cpp @@ -311,6 +311,11 @@ bool Macro::OnChangePreventedActionsSince(const TimePoint &time) const return _lastOnChangeActionsPreventedTime > time; } +Macro::TimePoint Macro::GetLastExecutionTime() const +{ + return _lastExecutionTime; +} + bool Macro::ConditionsShouldBeChecked() const { if (!_useCustomConditionCheckInterval) { diff --git a/lib/macro/macro.hpp b/lib/macro/macro.hpp index 352d86c3..318a41bc 100644 --- a/lib/macro/macro.hpp +++ b/lib/macro/macro.hpp @@ -138,6 +138,7 @@ public: bool HasValidSplitterPositions() const; bool WasExecutedSince(const TimePoint &) const; bool OnChangePreventedActionsSince(const TimePoint &) const; + TimePoint GetLastExecutionTime() const; void ResetUIHelpers(); // Hotkeys