diff --git a/CMakeLists.txt b/CMakeLists.txt
index 03ab9557..b6fa9695 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -46,7 +46,7 @@ if(BUILD_OUT_OF_TREE)
src/headers/switch-time.hpp
src/headers/switch-transitions.hpp
src/headers/switch-window.hpp
- src/headers/swtich-sequence.hpp
+ src/headers/switch-sequence.hpp
src/headers/switch-generic.hpp
)
@@ -196,7 +196,7 @@ else ()
src/headers/switch-time.hpp
src/headers/switch-transitions.hpp
src/headers/switch-window.hpp
- src/headers/swtich-sequence.hpp
+ src/headers/switch-sequence.hpp
src/headers/switch-generic.hpp
)
diff --git a/forms/advanced-scene-switcher.ui b/forms/advanced-scene-switcher.ui
index 3f78c5a7..9fa2f9f0 100644
--- a/forms/advanced-scene-switcher.ui
+++ b/forms/advanced-scene-switcher.ui
@@ -2814,99 +2814,6 @@
Sequence
- -
-
-
-
-
-
- When
-
-
-
- -
-
-
-
- 0
- 0
-
-
-
-
- 100
- 0
-
-
-
-
- -
-
-
- is active switch to
-
-
-
- -
-
-
-
- 0
- 0
-
-
-
-
- 100
- 0
-
-
-
-
- -
-
-
- after
-
-
-
- -
-
-
-
-
-
- 999999999.000000000000000
-
-
-
- -
-
-
- -
-
-
- using
-
-
-
- -
-
-
- -
-
-
- Qt::Horizontal
-
-
-
- 40
- 20
-
-
-
-
-
-
-
@@ -3059,19 +2966,6 @@
- -
-
-
-
- 75
- true
-
-
-
- SWITCHER CONDITION CHECK INTERVAL LONGER THAN SHORTEST SCENE ROUND TRIP WAIT (This might lead to undesired switching behaviour)
-
-
-
-
diff --git a/src/headers/advanced-scene-switcher.hpp b/src/headers/advanced-scene-switcher.hpp
index 6c27109d..23a6e6d5 100644
--- a/src/headers/advanced-scene-switcher.hpp
+++ b/src/headers/advanced-scene-switcher.hpp
@@ -36,7 +36,6 @@ public:
int PauseScenesFindByData(const QString &scene);
int PauseWindowsFindByData(const QString &window);
int IgnoreWindowsFindByData(const QString &window);
- int SceneSequenceFindByData(const QString &scene1);
int SceneTransitionsFindByData(const QString &scene1,
const QString &scene2);
int DefaultTransitionsFindByData(const QString &scene);
@@ -117,14 +116,12 @@ public slots:
void on_ignoreWindowsAdd_clicked();
void on_ignoreWindowsRemove_clicked();
- void on_sceneSequences_currentRowChanged(int idx);
void on_sceneSequenceAdd_clicked();
void on_sceneSequenceRemove_clicked();
void on_sceneSequenceSave_clicked();
void on_sceneSequenceLoad_clicked();
void on_sceneSequenceUp_clicked();
void on_sceneSequenceDown_clicked();
- void on_sceneSequenceDelayUnits_currentIndexChanged(int index);
void on_autoStopSceneCheckBox_stateChanged(int state);
void on_autoStopScenes_currentTextChanged(const QString &text);
diff --git a/src/headers/switch-sequence.hpp b/src/headers/switch-sequence.hpp
new file mode 100644
index 00000000..af336d2a
--- /dev/null
+++ b/src/headers/switch-sequence.hpp
@@ -0,0 +1,65 @@
+#pragma once
+#include "utility.hpp"
+#include "switch-generic.hpp"
+
+constexpr auto round_trip_func = 1;
+constexpr auto default_priority_1 = round_trip_func;
+
+typedef enum {
+ SECONDS,
+ MINUTES,
+ HOURS,
+} delay_units;
+
+struct SceneSequenceSwitch : SceneSwitcherEntry {
+ OBSWeakSource startScene = nullptr;
+ double delay = 0;
+ int delayMultiplier = 1;
+
+ const char *getType() { return "sequence"; }
+ bool initialized();
+ bool valid();
+ void logSleep(int dur);
+
+ inline SceneSequenceSwitch(){};
+ inline SceneSequenceSwitch(OBSWeakSource startScene_,
+ OBSWeakSource scene_,
+ OBSWeakSource transition_, double delay_,
+ int delayMultiplier_, bool usePreviousScene_)
+ : SceneSwitcherEntry(scene_, transition_, usePreviousScene_),
+ startScene(startScene_),
+ delay(delay_),
+ delayMultiplier(delayMultiplier_)
+ {
+ }
+};
+
+class SequenceWidget : public SwitchWidget {
+ Q_OBJECT
+
+public:
+ SequenceWidget(SceneSequenceSwitch *s);
+ SceneSequenceSwitch *getSwitchData();
+ void setSwitchData(SceneSequenceSwitch *s);
+
+ static void swapSwitchData(SequenceWidget *s1, SequenceWidget *s2);
+
+ void UpdateDelay();
+
+private slots:
+ void DelayChanged(double delay);
+ void DelayUnitsChanged(int idx);
+ void StartSceneChanged(const QString &text);
+
+private:
+ QDoubleSpinBox *delay;
+ QComboBox *delayUnits;
+ QComboBox *startScenes;
+
+ QLabel *whenLabel;
+ QLabel *switchLabel;
+ QLabel *afterLabel;
+ QLabel *usingLabel;
+
+ SceneSequenceSwitch *switchData;
+};
diff --git a/src/headers/switcher-data-structs.hpp b/src/headers/switcher-data-structs.hpp
index 1b2dd712..2485a711 100644
--- a/src/headers/switcher-data-structs.hpp
+++ b/src/headers/switcher-data-structs.hpp
@@ -18,7 +18,7 @@
#include "switch-time.hpp"
#include "switch-transitions.hpp"
#include "switch-window.hpp"
-#include "swtich-sequence.hpp"
+#include "switch-sequence.hpp"
constexpr auto default_interval = 300;
constexpr auto previous_scene_name = "Previous Scene";
@@ -72,8 +72,7 @@ struct SwitcherData {
std::vector ignoreWindowsSwitches;
- std::vector sceneSequenceSwitches;
- int sceneSequenceMultiplier = 1;
+ std::deque sceneSequenceSwitches;
std::deque randomSwitches;
diff --git a/src/headers/swtich-sequence.hpp b/src/headers/swtich-sequence.hpp
deleted file mode 100644
index 646ed8bb..00000000
--- a/src/headers/swtich-sequence.hpp
+++ /dev/null
@@ -1,44 +0,0 @@
-#pragma once
-#include
-#include "utility.hpp"
-#include "switch-generic.hpp"
-
-constexpr auto round_trip_func = 1;
-constexpr auto default_priority_1 = round_trip_func;
-
-struct SceneSequenceSwitch : SceneSwitcherEntry {
- OBSWeakSource startScene;
- double delay;
- std::string sceneSequenceStr;
-
- const char *getType() { return "sequence"; }
-
- bool valid()
- {
- return WeakSourceValid(startScene) &&
- (usePreviousScene || WeakSourceValid(scene)) &&
- WeakSourceValid(transition);
- }
-
- void logSleep(int dur)
- {
- blog(LOG_INFO, "Advanced Scene Switcher sequence sleep %d",
- dur);
- }
-
- inline SceneSequenceSwitch(OBSWeakSource startScene_,
- OBSWeakSource scene_,
- OBSWeakSource transition_, double delay_,
- bool usePreviousScene_, std::string str)
- : SceneSwitcherEntry(scene_, transition_, usePreviousScene_),
- startScene(startScene_),
- delay(delay_),
- sceneSequenceStr(str)
- {
- }
-};
-
-static inline QString MakeSceneSequenceSwitchName(const QString &scene1,
- const QString &scene2,
- const QString &transition,
- double delay);
diff --git a/src/switch-sequence.cpp b/src/switch-sequence.cpp
index b6e46734..0ab18e40 100644
--- a/src/switch-sequence.cpp
+++ b/src/switch-sequence.cpp
@@ -4,102 +4,22 @@
#include "headers/advanced-scene-switcher.hpp"
-constexpr auto seconds_index = 0;
-constexpr auto minutes_index = 1;
-constexpr auto hours_index = 2;
-
-void SceneSwitcher::on_sceneSequenceDelayUnits_currentIndexChanged(int index)
-{
- if (loading)
- return;
-
- std::lock_guard lock(switcher->m);
-
- double val = ui->sceneSequenceSpinBox->value();
-
- switch (switcher->sceneSequenceMultiplier) {
- case 1:
- val /= pow(60, index);
- break;
- case 60:
- val /= pow(60, index - 1);
- break;
- case 3600:
- val /= pow(60, index - 2);
- break;
- }
-
- ui->sceneSequenceSpinBox->setValue(val);
-
- switch (index) {
- case seconds_index:
- switcher->sceneSequenceMultiplier = 1;
- break;
- case minutes_index:
- switcher->sceneSequenceMultiplier = 60;
- break;
- case hours_index:
- switcher->sceneSequenceMultiplier = 3600;
- break;
- }
-}
+static QMetaObject::Connection addPulse;
void SceneSwitcher::on_sceneSequenceAdd_clicked()
{
- QString scene1Name = ui->sceneSequenceScenes1->currentText();
- QString scene2Name = ui->sceneSequenceScenes2->currentText();
- QString transitionName = ui->sceneSequenceTransitions->currentText();
+ ui->sceneSequences->disconnect(addPulse);
- if (scene1Name.isEmpty() || scene2Name.isEmpty())
- return;
+ std::lock_guard lock(switcher->m);
+ switcher->sceneSequenceSwitches.emplace_back();
- double delay = ui->sceneSequenceSpinBox->value() *
- switcher->sceneSequenceMultiplier;
-
- if (scene1Name == scene2Name)
- return;
-
- OBSWeakSource source1 = GetWeakSourceByQString(scene1Name);
- OBSWeakSource source2 = GetWeakSourceByQString(scene2Name);
- OBSWeakSource transition = GetWeakTransitionByQString(transitionName);
-
- QString text = MakeSceneSequenceSwitchName(scene1Name, scene2Name,
- transitionName, delay);
- QVariant v = QVariant::fromValue(text);
-
- int idx = SceneSequenceFindByData(scene1Name);
-
- if (idx == -1) {
- QListWidgetItem *item =
- new QListWidgetItem(text, ui->sceneSequences);
- item->setData(Qt::UserRole, v);
-
- std::lock_guard lock(switcher->m);
- switcher->sceneSequenceSwitches.emplace_back(
- source1, source2, transition, delay,
- (scene2Name == QString(previous_scene_name)),
- text.toUtf8().constData());
- } else {
- QListWidgetItem *item = ui->sceneSequences->item(idx);
- item->setText(text);
-
- {
- std::lock_guard lock(switcher->m);
- for (auto &s : switcher->sceneSequenceSwitches) {
- if (s.startScene == source1) {
- s.scene = source2;
- s.delay = delay;
- s.transition = transition;
- s.usePreviousScene =
- (scene2Name ==
- QString(previous_scene_name));
- s.sceneSequenceStr =
- text.toUtf8().constData();
- break;
- }
- }
- }
- }
+ QListWidgetItem *item;
+ item = new QListWidgetItem(ui->sceneSequences);
+ ui->sceneSequences->addItem(item);
+ SequenceWidget *sw =
+ new SequenceWidget(&switcher->sceneSequenceSwitches.back());
+ item->setSizeHint(sw->minimumSizeHint());
+ ui->sceneSequences->setItemWidget(item, sw);
}
void SceneSwitcher::on_sceneSequenceRemove_clicked()
@@ -108,26 +28,53 @@ void SceneSwitcher::on_sceneSequenceRemove_clicked()
if (!item)
return;
- std::string text =
- item->data(Qt::UserRole).toString().toUtf8().constData();
-
{
std::lock_guard lock(switcher->m);
+ int idx = ui->sceneSequences->currentRow();
auto &switches = switcher->sceneSequenceSwitches;
-
- for (auto it = switches.begin(); it != switches.end(); ++it) {
- auto &s = *it;
-
- if (s.sceneSequenceStr == text) {
- switches.erase(it);
- break;
- }
- }
+ switches.erase(switches.begin() + idx);
}
delete item;
}
+void SceneSwitcher::on_sceneSequenceUp_clicked()
+{
+ int index = ui->sceneSequences->currentRow();
+ if (!listMoveUp(ui->sceneSequences))
+ return;
+
+ SequenceWidget *s1 = (SequenceWidget *)ui->sceneSequences->itemWidget(
+ ui->sceneSequences->item(index));
+ SequenceWidget *s2 = (SequenceWidget *)ui->sceneSequences->itemWidget(
+ ui->sceneSequences->item(index - 1));
+ SequenceWidget::swapSwitchData(s1, s2);
+
+ std::lock_guard lock(switcher->m);
+
+ std::swap(switcher->sceneSequenceSwitches[index],
+ switcher->sceneSequenceSwitches[index - 1]);
+}
+
+void SceneSwitcher::on_sceneSequenceDown_clicked()
+{
+ int index = ui->sceneSequences->currentRow();
+
+ if (!listMoveDown(ui->sceneSequences))
+ return;
+
+ SequenceWidget *s1 = (SequenceWidget *)ui->sceneSequences->itemWidget(
+ ui->sceneSequences->item(index));
+ SequenceWidget *s2 = (SequenceWidget *)ui->sceneSequences->itemWidget(
+ ui->sceneSequences->item(index + 1));
+ SequenceWidget::swapSwitchData(s1, s2);
+
+ std::lock_guard lock(switcher->m);
+
+ std::swap(switcher->sceneSequenceSwitches[index],
+ switcher->sceneSequenceSwitches[index + 1]);
+}
+
void SceneSwitcher::on_sceneSequenceSave_clicked()
{
QString directory = QFileDialog::getSaveFileName(
@@ -145,50 +92,6 @@ void SceneSwitcher::on_sceneSequenceSave_clicked()
obs_data_release(obj);
}
-// to be removed once support for old file format is dropped
-bool oldSceneRoundTripLoad(QFile *file)
-{
- QTextStream in(file);
- std::vector lines;
-
- std::vector newSceneRoundTripSwitch;
-
- while (!in.atEnd()) {
- QString line = in.readLine();
- lines.push_back(line);
- if (lines.size() == 5) {
- OBSWeakSource scene1 = GetWeakSourceByQString(lines[0]);
- OBSWeakSource scene2 = GetWeakSourceByQString(lines[1]);
- OBSWeakSource transition =
- GetWeakTransitionByQString(lines[4]);
-
- if (WeakSourceValid(scene1) &&
- ((lines[1] == QString(previous_scene_name)) ||
- (WeakSourceValid(scene2))) &&
- WeakSourceValid(transition)) {
- newSceneRoundTripSwitch.emplace_back(
- SceneSequenceSwitch(
- GetWeakSourceByQString(lines[0]),
- GetWeakSourceByQString(lines[1]),
- GetWeakTransitionByQString(
- lines[4]),
- lines[2].toDouble() / 1000.,
- (lines[1] ==
- QString(previous_scene_name)),
- lines[3].toStdString()));
- }
- lines.clear();
- }
- }
-
- if (lines.size() != 0 || newSceneRoundTripSwitch.size() == 0)
- return false;
-
- switcher->sceneSequenceSwitches.clear();
- switcher->sceneSequenceSwitches = newSceneRoundTripSwitch;
- return true;
-}
-
void SceneSwitcher::on_sceneSequenceLoad_clicked()
{
std::lock_guard lock(switcher->m);
@@ -208,23 +111,9 @@ void SceneSwitcher::on_sceneSequenceLoad_clicked()
if (!obj) {
QMessageBox Msgbox;
- QString txt =
- "Advanced Scene Switcher failed to import settings!\n";
- txt += "Falling back to old format.";
- Msgbox.setText(txt);
+ Msgbox.setText(
+ "Advanced Scene Switcher failed to import settings!");
Msgbox.exec();
- if (oldSceneRoundTripLoad(&file)) {
- QString txt =
- "Advanced Scene Switcher settings imported successfully!\n";
- txt += "Please resave settings as support for old format will be dropped in next version.";
- Msgbox.setText(txt);
- Msgbox.exec();
- close();
- } else {
- Msgbox.setText(
- "Advanced Scene Switcher failed to import settings!");
- Msgbox.exec();
- }
return;
}
switcher->loadSceneSequenceSwitches(obj);
@@ -238,13 +127,16 @@ void SceneSwitcher::on_sceneSequenceLoad_clicked()
}
void SwitcherData::checkSceneSequence(bool &match, OBSWeakSource &scene,
- OBSWeakSource &transition,
- std::unique_lock &lock)
+ OBSWeakSource &transition,
+ std::unique_lock &lock)
{
obs_source_t *currentSource = obs_frontend_get_current_scene();
obs_weak_source_t *ws = obs_source_get_weak_source(currentSource);
for (SceneSequenceSwitch &s : sceneSequenceSwitches) {
+ if (!s.initialized())
+ continue;
+
if (s.startScene == ws) {
int dur = s.delay * 1000 - interval;
if (dur > 0) {
@@ -277,87 +169,6 @@ void SwitcherData::checkSceneSequence(bool &match, OBSWeakSource &scene,
obs_weak_source_release(ws);
}
-void SceneSwitcher::on_sceneSequences_currentRowChanged(int idx)
-{
- if (loading)
- return;
- if (idx == -1)
- return;
-
- QListWidgetItem *item = ui->sceneSequences->item(idx);
-
- QString sceneSequence = item->text();
-
- std::lock_guard lock(switcher->m);
- for (auto &s : switcher->sceneSequenceSwitches) {
- if (sceneSequence.compare(s.sceneSequenceStr.c_str()) == 0) {
- std::string scene1 = GetWeakSourceName(s.startScene);
- std::string scene2 = GetWeakSourceName(s.scene);
- std::string transitionName =
- GetWeakSourceName(s.transition);
- double delay = s.delay /
- switcher->sceneSequenceMultiplier;
- ui->sceneSequenceScenes1->setCurrentText(
- scene1.c_str());
- ui->sceneSequenceScenes2->setCurrentText(
- scene2.c_str());
- ui->sceneSequenceTransitions->setCurrentText(
- transitionName.c_str());
- ui->sceneSequenceSpinBox->setValue(delay);
- break;
- }
- }
-}
-
-int SceneSwitcher::SceneSequenceFindByData(const QString &scene1)
-{
- QRegExp rx(scene1 + " ->.*");
- int count = ui->sceneSequences->count();
- int idx = -1;
-
- for (int i = 0; i < count; i++) {
- QListWidgetItem *item = ui->sceneSequences->item(i);
- QString itemString = item->data(Qt::UserRole).toString();
-
- if (rx.exactMatch(itemString)) {
- idx = i;
- break;
- }
- }
-
- return idx;
-}
-
-void SceneSwitcher::on_sceneSequenceUp_clicked()
-{
- int index = ui->sceneSequences->currentRow();
- if (index != -1 && index != 0) {
- ui->sceneSequences->insertItem(
- index - 1, ui->sceneSequences->takeItem(index));
- ui->sceneSequences->setCurrentRow(index - 1);
-
- std::lock_guard lock(switcher->m);
-
- iter_swap(switcher->sceneSequenceSwitches.begin() + index,
- switcher->sceneSequenceSwitches.begin() + index - 1);
- }
-}
-
-void SceneSwitcher::on_sceneSequenceDown_clicked()
-{
- int index = ui->sceneSequences->currentRow();
- if (index != -1 && index != ui->sceneSequences->count() - 1) {
- ui->sceneSequences->insertItem(
- index + 1, ui->sceneSequences->takeItem(index));
- ui->sceneSequences->setCurrentRow(index + 1);
-
- std::lock_guard lock(switcher->m);
-
- iter_swap(switcher->sceneSequenceSwitches.begin() + index,
- switcher->sceneSequenceSwitches.begin() + index + 1);
- }
-}
-
void SwitcherData::saveSceneSequenceSwitches(obs_data_t *obj)
{
obs_data_array_t *sceneSequenceArray = obs_data_array_create();
@@ -383,8 +194,9 @@ void SwitcherData::saveSceneSequenceSwitches(obs_data_t *obj)
obs_data_set_string(array_obj, "transition",
transitionName);
obs_data_set_double(array_obj, "delay", s.delay);
- obs_data_array_push_back(sceneSequenceArray,
- array_obj);
+ obs_data_set_int(array_obj, "delayMultiplier",
+ s.delayMultiplier);
+ obs_data_array_push_back(sceneSequenceArray, array_obj);
obs_source_release(source1);
obs_source_release(source2);
obs_source_release(transition);
@@ -414,34 +226,19 @@ void SwitcherData::loadSceneSequenceSwitches(obs_data_t *obj)
obs_data_get_string(array_obj, "sceneRoundTripScene2");
const char *transition =
obs_data_get_string(array_obj, "transition");
-
- double delay = 0;
-
- // To be removed in future version
- // to be compatible with older versions
- if (!obs_data_has_user_value(array_obj, "delay")) {
- delay = double(obs_data_get_int(array_obj,
- "sceneRoundTripDelay"));
- delay = delay * 1000. +
- double(obs_data_get_int(
- array_obj, "sceneRoundTripDelayMs"));
- delay /= 1000.;
- } else {
- delay = obs_data_get_double(array_obj, "delay");
- }
-
- std::string str = MakeSceneSequenceSwitchName(
- scene1, scene2, transition, delay)
- .toUtf8()
- .constData();
- const char *sceneSequenceStr = str.c_str();
+ double delay = obs_data_get_double(array_obj, "delay");
+ int delayMultiplier =
+ obs_data_get_int(array_obj, "delayMultiplier");
+ if (delayMultiplier == 0 ||
+ (delayMultiplier != 1 && delayMultiplier % 60 != 0))
+ delayMultiplier = 1;
switcher->sceneSequenceSwitches.emplace_back(
GetWeakSourceByName(scene1),
GetWeakSourceByName(scene2),
GetWeakTransitionByName(transition), delay,
- (strcmp(scene2, previous_scene_name) == 0),
- sceneSequenceStr);
+ delayMultiplier,
+ (strcmp(scene2, previous_scene_name) == 0));
obs_data_release(array_obj);
}
@@ -450,58 +247,168 @@ void SwitcherData::loadSceneSequenceSwitches(obs_data_t *obj)
void SceneSwitcher::setupSequenceTab()
{
- populateSceneSelection(ui->sceneSequenceScenes1, false);
- populateSceneSelection(ui->sceneSequenceScenes2, true);
- populateTransitionSelection(ui->sceneSequenceTransitions);
-
- double smallestDelay = double(switcher->interval) / 1000;
for (auto &s : switcher->sceneSequenceSwitches) {
- std::string sceneName1 = GetWeakSourceName(s.startScene);
- std::string sceneName2 = (s.usePreviousScene)
- ? previous_scene_name
- : GetWeakSourceName(s.scene);
- std::string transitionName = GetWeakSourceName(s.transition);
- QString text = MakeSceneSequenceSwitchName(
- sceneName1.c_str(), sceneName2.c_str(),
- transitionName.c_str(), s.delay);
-
- QListWidgetItem *item =
- new QListWidgetItem(text, ui->sceneSequences);
- item->setData(Qt::UserRole, text);
-
- if (s.delay < smallestDelay)
- smallestDelay = s.delay;
+ QListWidgetItem *item;
+ item = new QListWidgetItem(ui->sceneSequences);
+ ui->sceneSequences->addItem(item);
+ SequenceWidget *sw = new SequenceWidget(&s);
+ item->setSizeHint(sw->minimumSizeHint());
+ ui->sceneSequences->setItemWidget(item, sw);
}
- (smallestDelay * 1000 < switcher->interval)
- ? ui->intervalWarning->setVisible(true)
- : ui->intervalWarning->setVisible(false);
- ui->sceneSequenceDelayUnits->addItem("seconds");
- ui->sceneSequenceDelayUnits->addItem("minutes");
- ui->sceneSequenceDelayUnits->addItem("hours");
+ if (switcher->sceneSequenceSwitches.size() == 0)
+ addPulse = PulseWidget(ui->sceneSequenceAdd, QColor(Qt::green));
+}
- switch (switcher->sceneSequenceMultiplier) {
- case 1:
- ui->sceneSequenceDelayUnits->setCurrentIndex(0);
+bool SceneSequenceSwitch::initialized()
+{
+ return SceneSwitcherEntry::initialized() && startScene;
+}
+
+bool SceneSequenceSwitch::valid()
+{
+ return !initialized() ||
+ (SceneSwitcherEntry::valid() && WeakSourceValid(startScene));
+}
+
+void SceneSequenceSwitch::logSleep(int dur)
+{
+ blog(LOG_INFO, "Advanced Scene Switcher sequence sleep %d", dur);
+}
+
+void populateDelayUnits(QComboBox *list)
+{
+ list->addItem("seconds");
+ list->addItem("minutes");
+ list->addItem("hours");
+}
+
+SequenceWidget::SequenceWidget(SceneSequenceSwitch *s) : SwitchWidget(s, false)
+{
+ delay = new QDoubleSpinBox();
+ delayUnits = new QComboBox();
+ startScenes = new QComboBox();
+
+ whenLabel = new QLabel("When");
+ switchLabel = new QLabel("is active switch to");
+ afterLabel = new QLabel("after");
+ usingLabel = new QLabel("using");
+
+ QWidget::connect(delay, SIGNAL(valueChanged(double)), this,
+ SLOT(DelayChanged(double)));
+ QWidget::connect(delayUnits, SIGNAL(currentIndexChanged(int)), this,
+ SLOT(DelayUnitsChanged(int)));
+ QWidget::connect(startScenes,
+ SIGNAL(currentTextChanged(const QString &)), this,
+ SLOT(StartSceneChanged(const QString &)));
+
+ delay->setMaximum(99999.000000);
+ SceneSwitcher::populateSceneSelection(startScenes, false);
+ populateDelayUnits(delayUnits);
+
+ if (s) {
+ switch (s->delayMultiplier) {
+ case 1:
+ delayUnits->setCurrentIndex(0);
+ break;
+ case 60:
+ delayUnits->setCurrentIndex(1);
+ break;
+ case 3600:
+ delayUnits->setCurrentIndex(2);
+ break;
+ default:
+ delayUnits->setCurrentIndex(0);
+ }
+ startScenes->setCurrentText(
+ GetWeakSourceName(s->startScene).c_str());
+ }
+
+ setStyleSheet("* { background-color: transparent; }");
+
+ QHBoxLayout *mainLayout = new QHBoxLayout;
+
+ mainLayout->addWidget(whenLabel);
+ mainLayout->addWidget(startScenes);
+ mainLayout->addWidget(switchLabel);
+ mainLayout->addWidget(scenes);
+ mainLayout->addWidget(afterLabel);
+ mainLayout->addWidget(delay);
+ mainLayout->addWidget(delayUnits);
+ mainLayout->addWidget(usingLabel);
+ mainLayout->addWidget(transitions);
+ mainLayout->addStretch();
+
+ setLayout(mainLayout);
+
+ switchData = s;
+
+ loading = false;
+
+ UpdateDelay();
+}
+
+SceneSequenceSwitch *SequenceWidget::getSwitchData()
+{
+ return switchData;
+}
+
+void SequenceWidget::setSwitchData(SceneSequenceSwitch *s)
+{
+ switchData = s;
+}
+
+void SequenceWidget::swapSwitchData(SequenceWidget *s1, SequenceWidget *s2)
+{
+ SwitchWidget::swapSwitchData(s1, s2);
+
+ SceneSequenceSwitch *t = s1->getSwitchData();
+ s1->setSwitchData(s2->getSwitchData());
+ s2->setSwitchData(t);
+}
+
+void SequenceWidget::UpdateDelay()
+{
+ if (switchData)
+ delay->setValue(switchData->delay /
+ switchData->delayMultiplier);
+}
+
+void SequenceWidget::DelayChanged(double delay)
+{
+ if (loading || !switchData)
+ return;
+ switchData->delay = delay * switchData->delayMultiplier;
+}
+
+void SequenceWidget::DelayUnitsChanged(int idx)
+{
+ if (loading || !switchData)
+ return;
+
+ delay_units unit = (delay_units)idx;
+
+ switch (unit) {
+ case SECONDS:
+ switchData->delayMultiplier = 1;
break;
- case 60:
- ui->sceneSequenceDelayUnits->setCurrentIndex(1);
+ case MINUTES:
+ switchData->delayMultiplier = 60;
break;
- case 3600:
- ui->sceneSequenceDelayUnits->setCurrentIndex(2);
+ case HOURS:
+ switchData->delayMultiplier = 60 * 60;
break;
default:
break;
}
+
+ UpdateDelay();
}
-static inline QString MakeSceneSequenceSwitchName(const QString &scene1,
- const QString &scene2,
- const QString &transition,
- double delay)
+void SequenceWidget::StartSceneChanged(const QString &text)
{
- return scene1 + QStringLiteral(" -> wait for ") +
- QString::number(delay) + QStringLiteral(" seconds -> ") +
- scene2 + QStringLiteral(" (using ") + transition +
- QStringLiteral(" transition)");
+ if (loading || !switchData)
+ return;
+ std::lock_guard lock(switcher->m);
+ switchData->startScene = GetWeakSourceByQString(text);
}