KinematicWidget.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 <Editor/KinematicWidget.h>
  9. #include <Editor/KinematicDescriptionDialog.h>
  10. #include <AzFramework/Physics/PropertyTypes.h>
  11. #include <AzToolsFramework/API/ToolsApplicationAPI.h>
  12. namespace PhysX
  13. {
  14. namespace Editor
  15. {
  16. AZ::u32 KinematicWidget::GetHandlerName() const
  17. {
  18. return Physics::Edit::KinematicSelector;
  19. }
  20. QWidget* KinematicWidget::CreateGUI(QWidget* parent)
  21. {
  22. widget_t* picker = new widget_t(parent);
  23. connect(
  24. picker,
  25. &ComboBoxEditButtonPair::valueChanged,
  26. this,
  27. [picker]()
  28. {
  29. AzToolsFramework::PropertyEditorGUIMessages::Bus::Broadcast(
  30. &AzToolsFramework::PropertyEditorGUIMessages::Bus::Handler::RequestWrite, picker);
  31. AzToolsFramework::PropertyEditorGUIMessages::Bus::Broadcast(
  32. &AzToolsFramework::PropertyEditorGUIMessages::Bus::Handler::OnEditingFinished, picker);
  33. });
  34. auto comboBox = picker->GetComboBox();
  35. comboBox->addItem("Simulated");
  36. comboBox->addItem("Kinematic");
  37. picker->GetEditButton()->setToolTip("Open Type dialog for a detailed description on the motion types");
  38. connect(picker->GetEditButton(), &QToolButton::clicked, this, &KinematicWidget::OnEditButtonClicked);
  39. m_widgetComboBox = comboBox;
  40. return picker;
  41. }
  42. void KinematicWidget::WriteGUIValuesIntoProperty(
  43. [[maybe_unused]] size_t index,
  44. widget_t* GUI,
  45. property_t& instance,
  46. [[maybe_unused]] AzToolsFramework::InstanceDataNode* node)
  47. {
  48. bool value = GUI->GetComboBox()->currentIndex() == 1;
  49. instance = static_cast<property_t>(value);
  50. }
  51. bool KinematicWidget::ReadValuesIntoGUI(
  52. [[maybe_unused]] size_t index,
  53. widget_t* GUI,
  54. [[maybe_unused]] const property_t& instance,
  55. [[maybe_unused]] AzToolsFramework::InstanceDataNode* node)
  56. {
  57. auto comboBox = GUI->GetComboBox();
  58. comboBox->blockSignals(true);
  59. comboBox->setCurrentIndex(instance ? 1 : 0);
  60. comboBox->blockSignals(false);
  61. return false;
  62. }
  63. void KinematicWidget::OnEditButtonClicked()
  64. {
  65. QWidget* mainWindow = nullptr;
  66. AzToolsFramework::EditorRequestBus::BroadcastResult(mainWindow, &AzToolsFramework::EditorRequests::GetMainWindow);
  67. KinematicDescriptionDialog kinematicDialog(m_widgetComboBox->currentIndex() == 1, mainWindow);
  68. int dialogResult = kinematicDialog.exec();
  69. if (dialogResult == QDialog::Accepted)
  70. {
  71. if (kinematicDialog.GetResult())
  72. {
  73. m_widgetComboBox->setCurrentIndex(1);
  74. }
  75. else
  76. {
  77. m_widgetComboBox->setCurrentIndex(0);
  78. }
  79. }
  80. }
  81. } // namespace Editor
  82. } // namespace PhysX
  83. #include <Editor/moc_KinematicWidget.cpp>