ViewportCameraSelectorWindow_Internals.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. #include <QAbstractItemModel>
  10. #include <QListView>
  11. #include <AzFramework/Components/CameraBus.h>
  12. #include <AzCore/Component/EntityBus.h>
  13. #include <AzToolsFramework/Entity/EditorEntityContextBus.h>
  14. #include <AzToolsFramework/API/ToolsApplicationAPI.h>
  15. #include <AzCore/Component/ComponentApplicationBus.h>
  16. #include <AzToolsFramework/API/EditorCameraBus.h>
  17. namespace Camera
  18. {
  19. namespace Internal
  20. {
  21. //! Each item in the list holds the camera's entityId and name.
  22. struct CameraListItem
  23. : public AZ::EntityBus::Handler
  24. {
  25. public:
  26. explicit CameraListItem(AZ::EntityId cameraId);
  27. ~CameraListItem();
  28. void OnEntityNameChanged(const AZStd::string& name) override { m_cameraName = name; }
  29. bool operator<(const CameraListItem& rhs) const;
  30. AZ::EntityId m_cameraId;
  31. AZStd::string m_cameraName;
  32. };
  33. // holds a list of camera items
  34. struct CameraListModel
  35. : public QAbstractListModel
  36. , public CameraNotificationBus::Handler
  37. {
  38. public:
  39. explicit CameraListModel(QWidget* myParent);
  40. ~CameraListModel();
  41. // QAbstractItemModel interface
  42. int rowCount(const QModelIndex& parent = QModelIndex()) const override;
  43. QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
  44. // CameraNotificationBus interface
  45. void OnCameraAdded(const AZ::EntityId& cameraId) override;
  46. void OnCameraRemoved(const AZ::EntityId& cameraId) override;
  47. void ConnectCameraNotificationBus();
  48. void DisconnecCameraNotificationBus();
  49. QModelIndex GetIndexForEntityId(const AZ::EntityId entityId);
  50. void Reset();
  51. private:
  52. AZStd::vector<CameraListItem> m_cameraItems;
  53. AZ::EntityId m_sequenceCameraEntityId;
  54. AZ::EntityId m_lastActiveCamera;
  55. };
  56. struct ViewportCameraSelectorWindow
  57. : public QListView
  58. , public EditorCameraNotificationBus::Handler
  59. , public AzToolsFramework::EditorEntityContextNotificationBus::Handler
  60. {
  61. public:
  62. ViewportCameraSelectorWindow(QWidget* parent = nullptr);
  63. ~ViewportCameraSelectorWindow();
  64. void currentChanged(const QModelIndex& current, const QModelIndex& previous) override;
  65. // EditorCameraNotificationBus overrides ...
  66. void OnViewportViewEntityChanged(const AZ::EntityId& newViewId) override;
  67. // AzToolsFramework::EditorEntityContextNotificationBus overrides ...
  68. void OnStartPlayInEditorBegin() override;
  69. void OnStopPlayInEditor() override;
  70. void OnPrepareForContextReset() override;
  71. void OnContextReset() override;
  72. // QListView overrides ...
  73. void mouseDoubleClickEvent(QMouseEvent* event) override;
  74. QModelIndex moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers) override;
  75. QModelIndex GetPreviousIndex() const;
  76. QModelIndex GetNextIndex() const;
  77. private:
  78. CameraListModel* m_cameraList = nullptr;
  79. bool m_ignoreViewportViewEntityChanged = false;
  80. };
  81. //! Wrapper for the ViewportCameraSelectorWindow so that we can add some descriptive helpful text.
  82. struct ViewportSelectorHolder
  83. : public QWidget
  84. {
  85. explicit ViewportSelectorHolder(QWidget* parent = nullptr);
  86. };
  87. //! Factory method for ViewportSelectorHolder.
  88. ViewportSelectorHolder* CreateNewSelectionWindow(QWidget* parent = nullptr);
  89. } // namespace Camera::Internal
  90. } // namespace Camera