From 27466154be97acb62b84656b5b63dcd2cf274f28 Mon Sep 17 00:00:00 2001 From: Dayo Lawal Date: Fri, 9 Jul 2021 15:10:20 -0500 Subject: [PATCH] AzQtApplication Window Signed-off-by: Dayo Lawal --- .../Application/AzQtApplication.h | 2 +- .../Window/AzQtApplicationWindow.cpp | 61 +++++++++++++ .../Window/AzQtApplicationWindow.h | 89 +++++++++++++++++++ .../AzQtComponents/azqtcomponents_files.cmake | 2 + .../Source/Window/MaterialEditorWindow.cpp | 44 +-------- .../Code/Source/Window/MaterialEditorWindow.h | 43 ++------- .../ShaderManagementConsoleApplication.cpp | 2 - .../Window/ShaderManagementConsoleWindow.cpp | 43 ++------- .../Window/ShaderManagementConsoleWindow.h | 44 ++------- 9 files changed, 175 insertions(+), 155 deletions(-) create mode 100644 Code/Framework/AzQtComponents/AzQtComponents/Application/Window/AzQtApplicationWindow.cpp create mode 100644 Code/Framework/AzQtComponents/AzQtComponents/Application/Window/AzQtApplicationWindow.h diff --git a/Code/Framework/AzQtComponents/AzQtComponents/Application/AzQtApplication.h b/Code/Framework/AzQtComponents/AzQtComponents/Application/AzQtApplication.h index 85e4400c31..60d582a50a 100644 --- a/Code/Framework/AzQtComponents/AzQtComponents/Application/AzQtApplication.h +++ b/Code/Framework/AzQtComponents/AzQtComponents/Application/AzQtApplication.h @@ -18,7 +18,7 @@ namespace AzQtComponents { - //! Base case for O3DE Tools Applications + //! Base class for O3DE Tools Applications class AZ_QT_COMPONENTS_API AzQtApplication : public QApplication { diff --git a/Code/Framework/AzQtComponents/AzQtComponents/Application/Window/AzQtApplicationWindow.cpp b/Code/Framework/AzQtComponents/AzQtComponents/Application/Window/AzQtApplicationWindow.cpp new file mode 100644 index 0000000000..b2dc0cf429 --- /dev/null +++ b/Code/Framework/AzQtComponents/AzQtComponents/Application/Window/AzQtApplicationWindow.cpp @@ -0,0 +1,61 @@ +/* +* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +* its licensors. +* +* For complete copyright and license terms please see the LICENSE at the root of this +* distribution (the "License"). All use of this software is governed by the License, +* or, if provided, by the license below or the license accompanying this file. Do not +* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* +*/ + +#include +#include + + +namespace AzQtComponents +{ + AzQtApplicationWindow::AzQtApplicationWindow(QWidget* parent /* = 0 */, const AZStd::string& objectName) + : AzQtComponents::DockMainWindow(parent) + { + m_advancedDockManager = new AzQtComponents::FancyDocking(this); + + setObjectName(objectName.c_str()); + setDockNestingEnabled(true); + setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea); + setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea); + setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea); + setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea); + + m_menuBar = new QMenuBar(this); + m_menuBar->setObjectName("MenuBar"); + setMenuBar(m_menuBar); + + m_centralWidget = new QWidget(this); + m_tabWidget = new AzQtComponents::TabWidget(m_centralWidget); + m_tabWidget->setObjectName("TabWidget"); + m_tabWidget->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Preferred); + m_tabWidget->setContentsMargins(0, 0, 0, 0); + + vl = new QVBoxLayout(m_centralWidget); + } + + void AzQtApplicationWindow::SelectPreviousTab() + { + if (m_tabWidget->count() > 1) + { + // Adding count to wrap around when index <= 0 + m_tabWidget->setCurrentIndex((m_tabWidget->currentIndex() + m_tabWidget->count() - 1) % m_tabWidget->count()); + } + } + + void AzQtApplicationWindow::SelectNextTab() + { + if (m_tabWidget->count() > 1) + { + m_tabWidget->setCurrentIndex((m_tabWidget->currentIndex() + 1) % m_tabWidget->count()); + } + } +} + diff --git a/Code/Framework/AzQtComponents/AzQtComponents/Application/Window/AzQtApplicationWindow.h b/Code/Framework/AzQtComponents/AzQtComponents/Application/Window/AzQtApplicationWindow.h new file mode 100644 index 0000000000..87d251f983 --- /dev/null +++ b/Code/Framework/AzQtComponents/AzQtComponents/Application/Window/AzQtApplicationWindow.h @@ -0,0 +1,89 @@ +/* + * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or + * its licensors. + * + * For complete copyright and license terms please see the LICENSE at the root of this + * distribution (the "License"). All use of this software is governed by the License, + * or, if provided, by the license below or the license accompanying this file. Do not + * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + */ + +#pragma once + +#if !defined(Q_MOC_RUN) +#include +#include +#include +#include + +AZ_PUSH_DISABLE_WARNING(4251 4800, "-Wunknown-warning-option") // disable warnings spawned by QT +#include +#include +#include +#include + +#include +#include +#include +#include +AZ_POP_DISABLE_WARNING +#endif + +namespace AzQtComponents +{ + /** + * //! Base class for O3DE Tools Applications Windows. Its responsibility is limited to initializing and connecting + * its panels, managing selection of assets, and performing high-level actions like saving. It contains... + */ + class AZ_QT_COMPONENTS_API AzQtApplicationWindow + : public AzQtComponents::DockMainWindow + { + Q_OBJECT + public: + AzQtApplicationWindow(QWidget* parent, const AZStd::string& objectName); + + protected: + virtual void SetupMenu() {}; + virtual void SetupTabs() {}; + + virtual void OpenTabContextMenu() {}; + + void SelectPreviousTab(); + void SelectNextTab(); + + AzQtComponents::FancyDocking* m_advancedDockManager = nullptr; + QMenuBar* m_menuBar = nullptr; + QWidget* m_centralWidget = nullptr; + AzQtComponents::TabWidget* m_tabWidget = nullptr; + + QVBoxLayout* vl; + + QMenu* m_menuFile = {}; + QAction* m_actionOpen = {}; + QAction* m_actionOpenRecent = {}; + QAction* m_actionClose = {}; + QAction* m_actionCloseAll = {}; + QAction* m_actionCloseOthers = {}; + QAction* m_actionSave = {}; + QAction* m_actionSaveAsCopy = {}; + QAction* m_actionSaveAll = {}; + QAction* m_actionExit = {}; + + QMenu* m_menuEdit = {}; + QAction* m_actionUndo = {}; + QAction* m_actionRedo = {}; + QAction* m_actionSettings = {}; + + QMenu* m_menuView = {}; + QAction* m_actionAssetBrowser = {}; + QAction* m_actionPythonTerminal = {}; + QAction* m_actionNextTab = {}; + QAction* m_actionPreviousTab = {}; + + QMenu* m_menuHelp = {}; + QAction* m_actionHelp = {}; + QAction* m_actionAbout = {}; + }; +} // namespace ShaderManagementConsole diff --git a/Code/Framework/AzQtComponents/AzQtComponents/azqtcomponents_files.cmake b/Code/Framework/AzQtComponents/AzQtComponents/azqtcomponents_files.cmake index bcfbb84778..98882c5132 100644 --- a/Code/Framework/AzQtComponents/AzQtComponents/azqtcomponents_files.cmake +++ b/Code/Framework/AzQtComponents/AzQtComponents/azqtcomponents_files.cmake @@ -9,6 +9,8 @@ set(FILES AzQtComponentsAPI.h Application/AzQtApplication.cpp Application/AzQtApplication.h + Application/Window/AzQtApplicationWindow.cpp + Application/Window/AzQtApplicationWindow.h Buses/DragAndDrop.h Buses/ShortcutDispatch.h DragAndDrop/MainWindowDragAndDrop.h diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindow.cpp b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindow.cpp index 7c3a912b95..3e39526689 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindow.cpp +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindow.cpp @@ -55,7 +55,7 @@ AZ_POP_DISABLE_WARNING namespace MaterialEditor { MaterialEditorWindow::MaterialEditorWindow(QWidget* parent /* = 0 */) - : AzQtComponents::DockMainWindow(parent) + : AzQtComponents::AzQtApplicationWindow(parent, "MaterialEditorWindow") { resize(1280, 1024); @@ -82,45 +82,25 @@ namespace MaterialEditor setWindowTitle(QApplication::applicationName()); } - m_advancedDockManager = new AzQtComponents::FancyDocking(this); - - setObjectName("MaterialEditorWindow"); - setDockNestingEnabled(true); - setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea); - setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea); - setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea); - setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea); - - m_menuBar = new QMenuBar(this); - m_menuBar->setObjectName("MenuBar"); - setMenuBar(m_menuBar); - m_toolBar = new MaterialEditorToolBar(this); m_toolBar->setObjectName("ToolBar"); addToolBar(m_toolBar); - m_centralWidget = new QWidget(this); - m_tabWidget = new AzQtComponents::TabWidget(m_centralWidget); - m_tabWidget->setObjectName("TabWidget"); - m_tabWidget->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Preferred); - m_tabWidget->setContentsMargins(0, 0, 0, 0); - m_materialViewport = new MaterialViewportWidget(m_centralWidget); m_materialViewport->setObjectName("Viewport"); m_materialViewport->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); - - QVBoxLayout* vl = new QVBoxLayout(m_centralWidget); + vl->setMargin(0); vl->setContentsMargins(0, 0, 0, 0); vl->addWidget(m_tabWidget); vl->addWidget(m_materialViewport); m_centralWidget->setLayout(vl); setCentralWidget(m_centralWidget); - + m_statusBar = new StatusBarWidget(this); m_statusBar->setObjectName("StatusBar"); statusBar()->addPermanentWidget(m_statusBar, 1); - + SetupMenu(); SetupTabs(); @@ -738,22 +718,6 @@ namespace MaterialEditor } } - void MaterialEditorWindow::SelectPreviousTab() - { - if (m_tabWidget->count() > 1) - { - // Adding count to wrap around when index <= 0 - m_tabWidget->setCurrentIndex((m_tabWidget->currentIndex() + m_tabWidget->count() - 1) % m_tabWidget->count()); - } - } - - void MaterialEditorWindow::SelectNextTab() - { - if (m_tabWidget->count() > 1) - { - m_tabWidget->setCurrentIndex((m_tabWidget->currentIndex() + 1) % m_tabWidget->count()); - } - } } // namespace MaterialEditor #include diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindow.h b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindow.h index 165767ecc5..b96ceb2aa4 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindow.h +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindow.h @@ -12,10 +12,11 @@ #include AZ_PUSH_DISABLE_WARNING(4251 4800, "-Wunknown-warning-option") // disable warnings spawned by QT -#include +//#include #include #include #include +#include #include #include @@ -43,7 +44,7 @@ namespace MaterialEditor * 3) MaterialPropertyInspector - The user edits the properties of the selected Material. */ class MaterialEditorWindow - : public AzQtComponents::DockMainWindow + : public AzQtComponents::AzQtApplicationWindow , private MaterialEditorWindowRequestBus::Handler , private MaterialDocumentNotificationBus::Handler { @@ -74,61 +75,31 @@ namespace MaterialEditor void OnDocumentUndoStateChanged(const AZ::Uuid& documentId) override; void OnDocumentSaved(const AZ::Uuid& documentId) override; - void SetupMenu(); + void SetupMenu() override; + void SetupTabs() override; - void SetupTabs(); void AddTabForDocumentId(const AZ::Uuid& documentId); void RemoveTabForDocumentId(const AZ::Uuid& documentId); void UpdateTabForDocumentId(const AZ::Uuid& documentId); - QString GetDocumentPath(const AZ::Uuid& documentId) const; AZ::Uuid GetDocumentIdFromTab(const int tabIndex) const; + QString GetDocumentPath(const AZ::Uuid& documentId) const; - void OpenTabContextMenu(); - void SelectPreviousTab(); - void SelectNextTab(); + void OpenTabContextMenu() override; void closeEvent(QCloseEvent* closeEvent) override; - AzQtComponents::FancyDocking* m_advancedDockManager = nullptr; - QWidget* m_centralWidget = nullptr; - QMenuBar* m_menuBar = nullptr; - AzQtComponents::TabWidget* m_tabWidget = nullptr; MaterialViewportWidget* m_materialViewport = nullptr; MaterialEditorToolBar* m_toolBar = nullptr; AZStd::unordered_map m_dockWidgets; - QMenu* m_menuFile = {}; QAction* m_actionNew = {}; - QAction* m_actionOpen = {}; - QAction* m_actionOpenRecent = {}; - QAction* m_actionClose = {}; - QAction* m_actionCloseAll = {}; - QAction* m_actionCloseOthers = {}; - QAction* m_actionSave = {}; - QAction* m_actionSaveAsCopy = {}; QAction* m_actionSaveAsChild = {}; - QAction* m_actionSaveAll = {}; - QAction* m_actionExit = {}; - QMenu* m_menuEdit = {}; - QAction* m_actionUndo = {}; - QAction* m_actionRedo = {}; - QAction* m_actionSettings = {}; - - QMenu* m_menuView = {}; - QAction* m_actionAssetBrowser = {}; QAction* m_actionInspector = {}; QAction* m_actionConsole = {}; - QAction* m_actionPythonTerminal = {}; QAction* m_actionPerfMonitor = {}; QAction* m_actionViewportSettings = {}; - QAction* m_actionNextTab = {}; - QAction* m_actionPreviousTab = {}; - - QMenu* m_menuHelp = {}; - QAction* m_actionHelp = {}; - QAction* m_actionAbout = {}; StatusBarWidget* m_statusBar = {}; }; diff --git a/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/ShaderManagementConsoleApplication.cpp b/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/ShaderManagementConsoleApplication.cpp index f5ee1f5bcb..d10893ff46 100644 --- a/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/ShaderManagementConsoleApplication.cpp +++ b/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/ShaderManagementConsoleApplication.cpp @@ -152,7 +152,6 @@ namespace ShaderManagementConsole { AzFramework::AssetSystemStatusBus::Handler::BusConnect(); AzToolsFramework::EditorPythonConsoleNotificationBus::Handler::BusConnect(); - AZ::Debug::TraceMessageBus::Handler::BusConnect(); AzFramework::Application::StartCommon(systemEntity); @@ -164,7 +163,6 @@ namespace ShaderManagementConsole void ShaderManagementConsoleApplication::OnShaderManagementConsoleWindowClosing() { ExitMainLoop(); - AZ::Debug::TraceMessageBus::Handler::BusDisconnect(); ShaderManagementConsoleWindowNotificationBus::Handler::BusDisconnect(); AzToolsFramework::EditorPythonConsoleNotificationBus::Handler::BusDisconnect(); } diff --git a/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/Window/ShaderManagementConsoleWindow.cpp b/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/Window/ShaderManagementConsoleWindow.cpp index 103299a361..dde818d9e6 100644 --- a/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/Window/ShaderManagementConsoleWindow.cpp +++ b/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/Window/ShaderManagementConsoleWindow.cpp @@ -37,30 +37,14 @@ AZ_POP_DISABLE_WARNING namespace ShaderManagementConsole { ShaderManagementConsoleWindow::ShaderManagementConsoleWindow(QWidget* parent /* = 0 */) - : AzQtComponents::DockMainWindow(parent) + : AzQtComponents::AzQtApplicationWindow(parent, "ShaderManagementConsoleWindow") { setWindowTitle("Shader Management Console"); - m_advancedDockManager = new AzQtComponents::FancyDocking(this); - - setDockNestingEnabled(true); - setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea); - setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea); - setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea); - setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea); - - m_menuBar = new QMenuBar(this); - setMenuBar(m_menuBar); - m_toolBar = new ShaderManagementConsoleToolBar(this); + m_toolBar->setObjectName("ToolBar"); addToolBar(m_toolBar); - m_centralWidget = new QWidget(this); - m_tabWidget = new AzQtComponents::TabWidget(m_centralWidget); - m_tabWidget->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Preferred); - m_tabWidget->setContentsMargins(0, 0, 0, 0); - - QVBoxLayout* vl = new QVBoxLayout(m_centralWidget); vl->setMargin(0); vl->setContentsMargins(0, 0, 0, 0); vl->addWidget(m_tabWidget); @@ -143,7 +127,7 @@ namespace ShaderManagementConsole m_actionUndo->setEnabled(canUndo); m_actionRedo->setEnabled(canRedo); - m_actionPreferences->setEnabled(false); + m_actionSettings->setEnabled(false); m_actionAssetBrowser->setEnabled(true); m_actionPythonTerminal->setEnabled(true); @@ -263,9 +247,9 @@ namespace ShaderManagementConsole m_menuEdit->addSeparator(); - m_actionPreferences = m_menuEdit->addAction("&Preferences...", [this]() { + m_actionSettings = m_menuEdit->addAction("&Preferences...", [this]() { }, QKeySequence::Preferences); - m_actionPreferences->setEnabled(false); + m_actionSettings->setEnabled(false); m_menuView = m_menuBar->addMenu("&View"); @@ -471,23 +455,6 @@ namespace ShaderManagementConsole } } - void ShaderManagementConsoleWindow::SelectPreviousTab() - { - if (m_tabWidget->count() > 1) - { - // Adding count to wrap around when index <= 0 - m_tabWidget->setCurrentIndex((m_tabWidget->currentIndex() + m_tabWidget->count() - 1) % m_tabWidget->count()); - } - } - - void ShaderManagementConsoleWindow::SelectNextTab() - { - if (m_tabWidget->count() > 1) - { - m_tabWidget->setCurrentIndex((m_tabWidget->currentIndex() + 1) % m_tabWidget->count()); - } - } - void ShaderManagementConsoleWindow::SelectDocumentForTab(const int tabIndex) { const AZ::Uuid documentId = GetDocumentIdFromTab(tabIndex); diff --git a/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/Window/ShaderManagementConsoleWindow.h b/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/Window/ShaderManagementConsoleWindow.h index 0f8824f809..9201be8db0 100644 --- a/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/Window/ShaderManagementConsoleWindow.h +++ b/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/Window/ShaderManagementConsoleWindow.h @@ -15,10 +15,11 @@ #include AZ_PUSH_DISABLE_WARNING(4251 4800, "-Wunknown-warning-option") // disable warnings spawned by QT -#include +//#include #include #include #include +#include #include #include @@ -41,7 +42,7 @@ namespace ShaderManagementConsole * its panels, managing selection of assets, and performing high-level actions like saving. It contains... */ class ShaderManagementConsoleWindow - : public AzQtComponents::DockMainWindow + : public AzQtComponents::AzQtApplicationWindow , private ShaderManagementConsoleDocumentNotificationBus::Handler { Q_OBJECT @@ -59,17 +60,15 @@ namespace ShaderManagementConsole void OnDocumentUndoStateChanged(const AZ::Uuid& documentId) override; void OnDocumentSaved(const AZ::Uuid& documentId) override; - void SetupMenu(); + void SetupMenu() override; + void SetupTabs() override; - void SetupTabs(); void AddTabForDocumentId(const AZ::Uuid& documentId); void RemoveTabForDocumentId(const AZ::Uuid& documentId); void UpdateTabForDocumentId(const AZ::Uuid& documentId); AZ::Uuid GetDocumentIdFromTab(const int tabIndex) const; - void OpenTabContextMenu(); - void SelectPreviousTab(); - void SelectNextTab(); + void OpenTabContextMenu() override; void SelectDocumentForTab(const int tabIndex); void CloseDocumentForTab(const int tabIndex); @@ -79,42 +78,11 @@ namespace ShaderManagementConsole void CreateDocumentContent(const AZ::Uuid& documentId, QStandardItemModel* model); - AzQtComponents::FancyDocking* m_advancedDockManager = nullptr; - QMenuBar* m_menuBar = nullptr; - QWidget* m_centralWidget = nullptr; - AzQtComponents::TabWidget* m_tabWidget = nullptr; ShaderManagementConsoleBrowserWidget* m_assetBrowser = nullptr; ShaderManagementConsoleToolBar* m_toolBar = nullptr; AzToolsFramework::CScriptTermDialog* m_pythonTerminal = nullptr; AzQtComponents::StyledDockWidget* m_assetBrowserDockWidget = nullptr; AzQtComponents::StyledDockWidget* m_pythonTerminalDockWidget = nullptr; - - QMenu* m_menuFile = {}; - QMenu* m_menuNew = {}; - QAction* m_actionOpen = {}; - QAction* m_actionOpenRecent = {}; - QAction* m_actionClose = {}; - QAction* m_actionCloseAll = {}; - QAction* m_actionCloseOthers = {}; - QAction* m_actionSave = {}; - QAction* m_actionSaveAsCopy = {}; - QAction* m_actionSaveAll = {}; - QAction* m_actionExit = {}; - - QMenu* m_menuEdit = {}; - QAction* m_actionUndo = {}; - QAction* m_actionRedo = {}; - QAction* m_actionPreferences = {}; - - QMenu* m_menuView = {}; - QAction* m_actionAssetBrowser = {}; - QAction* m_actionPythonTerminal = {}; - QAction* m_actionNextTab = {}; - QAction* m_actionPreviousTab = {}; - - QMenu* m_menuHelp = {}; - QAction* m_actionHelp = {}; - QAction* m_actionAbout = {}; }; } // namespace ShaderManagementConsole