mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-08-22 01:05:53 -05:00
add new UI for Time tab
This commit is contained in:
@@ -260,7 +260,7 @@
|
||||
<item>
|
||||
<widget class="QCheckBox" name="verboseLogging">
|
||||
<property name="text">
|
||||
<string>Enable verbose logging (Only needed for debugging)</string>
|
||||
<string>Enable verbose logging</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@@ -2688,81 +2688,6 @@
|
||||
<string notr="true">Time</string>
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_6">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_42">
|
||||
<item>
|
||||
<widget class="QComboBox" name="timeTrigger">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>100</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_55">
|
||||
<property name="text">
|
||||
<string>at</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QTimeEdit" name="timeEdit">
|
||||
<property name="displayFormat">
|
||||
<string>HH:mm:ss</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_59">
|
||||
<property name="text">
|
||||
<string>switch to</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="timeScenes">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>100</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_60">
|
||||
<property name="text">
|
||||
<string>using the</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="timeTransitions"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_61">
|
||||
<property name="text">
|
||||
<string>transition</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_40">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QListWidget" name="timeSwitches">
|
||||
<property name="enabled">
|
||||
|
||||
@@ -42,10 +42,8 @@ public:
|
||||
int SceneTransitionsFindByData(const QString &scene1,
|
||||
const QString &scene2);
|
||||
int DefaultTransitionsFindByData(const QString &scene);
|
||||
int executableFindByData(const QString &exe);
|
||||
int IgnoreIdleWindowsFindByData(const QString &window);
|
||||
int randomFindByData(const QString &scene);
|
||||
int timeFindByData(const timeTrigger &trigger, const QTime &time);
|
||||
|
||||
void UpdateNonMatchingScene(const QString &name);
|
||||
void UpdateAutoStopScene(const QString &name);
|
||||
@@ -187,7 +185,6 @@ public slots:
|
||||
void on_mediaUp_clicked();
|
||||
void on_mediaDown_clicked();
|
||||
|
||||
void on_timeSwitches_currentRowChanged(int idx);
|
||||
void on_timeAdd_clicked();
|
||||
void on_timeRemove_clicked();
|
||||
void on_timeUp_clicked();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <QDateTime>
|
||||
#include "utility.hpp"
|
||||
#include <QTimeEdit>
|
||||
|
||||
#include "switch-generic.hpp"
|
||||
|
||||
constexpr auto time_func = 7;
|
||||
@@ -20,24 +20,43 @@ typedef enum {
|
||||
} timeTrigger;
|
||||
|
||||
struct TimeSwitch : SceneSwitcherEntry {
|
||||
timeTrigger trigger;
|
||||
QTime time;
|
||||
std::string timeSwitchStr;
|
||||
timeTrigger trigger = ANY_DAY;
|
||||
QTime time = QTime();
|
||||
|
||||
const char *getType() { return "time"; }
|
||||
|
||||
inline TimeSwitch(){};
|
||||
inline TimeSwitch(OBSWeakSource scene_, OBSWeakSource transition_,
|
||||
timeTrigger trigger_, QTime time_,
|
||||
bool usePreviousScene_, std::string timeSwitchStr_)
|
||||
bool usePreviousScene_)
|
||||
: SceneSwitcherEntry(scene_, transition_, usePreviousScene_),
|
||||
trigger(trigger_),
|
||||
time(time_),
|
||||
timeSwitchStr(timeSwitchStr_)
|
||||
time(time_)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
static inline QString MakeTimeSwitchName(const QString &scene,
|
||||
const QString &transition,
|
||||
const timeTrigger &trigger,
|
||||
const QTime &time);
|
||||
class TimeSwitchWidget : public SwitchWidget {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
TimeSwitchWidget(TimeSwitch *s);
|
||||
TimeSwitch *getSwitchData();
|
||||
void setSwitchData(TimeSwitch *s);
|
||||
|
||||
static void swapSwitchData(TimeSwitchWidget *s1, TimeSwitchWidget *s2);
|
||||
|
||||
private slots:
|
||||
void TriggerChanged(int index);
|
||||
void TimeChanged(const QTime &time);
|
||||
|
||||
private:
|
||||
QComboBox *triggers;
|
||||
QTimeEdit *time;
|
||||
|
||||
QLabel *atLabel;
|
||||
QLabel *switchLabel;
|
||||
QLabel *usingLabel;
|
||||
|
||||
TimeSwitch *switchData;
|
||||
};
|
||||
|
||||
@@ -95,7 +95,7 @@ struct SwitcherData {
|
||||
|
||||
std::deque<MediaSwitch> mediaSwitches;
|
||||
|
||||
std::vector<TimeSwitch> timeSwitches;
|
||||
std::deque<TimeSwitch> timeSwitches;
|
||||
QDateTime liveTime;
|
||||
|
||||
std::deque<AudioSwitch> audioSwitches;
|
||||
|
||||
@@ -1,117 +1,21 @@
|
||||
#include "headers/advanced-scene-switcher.hpp"
|
||||
|
||||
static std::vector<std::pair<std::string, timeTrigger>> triggerTable = {
|
||||
{"On any day", timeTrigger::ANY_DAY},
|
||||
{"Mondays", timeTrigger::MONDAY},
|
||||
{"Tuesdays", timeTrigger::TUSEDAY},
|
||||
{"Wednesdays", timeTrigger::WEDNESDAY},
|
||||
{"Thursdays", timeTrigger::THURSDAY},
|
||||
{"Fridays", timeTrigger::FRIDAY},
|
||||
{"Saturdays", timeTrigger::SATURDAY},
|
||||
{"Sundays", timeTrigger::SUNDAY},
|
||||
{"Atfer streaming/recording start", timeTrigger::LIVE}};
|
||||
|
||||
void SceneSwitcher::on_timeSwitches_currentRowChanged(int idx)
|
||||
{
|
||||
if (loading)
|
||||
return;
|
||||
if (idx == -1)
|
||||
return;
|
||||
|
||||
QListWidgetItem *item = ui->timeSwitches->item(idx);
|
||||
|
||||
QString timeScenestr = item->data(Qt::UserRole).toString();
|
||||
|
||||
std::lock_guard<std::mutex> lock(switcher->m);
|
||||
for (auto &s : switcher->timeSwitches) {
|
||||
if (timeScenestr.compare(s.timeSwitchStr.c_str()) == 0) {
|
||||
QString sceneName = GetWeakSourceName(s.scene).c_str();
|
||||
QString transitionName =
|
||||
GetWeakSourceName(s.transition).c_str();
|
||||
ui->timeScenes->setCurrentText(sceneName);
|
||||
ui->timeTrigger->setCurrentIndex(s.trigger);
|
||||
ui->timeEdit->setTime(s.time);
|
||||
ui->timeTransitions->setCurrentText(transitionName);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int SceneSwitcher::timeFindByData(const timeTrigger &trigger, const QTime &time)
|
||||
{
|
||||
QRegExp rx(MakeTimeSwitchName(QStringLiteral(".*"),
|
||||
QStringLiteral(".*"), trigger, time));
|
||||
int count = ui->timeSwitches->count();
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
QListWidgetItem *item = ui->timeSwitches->item(i);
|
||||
QString str = item->data(Qt::UserRole).toString();
|
||||
|
||||
if (rx.exactMatch(str))
|
||||
return i;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
static QMetaObject::Connection addPulse;
|
||||
|
||||
void SceneSwitcher::on_timeAdd_clicked()
|
||||
{
|
||||
QString sceneName = ui->timeScenes->currentText();
|
||||
QString transitionName = ui->timeTransitions->currentText();
|
||||
QTime time = ui->timeEdit->time();
|
||||
ui->timeAdd->disconnect(addPulse);
|
||||
|
||||
if (sceneName.isEmpty())
|
||||
return;
|
||||
std::lock_guard<std::mutex> lock(switcher->m);
|
||||
switcher->timeSwitches.emplace_back();
|
||||
|
||||
OBSWeakSource source = GetWeakSourceByQString(sceneName);
|
||||
OBSWeakSource transition = GetWeakTransitionByQString(transitionName);
|
||||
|
||||
std::string triggerStr = ui->timeTrigger->currentText().toStdString();
|
||||
auto it = std::find_if(
|
||||
triggerTable.begin(), triggerTable.end(),
|
||||
[&triggerStr](
|
||||
const std::pair<std::string, timeTrigger> &element) {
|
||||
return element.first == triggerStr;
|
||||
});
|
||||
timeTrigger trigger = it->second;
|
||||
|
||||
QString text =
|
||||
MakeTimeSwitchName(sceneName, transitionName, trigger, time);
|
||||
QVariant v = QVariant::fromValue(text);
|
||||
|
||||
int idx = timeFindByData(trigger, time);
|
||||
|
||||
if (idx == -1) {
|
||||
std::lock_guard<std::mutex> lock(switcher->m);
|
||||
switcher->timeSwitches.emplace_back(
|
||||
source, transition, trigger, time,
|
||||
(sceneName == QString(previous_scene_name)),
|
||||
text.toUtf8().constData());
|
||||
|
||||
QListWidgetItem *item =
|
||||
new QListWidgetItem(text, ui->timeSwitches);
|
||||
item->setData(Qt::UserRole, v);
|
||||
} else {
|
||||
QListWidgetItem *item = ui->timeSwitches->item(idx);
|
||||
item->setText(text);
|
||||
item->setData(Qt::UserRole, v);
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(switcher->m);
|
||||
for (auto &s : switcher->timeSwitches) {
|
||||
if (s.trigger == trigger && s.time == time) {
|
||||
s.scene = source;
|
||||
s.transition = transition;
|
||||
s.usePreviousScene =
|
||||
(sceneName ==
|
||||
QString(previous_scene_name));
|
||||
s.timeSwitchStr =
|
||||
text.toUtf8().constData();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
QListWidgetItem *item;
|
||||
item = new QListWidgetItem(ui->timeSwitches);
|
||||
ui->timeSwitches->addItem(item);
|
||||
TimeSwitchWidget *sw =
|
||||
new TimeSwitchWidget(&switcher->timeSwitches.back());
|
||||
item->setSizeHint(sw->minimumSizeHint());
|
||||
ui->timeSwitches->setItemWidget(item, sw);
|
||||
}
|
||||
|
||||
void SceneSwitcher::on_timeRemove_clicked()
|
||||
@@ -120,21 +24,11 @@ void SceneSwitcher::on_timeRemove_clicked()
|
||||
if (!item)
|
||||
return;
|
||||
|
||||
std::string text =
|
||||
item->data(Qt::UserRole).toString().toUtf8().constData();
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(switcher->m);
|
||||
int idx = ui->timeSwitches->currentRow();
|
||||
auto &switches = switcher->timeSwitches;
|
||||
|
||||
for (auto it = switches.begin(); it != switches.end(); ++it) {
|
||||
auto &s = *it;
|
||||
|
||||
if (s.timeSwitchStr == text) {
|
||||
switches.erase(it);
|
||||
break;
|
||||
}
|
||||
}
|
||||
switches.erase(switches.begin() + idx);
|
||||
}
|
||||
|
||||
delete item;
|
||||
@@ -143,31 +37,38 @@ void SceneSwitcher::on_timeRemove_clicked()
|
||||
void SceneSwitcher::on_timeUp_clicked()
|
||||
{
|
||||
int index = ui->timeSwitches->currentRow();
|
||||
if (index != -1 && index != 0) {
|
||||
ui->timeSwitches->insertItem(index - 1,
|
||||
ui->timeSwitches->takeItem(index));
|
||||
ui->timeSwitches->setCurrentRow(index - 1);
|
||||
if (!listMoveUp(ui->timeSwitches))
|
||||
return;
|
||||
|
||||
std::lock_guard<std::mutex> lock(switcher->m);
|
||||
TimeSwitchWidget *s1 = (TimeSwitchWidget *)ui->timeSwitches->itemWidget(
|
||||
ui->timeSwitches->item(index));
|
||||
TimeSwitchWidget *s2 = (TimeSwitchWidget *)ui->timeSwitches->itemWidget(
|
||||
ui->timeSwitches->item(index - 1));
|
||||
TimeSwitchWidget::swapSwitchData(s1, s2);
|
||||
|
||||
iter_swap(switcher->timeSwitches.begin() + index,
|
||||
switcher->timeSwitches.begin() + index - 1);
|
||||
}
|
||||
std::lock_guard<std::mutex> lock(switcher->m);
|
||||
|
||||
std::swap(switcher->timeSwitches[index],
|
||||
switcher->timeSwitches[index - 1]);
|
||||
}
|
||||
|
||||
void SceneSwitcher::on_timeDown_clicked()
|
||||
{
|
||||
int index = ui->timeSwitches->currentRow();
|
||||
if (index != -1 && index != ui->timeSwitches->count() - 1) {
|
||||
ui->timeSwitches->insertItem(index + 1,
|
||||
ui->timeSwitches->takeItem(index));
|
||||
ui->timeSwitches->setCurrentRow(index + 1);
|
||||
|
||||
std::lock_guard<std::mutex> lock(switcher->m);
|
||||
if (!listMoveDown(ui->timeSwitches))
|
||||
return;
|
||||
|
||||
iter_swap(switcher->timeSwitches.begin() + index,
|
||||
switcher->timeSwitches.begin() + index + 1);
|
||||
}
|
||||
TimeSwitchWidget *s1 = (TimeSwitchWidget *)ui->timeSwitches->itemWidget(
|
||||
ui->timeSwitches->item(index));
|
||||
TimeSwitchWidget *s2 = (TimeSwitchWidget *)ui->timeSwitches->itemWidget(
|
||||
ui->timeSwitches->item(index + 1));
|
||||
TimeSwitchWidget::swapSwitchData(s1, s2);
|
||||
|
||||
std::lock_guard<std::mutex> lock(switcher->m);
|
||||
|
||||
std::swap(switcher->timeSwitches[index],
|
||||
switcher->timeSwitches[index + 1]);
|
||||
}
|
||||
|
||||
bool timesAreInInterval(QTime &time1, QTime &time2, int &interval)
|
||||
@@ -282,16 +183,10 @@ void SwitcherData::loadTimeSwitches(obs_data_t *obj)
|
||||
QTime time = QTime::fromString(
|
||||
obs_data_get_string(array_obj, "time"));
|
||||
|
||||
std::string timeSwitchStr =
|
||||
MakeTimeSwitchName(scene, transition, trigger, time)
|
||||
.toUtf8()
|
||||
.constData();
|
||||
|
||||
switcher->timeSwitches.emplace_back(
|
||||
GetWeakSourceByName(scene),
|
||||
GetWeakTransitionByName(transition), trigger, time,
|
||||
(strcmp(scene, previous_scene_name) == 0),
|
||||
timeSwitchStr);
|
||||
(strcmp(scene, previous_scene_name) == 0));
|
||||
|
||||
obs_data_release(array_obj);
|
||||
}
|
||||
@@ -303,70 +198,111 @@ void SceneSwitcher::setupTimeTab()
|
||||
populateSceneSelection(ui->timeScenes, true);
|
||||
populateTransitionSelection(ui->timeTransitions);
|
||||
|
||||
for (auto t : triggerTable) {
|
||||
ui->timeTrigger->addItem(t.first.c_str());
|
||||
for (auto &s : switcher->timeSwitches) {
|
||||
QListWidgetItem *item;
|
||||
item = new QListWidgetItem(ui->timeSwitches);
|
||||
ui->timeSwitches->addItem(item);
|
||||
TimeSwitchWidget *sw = new TimeSwitchWidget(&s);
|
||||
item->setSizeHint(sw->minimumSizeHint());
|
||||
ui->timeSwitches->setItemWidget(item, sw);
|
||||
}
|
||||
|
||||
// assuming the streaming / recording entry is always last
|
||||
ui->timeTrigger->setItemData(
|
||||
(int)triggerTable.size() - 1,
|
||||
if (switcher->timeSwitches.size() == 0)
|
||||
addPulse = PulseWidget(ui->timeAdd, QColor(Qt::green));
|
||||
}
|
||||
|
||||
void populateTriggers(QComboBox *list)
|
||||
{
|
||||
list->addItem("On any day");
|
||||
list->addItem("Mondays");
|
||||
list->addItem("Tuesdays");
|
||||
list->addItem("Wednesdays");
|
||||
list->addItem("Thursdays");
|
||||
list->addItem("Fridays");
|
||||
list->addItem("Saturdays");
|
||||
list->addItem("Sundays");
|
||||
list->addItem("Atfer streaming/recording start");
|
||||
|
||||
list->setItemData(
|
||||
8,
|
||||
"The time relative to the start of streaming / recording will be used",
|
||||
Qt::ToolTipRole);
|
||||
|
||||
for (auto &s : switcher->timeSwitches) {
|
||||
std::string sceneName = (s.usePreviousScene)
|
||||
? previous_scene_name
|
||||
: GetWeakSourceName(s.scene);
|
||||
std::string transitionName = GetWeakSourceName(s.transition);
|
||||
QString listText = MakeTimeSwitchName(sceneName.c_str(),
|
||||
transitionName.c_str(),
|
||||
s.trigger, s.time);
|
||||
|
||||
QListWidgetItem *item =
|
||||
new QListWidgetItem(listText, ui->timeSwitches);
|
||||
item->setData(Qt::UserRole, listText);
|
||||
}
|
||||
}
|
||||
|
||||
static inline QString MakeTimeSwitchName(const QString &scene,
|
||||
const QString &transition,
|
||||
const timeTrigger &trigger,
|
||||
const QTime &time)
|
||||
TimeSwitchWidget::TimeSwitchWidget(TimeSwitch *s) : SwitchWidget(s, false)
|
||||
{
|
||||
QString switchName;
|
||||
triggers = new QComboBox();
|
||||
time = new QTimeEdit();
|
||||
|
||||
switch (trigger) {
|
||||
case ANY_DAY:
|
||||
switchName = QStringLiteral("On any weekday");
|
||||
break;
|
||||
case MONDAY:
|
||||
switchName = QStringLiteral("Mondays");
|
||||
break;
|
||||
case TUSEDAY:
|
||||
switchName = QStringLiteral("Tusedays");
|
||||
break;
|
||||
case WEDNESDAY:
|
||||
switchName = QStringLiteral("Wednesdays");
|
||||
break;
|
||||
case THURSDAY:
|
||||
switchName = QStringLiteral("Thursdays");
|
||||
break;
|
||||
case FRIDAY:
|
||||
switchName = QStringLiteral("Fridays");
|
||||
break;
|
||||
case SATURDAY:
|
||||
switchName = QStringLiteral("Saturdays");
|
||||
break;
|
||||
case SUNDAY:
|
||||
switchName = QStringLiteral("Sundays");
|
||||
break;
|
||||
case LIVE:
|
||||
switchName = QStringLiteral(
|
||||
"Relative to starting streaming / recording");
|
||||
break;
|
||||
atLabel = new QLabel("at");
|
||||
switchLabel = new QLabel("switch to");
|
||||
usingLabel = new QLabel("using");
|
||||
|
||||
QWidget::connect(triggers, SIGNAL(currentIndexChanged(int)), this,
|
||||
SLOT(TriggerChanged(int)));
|
||||
QWidget::connect(time, SIGNAL(timeChanged(const QTime &)), this,
|
||||
SLOT(TimeChanged(const QTime &)));
|
||||
|
||||
populateTriggers(triggers);
|
||||
time->setDisplayFormat("HH:mm:ss");
|
||||
|
||||
if (s) {
|
||||
triggers->setCurrentIndex(s->trigger);
|
||||
time->setTime(s->time);
|
||||
}
|
||||
switchName += QStringLiteral(" at ") + time.toString() +
|
||||
QStringLiteral(" switch to ") + scene +
|
||||
QStringLiteral(" using ") + transition;
|
||||
return switchName;
|
||||
|
||||
setStyleSheet("* { background-color: transparent; }");
|
||||
|
||||
QHBoxLayout *mainLayout = new QHBoxLayout;
|
||||
|
||||
mainLayout->addWidget(triggers);
|
||||
mainLayout->addWidget(atLabel);
|
||||
mainLayout->addWidget(time);
|
||||
mainLayout->addWidget(switchLabel);
|
||||
mainLayout->addWidget(scenes);
|
||||
mainLayout->addWidget(usingLabel);
|
||||
mainLayout->addWidget(transitions);
|
||||
mainLayout->addStretch();
|
||||
|
||||
setLayout(mainLayout);
|
||||
|
||||
switchData = s;
|
||||
|
||||
loading = false;
|
||||
}
|
||||
|
||||
TimeSwitch *TimeSwitchWidget::getSwitchData()
|
||||
{
|
||||
return switchData;
|
||||
}
|
||||
|
||||
void TimeSwitchWidget::setSwitchData(TimeSwitch *s)
|
||||
{
|
||||
switchData = s;
|
||||
}
|
||||
|
||||
void TimeSwitchWidget::swapSwitchData(TimeSwitchWidget *s1,
|
||||
TimeSwitchWidget *s2)
|
||||
{
|
||||
SwitchWidget::swapSwitchData(s1, s2);
|
||||
|
||||
TimeSwitch *t = s1->getSwitchData();
|
||||
s1->setSwitchData(s2->getSwitchData());
|
||||
s2->setSwitchData(t);
|
||||
}
|
||||
|
||||
void TimeSwitchWidget::TriggerChanged(int index)
|
||||
{
|
||||
if (loading || !switchData)
|
||||
return;
|
||||
std::lock_guard<std::mutex> lock(switcher->m);
|
||||
switchData->trigger = (timeTrigger)index;
|
||||
}
|
||||
|
||||
void TimeSwitchWidget::TimeChanged(const QTime &time)
|
||||
{
|
||||
if (loading || !switchData)
|
||||
return;
|
||||
std::lock_guard<std::mutex> lock(switcher->m);
|
||||
switchData->time = time;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user