MipmapSettingWidget.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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 "MipmapSettingWidget.h"
  9. #include <Source/Editor/ui_MipmapSettingWidget.h>
  10. #include <AzCore/Component/ComponentApplicationBus.h>
  11. #include <AzCore/Serialization/SerializeContext.h>
  12. #include <AzToolsFramework/UI/PropertyEditor/ReflectedPropertyEditor.hxx>
  13. #include <AzQtComponents/Components/Widgets/CheckBox.h>
  14. #include <QCheckBox>
  15. #include <QSizePolicy>
  16. namespace ImageProcessingAtomEditor
  17. {
  18. using namespace ImageProcessingAtom;
  19. MipmapSettingWidget::MipmapSettingWidget(EditorTextureSetting& textureSetting, QWidget* parent /*= nullptr*/)
  20. : QWidget(parent)
  21. , m_ui(new Ui::MipmapSettingWidget)
  22. , m_textureSetting(&textureSetting)
  23. {
  24. m_ui->setupUi(this);
  25. AZ::SerializeContext* serializeContext = nullptr;
  26. AZ::ComponentApplicationBus::BroadcastResult(serializeContext, &AZ::ComponentApplicationBus::Events::GetSerializeContext);
  27. AZ_Assert(serializeContext, "Serialization context not available");
  28. m_ui->propertyEditor->SetAutoResizeLabels(true);
  29. m_ui->propertyEditor->Setup(serializeContext, this, true, 250);
  30. m_ui->propertyEditor->ClearInstances();
  31. TextureSettings* instance = &m_textureSetting->GetMultiplatformTextureSetting();
  32. const AZ::Uuid& classId = AZ::SerializeTypeInfo<TextureSettings>::GetUuid(instance);
  33. m_ui->propertyEditor->AddInstance(instance, classId);
  34. m_ui->propertyEditor->InvalidateAll();
  35. m_ui->propertyEditor->ExpandAll();
  36. // Style the Checkbox
  37. AzQtComponents::CheckBox::applyToggleSwitchStyle(m_ui->enableCheckBox);
  38. RefreshUI();
  39. EditorInternalNotificationBus::Handler::BusConnect();
  40. }
  41. MipmapSettingWidget::~MipmapSettingWidget()
  42. {
  43. EditorInternalNotificationBus::Handler::BusDisconnect();
  44. }
  45. void MipmapSettingWidget::RefreshUI()
  46. {
  47. TextureSettings& texSetting = m_textureSetting->GetMultiplatformTextureSetting();
  48. const PresetSettings* preset = BuilderSettingManager::Instance()->GetPreset(texSetting.m_preset);
  49. if (preset == nullptr || preset->m_mipmapSetting == nullptr)
  50. {
  51. m_ui->enableCheckBox->setCheckState(Qt::CheckState::Unchecked);
  52. m_ui->enableCheckBox->setEnabled(false);
  53. m_ui->propertyEditor->hide();
  54. }
  55. else
  56. {
  57. bool showMipMap = texSetting.m_enableMipmap;
  58. m_ui->enableCheckBox->setEnabled(true);
  59. m_ui->enableCheckBox->setCheckState(showMipMap ? Qt::CheckState::Checked : Qt::CheckState::Unchecked);
  60. QObject::connect(m_ui->enableCheckBox, &QCheckBox::clicked, this, &MipmapSettingWidget::OnCheckBoxStateChanged);
  61. if (showMipMap)
  62. {
  63. m_ui->propertyEditor->show();
  64. this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
  65. }
  66. else
  67. {
  68. m_ui->propertyEditor->hide();
  69. this->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
  70. }
  71. }
  72. m_ui->propertyEditor->InvalidateValues();
  73. }
  74. void MipmapSettingWidget::OnCheckBoxStateChanged(bool checked)
  75. {
  76. bool finalChecked = m_textureSetting->RefreshMipSetting(checked);
  77. if (finalChecked)
  78. {
  79. m_ui->propertyEditor->show();
  80. }
  81. else
  82. {
  83. m_ui->propertyEditor->hide();
  84. }
  85. EditorInternalNotificationBus::Broadcast(&EditorInternalNotificationBus::Events::OnEditorSettingsChanged, false, BuilderSettingManager::s_defaultPlatform);
  86. }
  87. void MipmapSettingWidget::AfterPropertyModified(AzToolsFramework::InstanceDataNode* /*pNode*/)
  88. {
  89. //Only the first texture setting reflected is changed, we need to propagate the change to every texture settings.
  90. m_textureSetting->PropagateCommonSettings();
  91. m_ui->propertyEditor->InvalidateValues();
  92. EditorInternalNotificationBus::Broadcast(&EditorInternalNotificationBus::Events::OnEditorSettingsChanged, false, BuilderSettingManager::s_defaultPlatform);
  93. }
  94. void MipmapSettingWidget::OnEditorSettingsChanged(bool needRefresh, const AZStd::string& /*platform*/)
  95. {
  96. if (needRefresh)
  97. {
  98. RefreshUI();
  99. }
  100. }
  101. }//namespace ImageProcessingAtomEditor
  102. #include <Source/Editor/moc_MipmapSettingWidget.cpp>