3
0

SlotConnectionPin.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 <QGraphicsItem>
  10. #include <AzCore/Component/EntityId.h>
  11. #include <AzCore/std/smart_ptr/unique_ptr.h>
  12. #include <Components/Slots/SlotLayoutItem.h>
  13. #include <GraphCanvas/Components/Connections/ConnectionBus.h>
  14. #include <GraphCanvas/Components/Slots/SlotBus.h>
  15. #include <GraphCanvas/Utils/StateControllers/StateController.h>
  16. namespace GraphCanvas
  17. {
  18. class SlotConnectionPin
  19. : public SlotLayoutItem
  20. , public SlotUIRequestBus::Handler
  21. , public SlotNotificationBus::Handler
  22. {
  23. public:
  24. AZ_RTTI(SlotConnectionPin, "{4E4A8C30-584A-434B-B8FC-0514C1E7D290}", QGraphicsLayoutItem, QGraphicsItem);
  25. AZ_CLASS_ALLOCATOR(SlotConnectionPin, AZ::SystemAllocator);
  26. SlotConnectionPin(const AZ::EntityId& slotId);
  27. ~SlotConnectionPin() override;
  28. void Activate();
  29. void Deactivate();
  30. // SlotNotificationBus
  31. void OnRegisteredToNode(const AZ::EntityId& nodeId) override;
  32. ////
  33. // SlotLayoutItem
  34. void RefreshStyle() override final;
  35. AZ::EntityId GetEntityId() const override
  36. {
  37. return m_slotId;
  38. }
  39. ////
  40. // SlotUIRequestBus
  41. QPointF GetPinCenter() const override;
  42. QPointF GetConnectionPoint() const override;
  43. QPointF GetJutDirection() const override;
  44. ////
  45. protected:
  46. virtual void OnSlotClicked();
  47. // QGraphicsItem
  48. QRectF boundingRect() const override;
  49. void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override;
  50. void keyPressEvent(QKeyEvent* keyEvent) override;
  51. void keyReleaseEvent(QKeyEvent* keyEvent) override;
  52. void hoverEnterEvent(QGraphicsSceneHoverEvent* hoverEvent) override;
  53. void hoverLeaveEvent(QGraphicsSceneHoverEvent* hoverEvent) override;
  54. void mousePressEvent(QGraphicsSceneMouseEvent* event) override;
  55. void mouseReleaseEvent(QGraphicsSceneMouseEvent* event) override;
  56. void mouseMoveEvent(QGraphicsSceneMouseEvent* event) override;
  57. ////
  58. void OnMouseEnter(bool hasAltModifier);
  59. void OnMouseLeave();
  60. // QGraphicsLayoutItem
  61. void setGeometry(const QRectF& rect) override;
  62. QSizeF sizeHint(Qt::SizeHint which, const QSizeF& constraint = {}) const override;
  63. ////
  64. void HandleNewConnection();
  65. virtual void DrawConnectionPin(QPainter *painter, QRectF drawRect, bool isConnected);
  66. virtual void OnRefreshStyle();
  67. ConnectionType m_connectionType;
  68. AZ::EntityId m_slotId;
  69. bool m_trackClick;
  70. bool m_deletionClick;
  71. bool m_hovered;
  72. StateSetter<RootGraphicsItemDisplayState> m_nodeDisplayStateStateSetter;
  73. };
  74. }