From dcf48e8ffc085bfbf64ded3a53847bf0741cf35b Mon Sep 17 00:00:00 2001 From: jp9000 Date: Wed, 6 Feb 2019 13:57:59 -0800 Subject: [PATCH] UI: Add function for adding extra docks to main window --- UI/data/locale/en-US.ini | 3 ++ UI/window-basic-main.cpp | 62 ++++++++++++++++++++++++++++++++++++++++ UI/window-basic-main.hpp | 4 +++ 3 files changed, 69 insertions(+) diff --git a/UI/data/locale/en-US.ini b/UI/data/locale/en-US.ini index 851ba744c..501610dac 100644 --- a/UI/data/locale/en-US.ini +++ b/UI/data/locale/en-US.ini @@ -172,6 +172,9 @@ Basic.Stats.DroppedFrames="Dropped Frames (Network)" Basic.Stats.MegabytesSent="Total Data Output" Basic.Stats.Bitrate="Bitrate" +ResetUIWarning.Title="Are you sure you want to reset the UI?" +ResetUIWarning.Text="Resetting the UI will hide additional docks. You will need to unhide these docks from the view menu if you want them to be visible.\n\nAre you sure you want to reset the UI?" + # updater Updater.Title="New update available" Updater.Text="There is a new update available:" diff --git a/UI/window-basic-main.cpp b/UI/window-basic-main.cpp index 6cc9da87d..6ce5ba7fa 100644 --- a/UI/window-basic-main.cpp +++ b/UI/window-basic-main.cpp @@ -6219,6 +6219,36 @@ int OBSBasic::GetProfilePath(char *path, size_t size, const char *file) const void OBSBasic::on_resetUI_triggered() { + /* prune deleted extra docks */ + for (int i = extraDocks.size() - 1; i >= 0 ; i--) { + if (!extraDocks[i]) { + extraDocks.removeAt(i); + } + } + + if (extraDocks.size()) { + QMessageBox::StandardButton button = QMessageBox::question( + this, + QTStr("ResetUIWarning.Title"), + QTStr("ResetUIWarning.Text")); + + if (button == QMessageBox::No) + return; + } + + /* undock/hide/center extra docks */ + for (int i = extraDocks.size() - 1; i >= 0 ; i--) { + if (extraDocks[i]) { + extraDocks[i]->setVisible(true); + extraDocks[i]->setFloating(true); + extraDocks[i]->move( + frameGeometry().topLeft() + + rect().center() - + extraDocks[i]->rect().center()); + extraDocks[i]->setVisible(false); + } + } + restoreState(startingDockLayout); #if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0) @@ -6273,6 +6303,14 @@ void OBSBasic::on_lockUI_toggled(bool lock) ui->transitionsDock->setFeatures(features); ui->controlsDock->setFeatures(features); statsDock->setFeatures(features); + + for (int i = extraDocks.size() - 1; i >= 0 ; i--) { + if (!extraDocks[i]) { + extraDocks.removeAt(i); + } else { + extraDocks[i]->setFeatures(features); + } + } } void OBSBasic::on_toggleListboxToolbars_toggled(bool visible) @@ -6858,6 +6896,30 @@ void OBSBasic::ResizeOutputSizeOfSource() on_actionFitToScreen_triggered(); } +QAction *OBSBasic::AddDockWidget(QDockWidget *dock) +{ + QAction *action = ui->viewMenuDocks->addAction(dock->windowTitle()); + action->setCheckable(true); + assignDockToggle(dock, action); + extraDocks.push_back(dock); + + bool lock = ui->lockUI->isChecked(); + QDockWidget::DockWidgetFeatures features = lock + ? QDockWidget::NoDockWidgetFeatures + : QDockWidget::AllDockWidgetFeatures; + + dock->setFeatures(features); + + /* prune deleted docks */ + for (int i = extraDocks.size() - 1; i >= 0 ; i--) { + if (!extraDocks[i]) { + extraDocks.removeAt(i); + } + } + + return action; +} + OBSBasic *OBSBasic::Get() { return reinterpret_cast(App()->GetMainWindow()); diff --git a/UI/window-basic-main.hpp b/UI/window-basic-main.hpp index 3b0f3d01e..652877a27 100644 --- a/UI/window-basic-main.hpp +++ b/UI/window-basic-main.hpp @@ -140,6 +140,8 @@ private: std::vector signalHandlers; + QList> extraDocks; + bool loaded = false; long disableSaving = 1; bool projectChanged = false; @@ -617,6 +619,8 @@ public: void CreatePropertiesWindow(obs_source_t *source); void CreateFiltersWindow(obs_source_t *source); + QAction *AddDockWidget(QDockWidget *dock); + static OBSBasic *Get(); protected: