diff --git a/app/core.cpp b/app/core.cpp index 136af0803..f1e7bcdb1 100644 --- a/app/core.cpp +++ b/app/core.cpp @@ -117,6 +117,8 @@ void Core::Stop() // Save Config //Config::Save(); + PanelManager::DestroyInstance(); + AudioManager::DestroyInstance(); NodeFactory::Destroy(); @@ -199,7 +201,7 @@ void Core::DialogImportShow() if (!files.isEmpty()) { // Locate the most recently focused Project panel (assume that's the panel the user wants to import into) - ProjectPanel* active_project_panel = olive::panel_manager->MostRecentlyFocused(); + ProjectPanel* active_project_panel = PanelManager::instance()->MostRecentlyFocused(); Project* active_project; if (active_project_panel == nullptr // Check that we found a Project panel @@ -229,7 +231,7 @@ void Core::DialogProjectPropertiesShow() void Core::DialogExportShow() { - ViewerPanel* latest_viewer = olive::panel_manager->MostRecentlyFocused(); + ViewerPanel* latest_viewer = PanelManager::instance()->MostRecentlyFocused(); if (latest_viewer && latest_viewer->GetConnectedViewer()) { if (latest_viewer->GetConnectedViewer()->Length() == 0) { @@ -247,7 +249,7 @@ void Core::DialogExportShow() void Core::CreateNewFolder() { // Locate the most recently focused Project panel (assume that's the panel the user wants to import into) - ProjectPanel* active_project_panel = olive::panel_manager->MostRecentlyFocused(); + ProjectPanel* active_project_panel = PanelManager::instance()->MostRecentlyFocused(); Project* active_project; if (active_project_panel == nullptr // Check that we found a Project panel @@ -279,7 +281,7 @@ void Core::CreateNewFolder() void Core::CreateNewSequence() { // Locate the most recently focused Project panel (assume that's the panel the user wants to import into) - ProjectPanel* active_project_panel = olive::panel_manager->MostRecentlyFocused(); + ProjectPanel* active_project_panel = PanelManager::instance()->MostRecentlyFocused(); Project* active_project; if (active_project_panel == nullptr // Check that we found a Project panel @@ -355,12 +357,12 @@ void Core::StartGUI(bool full_screen) olive::menu_shared.Initialize(); // Since we're starting GUI mode, create a PanelFocusManager (auto-deletes with QObject) - olive::panel_manager = new PanelManager(this); + PanelManager::CreateInstance(); // Connect the PanelFocusManager to the application's focus change signal connect(qApp, SIGNAL(focusChanged(QWidget*, QWidget*)), - olive::panel_manager, + PanelManager::instance(), SLOT(FocusChanged(QWidget*, QWidget*))); // Create main window and open it @@ -394,7 +396,7 @@ void Core::SaveAutorecovery() Project *Core::GetActiveProject() { // Locate the most recently focused Project panel (assume that's the panel the user wants to import into) - ProjectPanel* active_project_panel = olive::panel_manager->MostRecentlyFocused(); + ProjectPanel* active_project_panel = PanelManager::instance()->MostRecentlyFocused(); // If we couldn't find one, return nullptr if (active_project_panel == nullptr) { diff --git a/app/panel/panelmanager.cpp b/app/panel/panelmanager.cpp index de9c5181e..62eec13fd 100644 --- a/app/panel/panelmanager.cpp +++ b/app/panel/panelmanager.cpp @@ -22,7 +22,7 @@ #include "config/config.h" -PanelManager* olive::panel_manager = nullptr; +PanelManager* PanelManager::instance_ = nullptr; PanelManager::PanelManager(QObject *parent) : QObject(parent), @@ -78,6 +78,21 @@ bool PanelManager::ArePanelsLocked() return locked_; } +void PanelManager::CreateInstance() +{ + instance_ = new PanelManager(); +} + +void PanelManager::DestroyInstance() +{ + delete instance_; +} + +PanelManager *PanelManager::instance() +{ + return instance_; +} + void PanelManager::FocusChanged(QWidget *old, QWidget *now) { Q_UNUSED(old) diff --git a/app/panel/panelmanager.h b/app/panel/panelmanager.h index 28a9ab6a5..6e21bfcb5 100644 --- a/app/panel/panelmanager.h +++ b/app/panel/panelmanager.h @@ -44,7 +44,7 @@ class PanelManager : public QObject { Q_OBJECT public: - PanelManager(QObject* parent); + PanelManager(QObject* parent = nullptr); /** * @brief Destroy all panels @@ -97,6 +97,23 @@ public: */ bool ArePanelsLocked(); + /** + * @brief Create PanelManager singleton instance + */ + static void CreateInstance(); + + /** + * @brief Destroy PanelManager singleton instance + * + * If no PanelManager was created, this is a no-op. + */ + static void DestroyInstance(); + + /** + * @brief Access to PanelManager singleton instance + */ + static PanelManager* instance(); + public slots: /** * @brief Connect this to a QApplication's SIGNAL(focusChanged()) @@ -120,6 +137,11 @@ private: * @brief Internal panel movement is locked value */ bool locked_; + + /** + * @brief PanelManager singleton instance + */ + static PanelManager* instance_; }; template @@ -151,8 +173,4 @@ T* PanelManager::MostRecentlyFocused() return nullptr; } -namespace olive { -extern PanelManager* panel_manager; -} - #endif // PANELFOCUSMANAGER_H diff --git a/app/project/item/sequence/sequence.cpp b/app/project/item/sequence/sequence.cpp index b5debc99f..3f04d8520 100644 --- a/app/project/item/sequence/sequence.cpp +++ b/app/project/item/sequence/sequence.cpp @@ -40,9 +40,9 @@ void Sequence::Open(SequencePtr sequence) { // FIXME: This is fairly "hardcoded" behavior and doesn't support infinite panels - ViewerPanel* viewer_panel = olive::panel_manager->MostRecentlyFocused(); - TimelinePanel* timeline_panel = olive::panel_manager->MostRecentlyFocused(); - NodePanel* node_panel = olive::panel_manager->MostRecentlyFocused(); + ViewerPanel* viewer_panel = PanelManager::instance()->MostRecentlyFocused(); + TimelinePanel* timeline_panel = PanelManager::instance()->MostRecentlyFocused(); + NodePanel* node_panel = PanelManager::instance()->MostRecentlyFocused(); viewer_panel->ConnectViewerNode(sequence->viewer_output_); timeline_panel->ConnectTimelineNode(sequence->timeline_output_); diff --git a/app/widget/menu/menushared.cpp b/app/widget/menu/menushared.cpp index 213c0eece..837ae69d4 100644 --- a/app/widget/menu/menushared.cpp +++ b/app/widget/menu/menushared.cpp @@ -103,7 +103,7 @@ void MenuShared::AddItemsForClipEditMenu(Menu *m) void MenuShared::SplitAtPlayhead() { - TimelinePanel* timeline = olive::panel_manager->MostRecentlyFocused(); + TimelinePanel* timeline = PanelManager::instance()->MostRecentlyFocused(); if (timeline != nullptr) { timeline->SplitAtPlayhead(); @@ -112,7 +112,7 @@ void MenuShared::SplitAtPlayhead() void MenuShared::DeleteSelected() { - olive::panel_manager->CurrentlyFocused()->DeleteSelected(); + PanelManager::instance()->CurrentlyFocused()->DeleteSelected(); } void MenuShared::Retranslate() diff --git a/app/window/mainwindow/mainmenu.cpp b/app/window/mainwindow/mainmenu.cpp index aa09e0e15..eba46faba 100644 --- a/app/window/mainwindow/mainmenu.cpp +++ b/app/window/mainwindow/mainmenu.cpp @@ -198,7 +198,7 @@ MainMenu::MainMenu(QMainWindow *parent) : connect(window_menu_, SIGNAL(aboutToHide()), this, SLOT(WindowMenuAboutToHide())); window_menu_separator_ = window_menu_->addSeparator(); window_maximize_panel_item_ = window_menu_->AddItem("maximizepanel", parent, SLOT(ToggleMaximizedPanel()), "`"); - window_lock_layout_item_ = window_menu_->AddItem("lockpanels", olive::panel_manager, SLOT(SetPanelsLocked(bool))); + window_lock_layout_item_ = window_menu_->AddItem("lockpanels", PanelManager::instance(), SLOT(SetPanelsLocked(bool))); window_lock_layout_item_->setCheckable(true); window_menu_->addSeparator(); window_reset_layout_item_ = window_menu_->AddItem("resetdefaultlayout", nullptr, nullptr); @@ -368,7 +368,7 @@ void MainMenu::WindowMenuAboutToShow() window_menu_->insertActions(window_menu_separator_, panel_menu_actions); - window_lock_layout_item_->setChecked(olive::panel_manager->ArePanelsLocked()); + window_lock_layout_item_->setChecked(PanelManager::instance()->ArePanelsLocked()); } void MainMenu::WindowMenuAboutToHide() @@ -380,67 +380,67 @@ void MainMenu::WindowMenuAboutToHide() void MainMenu::ZoomInTriggered() { - olive::panel_manager->CurrentlyFocused()->ZoomIn(); + PanelManager::instance()->CurrentlyFocused()->ZoomIn(); } void MainMenu::ZoomOutTriggered() { - olive::panel_manager->CurrentlyFocused()->ZoomOut(); + PanelManager::instance()->CurrentlyFocused()->ZoomOut(); } void MainMenu::GoToStartTriggered() { - olive::panel_manager->CurrentlyFocused()->GoToStart(); + PanelManager::instance()->CurrentlyFocused()->GoToStart(); } void MainMenu::PrevFrameTriggered() { - olive::panel_manager->CurrentlyFocused()->PrevFrame(); + PanelManager::instance()->CurrentlyFocused()->PrevFrame(); } void MainMenu::PlayPauseTriggered() { - olive::panel_manager->CurrentlyFocused()->PlayPause(); + PanelManager::instance()->CurrentlyFocused()->PlayPause(); } void MainMenu::NextFrameTriggered() { - olive::panel_manager->CurrentlyFocused()->NextFrame(); + PanelManager::instance()->CurrentlyFocused()->NextFrame(); } void MainMenu::GoToEndTriggered() { - olive::panel_manager->CurrentlyFocused()->GoToEnd(); + PanelManager::instance()->CurrentlyFocused()->GoToEnd(); } void MainMenu::SelectAllTriggered() { - olive::panel_manager->CurrentlyFocused()->SelectAll(); + PanelManager::instance()->CurrentlyFocused()->SelectAll(); } void MainMenu::DeselectAllTriggered() { - olive::panel_manager->CurrentlyFocused()->DeselectAll(); + PanelManager::instance()->CurrentlyFocused()->DeselectAll(); } void MainMenu::RippleToInTriggered() { - olive::panel_manager->CurrentlyFocused()->RippleToIn(); + PanelManager::instance()->CurrentlyFocused()->RippleToIn(); } void MainMenu::RippleToOutTriggered() { - olive::panel_manager->CurrentlyFocused()->RippleToOut(); + PanelManager::instance()->CurrentlyFocused()->RippleToOut(); } void MainMenu::EditToInTriggered() { - olive::panel_manager->CurrentlyFocused()->EditToIn(); + PanelManager::instance()->CurrentlyFocused()->EditToIn(); } void MainMenu::EditToOutTriggered() { - olive::panel_manager->CurrentlyFocused()->EditToOut(); + PanelManager::instance()->CurrentlyFocused()->EditToOut(); } void MainMenu::ActionSearchTriggered() @@ -452,27 +452,27 @@ void MainMenu::ActionSearchTriggered() void MainMenu::ShuttleLeftTriggered() { - olive::panel_manager->CurrentlyFocused()->ShuttleLeft(); + PanelManager::instance()->CurrentlyFocused()->ShuttleLeft(); } void MainMenu::ShuttleStopTriggered() { - olive::panel_manager->CurrentlyFocused()->ShuttleStop(); + PanelManager::instance()->CurrentlyFocused()->ShuttleStop(); } void MainMenu::ShuttleRightTriggered() { - olive::panel_manager->CurrentlyFocused()->ShuttleRight(); + PanelManager::instance()->CurrentlyFocused()->ShuttleRight(); } void MainMenu::GoToPrevCutTriggered() { - olive::panel_manager->CurrentlyFocused()->GoToPrevCut(); + PanelManager::instance()->CurrentlyFocused()->GoToPrevCut(); } void MainMenu::GoToNextCutTriggered() { - olive::panel_manager->CurrentlyFocused()->GoToNextCut(); + PanelManager::instance()->CurrentlyFocused()->GoToNextCut(); } void MainMenu::Retranslate() diff --git a/app/window/mainwindow/mainwindow.cpp b/app/window/mainwindow/mainwindow.cpp index 46e9ed80b..00d9cbe7b 100644 --- a/app/window/mainwindow/mainwindow.cpp +++ b/app/window/mainwindow/mainwindow.cpp @@ -79,7 +79,7 @@ void olive::MainWindow::ToggleMaximizedPanel() // Assume nothing is maximized at the moment // Find the currently focused panel - PanelWidget* currently_hovered = olive::panel_manager->CurrentlyHovered(); + PanelWidget* currently_hovered = PanelManager::instance()->CurrentlyHovered(); // If no panel is hovered, do nothing if (currently_hovered == nullptr) { @@ -95,7 +95,7 @@ void olive::MainWindow::ToggleMaximizedPanel() premaximized_state_ = saveState(); // For every other panel that is on the main window, hide it - foreach (PanelWidget* panel, olive::panel_manager->panels()) { + foreach (PanelWidget* panel, PanelManager::instance()->panels()) { if (!panel->isFloating() && panel != currently_hovered) { panel->setVisible(false); } @@ -110,29 +110,29 @@ void olive::MainWindow::ToggleMaximizedPanel() void olive::MainWindow::ProjectOpen(Project* p) { // FIXME Use settings data to create panels and restore state if they exist - NodePanel* node_panel = olive::panel_manager->CreatePanel(this); + NodePanel* node_panel = PanelManager::instance()->CreatePanel(this); addDockWidget(Qt::TopDockWidgetArea, node_panel); - ParamPanel* param_panel = olive::panel_manager->CreatePanel(this); + ParamPanel* param_panel = PanelManager::instance()->CreatePanel(this); addDockWidget(Qt::TopDockWidgetArea, param_panel); - ViewerPanel* viewer_panel2 = olive::panel_manager->CreatePanel(this); + ViewerPanel* viewer_panel2 = PanelManager::instance()->CreatePanel(this); addDockWidget(Qt::TopDockWidgetArea, viewer_panel2); - ProjectPanel* project_panel = olive::panel_manager->CreatePanel(this); + ProjectPanel* project_panel = PanelManager::instance()->CreatePanel(this); project_panel->set_project(p); addDockWidget(Qt::BottomDockWidgetArea, project_panel); - ToolPanel* tool_panel = olive::panel_manager->CreatePanel(this); + ToolPanel* tool_panel = PanelManager::instance()->CreatePanel(this); addDockWidget(Qt::BottomDockWidgetArea, tool_panel); - TimelinePanel* timeline_panel = olive::panel_manager->CreatePanel(this); + TimelinePanel* timeline_panel = PanelManager::instance()->CreatePanel(this); addDockWidget(Qt::BottomDockWidgetArea, timeline_panel); - AudioMonitorPanel* audio_monitor_panel = olive::panel_manager->CreatePanel(this); + AudioMonitorPanel* audio_monitor_panel = PanelManager::instance()->CreatePanel(this); addDockWidget(Qt::BottomDockWidgetArea, audio_monitor_panel); - TaskManagerPanel* task_man_panel = olive::panel_manager->CreatePanel(this); + TaskManagerPanel* task_man_panel = PanelManager::instance()->CreatePanel(this); addDockWidget(Qt::BottomDockWidgetArea, task_man_panel); task_man_panel->setFloating(true); task_man_panel->setVisible(false); @@ -147,7 +147,7 @@ void olive::MainWindow::ProjectOpen(Project* p) void olive::MainWindow::closeEvent(QCloseEvent *e) { - olive::panel_manager->DeleteAllPanels(); + PanelManager::instance()->DeleteAllPanels(); // FIXME: Test code - We have no cache management and the cache is very much testing only, so we delete it on close // as to not clog up HDD space