1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
|
#include "macro-action-scene-collection.hpp"
#include "layout-helpers.hpp"
#include "plugin-state-helpers.hpp"
#include "selection-helpers.hpp"
#include <obs-frontend-api.h>
namespace advss {
const std::string MacroActionSceneCollection::id = "scene_collection";
bool MacroActionSceneCollection::_registered = MacroActionFactory::Register(
MacroActionSceneCollection::id,
{MacroActionSceneCollection::Create,
MacroActionSceneCollectionEdit::Create,
"AdvSceneSwitcher.action.sceneCollection"});
bool MacroActionSceneCollection::PerformAction()
{
// Changing the scene collection will also reload the settings of the
// scene switcher, so to avoid issues of not being able to change
// settings ignore this action if the settings dialog is opened.
if (SettingsWindowIsOpened()) {
return false;
}
obs_frontend_set_current_scene_collection(_sceneCollection.c_str());
// It does not make sense to continue as the current settings will be
// invalid after switching scene collection.
return false;
}
void MacroActionSceneCollection::LogAction() const
{
ablog(LOG_INFO, "set scene collection type to \"%s\"",
_sceneCollection.c_str());
}
bool MacroActionSceneCollection::Save(obs_data_t *obj) const
{
MacroAction::Save(obj);
obs_data_set_string(obj, "sceneCollection", _sceneCollection.c_str());
return true;
}
bool MacroActionSceneCollection::Load(obs_data_t *obj)
{
MacroAction::Load(obj);
_sceneCollection = obs_data_get_string(obj, "sceneCollection");
return true;
}
std::string MacroActionSceneCollection::GetShortDesc() const
{
return _sceneCollection;
}
std::shared_ptr<MacroAction> MacroActionSceneCollection::Create(Macro *m)
{
return std::make_shared<MacroActionSceneCollection>(m);
}
std::shared_ptr<MacroAction> MacroActionSceneCollection::Copy() const
{
return std::make_shared<MacroActionSceneCollection>(*this);
}
void populateSceneCollectionSelection(QComboBox *box)
{
auto sceneCollections = obs_frontend_get_scene_collections();
char **temp = sceneCollections;
while (*temp) {
const char *name = *temp;
box->addItem(name);
temp++;
}
bfree(sceneCollections);
box->model()->sort(0);
AddSelectionEntry(
box, obs_module_text("AdvSceneSwitcher.selectSceneCollection"),
false);
box->setCurrentIndex(0);
}
MacroActionSceneCollectionEdit::MacroActionSceneCollectionEdit(
QWidget *parent, std::shared_ptr<MacroActionSceneCollection> entryData)
: QWidget(parent)
{
_sceneCollections = new QComboBox();
populateSceneCollectionSelection(_sceneCollections);
QWidget::connect(_sceneCollections,
SIGNAL(currentTextChanged(const QString &)), this,
SLOT(SceneCollectionChanged(const QString &)));
QHBoxLayout *entryLayout = new QHBoxLayout;
std::unordered_map<std::string, QWidget *> widgetPlaceholders = {
{"{{sceneCollections}}", _sceneCollections},
};
PlaceWidgets(obs_module_text(
"AdvSceneSwitcher.action.sceneCollection.entry"),
entryLayout, widgetPlaceholders);
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addLayout(entryLayout);
mainLayout->addWidget(new QLabel(obs_module_text(
"AdvSceneSwitcher.action.sceneCollection.warning")));
setLayout(mainLayout);
_entryData = entryData;
UpdateEntryData();
_loading = false;
}
void MacroActionSceneCollectionEdit::UpdateEntryData()
{
if (!_entryData) {
return;
}
_sceneCollections->setCurrentText(
QString::fromStdString(_entryData->_sceneCollection));
}
void MacroActionSceneCollectionEdit::SceneCollectionChanged(const QString &text)
{
GUARD_LOADING_AND_LOCK();
_entryData->_sceneCollection = text.toStdString();
emit HeaderInfoChanged(
QString::fromStdString(_entryData->GetShortDesc()));
}
} // namespace advss
|