mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-08-06 04:44:32 -05:00
Clean up duplicate code
This commit is contained in:
parent
e2b3563810
commit
810235e0b7
|
|
@ -1,14 +1,5 @@
|
|||
#pragma once
|
||||
#include "macro.hpp"
|
||||
#include "section.hpp"
|
||||
#include "macro-entry-controls.hpp"
|
||||
|
||||
#include <QWidget>
|
||||
#include <QComboBox>
|
||||
#include <QVBoxLayout>
|
||||
#include <QGroupBox>
|
||||
#include <QLabel>
|
||||
#include <deque>
|
||||
|
||||
struct MacroActionInfo {
|
||||
using TCreateMethod = std::shared_ptr<MacroAction> (*)();
|
||||
|
|
@ -45,35 +36,12 @@ public:
|
|||
|
||||
private slots:
|
||||
void ActionSelectionChanged(const QString &text);
|
||||
void HeaderInfoChanged(const QString &);
|
||||
void Add();
|
||||
void Remove();
|
||||
void Up();
|
||||
void Down();
|
||||
void Collapsed(bool);
|
||||
signals:
|
||||
void MacroAdded(const QString &name);
|
||||
void MacroRemoved(const QString &name);
|
||||
void MacroRenamed(const QString &oldName, const QString newName);
|
||||
void SceneGroupAdded(const QString &name);
|
||||
void SceneGroupRemoved(const QString &name);
|
||||
void SceneGroupRenamed(const QString &oldName, const QString newName);
|
||||
void AddAt(int idx);
|
||||
void RemoveAt(int idx);
|
||||
void UpAt(int idx);
|
||||
void DownAt(int idx);
|
||||
|
||||
protected:
|
||||
void enterEvent(QEvent *e);
|
||||
void leaveEvent(QEvent *e);
|
||||
|
||||
QComboBox *_actionSelection;
|
||||
Section *_section;
|
||||
QLabel *_headerInfo;
|
||||
MacroEntryControls *_controls;
|
||||
|
||||
std::shared_ptr<MacroAction> *_entryData;
|
||||
|
||||
private:
|
||||
MacroSegment *Data();
|
||||
|
||||
QComboBox *_actionSelection;
|
||||
|
||||
std::shared_ptr<MacroAction> *_entryData;
|
||||
bool _loading = true;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,13 +1,5 @@
|
|||
#pragma once
|
||||
|
||||
#include "advanced-scene-switcher.hpp"
|
||||
#include "macro.hpp"
|
||||
#include "macro-condition-scene.hpp"
|
||||
#include "section.hpp"
|
||||
#include "macro-entry-controls.hpp"
|
||||
#include "utility.hpp"
|
||||
|
||||
#include <QGroupBox>
|
||||
|
||||
struct MacroConditionInfo {
|
||||
using TCreateMethod = std::shared_ptr<MacroCondition> (*)();
|
||||
|
|
@ -52,38 +44,15 @@ private slots:
|
|||
void DurationChanged(double seconds);
|
||||
void DurationConditionChanged(DurationCondition cond);
|
||||
void DurationUnitChanged(DurationUnit unit);
|
||||
void HeaderInfoChanged(const QString &);
|
||||
void Add();
|
||||
void Remove();
|
||||
void Up();
|
||||
void Down();
|
||||
void Collapsed(bool);
|
||||
signals:
|
||||
void MacroAdded(const QString &name);
|
||||
void MacroRemoved(const QString &name);
|
||||
void MacroRenamed(const QString &oldName, const QString newName);
|
||||
void SceneGroupAdded(const QString &name);
|
||||
void SceneGroupRemoved(const QString &name);
|
||||
void SceneGroupRenamed(const QString &oldName, const QString newName);
|
||||
void AddAt(int idx);
|
||||
void RemoveAt(int idx);
|
||||
void UpAt(int idx);
|
||||
void DownAt(int idx);
|
||||
|
||||
protected:
|
||||
void enterEvent(QEvent *e);
|
||||
void leaveEvent(QEvent *e);
|
||||
private:
|
||||
MacroSegment *Data();
|
||||
|
||||
QComboBox *_logicSelection;
|
||||
QComboBox *_conditionSelection;
|
||||
Section *_section;
|
||||
QLabel *_headerInfo;
|
||||
DurationConstraintEdit *_dur;
|
||||
MacroEntryControls *_controls;
|
||||
|
||||
std::shared_ptr<MacroCondition> *_entryData;
|
||||
|
||||
private:
|
||||
bool _isRoot = true;
|
||||
bool _loading = true;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
#pragma once
|
||||
#include "macro-segment.hpp"
|
||||
#include "duration-control.hpp"
|
||||
|
||||
#include <string>
|
||||
|
|
@ -36,22 +37,6 @@ struct LogicTypeInfo {
|
|||
std::string _name;
|
||||
};
|
||||
|
||||
class MacroSegment {
|
||||
public:
|
||||
void SetIndex(int idx) { _idx = idx; }
|
||||
int GetIndex() { return _idx; }
|
||||
void SetCollapsed(bool collapsed) { _collapsed = collapsed; }
|
||||
bool GetCollapsed() { return _collapsed; }
|
||||
virtual bool Save(obs_data_t *obj) = 0;
|
||||
virtual bool Load(obs_data_t *obj) = 0;
|
||||
virtual std::string GetShortDesc();
|
||||
virtual std::string GetId() = 0;
|
||||
|
||||
protected:
|
||||
int _idx;
|
||||
bool _collapsed = false;
|
||||
};
|
||||
|
||||
class MacroCondition : public MacroSegment {
|
||||
public:
|
||||
virtual bool CheckCondition() = 0;
|
||||
|
|
@ -159,23 +144,3 @@ public:
|
|||
void ResolveMacroRef();
|
||||
MacroRef _macro;
|
||||
};
|
||||
|
||||
// TODO: Rework macro condition and action edit to allow moving control
|
||||
// handling to MacroSegmentEdit
|
||||
class MacroSegmentEdit : public QWidget {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
MacroSegmentEdit(QWidget *parent = nullptr);
|
||||
// Use this function to avoid accidental edits when scrolling through
|
||||
// list of actions and conditions
|
||||
void SetFocusPolicyOfWidgets();
|
||||
};
|
||||
|
||||
class MouseWheelWidgetAdjustmentGuard : public QObject {
|
||||
public:
|
||||
explicit MouseWheelWidgetAdjustmentGuard(QObject *parent);
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject *o, QEvent *e) override;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
#include "headers/advanced-scene-switcher.hpp"
|
||||
#include "headers/macro-action-edit.hpp"
|
||||
#include "headers/macro-action-scene-switch.hpp"
|
||||
#include "headers/section.hpp"
|
||||
#include "headers/macro-controls.hpp"
|
||||
#include "headers/utility.hpp"
|
||||
#include "headers/advanced-scene-switcher.hpp"
|
||||
|
||||
std::map<std::string, MacroActionInfo> MacroActionFactory::_methods;
|
||||
|
||||
|
|
@ -63,40 +65,10 @@ MacroActionEdit::MacroActionEdit(QWidget *parent,
|
|||
: MacroSegmentEdit(parent), _entryData(entryData)
|
||||
{
|
||||
_actionSelection = new QComboBox();
|
||||
_section = new Section(300);
|
||||
_headerInfo = new QLabel();
|
||||
_controls = new MacroEntryControls();
|
||||
|
||||
QWidget::connect(_actionSelection,
|
||||
SIGNAL(currentTextChanged(const QString &)), this,
|
||||
SLOT(ActionSelectionChanged(const QString &)));
|
||||
QWidget::connect(_section, &Section::Collapsed, this,
|
||||
&MacroActionEdit::Collapsed);
|
||||
// Macro signals
|
||||
QWidget::connect(parent, SIGNAL(MacroAdded(const QString &)), this,
|
||||
SIGNAL(MacroAdded(const QString &)));
|
||||
QWidget::connect(parent, SIGNAL(MacroRemoved(const QString &)), this,
|
||||
SIGNAL(MacroRemoved(const QString &)));
|
||||
QWidget::connect(parent,
|
||||
SIGNAL(MacroRenamed(const QString &, const QString)),
|
||||
this,
|
||||
SIGNAL(MacroRenamed(const QString &, const QString)));
|
||||
|
||||
// Scene group signals
|
||||
QWidget::connect(parent, SIGNAL(SceneGroupAdded(const QString &)), this,
|
||||
SIGNAL(SceneGroupAdded(const QString &)));
|
||||
QWidget::connect(parent, SIGNAL(SceneGroupRemoved(const QString &)),
|
||||
this, SIGNAL(SceneGroupRemoved(const QString &)));
|
||||
QWidget::connect(
|
||||
parent,
|
||||
SIGNAL(SceneGroupRenamed(const QString &, const QString)), this,
|
||||
SIGNAL(SceneGroupRenamed(const QString &, const QString)));
|
||||
|
||||
// Control signals
|
||||
QWidget::connect(_controls, SIGNAL(Add()), this, SLOT(Add()));
|
||||
QWidget::connect(_controls, SIGNAL(Remove()), this, SLOT(Remove()));
|
||||
QWidget::connect(_controls, SIGNAL(Up()), this, SLOT(Up()));
|
||||
QWidget::connect(_controls, SIGNAL(Down()), this, SLOT(Down()));
|
||||
|
||||
populateActionSelection(_actionSelection);
|
||||
|
||||
|
|
@ -114,16 +86,6 @@ MacroActionEdit::MacroActionEdit(QWidget *parent,
|
|||
_loading = false;
|
||||
}
|
||||
|
||||
void MacroActionEdit::enterEvent(QEvent *)
|
||||
{
|
||||
_controls->Show(true);
|
||||
}
|
||||
|
||||
void MacroActionEdit::leaveEvent(QEvent *)
|
||||
{
|
||||
_controls->Show(false);
|
||||
}
|
||||
|
||||
void MacroActionEdit::ActionSelectionChanged(const QString &text)
|
||||
{
|
||||
if (_loading || !_entryData) {
|
||||
|
|
@ -156,46 +118,9 @@ void MacroActionEdit::UpdateEntryData(const std::string &id)
|
|||
SetFocusPolicyOfWidgets();
|
||||
}
|
||||
|
||||
void MacroActionEdit::HeaderInfoChanged(const QString &text)
|
||||
MacroSegment *MacroActionEdit::Data()
|
||||
{
|
||||
_headerInfo->setVisible(!text.isEmpty());
|
||||
_headerInfo->setText(text);
|
||||
}
|
||||
|
||||
void MacroActionEdit::Add()
|
||||
{
|
||||
if (_entryData) {
|
||||
// Insert after current entry
|
||||
emit AddAt((*_entryData)->GetIndex() + 1);
|
||||
}
|
||||
}
|
||||
|
||||
void MacroActionEdit::Remove()
|
||||
{
|
||||
if (_entryData) {
|
||||
emit RemoveAt((*_entryData)->GetIndex());
|
||||
}
|
||||
}
|
||||
|
||||
void MacroActionEdit::Up()
|
||||
{
|
||||
if (_entryData) {
|
||||
emit UpAt((*_entryData)->GetIndex());
|
||||
}
|
||||
}
|
||||
|
||||
void MacroActionEdit::Down()
|
||||
{
|
||||
if (_entryData) {
|
||||
emit DownAt((*_entryData)->GetIndex());
|
||||
}
|
||||
}
|
||||
|
||||
void MacroActionEdit::Collapsed(bool collapsed)
|
||||
{
|
||||
if (_entryData) {
|
||||
(*_entryData)->SetCollapsed(collapsed);
|
||||
}
|
||||
return _entryData->get();
|
||||
}
|
||||
|
||||
void AdvSceneSwitcher::AddMacroAction(int idx)
|
||||
|
|
@ -205,7 +130,7 @@ void AdvSceneSwitcher::AddMacroAction(int idx)
|
|||
return;
|
||||
}
|
||||
|
||||
if (idx < 0 || idx > macro->Actions().size()) {
|
||||
if (idx < 0 || idx > (int)macro->Actions().size()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -243,7 +168,7 @@ void AdvSceneSwitcher::RemoveMacroAction(int idx)
|
|||
return;
|
||||
}
|
||||
|
||||
if (idx < 0 || idx >= macro->Actions().size()) {
|
||||
if (idx < 0 || idx >= (int)macro->Actions().size()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -303,7 +228,7 @@ void AdvSceneSwitcher::MoveMacroActionUp(int idx)
|
|||
return;
|
||||
}
|
||||
|
||||
if (idx < 1 || idx >= macro->Actions().size()) {
|
||||
if (idx < 1 || idx >= (int)macro->Actions().size()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -317,7 +242,7 @@ void AdvSceneSwitcher::MoveMacroActionDown(int idx)
|
|||
return;
|
||||
}
|
||||
|
||||
if (idx < 0 || idx >= macro->Actions().size() - 1) {
|
||||
if (idx < 0 || idx >= (int)macro->Actions().size() - 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,9 @@
|
|||
#include "headers/advanced-scene-switcher.hpp"
|
||||
#include "headers/macro-condition-edit.hpp"
|
||||
#include "headers/macro-condition-scene.hpp"
|
||||
#include "headers/section.hpp"
|
||||
#include "headers/macro-controls.hpp"
|
||||
#include "headers/utility.hpp"
|
||||
|
||||
std::map<std::string, MacroConditionInfo> MacroConditionFactory::_methods;
|
||||
|
||||
|
|
@ -88,19 +92,14 @@ static inline void populateConditionSelection(QComboBox *list)
|
|||
MacroConditionEdit::MacroConditionEdit(
|
||||
QWidget *parent, std::shared_ptr<MacroCondition> *entryData,
|
||||
const std::string &id, bool root)
|
||||
: MacroSegmentEdit(parent), _isRoot(root), _entryData(entryData)
|
||||
: MacroSegmentEdit(parent), _entryData(entryData), _isRoot(root)
|
||||
{
|
||||
_logicSelection = new QComboBox();
|
||||
_conditionSelection = new QComboBox();
|
||||
_section = new Section(300);
|
||||
_headerInfo = new QLabel();
|
||||
_dur = new DurationConstraintEdit();
|
||||
_controls = new MacroEntryControls();
|
||||
|
||||
QWidget::connect(_logicSelection, SIGNAL(currentIndexChanged(int)),
|
||||
this, SLOT(LogicSelectionChanged(int)));
|
||||
QWidget::connect(_section, &Section::Collapsed, this,
|
||||
&MacroConditionEdit::Collapsed);
|
||||
QWidget::connect(_conditionSelection,
|
||||
SIGNAL(currentTextChanged(const QString &)), this,
|
||||
SLOT(ConditionSelectionChanged(const QString &)));
|
||||
|
|
@ -112,32 +111,6 @@ MacroConditionEdit::MacroConditionEdit(
|
|||
this,
|
||||
SLOT(DurationConditionChanged(DurationCondition)));
|
||||
|
||||
// Macro signals
|
||||
QWidget::connect(parent, SIGNAL(MacroAdded(const QString &)), this,
|
||||
SIGNAL(MacroAdded(const QString &)));
|
||||
QWidget::connect(parent, SIGNAL(MacroRemoved(const QString &)), this,
|
||||
SIGNAL(MacroRemoved(const QString &)));
|
||||
QWidget::connect(parent,
|
||||
SIGNAL(MacroRenamed(const QString &, const QString)),
|
||||
this,
|
||||
SIGNAL(MacroRenamed(const QString &, const QString)));
|
||||
|
||||
// Scene group signals
|
||||
QWidget::connect(parent, SIGNAL(SceneGroupAdded(const QString &)), this,
|
||||
SIGNAL(SceneGroupAdded(const QString &)));
|
||||
QWidget::connect(parent, SIGNAL(SceneGroupRemoved(const QString &)),
|
||||
this, SIGNAL(SceneGroupRemoved(const QString &)));
|
||||
QWidget::connect(
|
||||
parent,
|
||||
SIGNAL(SceneGroupRenamed(const QString &, const QString)), this,
|
||||
SIGNAL(SceneGroupRenamed(const QString &, const QString)));
|
||||
|
||||
// Control signals
|
||||
QWidget::connect(_controls, SIGNAL(Add()), this, SLOT(Add()));
|
||||
QWidget::connect(_controls, SIGNAL(Remove()), this, SLOT(Remove()));
|
||||
QWidget::connect(_controls, SIGNAL(Up()), this, SLOT(Up()));
|
||||
QWidget::connect(_controls, SIGNAL(Down()), this, SLOT(Down()));
|
||||
|
||||
populateLogicSelection(_logicSelection, root);
|
||||
populateConditionSelection(_conditionSelection);
|
||||
|
||||
|
|
@ -155,15 +128,6 @@ MacroConditionEdit::MacroConditionEdit(
|
|||
_loading = false;
|
||||
}
|
||||
|
||||
void MacroConditionEdit::enterEvent(QEvent *)
|
||||
{
|
||||
_controls->Show(true);
|
||||
}
|
||||
|
||||
void MacroConditionEdit::leaveEvent(QEvent *)
|
||||
{
|
||||
_controls->Show(false);
|
||||
}
|
||||
void MacroConditionEdit::LogicSelectionChanged(int idx)
|
||||
{
|
||||
if (_loading || !_entryData) {
|
||||
|
|
@ -274,46 +238,9 @@ void MacroConditionEdit::DurationUnitChanged(DurationUnit unit)
|
|||
(*_entryData)->SetDurationUnit(unit);
|
||||
}
|
||||
|
||||
void MacroConditionEdit::HeaderInfoChanged(const QString &text)
|
||||
MacroSegment *MacroConditionEdit::Data()
|
||||
{
|
||||
_headerInfo->setVisible(!text.isEmpty());
|
||||
_headerInfo->setText(text);
|
||||
}
|
||||
|
||||
void MacroConditionEdit::Add()
|
||||
{
|
||||
if (_entryData) {
|
||||
// Insert after current entry
|
||||
emit AddAt((*_entryData)->GetIndex() + 1);
|
||||
}
|
||||
}
|
||||
|
||||
void MacroConditionEdit::Remove()
|
||||
{
|
||||
if (_entryData) {
|
||||
emit RemoveAt((*_entryData)->GetIndex());
|
||||
}
|
||||
}
|
||||
|
||||
void MacroConditionEdit::Up()
|
||||
{
|
||||
if (_entryData) {
|
||||
emit UpAt((*_entryData)->GetIndex());
|
||||
}
|
||||
}
|
||||
|
||||
void MacroConditionEdit::Down()
|
||||
{
|
||||
if (_entryData) {
|
||||
emit DownAt((*_entryData)->GetIndex());
|
||||
}
|
||||
}
|
||||
|
||||
void MacroConditionEdit::Collapsed(bool collapsed)
|
||||
{
|
||||
if (_entryData) {
|
||||
(*_entryData)->SetCollapsed(collapsed);
|
||||
}
|
||||
return _entryData->get();
|
||||
}
|
||||
|
||||
void AdvSceneSwitcher::AddMacroCondition(int idx)
|
||||
|
|
@ -323,7 +250,7 @@ void AdvSceneSwitcher::AddMacroCondition(int idx)
|
|||
return;
|
||||
}
|
||||
|
||||
if (idx < 0 || idx > macro->Conditions().size()) {
|
||||
if (idx < 0 || idx > (int)macro->Conditions().size()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -365,7 +292,7 @@ void AdvSceneSwitcher::RemoveMacroCondition(int idx)
|
|||
return;
|
||||
}
|
||||
|
||||
if (idx < 0 || idx >= macro->Conditions().size()) {
|
||||
if (idx < 0 || idx >= (int)macro->Conditions().size()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -444,7 +371,7 @@ void AdvSceneSwitcher::MoveMacroConditionUp(int idx)
|
|||
return;
|
||||
}
|
||||
|
||||
if (idx < 1 || idx >= macro->Conditions().size()) {
|
||||
if (idx < 1 || idx >= (int)macro->Conditions().size()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -458,7 +385,7 @@ void AdvSceneSwitcher::MoveMacroConditionDown(int idx)
|
|||
return;
|
||||
}
|
||||
|
||||
if (idx < 0 || idx >= macro->Conditions().size() - 1) {
|
||||
if (idx < 0 || idx >= (int)macro->Conditions().size() - 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
#include "headers/macro.hpp"
|
||||
|
||||
#include "headers/macro-action-edit.hpp"
|
||||
#include "headers/macro-condition-edit.hpp"
|
||||
#include "headers/macro-action-scene-switch.hpp"
|
||||
#include "headers/advanced-scene-switcher.hpp"
|
||||
|
||||
#include <limits>
|
||||
#undef max
|
||||
|
|
@ -383,23 +383,6 @@ void Macro::SetHotkeysDesc()
|
|||
hotkeyDesc.toStdString().c_str());
|
||||
}
|
||||
|
||||
bool MacroSegment::Save(obs_data_t *obj)
|
||||
{
|
||||
obs_data_set_bool(obj, "collapsed", static_cast<int>(_collapsed));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MacroSegment::Load(obs_data_t *obj)
|
||||
{
|
||||
_collapsed = obs_data_get_bool(obj, "collapsed");
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string MacroSegment::GetShortDesc()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
bool MacroCondition::Save(obs_data_t *obj)
|
||||
{
|
||||
MacroSegment::Save(obj);
|
||||
|
|
@ -649,30 +632,3 @@ void MacroRefAction::ResolveMacroRef()
|
|||
{
|
||||
_macro.UpdateRef();
|
||||
}
|
||||
|
||||
MouseWheelWidgetAdjustmentGuard::MouseWheelWidgetAdjustmentGuard(QObject *parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
}
|
||||
|
||||
bool MouseWheelWidgetAdjustmentGuard::eventFilter(QObject *o, QEvent *e)
|
||||
{
|
||||
const QWidget *widget = static_cast<QWidget *>(o);
|
||||
if (e->type() == QEvent::Wheel && widget && !widget->hasFocus()) {
|
||||
e->ignore();
|
||||
return true;
|
||||
}
|
||||
|
||||
return QObject::eventFilter(o, e);
|
||||
}
|
||||
|
||||
MacroSegmentEdit::MacroSegmentEdit(QWidget *parent) : QWidget(parent) {}
|
||||
|
||||
void MacroSegmentEdit::SetFocusPolicyOfWidgets()
|
||||
{
|
||||
QList<QWidget *> widgets = this->findChildren<QWidget *>();
|
||||
for (auto w : widgets) {
|
||||
w->setFocusPolicy(Qt::StrongFocus);
|
||||
w->installEventFilter(new MouseWheelWidgetAdjustmentGuard(w));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user