AtomToolsMainWindow

Signed-off-by: Dayo Lawal <lawalfua@amazon.com>
This commit is contained in:
Dayo Lawal
2021-08-02 00:34:43 -05:00
parent 3cd40b151e
commit 8eb9205711
7 changed files with 217 additions and 218 deletions
@@ -0,0 +1,48 @@
/*
* Copyright (c) Contributors to the Open 3D Engine Project.
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
#pragma once
#include <AzCore/Memory/SystemAllocator.h>
#include <AzQtComponents/Components/DockMainWindow.h>
#include <AzQtComponents/Components/FancyDocking.h>
#include <AzQtComponents/Components/StyledDockWidget.h>
#include <AzQtComponents/Components/Widgets/TabWidget.h>
#include <QMenuBar>
#include <QStatusBar>
#include <QToolBar>
namespace AtomToolsFramework
{
class AtomToolsMainWindow
: public AzQtComponents::DockMainWindow
{
public:
AtomToolsMainWindow(QWidget* parent = 0);
protected:
AzQtComponents::FancyDocking* m_advancedDockManager = nullptr;
QWidget* m_centralWidget = nullptr;
QMenuBar* m_menuBar = nullptr;
AzQtComponents::TabWidget* m_tabWidget = nullptr;
virtual void SetupMenu();
virtual void SetupTabs();
virtual void AddTabForDocumentId(const AZ::Uuid& documentId);
virtual void RemoveTabForDocumentId(const AZ::Uuid& documentId);
virtual void UpdateTabForDocumentId(const AZ::Uuid& documentId);
virtual AZ::Uuid GetDocumentIdFromTab(const int tabIndex) const;
virtual void OpenTabContextMenu();
virtual void SelectPreviousTab();
virtual void SelectNextTab();
QMenu* m_menuFile = {};
};
}
@@ -0,0 +1,135 @@
/*
* Copyright (c) Contributors to the Open 3D Engine Project.
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
#include <AtomToolsFramework/Window/AtomToolsMainWindow.h>
namespace AtomToolsFramework
{
AtomToolsMainWindow::AtomToolsMainWindow(QWidget* parent)
: AzQtComponents::DockMainWindow(parent)
{
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);
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);
}
void AtomToolsMainWindow::SetupMenu()
{
// Generating the main menu manually because it's easier and we will have some dynamic or data driven entries
m_menuFile = m_menuBar->addMenu("&File");
}
void AtomToolsMainWindow::SetupTabs()
{
// The tab bar should only be visible if it has active documents
m_tabWidget->setVisible(false);
m_tabWidget->setTabBarAutoHide(false);
m_tabWidget->setMovable(true);
m_tabWidget->setTabsClosable(true);
m_tabWidget->setUsesScrollButtons(true);
// Add context menu for right-clicking on tabs
m_tabWidget->setContextMenuPolicy(Qt::ContextMenuPolicy::CustomContextMenu);
connect(m_tabWidget, &QWidget::customContextMenuRequested, this, [this]() {
OpenTabContextMenu();
});
}
void AtomToolsMainWindow::AddTabForDocumentId(const AZ::Uuid& documentId)
{
// Blocking signals from the tab bar so the currentChanged signal is not sent while a document is already being opened.
// This prevents the OnDocumentOpened notification from being sent recursively.
const QSignalBlocker blocker(m_tabWidget);
// If a tab for this document already exists then select it instead of creating a new one
for (int tabIndex = 0; tabIndex < m_tabWidget->count(); ++tabIndex)
{
if (documentId == GetDocumentIdFromTab(tabIndex))
{
m_tabWidget->setCurrentIndex(tabIndex);
m_tabWidget->repaint();
return;
}
}
}
void AtomToolsMainWindow::RemoveTabForDocumentId(const AZ::Uuid& documentId)
{
// We are not blocking signals here because we want closing tabs to close the associated document
// and automatically select the next document.
for (int tabIndex = 0; tabIndex < m_tabWidget->count(); ++tabIndex)
{
if (documentId == GetDocumentIdFromTab(tabIndex))
{
m_tabWidget->removeTab(tabIndex);
m_tabWidget->setVisible(m_tabWidget->count() > 0);
m_tabWidget->repaint();
break;
}
}
}
void AtomToolsMainWindow::UpdateTabForDocumentId(const AZ::Uuid& documentId)
{
// Whenever a document is opened, saved, or modified we need to update the tab label
if (!documentId.IsNull())
{
return;
}
}
AZ::Uuid AtomToolsMainWindow::GetDocumentIdFromTab(const int tabIndex) const
{
const QVariant tabData = m_tabWidget->tabBar()->tabData(tabIndex);
if (!tabData.isNull())
{
// We need to be able to convert between a UUID and a string to store and retrieve a document ID from the tab bar
const QString documentIdString = tabData.toString();
const QByteArray documentIdBytes = documentIdString.toUtf8();
const AZ::Uuid documentId(documentIdBytes.data(), documentIdBytes.size());
return documentId;
}
return AZ::Uuid::CreateNull();
}
void AtomToolsMainWindow::OpenTabContextMenu()
{
}
void AtomToolsMainWindow::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 AtomToolsMainWindow::SelectNextTab()
{
if (m_tabWidget->count() > 1)
{
m_tabWidget->setCurrentIndex((m_tabWidget->currentIndex() + 1) % m_tabWidget->count());
}
}
}
@@ -24,6 +24,7 @@ set(FILES
Include/AtomToolsFramework/Viewport/RenderViewportWidget.h
Include/AtomToolsFramework/Viewport/ModularViewportCameraController.h
Include/AtomToolsFramework/Viewport/ModularViewportCameraControllerRequestBus.h
Include/AtomToolsFramework/Window/AtomToolsMainWindow.h
Source/Application/AtomToolsApplication.cpp
Source/Communication/LocalServer.cpp
Source/Communication/LocalSocket.cpp
@@ -40,4 +41,5 @@ set(FILES
Source/Util/Util.cpp
Source/Viewport/RenderViewportWidget.cpp
Source/Viewport/ModularViewportCameraController.cpp
Source/Window/AtomToolsMainWindow.cpp
)