Add export / import functionality to macro tab

This enables the easy sharing of single / multiple macros across scene
collections.
Previously either all settings had to be copied via the export / import
functionality of the General tab or none at all.
This commit is contained in:
WarmUpTill
2023-07-30 00:53:17 +02:00
committed by WarmUpTill
parent dcae0e8e8b
commit 4b0a631987
9 changed files with 307 additions and 29 deletions

View File

@@ -0,0 +1,61 @@
#include "macro-export-import-dialog.hpp"
#include "obs-module-helper.hpp"
#include <QLayout>
#include <QLabel>
#include <QDialogButtonBox>
namespace advss {
MacroExportImportDialog::MacroExportImportDialog(Type type)
: QDialog(nullptr), _importExportString(new QPlainTextEdit(this))
{
_importExportString->setReadOnly(type == Type::EXPORT_MACRO);
auto label = new QLabel(obs_module_text(
type == Type::EXPORT_MACRO
? "AdvSceneSwitcher.macroTab.export.info"
: "AdvSceneSwitcher.macroTab.import.info"));
label->setWordWrap(true);
QDialogButtonBox *buttons = nullptr;
if (type == Type::EXPORT_MACRO) {
buttons = new QDialogButtonBox(QDialogButtonBox::Ok);
} else {
buttons = new QDialogButtonBox(QDialogButtonBox::Ok |
QDialogButtonBox::Cancel);
}
connect(buttons, &QDialogButtonBox::accepted, this, &QDialog::accept);
connect(buttons, &QDialogButtonBox::rejected, this, &QDialog::reject);
buttons->setCenterButtons(true);
auto layout = new QVBoxLayout;
layout->addWidget(label);
layout->addWidget(_importExportString);
layout->addWidget(buttons);
setLayout(layout);
setWindowTitle(obs_module_text("AdvSceneSwitcher.windowTitle"));
}
void MacroExportImportDialog::ExportMacros(const QString &json)
{
MacroExportImportDialog dialog(
MacroExportImportDialog::Type::EXPORT_MACRO);
dialog._importExportString->setPlainText(json);
dialog.adjustSize();
dialog.updateGeometry();
dialog.exec();
}
bool MacroExportImportDialog::ImportMacros(QString &json)
{
MacroExportImportDialog dialog(
MacroExportImportDialog::Type::IMPORT_MACRO);
if (dialog.exec() == QDialog::Accepted) {
json = dialog._importExportString->toPlainText();
return true;
}
return false;
}
} // namespace advss

View File

@@ -0,0 +1,20 @@
#pragma once
#include <QDialog>
#include <QPlainTextEdit>
namespace advss {
class MacroExportImportDialog : public QDialog {
Q_OBJECT
public:
enum class Type { EXPORT_MACRO, IMPORT_MACRO };
MacroExportImportDialog(Type type);
static void ExportMacros(const QString &json);
static bool ImportMacros(QString &json);
private:
QPlainTextEdit *_importExportString;
};
} // namespace advss