mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-03-21 17:34:57 -05:00
Add MacroSelection widget
This commit is contained in:
parent
4a84bede37
commit
6893d9539e
|
|
@ -108,6 +108,7 @@ set(advanced-scene-switcher_HEADERS
|
|||
src/headers/macro-condition-video.hpp
|
||||
src/headers/macro-condition-window.hpp
|
||||
src/headers/macro.hpp
|
||||
src/headers/macro-selection.hpp
|
||||
src/headers/curl-helper.hpp
|
||||
src/headers/screenshot-helper.hpp
|
||||
src/headers/name-dialog.hpp
|
||||
|
|
@ -173,6 +174,7 @@ set(advanced-scene-switcher_SOURCES
|
|||
src/macro-condition-video.cpp
|
||||
src/macro-condition-window.cpp
|
||||
src/macro.cpp
|
||||
src/macro-selection.cpp
|
||||
src/macro-tab.cpp
|
||||
src/curl-helper.cpp
|
||||
src/screenshot-helper.cpp
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
#include <QDoubleSpinBox>
|
||||
#include "macro-action-edit.hpp"
|
||||
#include "macro-selection.hpp"
|
||||
|
||||
enum class PauseAction {
|
||||
PAUSE,
|
||||
|
|
@ -45,13 +46,11 @@ public:
|
|||
|
||||
private slots:
|
||||
void MacroChanged(const QString &text);
|
||||
void ActionChanged(int value);
|
||||
void MacroAdd(const QString &name);
|
||||
void MacroRemove(const QString &name);
|
||||
void MacroRename(const QString &oldName, const QString &newName);
|
||||
void ActionChanged(int value);
|
||||
|
||||
protected:
|
||||
QComboBox *_macros;
|
||||
MacroSelection *_macros;
|
||||
QComboBox *_actions;
|
||||
std::shared_ptr<MacroActionPause> _entryData;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
#pragma once
|
||||
#include "macro.hpp"
|
||||
#include "macro-selection.hpp"
|
||||
#include <QWidget>
|
||||
#include <QSpinBox>
|
||||
#include <QLabel>
|
||||
|
|
@ -49,16 +50,14 @@ public:
|
|||
|
||||
private slots:
|
||||
void MacroChanged(const QString &text);
|
||||
void MacroRemove(const QString &name);
|
||||
void CountChanged(int value);
|
||||
void ConditionChanged(int cond);
|
||||
void MacroAdd(const QString &name);
|
||||
void MacroRemove(const QString &name);
|
||||
void MacroRename(const QString &oldName, const QString &newName);
|
||||
void ResetClicked();
|
||||
void UpdateCount();
|
||||
|
||||
protected:
|
||||
QComboBox *_macros;
|
||||
MacroSelection *_macros;
|
||||
QComboBox *_conditions;
|
||||
QSpinBox *_count;
|
||||
QLabel *_currentCount;
|
||||
|
|
|
|||
17
src/headers/macro-selection.hpp
Normal file
17
src/headers/macro-selection.hpp
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
#pragma once
|
||||
#include <QComboBox>
|
||||
|
||||
class Macro;
|
||||
|
||||
class MacroSelection : public QComboBox {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
MacroSelection(QWidget *parent);
|
||||
void SetCurrentMacro(Macro *);
|
||||
|
||||
private slots:
|
||||
void MacroAdd(const QString &name);
|
||||
void MacroRemove(const QString &name);
|
||||
void MacroRename(const QString &oldName, const QString &newName);
|
||||
};
|
||||
|
|
@ -75,36 +75,21 @@ static inline void populateActionSelection(QComboBox *list)
|
|||
}
|
||||
}
|
||||
|
||||
static inline void populateMacroSelection(QComboBox *list)
|
||||
{
|
||||
list->addItem(obs_module_text("AdvSceneSwitcher.selectMacro"));
|
||||
for (auto &m : switcher->macros) {
|
||||
list->addItem(QString::fromStdString(m.Name()));
|
||||
}
|
||||
}
|
||||
|
||||
MacroActionPauseEdit::MacroActionPauseEdit(
|
||||
QWidget *parent, std::shared_ptr<MacroActionPause> entryData)
|
||||
: QWidget(parent)
|
||||
{
|
||||
_macros = new QComboBox();
|
||||
_macros = new MacroSelection(parent);
|
||||
_actions = new QComboBox();
|
||||
|
||||
populateActionSelection(_actions);
|
||||
populateMacroSelection(_macros);
|
||||
|
||||
QWidget::connect(_macros, SIGNAL(currentTextChanged(const QString &)),
|
||||
this, SLOT(MacroChanged(const QString &)));
|
||||
QWidget::connect(_actions, SIGNAL(currentIndexChanged(int)), this,
|
||||
SLOT(ActionChanged(int)));
|
||||
QWidget::connect(parent, SIGNAL(MacroAdded(const QString &)), this,
|
||||
SLOT(MacroAdd(const QString &)));
|
||||
QWidget::connect(parent, SIGNAL(MacroRemoved(const QString &)), this,
|
||||
SLOT(MacroRemove(const QString &)));
|
||||
QWidget::connect(parent,
|
||||
SIGNAL(MacroRenamed(const QString &, const QString &)),
|
||||
this,
|
||||
SLOT(MacroRename(const QString &, const QString &)));
|
||||
QWidget::connect(_actions, SIGNAL(currentIndexChanged(int)), this,
|
||||
SLOT(ActionChanged(int)));
|
||||
|
||||
QHBoxLayout *mainLayout = new QHBoxLayout;
|
||||
std::unordered_map<std::string, QWidget *> widgetPlaceholders = {
|
||||
|
|
@ -126,12 +111,7 @@ void MacroActionPauseEdit::UpdateEntryData()
|
|||
return;
|
||||
}
|
||||
_actions->setCurrentIndex(static_cast<int>(_entryData->_action));
|
||||
if (_entryData->_macro) {
|
||||
_macros->setCurrentText(
|
||||
QString::fromStdString(_entryData->_macro->Name()));
|
||||
} else {
|
||||
_macros->setCurrentIndex(0);
|
||||
}
|
||||
_macros->SetCurrentMacro(_entryData->_macro);
|
||||
}
|
||||
|
||||
void MacroActionPauseEdit::MacroChanged(const QString &text)
|
||||
|
|
@ -154,11 +134,6 @@ void MacroActionPauseEdit::ActionChanged(int value)
|
|||
_entryData->_action = static_cast<PauseAction>(value);
|
||||
}
|
||||
|
||||
void MacroActionPauseEdit::MacroAdd(const QString &name)
|
||||
{
|
||||
_macros->addItem(name);
|
||||
}
|
||||
|
||||
void MacroActionPauseEdit::MacroRemove(const QString &name)
|
||||
{
|
||||
int idx = _macros->findText(name);
|
||||
|
|
@ -172,18 +147,3 @@ void MacroActionPauseEdit::MacroRemove(const QString &name)
|
|||
}
|
||||
_macros->setCurrentIndex(0);
|
||||
}
|
||||
|
||||
void MacroActionPauseEdit::MacroRename(const QString &oldName,
|
||||
const QString &newName)
|
||||
{
|
||||
bool renameSelected = _macros->currentText() == oldName;
|
||||
int idx = _macros->findText(oldName);
|
||||
if (idx == -1) {
|
||||
return;
|
||||
}
|
||||
_macros->removeItem(idx);
|
||||
_macros->insertItem(idx, newName);
|
||||
if (renameSelected) {
|
||||
_macros->setCurrentIndex(_macros->findText(newName));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,19 +63,11 @@ static inline void populateConditionSelection(QComboBox *list)
|
|||
}
|
||||
}
|
||||
|
||||
static inline void populateMacroSelection(QComboBox *list)
|
||||
{
|
||||
list->addItem(obs_module_text("AdvSceneSwitcher.selectMacro"));
|
||||
for (auto &m : switcher->macros) {
|
||||
list->addItem(QString::fromStdString(m.Name()));
|
||||
}
|
||||
}
|
||||
|
||||
MacroConditionCounterEdit::MacroConditionCounterEdit(
|
||||
QWidget *parent, std::shared_ptr<MacroConditionCounter> entryData)
|
||||
: QWidget(parent)
|
||||
{
|
||||
_macros = new QComboBox();
|
||||
_macros = new MacroSelection(parent);
|
||||
_conditions = new QComboBox();
|
||||
_count = new QSpinBox();
|
||||
_currentCount = new QLabel();
|
||||
|
|
@ -83,12 +75,12 @@ MacroConditionCounterEdit::MacroConditionCounterEdit(
|
|||
obs_module_text("AdvSceneSwitcher.condition.counter.reset"));
|
||||
|
||||
_count->setMaximum(10000000);
|
||||
|
||||
populateConditionSelection(_conditions);
|
||||
populateMacroSelection(_macros);
|
||||
|
||||
QWidget::connect(_macros, SIGNAL(currentTextChanged(const QString &)),
|
||||
this, SLOT(MacroChanged(const QString &)));
|
||||
QWidget::connect(parent, SIGNAL(MacroRemoved(const QString &)), this,
|
||||
SLOT(MacroRemove(const QString &)));
|
||||
QWidget::connect(_conditions, SIGNAL(currentIndexChanged(int)), this,
|
||||
SLOT(ConditionChanged(int)));
|
||||
QWidget::connect(_count, SIGNAL(valueChanged(int)), this,
|
||||
|
|
@ -96,15 +88,6 @@ MacroConditionCounterEdit::MacroConditionCounterEdit(
|
|||
QWidget::connect(_resetCount, SIGNAL(clicked()), this,
|
||||
SLOT(ResetClicked()));
|
||||
|
||||
QWidget::connect(parent, SIGNAL(MacroAdded(const QString &)), this,
|
||||
SLOT(MacroAdd(const QString &)));
|
||||
QWidget::connect(parent, SIGNAL(MacroRemoved(const QString &)), this,
|
||||
SLOT(MacroRemove(const QString &)));
|
||||
QWidget::connect(parent,
|
||||
SIGNAL(MacroRenamed(const QString &, const QString &)),
|
||||
this,
|
||||
SLOT(MacroRename(const QString &, const QString &)));
|
||||
|
||||
QVBoxLayout *mainLayout = new QVBoxLayout;
|
||||
QHBoxLayout *line1Layout = new QHBoxLayout;
|
||||
QHBoxLayout *line2Layout = new QHBoxLayout;
|
||||
|
|
@ -136,12 +119,7 @@ void MacroConditionCounterEdit::UpdateEntryData()
|
|||
return;
|
||||
}
|
||||
|
||||
if (_entryData->_macro) {
|
||||
_macros->setCurrentText(
|
||||
QString::fromStdString(_entryData->_macro->Name()));
|
||||
} else {
|
||||
_macros->setCurrentIndex(0);
|
||||
}
|
||||
_macros->SetCurrentMacro(_entryData->_macro);
|
||||
_conditions->setCurrentIndex(static_cast<int>(_entryData->_condition));
|
||||
_count->setValue(_entryData->_count);
|
||||
ResetTimer();
|
||||
|
|
@ -178,11 +156,6 @@ void MacroConditionCounterEdit::ConditionChanged(int cond)
|
|||
_entryData->_condition = static_cast<CounterCondition>(cond);
|
||||
}
|
||||
|
||||
void MacroConditionCounterEdit::MacroAdd(const QString &name)
|
||||
{
|
||||
_macros->addItem(name);
|
||||
}
|
||||
|
||||
void MacroConditionCounterEdit::MacroRemove(const QString &name)
|
||||
{
|
||||
int idx = _macros->findText(name);
|
||||
|
|
@ -197,21 +170,6 @@ void MacroConditionCounterEdit::MacroRemove(const QString &name)
|
|||
_macros->setCurrentIndex(0);
|
||||
}
|
||||
|
||||
void MacroConditionCounterEdit::MacroRename(const QString &oldName,
|
||||
const QString &newName)
|
||||
{
|
||||
bool renameSelected = _macros->currentText() == oldName;
|
||||
int idx = _macros->findText(oldName);
|
||||
if (idx == -1) {
|
||||
return;
|
||||
}
|
||||
_macros->removeItem(idx);
|
||||
_macros->insertItem(idx, newName);
|
||||
if (renameSelected) {
|
||||
_macros->setCurrentIndex(_macros->findText(newName));
|
||||
}
|
||||
}
|
||||
|
||||
void MacroConditionCounterEdit::ResetClicked()
|
||||
{
|
||||
if (_loading || !_entryData || !_entryData->_macro) {
|
||||
|
|
|
|||
57
src/macro-selection.cpp
Normal file
57
src/macro-selection.cpp
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
#include "headers/macro-selection.hpp"
|
||||
#include "headers/advanced-scene-switcher.hpp"
|
||||
|
||||
MacroSelection::MacroSelection(QWidget *parent) : QComboBox(parent)
|
||||
{
|
||||
addItem(obs_module_text("AdvSceneSwitcher.selectMacro"));
|
||||
for (auto &m : switcher->macros) {
|
||||
addItem(QString::fromStdString(m.Name()));
|
||||
}
|
||||
|
||||
QWidget::connect(parent, SIGNAL(MacroAdded(const QString &)), this,
|
||||
SLOT(MacroAdd(const QString &)));
|
||||
QWidget::connect(parent, SIGNAL(MacroRemoved(const QString &)), this,
|
||||
SLOT(MacroRemove(const QString &)));
|
||||
QWidget::connect(parent,
|
||||
SIGNAL(MacroRenamed(const QString &, const QString &)),
|
||||
this,
|
||||
SLOT(MacroRename(const QString &, const QString &)));
|
||||
}
|
||||
|
||||
void MacroSelection::MacroAdd(const QString &name)
|
||||
{
|
||||
addItem(name);
|
||||
}
|
||||
|
||||
void MacroSelection::SetCurrentMacro(Macro *m)
|
||||
{
|
||||
if (!m) {
|
||||
this->setCurrentIndex(0);
|
||||
} else {
|
||||
this->setCurrentText(QString::fromStdString(m->Name()));
|
||||
}
|
||||
}
|
||||
|
||||
void MacroSelection::MacroRemove(const QString &name)
|
||||
{
|
||||
int idx = findText(name);
|
||||
if (idx == -1) {
|
||||
return;
|
||||
}
|
||||
removeItem(idx);
|
||||
setCurrentIndex(0);
|
||||
}
|
||||
|
||||
void MacroSelection::MacroRename(const QString &oldName, const QString &newName)
|
||||
{
|
||||
bool renameSelected = currentText() == oldName;
|
||||
int idx = findText(oldName);
|
||||
if (idx == -1) {
|
||||
return;
|
||||
}
|
||||
removeItem(idx);
|
||||
insertItem(idx, newName);
|
||||
if (renameSelected) {
|
||||
setCurrentIndex(findText(newName));
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user