ViewPane.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. #ifndef CRYINCLUDE_EDITOR_VIEWPANE_H
  9. #define CRYINCLUDE_EDITOR_VIEWPANE_H
  10. #pragma once
  11. // ViewPane.h : header file
  12. //
  13. #if !defined(Q_MOC_RUN)
  14. #include "ViewportTitleDlg.h"
  15. #include <AzCore/Component/Component.h>
  16. #include <AzToolsFramework/ActionManager/ActionManagerRegistrationNotificationBus.h>
  17. #include <AzQtComponents/Components/ToolBarArea.h>
  18. #include <Include/SandboxAPI.h>
  19. #endif
  20. class CViewport;
  21. class QScrollArea;
  22. class QToolBar;
  23. class ViewportTitleExpanderWatcher;
  24. namespace AzToolsFramework
  25. {
  26. class ActionManagerInterface;
  27. class MenuManagerInterface;
  28. class ToolBarManagerInterface;
  29. }
  30. /////////////////////////////////////////////////////////////////////////////
  31. // CViewPane view
  32. class CLayoutViewPane
  33. : public AzQtComponents::ToolBarArea
  34. , private AzToolsFramework::ActionManagerRegistrationNotificationBus::Handler
  35. {
  36. Q_OBJECT
  37. public:
  38. CLayoutViewPane(QWidget* parent = nullptr);
  39. virtual ~CLayoutViewPane();
  40. // Operations
  41. public:
  42. // ActionManagerRegistrationNotificationBus overrides ...
  43. void OnMenuRegistrationHook() override;
  44. void OnToolBarRegistrationHook() override;
  45. void OnActionRegistrationHook() override;
  46. void OnMenuBindingHook() override;
  47. void OnToolBarBindingHook() override;
  48. // Set get this pane id.
  49. void SetId(int id) { m_id = id; }
  50. int GetId() { return m_id; }
  51. void SetViewClass(const QString& sClass);
  52. QString GetViewClass() const;
  53. //! Assign viewport to this pane.
  54. void SwapViewports(CLayoutViewPane* pView);
  55. void AttachViewport(QWidget* pViewport);
  56. //! Detach viewport from this pane.
  57. void DetachViewport();
  58. // Releases and destroy attached viewport.
  59. void ReleaseViewport();
  60. void SetFullscren(bool f);
  61. bool IsFullscreen() const { return m_bFullscreen; }
  62. QWidget* GetViewport() { return m_viewport; }
  63. //////////////////////////////////////////////////////////////////////////
  64. bool IsActiveView() const { return m_active; }
  65. void ShowTitleMenu();
  66. void ToggleMaximize();
  67. void SetFocusToViewport();
  68. void ResizeViewport(int width, int height);
  69. void SetAspectRatio(unsigned int x, unsigned int y);
  70. void SetViewportFOV(float fovDegrees);
  71. void OnFOVChanged(float fovRadians);
  72. enum class ViewportExpansionPolicy
  73. {
  74. AutoExpand,
  75. FixedSize
  76. };
  77. ViewportExpansionPolicy GetViewportExpansionPolicy() { return m_viewportPolicy; }
  78. //! Determine whether the viewport will be a fixed-size (scrollable if necessary)
  79. //! independent of the main window size, or auto-expanding based directly on the main window size.
  80. void SetViewportExpansionPolicy(ViewportExpansionPolicy policy);
  81. protected:
  82. void OnMenuLayoutConfig();
  83. void OnMenuViewSelected(const QString& paneName);
  84. void OnMenuMaximized();
  85. void mouseDoubleClickEvent(QMouseEvent* event) override;
  86. void OnDestroy();
  87. void focusInEvent(QFocusEvent* event) override;
  88. void DisconnectRenderViewportInteractionRequestBus();
  89. private:
  90. static constexpr int MIN_VIEWPORT_RES = 64;
  91. static constexpr int MAX_VIEWPORT_RES = 8192;
  92. static constexpr int MAX_CLASSVIEWS = 100;
  93. static constexpr int VIEW_BORDER = 0;
  94. enum TitleMenuCommonCommands
  95. {
  96. ID_MAXIMIZED = 50000,
  97. ID_LAYOUT_CONFIG,
  98. FIRST_ID_CLASSVIEW,
  99. LAST_ID_CLASSVIEW = FIRST_ID_CLASSVIEW + MAX_CLASSVIEWS - 1
  100. };
  101. QString m_viewPaneClass;
  102. bool m_bFullscreen;
  103. CViewportTitleDlg* m_viewportTitleDlg;
  104. int m_id;
  105. int m_nBorder;
  106. QWidget* m_viewport;
  107. QScrollArea* m_viewportScrollArea = nullptr;
  108. ViewportExpansionPolicy m_viewportPolicy = ViewportExpansionPolicy::AutoExpand;
  109. bool m_active;
  110. AzToolsFramework::ActionManagerInterface* m_actionManagerInterface = nullptr;
  111. AzToolsFramework::MenuManagerInterface* m_menuManagerInterface = nullptr;
  112. AzToolsFramework::ToolBarManagerInterface* m_toolBarManagerInterface = nullptr;
  113. };
  114. /////////////////////////////////////////////////////////////////////////////
  115. namespace AzToolsFramework
  116. {
  117. //! A component to reflect scriptable commands for the Editor
  118. class ViewPanePythonFuncsHandler
  119. : public AZ::Component
  120. {
  121. public:
  122. AZ_COMPONENT(ViewPanePythonFuncsHandler, "{25C99C8F-4440-4656-ABC4-32134F496CC1}")
  123. SANDBOX_API static void Reflect(AZ::ReflectContext* context);
  124. // AZ::Component ...
  125. void Activate() override {}
  126. void Deactivate() override {}
  127. };
  128. } // namespace AzToolsFramework
  129. #endif // CRYINCLUDE_EDITOR_VIEWPANE_H