diff --git a/Code/Framework/AzQtComponents/AzQtComponents/Application/ToolsApplication.cpp b/Code/Framework/AzQtComponents/AzQtComponents/Application/ToolsApplication.cpp new file mode 100644 index 0000000000..d077fbe211 --- /dev/null +++ b/Code/Framework/AzQtComponents/AzQtComponents/Application/ToolsApplication.cpp @@ -0,0 +1,174 @@ +/* + * 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 // This should be the first include to make sure Windows.h is defined with NOMINMAX + +namespace AzQtComponents +{ + /* + AZStd::string_view GetBuildTargetName() + { +#if !defined(LY_CMAKE_TARGET) +#error "LY_CMAKE_TARGET must be defined in order to add this source file to a CMake executable target" +#endif + return AZStd::string_view { LY_CMAKE_TARGET }; + } + */ + + class ToolsApplication::Impl + : private AZ::Debug::TraceMessageBus::Handler + , public AzFramework::Application + { + friend class ToolsApplication; + + public: + Impl(ToolsApplication* app) : m_app(app) + { + + } + ToolsApplication* m_app; + + bool OnOutput(const char* window, const char* message) override; + + protected: + struct LogMessage + { + AZStd::string window; + AZStd::string message; + }; + + AZStd::vector m_startupLogSink; + AZStd::unique_ptr m_logFile; + + }; + + ToolsApplication::ToolsApplication(int& argc, char** argv) + : QApplication(argc, argv) + , m_impl(new Impl(this)) + { + /* + QApplication::setOrganizationName("Amazon"); + QApplication::setOrganizationDomain("amazon.com"); + QApplication::setApplicationName("O3DEToolsApplication"); + + AzQtComponents::PrepareQtPaths(); + + QLocale::setDefault(QLocale(QLocale::English, QLocale::UnitedStates)); + + // Must be set before QApplication is initialized, so that we support HighDpi monitors, like the Retina displays + // on Windows 10 + + QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); + QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); + QCoreApplication::setAttribute(Qt::AA_DontCreateNativeWidgetSiblings); + QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough); + AzQtComponents::Utilities::HandleDpiAwareness(AzQtComponents::Utilities::SystemDpiAware); + */ + + //m_impl->AZ::Debug::TraceMessageBus::Handler::BusConnect(); + + } + + ToolsApplication::~ToolsApplication() + { + //m_impl->AZ::Debug::TraceMessageBus::Handler::BusDisconnect(); + } + + + bool ToolsApplication::Impl::OnOutput(const char* window, const char* message) + { + // Suppress spam from the Source Control system + constexpr char sourceControlWindow[] = "Source Control"; + + if (0 == strncmp(window, sourceControlWindow, AZ_ARRAY_SIZE(sourceControlWindow))) + { + return true; + } + + if (m_logFile) + { + m_logFile->AppendLog(AzFramework::LogFile::SEV_NORMAL, window, message); + } + else + { + m_startupLogSink.push_back({ window, message }); + } + return false; + } + + /* + bool ToolsApplication::AddDockWidget(const AZStd::string& name, QWidget* widget, uint32_t area, uint32_t orientation) + { + auto dockWidgetItr = m_dockWidgets.find(name); + if (dockWidgetItr != m_dockWidgets.end() || !widget) + { + return false; + } + + auto dockWidget = new AzQtComponents::StyledDockWidget(name.c_str()); + dockWidget->setObjectName(QString("%1_DockWidget").arg(name.c_str())); + dockWidget->setFeatures(QDockWidget::DockWidgetClosable | QDockWidget::DockWidgetFloatable | QDockWidget::DockWidgetMovable); + widget->setObjectName(name.c_str()); + widget->setParent(dockWidget); + widget->setMinimumSize(QSize(300, 300)); + dockWidget->setWidget(widget); + //QMainWindow::addDockWidget(aznumeric_cast(area), dockWidget); + //QMainWindow::resizeDocks({ dockWidget }, { 400 }, aznumeric_cast(orientation)); + m_dockWidgets[name] = dockWidget; + return true; + } + + void ToolsApplication::RemoveDockWidget(const AZStd::string& name) + { + auto dockWidgetItr = m_dockWidgets.find(name); + if (dockWidgetItr != m_dockWidgets.end()) + { + delete dockWidgetItr->second; + m_dockWidgets.erase(dockWidgetItr); + } + } + + void ToolsApplication::SetDockWidgetVisible(const AZStd::string& name, bool visible) + { + auto dockWidgetItr = m_dockWidgets.find(name); + if (dockWidgetItr != m_dockWidgets.end()) + { + dockWidgetItr->second->setVisible(visible); + } + } + + bool ToolsApplication::IsDockWidgetVisible(const AZStd::string& name) const + { + auto dockWidgetItr = m_dockWidgets.find(name); + if (dockWidgetItr != m_dockWidgets.end()) + { + return dockWidgetItr->second->isVisible(); + } + return false; + } + + AZStd::vector ToolsApplication::GetDockWidgetNames() const + { + AZStd::vector names; + names.reserve(m_dockWidgets.size()); + for (const auto& dockWidgetPair : m_dockWidgets) + { + names.push_back(dockWidgetPair.first); + } + return names; + } + */ + +} // namespace AzQtComponents + diff --git a/Code/Framework/AzQtComponents/AzQtComponents/Application/ToolsApplication.h b/Code/Framework/AzQtComponents/AzQtComponents/Application/ToolsApplication.h new file mode 100644 index 0000000000..a25507a14e --- /dev/null +++ b/Code/Framework/AzQtComponents/AzQtComponents/Application/ToolsApplication.h @@ -0,0 +1,84 @@ +/* + * 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 + +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include + + +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace AzQtComponents +{ + class AZ_QT_COMPONENTS_API ToolsApplication + : public QApplication + { + public: + ToolsApplication(int& argc, char** argv); + ~ToolsApplication(); + + private: + AZ_PUSH_DISABLE_DLL_EXPORT_MEMBER_WARNING + class Impl; + AZStd::unique_ptr m_impl; + AZ_POP_DISABLE_DLL_EXPORT_MEMBER_WARNING + + //QTimer m_timer; + //void Tick(float deltaOverride = -1.f) override; + + + /* + bool AddDockWidget(const AZStd::string& name, QWidget* widget, uint32_t area, uint32_t orientation); + void RemoveDockWidget(const AZStd::string& name); + void SetDockWidgetVisible(const AZStd::string& name, bool visible); + bool IsDockWidgetVisible(const AZStd::string& name) const; + AZStd::vector GetDockWidgetNames() const; + + AZStd::unordered_map m_dockWidgets; + */ + }; +} // namespace AzQtComponents + + diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/MaterialEditorApplication.cpp b/Gems/Atom/Tools/MaterialEditor/Code/Source/MaterialEditorApplication.cpp index a5435106c6..73bede14a5 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/MaterialEditorApplication.cpp +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/MaterialEditorApplication.cpp @@ -72,7 +72,7 @@ namespace MaterialEditor MaterialEditorApplication::MaterialEditorApplication(int* argc, char*** argv) : Application(argc, argv) - , QApplication(*argc, *argv) + , ToolsApplication(*argc, *argv) { AZ::Debug::TraceMessageBus::Handler::BusConnect(); diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/MaterialEditorApplication.h b/Gems/Atom/Tools/MaterialEditor/Code/Source/MaterialEditorApplication.h index 4d23cc640f..b7b3e13cca 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/MaterialEditorApplication.h +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/MaterialEditorApplication.h @@ -21,6 +21,8 @@ #include #include +#include + #include #include @@ -30,13 +32,14 @@ namespace MaterialEditor class MaterialEditorApplication : public AzFramework::Application - , public QApplication + //, public QApplication , private AzToolsFramework::AssetDatabase::AssetDatabaseRequestsBus::Handler , private MaterialEditorWindowNotificationBus::Handler , private AzFramework::AssetSystemStatusBus::Handler , private AZ::UserSettingsOwnerRequestBus::Handler , private AZ::Debug::TraceMessageBus::Handler , private AzToolsFramework::EditorPythonConsoleNotificationBus::Handler + , public AzQtComponents::ToolsApplication { public: AZ_TYPE_INFO(MaterialEditor::MaterialEditorApplication, "{30F90CA5-1253-49B5-8143-19CEE37E22BB}"); diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/main.cpp b/Gems/Atom/Tools/MaterialEditor/Code/Source/main.cpp index d1b937fde0..3ea7d37175 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/main.cpp +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/main.cpp @@ -39,7 +39,7 @@ int main(int argc, char** argv) QCoreApplication::setAttribute(Qt::AA_DontCreateNativeWidgetSiblings); QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough); AzQtComponents::Utilities::HandleDpiAwareness(AzQtComponents::Utilities::SystemDpiAware); - + //*/ MaterialEditor::MaterialEditorApplication app(&argc, &argv); auto globalEventFilter = new AzQtComponents::GlobalEventFilter(&app);