NodeFrameGraphicsWidget.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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 <AzCore/PlatformDef.h>
  10. AZ_PUSH_DISABLE_WARNING(4251 4800, "-Wunknown-warning-option")
  11. #include <QGraphicsWidget>
  12. AZ_POP_DISABLE_WARNING
  13. #include <GraphCanvas/Components/GeometryBus.h>
  14. #include <GraphCanvas/Components/Nodes/NodeBus.h>
  15. #include <GraphCanvas/Components/Nodes/NodeLayoutBus.h>
  16. #include <GraphCanvas/Components/Nodes/NodeUIBus.h>
  17. #include <GraphCanvas/Components/VisualBus.h>
  18. #include <GraphCanvas/Widgets/RootGraphicsItem.h>
  19. #include <GraphCanvas/Styling/StyleHelper.h>
  20. namespace GraphCanvas
  21. {
  22. //! Base class to handle a bunch of the weird quirky stuff that the NodeFrames need to manage.
  23. //! Will not paint anything.
  24. class NodeFrameGraphicsWidget
  25. : public RootGraphicsItem<QGraphicsWidget>
  26. , public SceneMemberUIRequestBus::Handler
  27. , public GeometryNotificationBus::Handler
  28. , public VisualRequestBus::Handler
  29. , public NodeNotificationBus::Handler
  30. , public NodeUIRequestBus::Handler
  31. , public StyleNotificationBus::Handler
  32. {
  33. private:
  34. enum NodeFrameDisplayState
  35. {
  36. None,
  37. Inspection,
  38. Deletion
  39. };
  40. enum StepAxis
  41. {
  42. Unknown,
  43. Height,
  44. Width
  45. };
  46. public:
  47. AZ_TYPE_INFO(NodeFrameGraphicsWidget, "{33B9DFFB-9E40-4D55-82A7-85468F7E7790}");
  48. AZ_CLASS_ALLOCATOR(NodeFrameGraphicsWidget, AZ::SystemAllocator, 0);
  49. // Do not allow Serialization of Graphics Ui classes
  50. static void Reflect(AZ::ReflectContext*) = delete;
  51. NodeFrameGraphicsWidget(const AZ::EntityId& nodeVisual);
  52. ~NodeFrameGraphicsWidget() override = default;
  53. void Activate();
  54. void Deactivate();
  55. // RootVisualNotificationsHelper
  56. QRectF GetBoundingRect() const override;
  57. ////
  58. // SceneMemberUIRequestBus
  59. QGraphicsItem* GetRootGraphicsItem() override;
  60. QGraphicsLayoutItem* GetRootGraphicsLayoutItem() override;
  61. void SetSelected(bool selected) override;
  62. bool IsSelected() const override;
  63. void SetZValue(qreal zValue) override;
  64. qreal GetZValue() const override;
  65. ////
  66. // GeometryNotificationBus
  67. void OnPositionChanged(const AZ::EntityId& entityId, const AZ::Vector2& position) override;
  68. ////
  69. // StyleNotificationBus
  70. void OnStyleChanged() override;
  71. ////
  72. // QGraphicsItem
  73. QSizeF sizeHint(Qt::SizeHint which, const QSizeF& constraint = QSizeF()) const override;
  74. void resizeEvent(QGraphicsSceneResizeEvent *) override;
  75. ////
  76. // RootGraphicsItem
  77. void OnDeleteItem() override;
  78. ////
  79. // VisualRequestBus
  80. QGraphicsItem* AsGraphicsItem() override;
  81. bool Contains(const AZ::Vector2& position) const override;
  82. void SetVisible(bool visible) override;
  83. bool IsVisible() const override;
  84. ////
  85. // NodeNotificationBus
  86. void OnNodeActivated() override;
  87. void OnAddedToScene(const AZ::EntityId& graphId) override;
  88. void OnNodeWrapped(const AZ::EntityId& wrappingNode) override;
  89. ////
  90. // NodeUIRequestBus
  91. void AdjustSize() override;
  92. void SetSteppedSizingEnabled(bool sizing) override;
  93. void SetSnapToGrid(bool snapToGrid) override;
  94. void SetResizeToGrid(bool resizeToGrid) override;
  95. void SetGrid(AZ::EntityId gridId) override;
  96. qreal GetCornerRadius() const override;
  97. qreal GetBorderWidth() const override;
  98. ////
  99. protected:
  100. void SetDisplayState(NodeFrameDisplayState displayState);
  101. void UpdateDisplayState(NodeFrameDisplayState displayState, bool enabled);
  102. int GrowToNextStep(int value, int step, StepAxis stepAxis = StepAxis::Unknown) const;
  103. int RoundToClosestStep(int value, int step) const;
  104. int ShrinkToPreviousStep(int value, int step) const;
  105. virtual void OnActivated();
  106. virtual void OnDeactivated();
  107. virtual void OnRefreshStyle();
  108. protected:
  109. NodeFrameGraphicsWidget(const NodeFrameGraphicsWidget&) = delete;
  110. Styling::StyleHelper m_style;
  111. NodeFrameDisplayState m_displayState;
  112. bool m_enabledSteppedSizing = true;
  113. EditorId m_editorId;
  114. AZ::EntityId m_wrapperNode;
  115. bool m_isWrapped = false;
  116. };
  117. }