MainWindow.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #if !defined(Q_MOC_RUN)
  10. #include <AzCore/std/smart_ptr/shared_ptr.h>
  11. #include <AzCore/Component/Component.h>
  12. #include <AzCore/EBus/Event.h>
  13. #include <QComboBox>
  14. #include <QMainWindow>
  15. #include <QScopedPointer>
  16. #include <QSettings>
  17. #include <QList>
  18. #include <QPointer>
  19. #include <QToolButton>
  20. #include <QTimer>
  21. #include "Include/SandboxAPI.h"
  22. #include <AzQtComponents/Components/ToolButtonComboBox.h>
  23. #include <AzQtComponents/Components/Widgets/ToolBar.h>
  24. #include <AzToolsFramework/SourceControl/SourceControlAPI.h>
  25. #include "IEditor.h"
  26. #include <Core/EditorActionsHandler.h>
  27. #endif
  28. class ActionManager;
  29. class AssetImporterManager;
  30. class CLayoutViewPane;
  31. class CLayoutWnd;
  32. class CMainFrame;
  33. class EngineConnectionListener;
  34. class LevelEditorMenuHandler;
  35. class MainStatusBar;
  36. class UndoStackStateAdapter;
  37. class QComboBox;
  38. class QToolButton;
  39. class QtViewport;
  40. class QtViewPaneManager;
  41. class QWidgetAction;
  42. struct QtViewPane;
  43. namespace AzQtComponents
  44. {
  45. class DockMainWindow;
  46. }
  47. namespace AzToolsFramework
  48. {
  49. class Ticker;
  50. class QtSourceControlNotificationHandler;
  51. //! @name Reverse URLs.
  52. //! Used to identify common actions and override them when necessary.
  53. //@{
  54. constexpr inline AZ::Crc32 EditModeMove = AZ_CRC_CE("org.o3de.action.editor.editmode.move");
  55. constexpr inline AZ::Crc32 EditModeRotate = AZ_CRC_CE("org.o3de.action.editor.editmode.rotate");
  56. constexpr inline AZ::Crc32 EditModeScale = AZ_CRC_CE("org.o3de.action.editor.editmode.scale");
  57. constexpr inline AZ::Crc32 SnapToGrid = AZ_CRC_CE("org.o3de.action.editor.snaptogrid");
  58. constexpr inline AZ::Crc32 SnapAngle = AZ_CRC_CE("org.o3de.action.editor.snapangle");
  59. //@}
  60. }
  61. #define MAINFRM_LAYOUT_NORMAL "NormalLayout"
  62. #define MAINFRM_LAYOUT_PREVIEW "PreviewLayout"
  63. // Sub-classing so we can add slots to our toolbar widgets
  64. // Using lambdas is prone to crashes since the lambda doesn't know when the widget is deleted.
  65. class UndoRedoToolButton
  66. : public QToolButton
  67. {
  68. Q_OBJECT
  69. public:
  70. explicit UndoRedoToolButton(QWidget* parent);
  71. public Q_SLOTS:
  72. void Update(int count);
  73. };
  74. AZ_PUSH_DISABLE_DLL_EXPORT_BASECLASS_WARNING
  75. AZ_PUSH_DISABLE_DLL_EXPORT_MEMBER_WARNING
  76. class SANDBOX_API MainWindow
  77. : public QMainWindow
  78. , public IEditorNotifyListener
  79. , private AzToolsFramework::SourceControlNotificationBus::Handler
  80. {
  81. AZ_POP_DISABLE_DLL_EXPORT_MEMBER_WARNING
  82. AZ_POP_DISABLE_DLL_EXPORT_BASECLASS_WARNING
  83. Q_OBJECT
  84. public:
  85. explicit MainWindow(QWidget* parent = nullptr);
  86. ~MainWindow();
  87. #ifdef Q_OS_WIN
  88. HWND GetNativeHandle();
  89. #endif // #ifdef Q_OS_WIN
  90. void Initialize();
  91. // Returns the old and original main frame which we're porting away from.
  92. // ActionManager still needs it, to SendMessage() to it.
  93. CMainFrame* GetOldMainFrame() const;
  94. bool IsPreview() const;
  95. // The singleton is just a hack for now, it should be removed once everything
  96. // is ported to Qt.
  97. static MainWindow* instance();
  98. MainStatusBar* StatusBar() const;
  99. CLayoutWnd* GetLayout() const;
  100. void OpenViewPane(int paneId);
  101. void OpenViewPane(QtViewPane* pane);
  102. void SetActiveView(CLayoutViewPane* vp);
  103. /**
  104. * Returns the active view layout (Perspective, Top, Bottom, or Left, etc).
  105. * This particularly useful when in multi-layout mode, it represents the default viewport to use
  106. * when needing to interact with one.
  107. * When the user gives mouse focus to a viewport it becomes the active one, when unfocusing it
  108. * however, it remains the active one, unless another viewport got focus.
  109. */
  110. CLayoutViewPane* GetActiveView() const;
  111. QtViewport* GetActiveViewport() const;
  112. void AdjustToolBarIconSize(AzQtComponents::ToolBar::ToolBarIconSize size);
  113. void InvalidateControls();
  114. void OnCustomizeToolbar();
  115. void SaveConfig();
  116. void RefreshStyle();
  117. //! Reset timers used for auto saving.
  118. void StopAutoSaveTimers();
  119. void StartAutoSaveTimers();
  120. void ResetAutoSaveTimers();
  121. void ResetBackgroundUpdateTimer();
  122. LevelEditorMenuHandler* GetLevelEditorMenuHandler() { return m_levelEditorMenuHandler; }
  123. bool event(QEvent* event) override;
  124. Q_SIGNALS:
  125. void ToggleRefCoordSys();
  126. void UpdateRefCoordSys();
  127. void DeleteSelection();
  128. protected:
  129. void OnEditorNotifyEvent(EEditorNotifyEvent ev) override;
  130. void closeEvent(QCloseEvent* event) override;
  131. void keyPressEvent(QKeyEvent* e) override;
  132. void dragEnterEvent(QDragEnterEvent *event) override;
  133. void dragMoveEvent(QDragMoveEvent* event) override;
  134. void dragLeaveEvent(QDragLeaveEvent* event) override;
  135. void dropEvent(QDropEvent *event) override;
  136. bool focusNextPrevChild(bool next) override;
  137. private:
  138. void OnGotoSelected();
  139. void ToggleConsole();
  140. void RegisterOpenWndCommands();
  141. void InitCentralWidget();
  142. void InitStatusBar();
  143. template <class TValue>
  144. void ReadConfigValue(const QString& key, TValue& value)
  145. {
  146. value = m_settings.value(key, value).template value<TValue>();
  147. }
  148. // AzToolsFramework::SourceControlNotificationBus::Handler:
  149. void ConnectivityStateChanged(const AzToolsFramework::SourceControlState state) override;
  150. QWidget* CreateSpacerRightWidget();
  151. private Q_SLOTS:
  152. void OnStopAllSounds();
  153. void OnRefreshAudioSystem();
  154. void SaveLayout();
  155. void ViewDeletePaneLayout(const QString& layoutName);
  156. void ViewRenamePaneLayout(const QString& layoutName);
  157. void ViewLoadPaneLayout(const QString& layoutName);
  158. void ViewSavePaneLayout(const QString& layoutName);
  159. void OnConnectionStatusClicked();
  160. void OnUpdateConnectionStatus();
  161. void ShowConnectionDisconnectedDialog();
  162. void OnEscapeAction();
  163. void OnOpenAssetImporterManager(const QStringList& list);
  164. void OnOpenAssetImporterManagerAtPath(const QStringList& list, const QString& path);
  165. private:
  166. friend class EditorActionsHandler;
  167. bool IsGemEnabled(const QString& uuid, const QString& version) const;
  168. // Broadcast the SystemTick event
  169. void SystemTick();
  170. QStringList coordSysList() const;
  171. void RegisterStdViewClasses();
  172. CMainFrame* m_oldMainFrame;
  173. QtViewPaneManager* m_viewPaneManager;
  174. UndoStackStateAdapter* m_undoStateAdapter;
  175. CLayoutViewPane* m_activeView;
  176. QSettings m_settings;
  177. AssetImporterManager* m_assetImporterManager;
  178. LevelEditorMenuHandler* m_levelEditorMenuHandler = nullptr;
  179. CLayoutWnd* m_pLayoutWnd;
  180. AZ_PUSH_DISABLE_DLL_EXPORT_MEMBER_WARNING
  181. AZStd::shared_ptr<EngineConnectionListener> m_connectionListener;
  182. QTimer* m_connectionLostTimer;
  183. QScopedPointer<AzToolsFramework::QtSourceControlNotificationHandler> m_sourceControlNotifHandler;
  184. EditorActionsHandler m_editorActionsHandler;
  185. AZ_POP_DISABLE_DLL_EXPORT_MEMBER_WARNING
  186. static MainWindow* m_instance;
  187. AzQtComponents::DockMainWindow* m_viewPaneHost;
  188. QTimer* m_autoSaveTimer;
  189. QTimer* m_autoRemindTimer;
  190. QTimer* m_backgroundUpdateTimer;
  191. bool m_connectedToAssetProcessor = false;
  192. bool m_showAPDisconnectDialog = false;
  193. bool m_selectedEntityHasRoot = false;
  194. friend class WidgetAction;
  195. friend class LevelEditorMenuHandler;
  196. };
  197. namespace AzToolsFramework
  198. {
  199. //! A component to reflect scriptable commands for MainWindow
  200. class MainWindowEditorFuncsHandler
  201. : public AZ::Component
  202. {
  203. public:
  204. AZ_COMPONENT(MainWindowEditorFuncsHandler, "{C879102B-C767-4349-8F06-B69119CAC462}")
  205. SANDBOX_API static void Reflect(AZ::ReflectContext* context);
  206. // AZ::Component ...
  207. void Activate() override {}
  208. void Deactivate() override {}
  209. };
  210. } // namespace AZ