diff --git a/CMakeLists.txt b/CMakeLists.txt index 717c63f3..cee94a99 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -257,7 +257,7 @@ set(advanced-scene-switcher_HEADERS src/headers/duration-control.hpp src/headers/file-selection.hpp src/headers/section.hpp - src/headers/status-dock.hpp + src/headers/status-control.hpp src/headers/platform-funcs.hpp src/headers/utility.hpp src/headers/volume-control.hpp @@ -354,7 +354,7 @@ set(advanced-scene-switcher_SOURCES src/transition-selection.cpp src/name-dialog.cpp src/duration-control.cpp - src/status-dock.cpp + src/status-control.cpp src/section.cpp src/utility.cpp src/volume-control.cpp diff --git a/forms/advanced-scene-switcher.ui b/forms/advanced-scene-switcher.ui index 8e94da28..ce9228de 100644 --- a/forms/advanced-scene-switcher.ui +++ b/forms/advanced-scene-switcher.ui @@ -56,10 +56,30 @@ - + + + + + + + + AdvSceneSwitcher.generalTab.status.onStartup + + + + + + + + + + AdvSceneSwitcher.generalTab.status.autoStart + + + @@ -82,6 +102,13 @@ + + + + AdvSceneSwitcher.generalTab.status.hotkeytips + + + @@ -90,66 +117,10 @@ - - - AdvSceneSwitcher.generalTab.status.start - - + - - - - - AdvSceneSwitcher.status.inactive - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - AdvSceneSwitcher.generalTab.status.hotkeytips - - - - - - - AdvSceneSwitcher.generalTab.status.onStartup - - - - - - - AdvSceneSwitcher.generalTab.status.currentStatus - - - - - - - AdvSceneSwitcher.generalTab.status.autoStart - - - - - + diff --git a/src/advanced-scene-switcher.cpp b/src/advanced-scene-switcher.cpp index 104e0d25..8225a8c6 100644 --- a/src/advanced-scene-switcher.cpp +++ b/src/advanced-scene-switcher.cpp @@ -9,7 +9,7 @@ #include #include "headers/advanced-scene-switcher.hpp" -#include "headers/status-dock.hpp" +#include "headers/status-control.hpp" #include "headers/curl-helper.hpp" #include "headers/utility.hpp" #include "headers/version.h" diff --git a/src/general.cpp b/src/general.cpp index 5203cf5b..3c688f8c 100644 --- a/src/general.cpp +++ b/src/general.cpp @@ -1,13 +1,11 @@ #include "headers/advanced-scene-switcher.hpp" -#include "headers/status-dock.hpp" +#include "headers/status-control.hpp" #include "headers/utility.hpp" #include "headers/version.h" #include #include -QMetaObject::Connection inactivePluse; - void AdvSceneSwitcher::on_close_clicked() { close(); @@ -147,41 +145,6 @@ void AdvSceneSwitcher::on_checkInterval_valueChanged(int value) switcher->interval = value; } -void AdvSceneSwitcher::SetStarted() -{ - ui->toggleStartButton->setText( - obs_module_text("AdvSceneSwitcher.generalTab.status.stop")); - ui->pluginRunningText->setText( - obs_module_text("AdvSceneSwitcher.status.active")); - ui->pluginRunningText->disconnect(inactivePluse); - currentStatusActive = true; -} - -void AdvSceneSwitcher::SetStopped() -{ - ui->toggleStartButton->setText( - obs_module_text("AdvSceneSwitcher.generalTab.status.start")); - ui->pluginRunningText->setText( - obs_module_text("AdvSceneSwitcher.status.inactive")); - if (!switcher->disableHints) { - inactivePluse = PulseWidget(ui->pluginRunningText, - QColor(Qt::red), QColor(0, 0, 0, 0), - "QLabel "); - } - currentStatusActive = false; -} - -void AdvSceneSwitcher::on_toggleStartButton_clicked() -{ - if (switcher->th && switcher->th->isRunning()) { - switcher->Stop(); - SetStopped(); - } else { - switcher->Start(); - SetStarted(); - } -} - void AdvSceneSwitcher::closeEvent(QCloseEvent *) { if (!switcher) { @@ -791,21 +754,6 @@ void populateAutoStartEventSelection(QComboBox *cb) "AdvSceneSwitcher.generalTab.status.autoStart.recordingAndStreaming")); } -void AdvSceneSwitcher::updateStatus() -{ - if (switcher->th && switcher->th->isRunning()) { - if (currentStatusActive) { - return; - } - SetStarted(); - } else { - if (!currentStatusActive) { - return; - } - SetStopped(); - } -} - void AdvSceneSwitcher::setupGeneralTab() { populateSceneSelection(ui->noMatchSwitchScene, false); @@ -926,17 +874,14 @@ void AdvSceneSwitcher::setupGeneralTab() ui->autoStartEvent->setCurrentIndex( static_cast(switcher->autoStartEvent)); - if (switcher->th && switcher->th->isRunning()) { - SetStarted(); - } else { - SetStopped(); - } - - // Updates the UI status element if the status changed externally - // (e.g. via hotkeys) - QTimer *statusTimer = new QTimer(this); - connect(statusTimer, SIGNAL(timeout()), this, SLOT(updateStatus())); - statusTimer->start(1000); + // Set up status control + auto statusControl = new StatusControl(this, true); + ui->statusLayout->addWidget(statusControl->StatusPrefixLabel(), 1, 0); + auto tmp = new QHBoxLayout; + tmp->addWidget(statusControl->StatusLabel()); + tmp->addStretch(); + ui->statusLayout->addLayout(tmp, 1, 1); + ui->statusLayout->addWidget(statusControl->Button(), 2, 1); setWindowTitle(windowTitle() + " - " + g_GIT_TAG); } diff --git a/src/headers/advanced-scene-switcher.hpp b/src/headers/advanced-scene-switcher.hpp index f66b3544..b29bde62 100644 --- a/src/headers/advanced-scene-switcher.hpp +++ b/src/headers/advanced-scene-switcher.hpp @@ -28,7 +28,6 @@ class AdvSceneSwitcher : public QDialog { public: std::unique_ptr ui; bool loading = true; - bool currentStatusActive = false; AdvSceneSwitcher(QWidget *parent); ~AdvSceneSwitcher(); @@ -36,9 +35,6 @@ public: void reject() override; void closeEvent(QCloseEvent *event) override; - void SetStarted(); - void SetStopped(); - void SetShowFrames(); void SetHideFrames(); void clearFrames(QListWidget *list); @@ -109,7 +105,6 @@ public slots: void on_autoStartEvent_currentIndexChanged(int index); void on_noMatchSwitchScene_currentTextChanged(const QString &text); void on_checkInterval_valueChanged(int value); - void on_toggleStartButton_clicked(); void on_tabMoved(int from, int to); void on_tabWidget_currentChanged(int index); @@ -272,7 +267,6 @@ public slots: void on_threadPriority_currentTextChanged(const QString &text); void updateScreenRegionCursorPos(); - void updateStatus(); void on_close_clicked(); diff --git a/src/headers/status-dock.hpp b/src/headers/status-control.hpp similarity index 57% rename from src/headers/status-dock.hpp rename to src/headers/status-control.hpp index dca96d8f..4f190cb7 100644 --- a/src/headers/status-dock.hpp +++ b/src/headers/status-control.hpp @@ -5,11 +5,14 @@ #include #include -class StatusDock : public QDockWidget { +class StatusControl : public QWidget { Q_OBJECT public: - StatusDock(QWidget *parent = 0); + StatusControl(QWidget *parent = 0, bool noLayout = false); + QPushButton *Button() { return _button; } + QLabel *StatusLabel() { return _status; } + QLabel *StatusPrefixLabel() { return _statusPrefix; } private slots: void ButtonClicked(); @@ -21,7 +24,18 @@ private: QPushButton *_button; QLabel *_status; + QLabel *_statusPrefix; QTimer _timer; + QMetaObject::Connection _pulse; + + bool _setToStopped = true; +}; + +class StatusDock : public QDockWidget { + Q_OBJECT + +public: + StatusDock(QWidget *parent = 0); }; extern StatusDock *dock; diff --git a/src/status-dock.cpp b/src/status-control.cpp similarity index 60% rename from src/status-dock.cpp rename to src/status-control.cpp index 9f2086b1..5061f9a8 100644 --- a/src/status-dock.cpp +++ b/src/status-control.cpp @@ -1,4 +1,4 @@ -#include "headers/status-dock.hpp" +#include "headers/status-control.hpp" #include "headers/advanced-scene-switcher.hpp" #include "headers/utility.hpp" @@ -8,31 +8,39 @@ StatusDock *dock = nullptr; -StatusDock::StatusDock(QWidget *parent) - : QDockWidget(obs_module_text("AdvSceneSwitcher.windowTitle"), parent) +StatusControl::StatusControl(QWidget *parent, bool noLayout) : QWidget(parent) { - _button = new QPushButton( - obs_module_text("AdvSceneSwitcher.generalTab.status.start")); - _status = - new QLabel(obs_module_text("AdvSceneSwitcher.status.inactive")); + _button = new QPushButton("-", this); + _status = new QLabel("-", this); + _statusPrefix = new QLabel( + obs_module_text( + "AdvSceneSwitcher.generalTab.status.currentStatus"), + this); + QWidget::connect(_button, SIGNAL(clicked()), this, SLOT(ButtonClicked())); - QHBoxLayout *statusLayout = new QHBoxLayout; - statusLayout->addWidget(new QLabel(obs_module_text( - "AdvSceneSwitcher.generalTab.status.currentStatus"))); - statusLayout->addWidget(_status); - QVBoxLayout *layout = new QVBoxLayout; - layout->addLayout(statusLayout); - layout->addWidget(_button); - layout->addStretch(); - QWidget *tmp = new QWidget; - tmp->setLayout(layout); - setWidget(tmp); + + if (!noLayout) { + QHBoxLayout *statusLayout = new QHBoxLayout(); + statusLayout->addWidget(_statusPrefix); + statusLayout->addWidget(_status); + statusLayout->addStretch(); + QVBoxLayout *layout = new QVBoxLayout(); + layout->addLayout(statusLayout); + layout->addWidget(_button); + setLayout(layout); + } + + if (switcher->stop) { + SetStopped(); + } else { + SetStarted(); + } connect(&_timer, SIGNAL(timeout()), this, SLOT(UpdateStatus())); _timer.start(1000); } -void StatusDock::ButtonClicked() +void StatusControl::ButtonClicked() { if (switcher->th && switcher->th->isRunning()) { switcher->Stop(); @@ -43,27 +51,52 @@ void StatusDock::ButtonClicked() } } -void StatusDock::UpdateStatus() +void StatusControl::UpdateStatus() { if (switcher->th && switcher->th->isRunning()) { - SetStopped(); - } else { + if (!_setToStopped) { + return; + } SetStarted(); + } else { + if (_setToStopped) { + return; + } + SetStopped(); } } -void StatusDock::SetStopped() +void StatusControl::SetStarted() { _button->setText( obs_module_text("AdvSceneSwitcher.generalTab.status.stop")); _status->setText(obs_module_text("AdvSceneSwitcher.status.active")); + _status->disconnect(_pulse); + _setToStopped = false; } -void StatusDock::SetStarted() +void StatusControl::SetStopped() { _button->setText( obs_module_text("AdvSceneSwitcher.generalTab.status.start")); _status->setText(obs_module_text("AdvSceneSwitcher.status.inactive")); + if (!switcher->disableHints) { + _pulse = PulseWidget(_status, QColor(Qt::red), + QColor(0, 0, 0, 0), "QLabel "); + } + _setToStopped = true; +} + +StatusDock::StatusDock(QWidget *parent) + : QDockWidget(obs_module_text("AdvSceneSwitcher.windowTitle"), parent) +{ + // Not sure why an extra QWidget wrapper is necessary... + // without it the dock widget seems to be partially transparent. + QWidget *tmp = new QWidget; + QHBoxLayout *layout = new QHBoxLayout; + layout->addWidget(new StatusControl(this)); + tmp->setLayout(layout); + setWidget(tmp); } void saveDock(obs_data_t *obj)