PlatformSelectionWidget.cpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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 <source/ui/PlatformSelectionWidget.h>
  9. #include <source/ui/ui_PlatformSelectionWidget.h>
  10. #include <AzCore/std/string/string.h>
  11. namespace AssetBundler
  12. {
  13. PlatformSelectionWidget::PlatformSelectionWidget(QWidget* parent)
  14. : QWidget(parent)
  15. {
  16. m_ui.reset(new Ui::PlatformSelectionWidget);
  17. m_ui->setupUi(this);
  18. m_platformHelper.reset(new AzFramework::PlatformHelper);
  19. m_selectedPlatforms = AzFramework::PlatformFlags::Platform_NONE;
  20. m_partiallySelectedPlatforms = AzFramework::PlatformFlags::Platform_NONE;
  21. }
  22. void PlatformSelectionWidget::Init(const AzFramework::PlatformFlags& enabledPlatforms, const QString& disabledPatformMessageOverride)
  23. {
  24. using namespace AzFramework;
  25. // Set up Platform Checkboxes
  26. for (const AZStd::string_view& platformString : m_platformHelper->GetPlatforms(PlatformFlags::AllNamedPlatforms))
  27. {
  28. // Create the CheckBox and store what platform it maps to
  29. QSharedPointer<QCheckBox> platformCheckBox(new QCheckBox(QString::fromUtf8(platformString.data(), static_cast<int>(platformString.size()))));
  30. m_platformCheckBoxes.push_back(platformCheckBox);
  31. PlatformFlags currentPlatformFlag = m_platformHelper->GetPlatformFlag(platformString);
  32. m_platformList.push_back(currentPlatformFlag);
  33. // Add the CheckBox to the view
  34. m_ui->platformCheckBoxLayout->addWidget(platformCheckBox.data());
  35. // If the platform is not enabled for the current project, disable it and tell the user
  36. if ((enabledPlatforms & currentPlatformFlag) == PlatformFlags::Platform_NONE)
  37. {
  38. platformCheckBox->setEnabled(false);
  39. if (disabledPatformMessageOverride.isEmpty())
  40. {
  41. platformCheckBox->setToolTip(tr("This platform is not enabled for the current project."));
  42. }
  43. else
  44. {
  45. platformCheckBox->setToolTip(disabledPatformMessageOverride);
  46. }
  47. }
  48. else
  49. {
  50. connect(platformCheckBox.data(), &QCheckBox::stateChanged, this, &PlatformSelectionWidget::OnPlatformSelectionChanged);
  51. }
  52. }
  53. }
  54. void PlatformSelectionWidget::SetSelectedPlatforms(
  55. const AzFramework::PlatformFlags& selectedPlatforms,
  56. const AzFramework::PlatformFlags& partiallySelectedPlatforms)
  57. {
  58. m_selectedPlatforms = AzFramework::PlatformFlags::Platform_NONE;
  59. m_partiallySelectedPlatforms = AzFramework::PlatformFlags::Platform_NONE;
  60. for (int checkBoxIndex = 0; checkBoxIndex < m_platformCheckBoxes.size(); ++checkBoxIndex)
  61. {
  62. AzFramework::PlatformFlags checkBoxPlatform = m_platformList[checkBoxIndex];
  63. bool isSelected = (checkBoxPlatform & selectedPlatforms) != AzFramework::PlatformFlags::Platform_NONE;
  64. m_platformCheckBoxes[checkBoxIndex]->setChecked(isSelected);
  65. if (isSelected)
  66. {
  67. m_selectedPlatforms |= checkBoxPlatform;
  68. }
  69. // Set the check status to Qt::PartiallyChecked when some of the selected items support the current platform
  70. bool isPartiallySelected = (checkBoxPlatform & partiallySelectedPlatforms) != AzFramework::PlatformFlags::Platform_NONE;
  71. if (isPartiallySelected)
  72. {
  73. m_platformCheckBoxes[checkBoxIndex]->setCheckState(Qt::PartiallyChecked);
  74. m_partiallySelectedPlatforms |= checkBoxPlatform;
  75. }
  76. }
  77. emit PlatformsSelected(m_selectedPlatforms, m_partiallySelectedPlatforms);
  78. }
  79. AzFramework::PlatformFlags PlatformSelectionWidget::GetSelectedPlatforms()
  80. {
  81. return m_selectedPlatforms;
  82. }
  83. AzFramework::PlatformFlags PlatformSelectionWidget::GetPartiallySelectedPlatforms()
  84. {
  85. return m_partiallySelectedPlatforms;
  86. }
  87. void PlatformSelectionWidget::OnPlatformSelectionChanged()
  88. {
  89. m_selectedPlatforms = AzFramework::PlatformFlags::Platform_NONE;
  90. m_partiallySelectedPlatforms = AzFramework::PlatformFlags::Platform_NONE;
  91. for (int checkBoxIndex = 0; checkBoxIndex < m_platformCheckBoxes.size(); ++checkBoxIndex)
  92. {
  93. if (m_platformCheckBoxes[checkBoxIndex]->checkState() == Qt::Checked)
  94. {
  95. m_selectedPlatforms |= m_platformList[checkBoxIndex];
  96. }
  97. else if (m_platformCheckBoxes[checkBoxIndex]->checkState() == Qt::PartiallyChecked)
  98. {
  99. m_partiallySelectedPlatforms |= m_platformList[checkBoxIndex];
  100. }
  101. }
  102. emit PlatformsSelected(m_selectedPlatforms, m_partiallySelectedPlatforms);
  103. }
  104. } // namespace AssetBundler
  105. #include <source/ui/moc_PlatformSelectionWidget.cpp>