mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-03-22 01:44:49 -05:00
Clean up adding new macros to Random action
This commit is contained in:
parent
4d32e921f9
commit
ad08df3d2f
|
|
@ -354,9 +354,7 @@ AdvSceneSwitcher.action.timer.type.reset="Reset"
|
|||
AdvSceneSwitcher.action.timer.type.setTimeRemaining="Set time remaining of"
|
||||
AdvSceneSwitcher.action.timer.entry="{{timerAction}} timers on {{macros}} {{duration}}"
|
||||
AdvSceneSwitcher.action.random="Random"
|
||||
AdvSceneSwitcher.action.random.arguments="Macros:"
|
||||
AdvSceneSwitcher.action.random.addArgument="Add Macro"
|
||||
AdvSceneSwitcher.action.random.entry="Run {{macroSelection}}"
|
||||
AdvSceneSwitcher.action.random.entry="Randomly run any of the following macros (paused macros are ignored)"
|
||||
|
||||
; Transition Tab
|
||||
AdvSceneSwitcher.transitionTab.title="Transition"
|
||||
|
|
@ -604,6 +602,7 @@ AdvSceneSwitcher.hotkey.macro.pause="Pause macro %1"
|
|||
AdvSceneSwitcher.hotkey.macro.unpause="Unpause macro %1"
|
||||
|
||||
AdvSceneSwitcher.askBackup="Detected a new version of the Advanced Scene Switcher.\nShould a backup of the old settings be created?"
|
||||
AdvSceneSwitcher.askForMacro="Select macro {{macroSelection}}"
|
||||
|
||||
AdvSceneSwitcher.close="Close"
|
||||
AdvSceneSwitcher.browse="Browse"
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
#include <QPushButton>
|
||||
#include <QListWidget>
|
||||
#include <QDialog>
|
||||
#include <unordered_map>
|
||||
|
||||
class MacroActionRandom : public MultiMacroRefAction {
|
||||
|
|
@ -27,6 +28,17 @@ private:
|
|||
static const std::string id;
|
||||
};
|
||||
|
||||
class MacroDialog : public QDialog {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
MacroDialog(QWidget *parent);
|
||||
static bool AskForMacro(QWidget *parent, std::string ¯oName);
|
||||
|
||||
private:
|
||||
MacroSelection *_macroSelection;
|
||||
};
|
||||
|
||||
class MacroActionRandomEdit : public QWidget {
|
||||
Q_OBJECT
|
||||
|
||||
|
|
@ -48,16 +60,14 @@ private slots:
|
|||
void MacroRename(const QString &oldName, const QString &newName);
|
||||
void AddMacro();
|
||||
void RemoveMacro();
|
||||
int FindEntry(const std::string ¯o);
|
||||
void MacroSelectionChanged(int idx);
|
||||
|
||||
protected:
|
||||
std::shared_ptr<MacroActionRandom> _entryData;
|
||||
|
||||
private:
|
||||
int FindEntry(const std::string ¯o);
|
||||
void SetMacroListSize();
|
||||
|
||||
MacroSelection *_macroSelection;
|
||||
QListWidget *_macroList;
|
||||
QPushButton *_add;
|
||||
QPushButton *_remove;
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
#include "headers/name-dialog.hpp"
|
||||
#include "headers/utility.hpp"
|
||||
|
||||
#include <QDialogButtonBox>
|
||||
#include <cstdlib>
|
||||
|
||||
const std::string MacroActionRandom::id = "random";
|
||||
|
|
@ -93,7 +94,6 @@ MacroActionRandomEdit::MacroActionRandomEdit(
|
|||
QWidget *parent, std::shared_ptr<MacroActionRandom> entryData)
|
||||
: QWidget(parent)
|
||||
{
|
||||
_macroSelection = new MacroSelection(window());
|
||||
_macroList = new QListWidget();
|
||||
_macroList->setSortingEnabled(true);
|
||||
_add = new QPushButton();
|
||||
|
|
@ -117,9 +117,7 @@ MacroActionRandomEdit::MacroActionRandomEdit(
|
|||
SLOT(MacroRename(const QString &, const QString &)));
|
||||
|
||||
auto *entryLayout = new QHBoxLayout;
|
||||
std::unordered_map<std::string, QWidget *> widgetPlaceholders = {
|
||||
{"{{macroSelection}}", _macroSelection},
|
||||
};
|
||||
std::unordered_map<std::string, QWidget *> widgetPlaceholders = {};
|
||||
placeWidgets(obs_module_text("AdvSceneSwitcher.action.random.entry"),
|
||||
entryLayout, widgetPlaceholders);
|
||||
|
||||
|
|
@ -130,8 +128,6 @@ MacroActionRandomEdit::MacroActionRandomEdit(
|
|||
|
||||
auto *mainLayout = new QVBoxLayout;
|
||||
mainLayout->addLayout(entryLayout);
|
||||
mainLayout->addWidget(new QLabel(
|
||||
obs_module_text("AdvSceneSwitcher.action.random.arguments")));
|
||||
mainLayout->addWidget(_macroList);
|
||||
mainLayout->addLayout(argButtonLayout);
|
||||
setLayout(mainLayout);
|
||||
|
|
@ -193,8 +189,14 @@ void MacroActionRandomEdit::AddMacro()
|
|||
return;
|
||||
}
|
||||
|
||||
auto macroName = _macroSelection->currentText();
|
||||
MacroRef macro(macroName.toStdString());
|
||||
std::string macroName;
|
||||
bool accepted = MacroDialog::AskForMacro(this, macroName);
|
||||
|
||||
if (!accepted || macroName.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
MacroRef macro(macroName);
|
||||
|
||||
if (!macro.get()) {
|
||||
return;
|
||||
|
|
@ -204,9 +206,10 @@ void MacroActionRandomEdit::AddMacro()
|
|||
return;
|
||||
}
|
||||
|
||||
QVariant v = QVariant::fromValue(macroName);
|
||||
QListWidgetItem *item = new QListWidgetItem(macroName, _macroList);
|
||||
item->setData(Qt::UserRole, macroName);
|
||||
QVariant v = QVariant::fromValue(QString::fromStdString(macroName));
|
||||
QListWidgetItem *item = new QListWidgetItem(
|
||||
QString::fromStdString(macroName), _macroList);
|
||||
item->setData(Qt::UserRole, QString::fromStdString(macroName));
|
||||
|
||||
std::lock_guard<std::mutex> lock(switcher->m);
|
||||
_entryData->_macros.push_back(macro);
|
||||
|
|
@ -254,19 +257,52 @@ int MacroActionRandomEdit::FindEntry(const std::string ¯o)
|
|||
return idx;
|
||||
}
|
||||
|
||||
void MacroActionRandomEdit::MacroSelectionChanged(int idx)
|
||||
{
|
||||
if (_loading || !_entryData || idx == -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
QListWidgetItem *item = _macroList->item(idx);
|
||||
QString name = item->text();
|
||||
_macroSelection->SetCurrentMacro(GetMacroByName(name.toUtf8().data()));
|
||||
}
|
||||
|
||||
void MacroActionRandomEdit::SetMacroListSize()
|
||||
{
|
||||
setHeightToContentHeight(_macroList);
|
||||
adjustSize();
|
||||
}
|
||||
|
||||
MacroDialog::MacroDialog(QWidget *)
|
||||
{
|
||||
setModal(true);
|
||||
setWindowModality(Qt::WindowModality::ApplicationModal);
|
||||
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
||||
setMinimumWidth(350);
|
||||
setMinimumHeight(70);
|
||||
|
||||
QDialogButtonBox *buttonbox = new QDialogButtonBox(
|
||||
QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
||||
|
||||
buttonbox->setCenterButtons(true);
|
||||
connect(buttonbox, &QDialogButtonBox::accepted, this, &QDialog::accept);
|
||||
connect(buttonbox, &QDialogButtonBox::rejected, this, &QDialog::reject);
|
||||
|
||||
_macroSelection = new MacroSelection(window());
|
||||
auto *selectionLayout = new QHBoxLayout;
|
||||
std::unordered_map<std::string, QWidget *> widgetPlaceholders = {
|
||||
{"{{macroSelection}}", _macroSelection},
|
||||
};
|
||||
placeWidgets(obs_module_text("AdvSceneSwitcher.askForMacro"),
|
||||
selectionLayout, widgetPlaceholders);
|
||||
auto *layout = new QVBoxLayout();
|
||||
layout->addLayout(selectionLayout);
|
||||
layout->addWidget(buttonbox);
|
||||
setLayout(layout);
|
||||
}
|
||||
|
||||
bool MacroDialog::AskForMacro(QWidget *parent, std::string ¯oName)
|
||||
{
|
||||
MacroDialog dialog(parent);
|
||||
dialog.setWindowTitle(obs_module_text("AdvSceneSwitcher.windowTitle"));
|
||||
|
||||
if (dialog.exec() != DialogCode::Accepted) {
|
||||
return false;
|
||||
}
|
||||
macroName = dialog._macroSelection->currentText().toUtf8().constData();
|
||||
if (macroName == obs_module_text("AdvSceneSwitcher.selectMacro")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user