MainWindow.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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. class SANDBOX_API MainWindow
  75. : public QMainWindow
  76. , public IEditorNotifyListener
  77. , private AzToolsFramework::SourceControlNotificationBus::Handler
  78. {
  79. Q_OBJECT
  80. public:
  81. explicit MainWindow(QWidget* parent = nullptr);
  82. ~MainWindow();
  83. #ifdef Q_OS_WIN
  84. HWND GetNativeHandle();
  85. #endif // #ifdef Q_OS_WIN
  86. void Initialize();
  87. // Returns the old and original main frame which we're porting away from.
  88. // ActionManager still needs it, to SendMessage() to it.
  89. CMainFrame* GetOldMainFrame() const;
  90. bool IsPreview() const;
  91. // The singleton is just a hack for now, it should be removed once everything
  92. // is ported to Qt.
  93. static MainWindow* instance();
  94. MainStatusBar* StatusBar() const;
  95. CLayoutWnd* GetLayout() const;
  96. void OpenViewPane(int paneId);
  97. void OpenViewPane(QtViewPane* pane);
  98. void SetActiveView(CLayoutViewPane* vp);
  99. /**
  100. * Returns the active view layout (Perspective, Top, Bottom, or Left, etc).
  101. * This particularly useful when in multi-layout mode, it represents the default viewport to use
  102. * when needing to interact with one.
  103. * When the user gives mouse focus to a viewport it becomes the active one, when unfocusing it
  104. * however, it remains the active one, unless another viewport got focus.
  105. */
  106. CLayoutViewPane* GetActiveView() const;
  107. QtViewport* GetActiveViewport() const;
  108. void AdjustToolBarIconSize(AzQtComponents::ToolBar::ToolBarIconSize size);
  109. void InvalidateControls();
  110. void OnCustomizeToolbar();
  111. void SaveConfig();
  112. void RefreshStyle();
  113. //! Reset timers used for auto saving.
  114. void StopAutoSaveTimers();
  115. void StartAutoSaveTimers();
  116. void ResetAutoSaveTimers();
  117. void ResetBackgroundUpdateTimer();
  118. LevelEditorMenuHandler* GetLevelEditorMenuHandler() { return m_levelEditorMenuHandler; }
  119. bool event(QEvent* event) override;
  120. Q_SIGNALS:
  121. void ToggleRefCoordSys();
  122. void UpdateRefCoordSys();
  123. void DeleteSelection();
  124. protected:
  125. void OnEditorNotifyEvent(EEditorNotifyEvent ev) override;
  126. void closeEvent(QCloseEvent* event) override;
  127. void keyPressEvent(QKeyEvent* e) override;
  128. void dragEnterEvent(QDragEnterEvent *event) override;
  129. void dragMoveEvent(QDragMoveEvent* event) override;
  130. void dragLeaveEvent(QDragLeaveEvent* event) override;
  131. void dropEvent(QDropEvent *event) override;
  132. bool focusNextPrevChild(bool next) override;
  133. private:
  134. void OnGotoSelected();
  135. void ToggleConsole();
  136. void RegisterOpenWndCommands();
  137. void InitCentralWidget();
  138. void InitStatusBar();
  139. template <class TValue>
  140. void ReadConfigValue(const QString& key, TValue& value)
  141. {
  142. value = m_settings.value(key, value).template value<TValue>();
  143. }
  144. // AzToolsFramework::SourceControlNotificationBus::Handler:
  145. void ConnectivityStateChanged(const AzToolsFramework::SourceControlState state) override;
  146. QWidget* CreateSpacerRightWidget();
  147. private Q_SLOTS:
  148. void OnStopAllSounds();
  149. void OnRefreshAudioSystem();
  150. void SaveLayout();
  151. void ViewDeletePaneLayout(const QString& layoutName);
  152. void ViewRenamePaneLayout(const QString& layoutName);
  153. void ViewLoadPaneLayout(const QString& layoutName);
  154. void ViewSavePaneLayout(const QString& layoutName);
  155. void OnConnectionStatusClicked();
  156. void OnUpdateConnectionStatus();
  157. void ShowConnectionDisconnectedDialog();
  158. void OnEscapeAction();
  159. void OnOpenAssetImporterManager(const QStringList& list);
  160. void OnOpenAssetImporterManagerAtPath(const QStringList& list, const QString& path);
  161. private:
  162. friend class EditorActionsHandler;
  163. bool IsGemEnabled(const QString& uuid, const QString& version) const;
  164. // Broadcast the SystemTick event
  165. void SystemTick();
  166. QStringList coordSysList() const;
  167. void RegisterStdViewClasses();
  168. CMainFrame* m_oldMainFrame;
  169. QtViewPaneManager* m_viewPaneManager;
  170. UndoStackStateAdapter* m_undoStateAdapter;
  171. CLayoutViewPane* m_activeView;
  172. QSettings m_settings;
  173. AssetImporterManager* m_assetImporterManager;
  174. LevelEditorMenuHandler* m_levelEditorMenuHandler = nullptr;
  175. CLayoutWnd* m_pLayoutWnd;
  176. AZStd::shared_ptr<EngineConnectionListener> m_connectionListener;
  177. QTimer* m_connectionLostTimer;
  178. QScopedPointer<AzToolsFramework::QtSourceControlNotificationHandler> m_sourceControlNotifHandler;
  179. EditorActionsHandler m_editorActionsHandler;
  180. static MainWindow* m_instance;
  181. AzQtComponents::DockMainWindow* m_viewPaneHost;
  182. QTimer* m_autoSaveTimer;
  183. QTimer* m_autoRemindTimer;
  184. QTimer* m_backgroundUpdateTimer;
  185. bool m_connectedToAssetProcessor = false;
  186. bool m_showAPDisconnectDialog = false;
  187. bool m_selectedEntityHasRoot = false;
  188. friend class WidgetAction;
  189. friend class LevelEditorMenuHandler;
  190. };
  191. namespace AzToolsFramework
  192. {
  193. //! A component to reflect scriptable commands for MainWindow
  194. class MainWindowEditorFuncsHandler
  195. : public AZ::Component
  196. {
  197. public:
  198. AZ_COMPONENT(MainWindowEditorFuncsHandler, "{C879102B-C767-4349-8F06-B69119CAC462}")
  199. SANDBOX_API static void Reflect(AZ::ReflectContext* context);
  200. // AZ::Component ...
  201. void Activate() override {}
  202. void Deactivate() override {}
  203. };
  204. } // namespace AZ