mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-08-22 01:05:53 -05:00
Highlight recently executed action and true conditions
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
#include <QWidget>
|
||||
#include <QFrame>
|
||||
#include <QVBoxLayout>
|
||||
#include <QTimer>
|
||||
#include <obs.hpp>
|
||||
|
||||
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 {
|
||||
|
||||
@@ -110,6 +110,7 @@ public:
|
||||
|
||||
// UI helpers for the macro tab
|
||||
bool WasExecutedRecently();
|
||||
void ResetUIHelpers();
|
||||
|
||||
private:
|
||||
void SetupHotkeys();
|
||||
|
||||
@@ -63,7 +63,8 @@ static inline void populateActionSelection(QComboBox *list)
|
||||
MacroActionEdit::MacroActionEdit(QWidget *parent,
|
||||
std::shared_ptr<MacroAction> *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);
|
||||
|
||||
@@ -92,7 +92,9 @@ static inline void populateConditionSelection(QComboBox *list)
|
||||
MacroConditionEdit::MacroConditionEdit(
|
||||
QWidget *parent, std::shared_ptr<MacroCondition> *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);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "headers/macro-segment.hpp"
|
||||
#include "headers/section.hpp"
|
||||
#include "headers/utility.hpp"
|
||||
|
||||
#include <obs.hpp>
|
||||
#include <QEvent>
|
||||
@@ -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()) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user