mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-03-21 17:34:57 -05:00
Fix macro segment highlighting not being in sync
Each macro segment had its own internal timer to handle highlighting. This handing was now moved centrally to the macro tab.
This commit is contained in:
parent
a360d53419
commit
8f55856fd5
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -29,8 +29,7 @@ static inline void populateActionSelection(QComboBox *list)
|
|||
MacroActionEdit::MacroActionEdit(QWidget *parent,
|
||||
std::shared_ptr<MacroAction> *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()));
|
||||
|
||||
|
|
|
|||
|
|
@ -121,8 +121,7 @@ void DurationModifierEdit::Collapse(bool collapse)
|
|||
MacroConditionEdit::MacroConditionEdit(
|
||||
QWidget *parent, std::shared_ptr<MacroCondition> *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);
|
||||
|
|
|
|||
|
|
@ -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<QWidget *> widgets = this->findChildren<QWidget *>();
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -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<int> &pos)
|
||||
static bool shouldRestoreSplitter(const QList<int> &pos)
|
||||
{
|
||||
if (pos.size() == 0) {
|
||||
return false;
|
||||
|
|
@ -798,6 +796,36 @@ bool shouldRestoreSplitter(const QList<int> &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)
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user