NewProjectSettingsScreen.cpp 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /*
  2. * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
  3. * its licensors.
  4. *
  5. * For complete copyright and license terms please see the LICENSE at the root of this
  6. * distribution (the "License"). All use of this software is governed by the License,
  7. * or, if provided, by the license below or the license accompanying this file. Do not
  8. * remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
  9. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. *
  11. */
  12. #include <NewProjectSettingsScreen.h>
  13. #include <PythonBindingsInterface.h>
  14. #include <FormLineEditWidget.h>
  15. #include <FormBrowseEditWidget.h>
  16. #include <PathValidator.h>
  17. #include <QVBoxLayout>
  18. #include <QHBoxLayout>
  19. #include <QFileDialog>
  20. #include <QLabel>
  21. #include <QLineEdit>
  22. #include <QRadioButton>
  23. #include <QButtonGroup>
  24. #include <QPushButton>
  25. #include <QSpacerItem>
  26. #include <QStandardPaths>
  27. #include <QFrame>
  28. namespace O3DE::ProjectManager
  29. {
  30. constexpr const char* k_pathProperty = "Path";
  31. NewProjectSettingsScreen::NewProjectSettingsScreen(QWidget* parent)
  32. : ScreenWidget(parent)
  33. {
  34. QHBoxLayout* hLayout = new QHBoxLayout(this);
  35. hLayout->setAlignment(Qt::AlignLeft);
  36. hLayout->setContentsMargins(0,0,0,0);
  37. // if we don't provide a parent for this box layout the stylesheet doesn't take
  38. // if we don't set this in a frame (just use a sub-layout) all the content will align incorrectly horizontally
  39. QFrame* projectSettingsFrame = new QFrame(this);
  40. projectSettingsFrame->setObjectName("projectSettings");
  41. QVBoxLayout* vLayout = new QVBoxLayout(this);
  42. // you cannot remove content margins in qss
  43. vLayout->setContentsMargins(0,0,0,0);
  44. vLayout->setAlignment(Qt::AlignTop);
  45. {
  46. m_projectName = new FormLineEditWidget(tr("Project name"), tr("New Project"), this);
  47. m_projectName->setErrorLabelText(
  48. tr("A project with this name already exists at this location. Please choose a new name or location."));
  49. vLayout->addWidget(m_projectName);
  50. m_projectPath =
  51. new FormBrowseEditWidget(tr("Project Location"), QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation), this);
  52. m_projectPath->lineEdit()->setReadOnly(true);
  53. m_projectPath->setErrorLabelText(tr("Please provide a valid path to a folder that exists"));
  54. m_projectPath->lineEdit()->setValidator(new PathValidator(PathValidator::PathMode::ExistingFolder, this));
  55. vLayout->addWidget(m_projectPath);
  56. // if we don't use a QFrame we cannot "contain" the widgets inside and move them around
  57. // as a group
  58. QFrame* projectTemplateWidget = new QFrame(this);
  59. projectTemplateWidget->setObjectName("projectTemplate");
  60. QVBoxLayout* containerLayout = new QVBoxLayout();
  61. containerLayout->setAlignment(Qt::AlignTop);
  62. {
  63. QLabel* projectTemplateLabel = new QLabel(tr("Select a Project Template"));
  64. projectTemplateLabel->setObjectName("projectTemplateLabel");
  65. containerLayout->addWidget(projectTemplateLabel);
  66. QLabel* projectTemplateDetailsLabel = new QLabel(tr("Project templates are pre-configured with relevant Gems that provide "
  67. "additional functionality and content to the project."));
  68. projectTemplateDetailsLabel->setWordWrap(true);
  69. projectTemplateDetailsLabel->setObjectName("projectTemplateDetailsLabel");
  70. containerLayout->addWidget(projectTemplateDetailsLabel);
  71. QHBoxLayout* templateLayout = new QHBoxLayout(this);
  72. containerLayout->addItem(templateLayout);
  73. m_projectTemplateButtonGroup = new QButtonGroup(this);
  74. m_projectTemplateButtonGroup->setObjectName("templateButtonGroup");
  75. auto templatesResult = PythonBindingsInterface::Get()->GetProjectTemplates();
  76. if (templatesResult.IsSuccess() && !templatesResult.GetValue().isEmpty())
  77. {
  78. for (auto projectTemplate : templatesResult.GetValue())
  79. {
  80. QRadioButton* radioButton = new QRadioButton(projectTemplate.m_name, this);
  81. radioButton->setProperty(k_pathProperty, projectTemplate.m_path);
  82. m_projectTemplateButtonGroup->addButton(radioButton);
  83. containerLayout->addWidget(radioButton);
  84. }
  85. m_projectTemplateButtonGroup->buttons().first()->setChecked(true);
  86. }
  87. }
  88. projectTemplateWidget->setLayout(containerLayout);
  89. vLayout->addWidget(projectTemplateWidget);
  90. }
  91. projectSettingsFrame->setLayout(vLayout);
  92. hLayout->addWidget(projectSettingsFrame);
  93. QWidget* projectTemplateDetails = new QWidget(this);
  94. projectTemplateDetails->setObjectName("projectTemplateDetails");
  95. hLayout->addWidget(projectTemplateDetails);
  96. this->setLayout(hLayout);
  97. }
  98. ProjectManagerScreen NewProjectSettingsScreen::GetScreenEnum()
  99. {
  100. return ProjectManagerScreen::NewProjectSettings;
  101. }
  102. ProjectInfo NewProjectSettingsScreen::GetProjectInfo()
  103. {
  104. ProjectInfo projectInfo;
  105. projectInfo.m_projectName = m_projectName->lineEdit()->text();
  106. projectInfo.m_path = QDir::toNativeSeparators(m_projectPath->lineEdit()->text() + "/" + projectInfo.m_projectName);
  107. return projectInfo;
  108. }
  109. QString NewProjectSettingsScreen::GetProjectTemplatePath()
  110. {
  111. return m_projectTemplateButtonGroup->checkedButton()->property(k_pathProperty).toString();
  112. }
  113. bool NewProjectSettingsScreen::Validate()
  114. {
  115. bool projectNameIsValid = true;
  116. if (m_projectName->lineEdit()->text().isEmpty())
  117. {
  118. projectNameIsValid = false;
  119. }
  120. bool projectPathIsValid = true;
  121. if (m_projectPath->lineEdit()->text().isEmpty())
  122. {
  123. projectPathIsValid = false;
  124. }
  125. QDir path(QDir::toNativeSeparators(m_projectPath->lineEdit()->text() + "/" + m_projectName->lineEdit()->text()));
  126. if (path.exists() && !path.isEmpty())
  127. {
  128. projectPathIsValid = false;
  129. }
  130. return projectNameIsValid && projectPathIsValid;
  131. }
  132. } // namespace O3DE::ProjectManager