VectorNodePropertyDisplay.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. #if !defined(Q_MOC_RUN)
  10. #include <QEvent>
  11. #include <QGraphicsWidget>
  12. #include <QObject>
  13. #include <AzQtComponents/Components/Widgets/VectorInput.h>
  14. #include <GraphCanvas/Components/NodePropertyDisplay/NodePropertyDisplay.h>
  15. #include <GraphCanvas/Components/NodePropertyDisplay/VectorDataInterface.h>
  16. #include <GraphCanvas/Components/MimeDataHandlerBus.h>
  17. #include <GraphCanvas/Styling/StyleHelper.h>
  18. #endif
  19. class QGraphicsPixmapItem;
  20. class QGraphicsLinearLayout;
  21. class QPixmap;
  22. namespace GraphCanvas
  23. {
  24. class GraphCanvasLabel;
  25. class VectorNodePropertyDisplay;
  26. class VectorEventFilter
  27. : public QObject
  28. {
  29. Q_OBJECT
  30. public:
  31. AZ_CLASS_ALLOCATOR(VectorEventFilter, AZ::SystemAllocator);
  32. VectorEventFilter(VectorNodePropertyDisplay* owner);
  33. ~VectorEventFilter() = default;
  34. bool eventFilter(QObject *object, QEvent *event) override;
  35. private:
  36. VectorNodePropertyDisplay* m_owner;
  37. };
  38. class IconLayoutItem
  39. : public QGraphicsWidget{
  40. public:
  41. AZ_CLASS_ALLOCATOR(IconLayoutItem, AZ::SystemAllocator);
  42. IconLayoutItem(QGraphicsItem *parent = nullptr);
  43. ~IconLayoutItem();
  44. void setIcon(const QPixmap& pixmap);
  45. private:
  46. QGraphicsPixmapItem* m_pixmap;
  47. };
  48. class ReadOnlyVectorControl
  49. : public QGraphicsWidget
  50. {
  51. public:
  52. AZ_CLASS_ALLOCATOR(ReadOnlyVectorControl, AZ::SystemAllocator);
  53. ReadOnlyVectorControl(int index, const VectorDataInterface& dataInterface);
  54. ~ReadOnlyVectorControl();
  55. void RefreshStyle(const AZ::EntityId& sceneId);
  56. void UpdateDisplay();
  57. int GetIndex() const;
  58. GraphCanvasLabel* GetTextLabel();
  59. const GraphCanvasLabel* GetTextLabel() const;
  60. GraphCanvasLabel* GetValueLabel();
  61. const GraphCanvasLabel* GetValueLabel() const;
  62. private:
  63. QGraphicsLinearLayout* m_layout;
  64. GraphCanvasLabel* m_textLabel;
  65. GraphCanvasLabel* m_valueLabel;
  66. int m_index;
  67. const VectorDataInterface& m_dataInterface;
  68. };
  69. class VectorNodePropertyDisplay
  70. : public NodePropertyDisplay
  71. {
  72. friend class VectorEventFilter;
  73. public:
  74. AZ_CLASS_ALLOCATOR(VectorNodePropertyDisplay, AZ::SystemAllocator);
  75. VectorNodePropertyDisplay(VectorDataInterface* dataInterface);
  76. virtual ~VectorNodePropertyDisplay();
  77. // DataSource
  78. void RefreshStyle() override;
  79. void UpdateDisplay() override;
  80. QGraphicsLayoutItem* GetDisabledGraphicsLayoutItem() override;
  81. QGraphicsLayoutItem* GetDisplayGraphicsLayoutItem() override;
  82. QGraphicsLayoutItem* GetEditableGraphicsLayoutItem() override;
  83. ////
  84. // DataSlotNotifications
  85. void OnDragDropStateStateChanged(const DragDropState& dragState) override;
  86. ////
  87. private:
  88. void EditStart();
  89. void EditFinished();
  90. void SetupProxyWidget();
  91. void CleanupProxyWidget();
  92. void SubmitValue();
  93. Styling::StyleHelper m_styleHelper;
  94. VectorDataInterface* m_dataInterface{};
  95. QWidget* m_widgetContainer{};
  96. GraphCanvasLabel* m_disabledLabel{};
  97. AzQtComponents::VectorInput* m_propertyVectorCtrl{};
  98. QToolButton* m_button{};
  99. QGraphicsProxyWidget* m_proxyWidget{};
  100. QGraphicsWidget* m_displayWidget{};
  101. IconLayoutItem* m_iconDisplay{};
  102. AZStd::vector<ReadOnlyVectorControl*> m_vectorDisplays{};
  103. };
  104. } // namespace GraphCanvas