StringNodePropertyDisplay.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 <qlineedit.h>
  11. #include <AzCore/Component/TickBus.h>
  12. #include <GraphCanvas/Components/NodePropertyDisplay/NodePropertyDisplay.h>
  13. #include <GraphCanvas/Components/NodePropertyDisplay/StringDataInterface.h>
  14. #endif
  15. class QGraphicsProxyWidget;
  16. namespace GraphCanvas
  17. {
  18. class GraphCanvasLabel;
  19. namespace Internal
  20. {
  21. // Need to know when the line edit gets focus in order to
  22. // manage the layout display when the mouse hovers off, but the
  23. // widget still has focus. Qt does not expose focus events in any
  24. // signal way, so this exposes that functionality for me.
  25. class FocusableLineEdit
  26. : public QLineEdit
  27. {
  28. Q_OBJECT
  29. public:
  30. AZ_CLASS_ALLOCATOR(FocusableLineEdit, AZ::SystemAllocator);
  31. FocusableLineEdit() = default;
  32. ~FocusableLineEdit() = default;
  33. signals:
  34. void OnFocusIn();
  35. void OnFocusOut();
  36. private:
  37. void focusInEvent(QFocusEvent* focusEvent)
  38. {
  39. QLineEdit::focusInEvent(focusEvent);
  40. emit OnFocusIn();
  41. }
  42. void focusOutEvent(QFocusEvent* focusEvent)
  43. {
  44. QLineEdit::focusOutEvent(focusEvent);
  45. emit OnFocusOut();
  46. }
  47. };
  48. }
  49. class StringNodePropertyDisplay
  50. : public NodePropertyDisplay
  51. , public AZ::SystemTickBus::Handler
  52. {
  53. public:
  54. AZ_CLASS_ALLOCATOR(StringNodePropertyDisplay, AZ::SystemAllocator);
  55. StringNodePropertyDisplay(StringDataInterface* dataInterface);
  56. virtual ~StringNodePropertyDisplay();
  57. // DataSource
  58. void RefreshStyle() override;
  59. void UpdateDisplay() override;
  60. QGraphicsLayoutItem* GetDisabledGraphicsLayoutItem() override;
  61. QGraphicsLayoutItem* GetDisplayGraphicsLayoutItem() override;
  62. QGraphicsLayoutItem* GetEditableGraphicsLayoutItem() override;
  63. ////
  64. // DataSlotNotifications
  65. void OnDragDropStateStateChanged(const DragDropState& dragState) override;
  66. ////
  67. // AZ::SystemTickBus::Handler
  68. void OnSystemTick() override;
  69. ////
  70. private:
  71. void OnFocusOut();
  72. void EditStart();
  73. void SubmitValue();
  74. void EditFinished();
  75. void SetupProxyWidget();
  76. void CleanupProxyWidget();
  77. void ResizeToContents();
  78. StringDataInterface* m_dataInterface;
  79. GraphCanvasLabel* m_disabledLabel;
  80. GraphCanvasLabel* m_displayLabel;
  81. Internal::FocusableLineEdit* m_lineEdit;
  82. QGraphicsProxyWidget* m_proxyWidget;
  83. bool m_isNudging;
  84. };
  85. }