mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-04-20 17:17:25 -05:00
Add MacroSegment and MacroSegmentEdit to remove duplicate code
This commit is contained in:
parent
84e4b740a8
commit
76c5ec480b
|
|
@ -204,6 +204,7 @@ set(advanced-scene-switcher_HEADERS
|
|||
src/headers/macro-condition-window.hpp
|
||||
src/headers/macro.hpp
|
||||
src/headers/macro-entry-controls.hpp
|
||||
src/headers/macro-segment.hpp
|
||||
src/headers/macro-selection.hpp
|
||||
src/headers/curl-helper.hpp
|
||||
src/headers/hotkey.hpp
|
||||
|
|
@ -285,6 +286,7 @@ set(advanced-scene-switcher_SOURCES
|
|||
src/macro-condition-window.cpp
|
||||
src/macro.cpp
|
||||
src/macro-entry-controls.cpp
|
||||
src/macro-segment.cpp
|
||||
src/macro-selection.cpp
|
||||
src/macro-tab.cpp
|
||||
src/curl-helper.cpp
|
||||
|
|
|
|||
71
src/headers/macro-segment.hpp
Normal file
71
src/headers/macro-segment.hpp
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
#pragma once
|
||||
#include <QWidget>
|
||||
#include <obs.hpp>
|
||||
|
||||
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 Section;
|
||||
class QLabel;
|
||||
class MacroEntryControls;
|
||||
|
||||
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();
|
||||
|
||||
protected slots:
|
||||
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);
|
||||
|
||||
Section *_section;
|
||||
QLabel *_headerInfo;
|
||||
MacroEntryControls *_controls;
|
||||
|
||||
private:
|
||||
virtual MacroSegment *Data() = 0;
|
||||
};
|
||||
|
||||
class MouseWheelWidgetAdjustmentGuard : public QObject {
|
||||
public:
|
||||
explicit MouseWheelWidgetAdjustmentGuard(QObject *parent);
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject *o, QEvent *e) override;
|
||||
};
|
||||
141
src/macro-segment.cpp
Normal file
141
src/macro-segment.cpp
Normal file
|
|
@ -0,0 +1,141 @@
|
|||
#include "headers/macro-segment.hpp"
|
||||
#include "headers/macro-entry-controls.hpp"
|
||||
#include "headers/section.hpp"
|
||||
|
||||
#include <obs.hpp>
|
||||
#include <QEvent>
|
||||
#include <QLabel>
|
||||
|
||||
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 "";
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
_section = new Section(300);
|
||||
_headerInfo = new QLabel();
|
||||
_controls = new MacroEntryControls();
|
||||
|
||||
QWidget::connect(_section, &Section::Collapsed, this,
|
||||
&MacroSegmentEdit::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, &MacroEntryControls::Add, this,
|
||||
&MacroSegmentEdit::Add);
|
||||
QWidget::connect(_controls, &MacroEntryControls::Remove, this,
|
||||
&MacroSegmentEdit::Remove);
|
||||
QWidget::connect(_controls, &MacroEntryControls::Up, this,
|
||||
&MacroSegmentEdit::Up);
|
||||
QWidget::connect(_controls, &MacroEntryControls::Down, this,
|
||||
&MacroSegmentEdit::Down);
|
||||
}
|
||||
|
||||
void MacroSegmentEdit::HeaderInfoChanged(const QString &text)
|
||||
{
|
||||
_headerInfo->setVisible(!text.isEmpty());
|
||||
_headerInfo->setText(text);
|
||||
}
|
||||
|
||||
void MacroSegmentEdit::Add()
|
||||
{
|
||||
if (Data()) {
|
||||
// Insert after current entry
|
||||
emit AddAt(Data()->GetIndex() + 1);
|
||||
}
|
||||
}
|
||||
|
||||
void MacroSegmentEdit::Remove()
|
||||
{
|
||||
if (Data()) {
|
||||
emit RemoveAt(Data()->GetIndex());
|
||||
}
|
||||
}
|
||||
|
||||
void MacroSegmentEdit::Up()
|
||||
{
|
||||
if (Data()) {
|
||||
emit UpAt(Data()->GetIndex());
|
||||
}
|
||||
}
|
||||
|
||||
void MacroSegmentEdit::Down()
|
||||
{
|
||||
if (Data()) {
|
||||
emit DownAt(Data()->GetIndex());
|
||||
}
|
||||
}
|
||||
|
||||
void MacroSegmentEdit::Collapsed(bool collapsed)
|
||||
{
|
||||
if (Data()) {
|
||||
Data()->SetCollapsed(collapsed);
|
||||
}
|
||||
}
|
||||
|
||||
void MacroSegmentEdit::enterEvent(QEvent *)
|
||||
{
|
||||
_controls->Show(true);
|
||||
}
|
||||
|
||||
void MacroSegmentEdit::leaveEvent(QEvent *)
|
||||
{
|
||||
_controls->Show(false);
|
||||
}
|
||||
|
||||
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