TransformRowHandler.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. #include <AzCore/EBus/EBus.h>
  9. #include <AzToolsFramework/Debug/TraceContext.h>
  10. #include <AzToolsFramework/UI/PropertyEditor/PropertyVectorCtrl.hxx>
  11. #include <AzToolsFramework/UI/PropertyEditor/PropertyDoubleSpinCtrl.hxx>
  12. #include <SceneAPI/SceneUI/RowWidgets/TransformRowHandler.h>
  13. namespace AZ
  14. {
  15. namespace SceneAPI
  16. {
  17. namespace SceneUI
  18. {
  19. AZ_CLASS_ALLOCATOR_IMPL(TranformRowHandler, SystemAllocator);
  20. TranformRowHandler* TranformRowHandler::s_instance = nullptr;
  21. QWidget* TranformRowHandler::CreateGUI(QWidget* parent)
  22. {
  23. return aznew TransformRowWidget(parent);
  24. }
  25. u32 TranformRowHandler::GetHandlerName() const
  26. {
  27. return AZ_CRC_CE("TranformRow");
  28. }
  29. bool TranformRowHandler::AutoDelete() const
  30. {
  31. return false;
  32. }
  33. bool TranformRowHandler::IsDefaultHandler() const
  34. {
  35. return true;
  36. }
  37. void TranformRowHandler::ConsumeAttribute(TransformRowWidget* widget, u32 attrib,
  38. AzToolsFramework::PropertyAttributeReader* attrValue, const char* debugName)
  39. {
  40. if (attrib == AZ::Edit::Attributes::ReadOnly)
  41. {
  42. bool value;
  43. if (attrValue->Read<bool>(value))
  44. {
  45. widget->SetEnableEdit(!value);
  46. }
  47. }
  48. else
  49. {
  50. AzToolsFramework::Vector3PropertyHandler vector3Handler;
  51. vector3Handler.ConsumeAttribute(widget->GetTranslationWidget(), attrib, attrValue, debugName);
  52. vector3Handler.ConsumeAttribute(widget->GetRotationWidget(), attrib, attrValue, debugName);
  53. AzToolsFramework::doublePropertySpinboxHandler spinboxHandler;
  54. spinboxHandler.ConsumeAttribute(widget->GetScaleWidget(), attrib, attrValue, debugName);
  55. }
  56. }
  57. void TranformRowHandler::WriteGUIValuesIntoProperty(size_t /*index*/, TransformRowWidget* GUI,
  58. property_t& instance, AzToolsFramework::InstanceDataNode* /*node*/)
  59. {
  60. GUI->GetTransform(instance);
  61. }
  62. bool TranformRowHandler::ReadValuesIntoGUI(size_t /*index*/, TransformRowWidget* GUI, const property_t& instance,
  63. AzToolsFramework::InstanceDataNode* /*node*/)
  64. {
  65. GUI->SetTransform(instance);
  66. return false;
  67. }
  68. void TranformRowHandler::Register()
  69. {
  70. using namespace AzToolsFramework;
  71. if (!s_instance)
  72. {
  73. s_instance = aznew TranformRowHandler();
  74. PropertyTypeRegistrationMessages::Bus::Broadcast(&PropertyTypeRegistrationMessages::Bus::Events::RegisterPropertyType, s_instance);
  75. }
  76. }
  77. void TranformRowHandler::Unregister()
  78. {
  79. using namespace AzToolsFramework;
  80. if (s_instance)
  81. {
  82. PropertyTypeRegistrationMessages::Bus::Broadcast(&PropertyTypeRegistrationMessages::Bus::Events::UnregisterPropertyType, s_instance);
  83. delete s_instance;
  84. s_instance = nullptr;
  85. }
  86. }
  87. void TranformRowHandler::ConsumeFilterTypeAttribute(TransformRowWidget* /*widget*/,
  88. AzToolsFramework::PropertyAttributeReader* /*attrValue*/)
  89. {
  90. }
  91. } // namespace SceneUI
  92. } // namespace SceneAPI
  93. } // namespace AZ
  94. #include <RowWidgets/moc_TransformRowHandler.cpp>