BookmarkAnchorVisualComponent.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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 <qgraphicswidget.h>
  10. #include <qcolor.h>
  11. #include <AzCore/Component/Component.h>
  12. #include <AzCore/Component/EntityBus.h>
  13. #include <AzCore/Math/Color.h>
  14. #include <AzCore/Component/TickBus.h>
  15. #include <GraphCanvas/Components/Bookmarks/BookmarkBus.h>
  16. #include <GraphCanvas/Components/EntitySaveDataBus.h>
  17. #include <GraphCanvas/Components/GeometryBus.h>
  18. #include <GraphCanvas/Components/GraphCanvasPropertyBus.h>
  19. #include <GraphCanvas/Components/SceneBus.h>
  20. #include <GraphCanvas/Components/StyleBus.h>
  21. #include <GraphCanvas/Components/VisualBus.h>
  22. #include <GraphCanvas/Styling/StyleHelper.h>
  23. #include <GraphCanvas/Types/EntitySaveData.h>
  24. #include <GraphCanvas/Widgets/RootGraphicsItem.h>
  25. namespace GraphCanvas
  26. {
  27. //! The actual visual graphics item
  28. class BookmarkAnchorVisualGraphicsWidget
  29. : public RootGraphicsItem<QGraphicsWidget>
  30. , public GeometryNotificationBus::Handler
  31. , public StyleNotificationBus::Handler
  32. , public SceneMemberNotificationBus::Handler
  33. , public BookmarkNotificationBus::Handler
  34. {
  35. public:
  36. AZ_TYPE_INFO(BookmarkAnchorVisualGraphicsWidget, "");
  37. AZ_CLASS_ALLOCATOR(BookmarkAnchorVisualGraphicsWidget, AZ::SystemAllocator);
  38. BookmarkAnchorVisualGraphicsWidget(const AZ::EntityId& busId);
  39. virtual ~BookmarkAnchorVisualGraphicsWidget() = default;
  40. void SetColor(const QColor& drawColor);
  41. QPainterPath GetOutline() const;
  42. // RootGraphicsItem
  43. QRectF GetBoundingRect() const override;
  44. ////
  45. // BookmarkNotifications
  46. void OnBookmarkTriggered() override;
  47. void OnBookmarkNameChanged() override;
  48. ////
  49. // StyleNotificationBus
  50. void OnStyleChanged() override;
  51. ////
  52. // GeometryNotificationBus
  53. void OnPositionChanged(const AZ::EntityId& entityId, const AZ::Vector2& position) override;
  54. ////
  55. // SceneMemberNotificationBus
  56. void OnSceneSet(const AZ::EntityId& sceneId) override;
  57. ////
  58. // QGraphicsWidget
  59. void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override;
  60. ////
  61. private:
  62. QPainterPath m_outline;
  63. QColor m_drawColor;
  64. Styling::StyleHelper m_style;
  65. float m_animationDuration;
  66. };
  67. //! Some sort of visual indicator of a bookmark, just to help focus, and allow for easier changing of bookmark locations
  68. class BookmarkAnchorVisualComponent
  69. : public GraphCanvasPropertyComponent
  70. , public SceneMemberUIRequestBus::Handler
  71. , public SceneMemberNotificationBus::Handler
  72. , public BookmarkNotificationBus::Handler
  73. {
  74. public:
  75. // Dummy class retained to avoid crashes on graph processing.
  76. class BookmarkAnchorVisualComponentSaveData
  77. : public ComponentSaveData
  78. {
  79. public:
  80. AZ_RTTI(BookmarkAnchorVisualComponentSaveData, "{1EDD7480-8CB5-4656-8B04-00E82ED0063A}", ComponentSaveData);
  81. AZ_CLASS_ALLOCATOR(BookmarkAnchorVisualComponentSaveData, AZ::SystemAllocator);
  82. BookmarkAnchorVisualComponentSaveData() = default;
  83. };
  84. AZ_COMPONENT(BookmarkAnchorVisualComponent, "{AD921E77-962B-417F-88FB-500FA679DFDF}");
  85. static void Reflect(AZ::ReflectContext* reflectContext);
  86. BookmarkAnchorVisualComponent();
  87. ~BookmarkAnchorVisualComponent() = default;
  88. // AZ::Component
  89. void Init() override;
  90. void Activate() override;
  91. void Deactivate() override;
  92. ////
  93. // SceneMemberUIRequestBus
  94. QGraphicsItem* GetRootGraphicsItem() override;
  95. QGraphicsLayoutItem* GetRootGraphicsLayoutItem() override;
  96. void SetSelected(bool selected) override;
  97. bool IsSelected() const override;
  98. QPainterPath GetOutline() const override;
  99. void SetZValue(qreal zValue) override;
  100. qreal GetZValue() const override;
  101. ////
  102. // SceneMemberNotifications
  103. void OnSceneSet(const AZ::EntityId& graphId) override;
  104. ////
  105. // BookmarkNotifications
  106. void OnBookmarkColorChanged() override;
  107. ////
  108. private:
  109. BookmarkAnchorVisualComponent(const BookmarkAnchorVisualComponent&) = delete;
  110. const BookmarkAnchorVisualComponent& operator=(const BookmarkAnchorVisualComponent&) = delete;
  111. AZStd::unique_ptr<BookmarkAnchorVisualGraphicsWidget> m_graphicsWidget;
  112. };
  113. }