mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-04-01 23:05:35 -05:00
Using int is an id was getting messy with more and more conditions and actions beeing added. It also made the order of conditions and actions in the respective comboboxes unchangable as there was a 1 to 1 relation of index and id.
84 lines
2.0 KiB
C++
84 lines
2.0 KiB
C++
#include "headers/macro-condition-edit.hpp"
|
|
#include "headers/macro-condition-idle.hpp"
|
|
#include "headers/utility.hpp"
|
|
#include "headers/advanced-scene-switcher.hpp"
|
|
|
|
const std::string MacroConditionIdle::id = "idle";
|
|
|
|
bool MacroConditionIdle::_registered = MacroConditionFactory::Register(
|
|
MacroConditionIdle::id,
|
|
{MacroConditionIdle::Create, MacroConditionIdleEdit::Create,
|
|
"AdvSceneSwitcher.condition.idle"});
|
|
|
|
bool MacroConditionIdle::CheckCondition()
|
|
{
|
|
return secondsSinceLastInput() >= _duration.seconds;
|
|
}
|
|
|
|
bool MacroConditionIdle::Save(obs_data_t *obj)
|
|
{
|
|
MacroCondition::Save(obj);
|
|
_duration.Save(obj);
|
|
return true;
|
|
}
|
|
|
|
bool MacroConditionIdle::Load(obs_data_t *obj)
|
|
{
|
|
MacroCondition::Load(obj);
|
|
_duration.Load(obj);
|
|
return true;
|
|
}
|
|
|
|
MacroConditionIdleEdit::MacroConditionIdleEdit(
|
|
QWidget *parent, std::shared_ptr<MacroConditionIdle> entryData)
|
|
: QWidget(parent)
|
|
{
|
|
_duration = new DurationSelection();
|
|
|
|
QWidget::connect(_duration, SIGNAL(DurationChanged(double)), this,
|
|
SLOT(DurationChanged(double)));
|
|
QWidget::connect(_duration, SIGNAL(UnitChanged(DurationUnit)), this,
|
|
SLOT(DurationUnitChanged(DurationUnit)));
|
|
|
|
QHBoxLayout *mainLayout = new QHBoxLayout;
|
|
std::unordered_map<std::string, QWidget *> widgetPlaceholders = {
|
|
{"{{duration}}", _duration},
|
|
};
|
|
placeWidgets(obs_module_text("AdvSceneSwitcher.condition.idle.entry"),
|
|
mainLayout, widgetPlaceholders);
|
|
setLayout(mainLayout);
|
|
|
|
_entryData = entryData;
|
|
UpdateEntryData();
|
|
_loading = false;
|
|
}
|
|
|
|
void MacroConditionIdleEdit::DurationChanged(double seconds)
|
|
{
|
|
if (_loading || !_entryData) {
|
|
return;
|
|
}
|
|
|
|
std::lock_guard<std::mutex> lock(switcher->m);
|
|
_entryData->_duration.seconds = seconds;
|
|
}
|
|
|
|
void MacroConditionIdleEdit::DurationUnitChanged(DurationUnit unit)
|
|
{
|
|
if (_loading || !_entryData) {
|
|
return;
|
|
}
|
|
|
|
std::lock_guard<std::mutex> lock(switcher->m);
|
|
_entryData->_duration.displayUnit = unit;
|
|
}
|
|
|
|
void MacroConditionIdleEdit::UpdateEntryData()
|
|
{
|
|
if (!_entryData) {
|
|
return;
|
|
}
|
|
|
|
_duration->SetDuration(_entryData->_duration);
|
|
}
|