NumericNodePropertyDisplay.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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>
  11. #include <AzQtComponents/Components/Widgets/SpinBox.h>
  12. #include <GraphCanvas/Components/NodePropertyDisplay/NodePropertyDisplay.h>
  13. #include <GraphCanvas/Components/NodePropertyDisplay/NumericDataInterface.h>
  14. #endif
  15. class QGraphicsProxyWidget;
  16. namespace GraphCanvas
  17. {
  18. class GraphCanvasLabel;
  19. namespace Internal
  20. {
  21. // Need to know when the spin box 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 FocusableDoubleSpinBox
  26. : public AzQtComponents::DoubleSpinBox
  27. {
  28. Q_OBJECT
  29. public:
  30. AZ_CLASS_ALLOCATOR(FocusableDoubleSpinBox, AZ::SystemAllocator);
  31. FocusableDoubleSpinBox() = default;
  32. ~FocusableDoubleSpinBox() = default;
  33. void deselectAll()
  34. {
  35. lineEdit()->deselect();
  36. lineEdit()->setCursorPosition(0);
  37. }
  38. signals:
  39. void OnFocusIn();
  40. void OnFocusOut();
  41. protected:
  42. void focusInEvent(QFocusEvent* focusEvent) override
  43. {
  44. AzQtComponents::DoubleSpinBox::focusInEvent(focusEvent);
  45. emit OnFocusIn();
  46. }
  47. void focusOutEvent(QFocusEvent* focusEvent) override
  48. {
  49. AzQtComponents::DoubleSpinBox::focusOutEvent(focusEvent);
  50. emit OnFocusOut();
  51. }
  52. };
  53. }
  54. class NumericNodePropertyDisplay
  55. : public NodePropertyDisplay
  56. {
  57. public:
  58. AZ_CLASS_ALLOCATOR(NumericNodePropertyDisplay, AZ::SystemAllocator);
  59. NumericNodePropertyDisplay(NumericDataInterface* dataInterface);
  60. virtual ~NumericNodePropertyDisplay();
  61. // NodePropertyDisplay
  62. void RefreshStyle() override;
  63. void UpdateDisplay() override;
  64. QGraphicsLayoutItem* GetDisabledGraphicsLayoutItem() override;
  65. QGraphicsLayoutItem* GetDisplayGraphicsLayoutItem() override;
  66. QGraphicsLayoutItem* GetEditableGraphicsLayoutItem() override;
  67. ////
  68. // DataSlotNotifications
  69. void OnDragDropStateStateChanged(const DragDropState& dragState) override;
  70. ////
  71. private:
  72. void EditStart();
  73. void SubmitValue();
  74. void EditFinished();
  75. void SetupProxyWidget();
  76. void CleanupProxyWidget();
  77. NumericDataInterface* m_dataInterface;
  78. GraphCanvasLabel* m_disabledLabel;
  79. GraphCanvasLabel* m_displayLabel;
  80. Internal::FocusableDoubleSpinBox* m_spinBox;
  81. QGraphicsProxyWidget* m_proxyWidget;
  82. };
  83. }