AddRemoteProjectDialog.cpp 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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 <AddRemoteProjectDialog.h>
  9. #include <FormFolderBrowseEditWidget.h>
  10. #include <TextOverflowWidget.h>
  11. #include <AzQtComponents/Components/Widgets/CheckBox.h>
  12. #include <ProjectUtils.h>
  13. #include <QVBoxLayout>
  14. #include <QGridLayout>
  15. #include <QLabel>
  16. #include <QLineEdit>
  17. #include <QCheckBox>
  18. #include <QDialogButtonBox>
  19. #include <QPushButton>
  20. #include <QDir>
  21. namespace O3DE::ProjectManager
  22. {
  23. AddRemoteProjectDialog::AddRemoteProjectDialog(QWidget* parent)
  24. : QDialog(parent)
  25. {
  26. setWindowTitle(tr("Add a remote project"));
  27. setModal(true);
  28. setObjectName("addRemoteProjectDialog");
  29. setFixedSize(QSize(760, 600));
  30. QVBoxLayout* vLayout = new QVBoxLayout();
  31. vLayout->setContentsMargins(30, 30, 25, 10);
  32. vLayout->setSpacing(0);
  33. vLayout->setAlignment(Qt::AlignTop);
  34. setLayout(vLayout);
  35. QLabel* instructionTitleLabel = new QLabel(tr("Please enter a remote URL for your project"), this);
  36. instructionTitleLabel->setObjectName("remoteProjectDialogInstructionTitleLabel");
  37. instructionTitleLabel->setAlignment(Qt::AlignLeft);
  38. vLayout->addWidget(instructionTitleLabel);
  39. vLayout->addSpacing(10);
  40. m_repoPath = new FormLineEditWidget(tr("Remote URL"), "", this);
  41. m_repoPath->setMinimumSize(QSize(600, 0));
  42. vLayout->addWidget(m_repoPath);
  43. vLayout->addSpacing(10);
  44. QLabel* warningLabel = new QLabel(tr("Online repositories may contain files that could potentially harm your computer,"
  45. " please ensure you understand the risks before downloading from third-party sources."), this);
  46. warningLabel->setObjectName("remoteProjectDialogWarningLabel");
  47. warningLabel->setWordWrap(true);
  48. warningLabel->setAlignment(Qt::AlignLeft);
  49. vLayout->addWidget(warningLabel);
  50. vLayout->addSpacing(10);
  51. QFrame* hLine = new QFrame();
  52. hLine->setFrameShape(QFrame::HLine);
  53. hLine->setObjectName("horizontalSeparatingLine");
  54. vLayout->addWidget(hLine);
  55. vLayout->addSpacing(10);
  56. m_downloadProjectLabel = new QLabel(tr("Download Project..."), this);
  57. m_downloadProjectLabel->setObjectName("remoteProjectDialogDownloadProjectLabel");
  58. m_downloadProjectLabel->setAlignment(Qt::AlignLeft);
  59. vLayout->addWidget(m_downloadProjectLabel);
  60. m_installPath = new FormFolderBrowseEditWidget(tr("Local project directory"));
  61. m_installPath->setMinimumSize(QSize(600, 0));
  62. vLayout->addWidget(m_installPath);
  63. vLayout->addSpacing(10);
  64. QHBoxLayout* buildHLayout = new QHBoxLayout(this);
  65. buildHLayout->setContentsMargins(0, 0, 0, 0);
  66. buildHLayout->setAlignment(Qt::AlignLeft);
  67. m_autoBuild = new QCheckBox(this);
  68. m_autoBuild->setChecked(true);
  69. AzQtComponents::CheckBox::applyToggleSwitchStyle(m_autoBuild);
  70. buildHLayout->addWidget(m_autoBuild);
  71. buildHLayout->addSpacing(10);
  72. m_buildToggleLabel = new QLabel(tr("Automatically build project"), this);
  73. m_buildToggleLabel->setAlignment(Qt::AlignLeft);
  74. buildHLayout->addWidget(m_buildToggleLabel);
  75. vLayout->addLayout(buildHLayout);
  76. vLayout->addSpacing(20);
  77. QGridLayout* extraInfoGridLayout = new QGridLayout(this);
  78. extraInfoGridLayout->setContentsMargins(0, 0, 0, 0);
  79. extraInfoGridLayout->setHorizontalSpacing(5);
  80. extraInfoGridLayout->setVerticalSpacing(15);
  81. extraInfoGridLayout->setAlignment(Qt::AlignLeft);
  82. m_requirementsTitleLabel = new QLabel(tr("Requirements"), this);
  83. m_requirementsTitleLabel->setObjectName("remoteProjectDialogRequirementsTitleLabel");
  84. m_requirementsTitleLabel->setAlignment(Qt::AlignLeft);
  85. extraInfoGridLayout->addWidget(m_requirementsTitleLabel, 0, 0);
  86. m_licensesTitleLabel = new QLabel(tr("Licenses"), this);
  87. m_licensesTitleLabel->setObjectName("remoteProjectDialogLicensesTitleLabel");
  88. m_licensesTitleLabel->setAlignment(Qt::AlignLeft);
  89. extraInfoGridLayout->addWidget(m_licensesTitleLabel, 0, 1);
  90. extraInfoGridLayout->setVerticalSpacing(15);
  91. m_requirementsContentLabel = new TextOverflowLabel(tr("Requirements"));
  92. m_requirementsContentLabel->setObjectName("remoteProjectDialogRequirementsContentLabel");
  93. m_requirementsContentLabel->setWordWrap(true);
  94. m_requirementsContentLabel->setAlignment(Qt::AlignLeft);
  95. m_requirementsContentLabel->setFixedWidth(350);
  96. extraInfoGridLayout->addWidget(m_requirementsContentLabel, 1, 0);
  97. m_licensesContentLabel = new TextOverflowLabel(tr("Licenses"));
  98. m_licensesContentLabel->setObjectName("remoteProjectDialogLicensesContentLabel");
  99. m_licensesContentLabel->setWordWrap(true);
  100. m_licensesContentLabel->setAlignment(Qt::AlignLeft);
  101. m_licensesContentLabel->setFixedWidth(350);
  102. extraInfoGridLayout->addWidget(m_licensesContentLabel, 1, 1);
  103. vLayout->addLayout(extraInfoGridLayout);
  104. vLayout->addStretch();
  105. m_dialogButtons = new QDialogButtonBox();
  106. m_dialogButtons->setObjectName("footer");
  107. vLayout->addWidget(m_dialogButtons);
  108. QPushButton* cancelButton = m_dialogButtons->addButton(tr("Cancel"), QDialogButtonBox::RejectRole);
  109. cancelButton->setProperty("secondary", true);
  110. m_applyButton = m_dialogButtons->addButton(tr("Download && Build"), QDialogButtonBox::ApplyRole);
  111. connect(cancelButton, &QPushButton::clicked, this, &QDialog::reject);
  112. connect(m_applyButton, &QPushButton::clicked, this, &QDialog::accept);
  113. connect(
  114. m_autoBuild, &QCheckBox::clicked, [this](bool checked)
  115. {
  116. if (checked)
  117. {
  118. m_applyButton->setText(tr("Download && Build"));
  119. }
  120. else
  121. {
  122. m_applyButton->setText(tr("Download"));
  123. }
  124. }
  125. );
  126. // Simulate repo being entered and UI enabling
  127. connect(
  128. m_repoPath->lineEdit(), &QLineEdit::textEdited,
  129. [this](const QString& text)
  130. {
  131. SetDialogReady(!text.isEmpty());
  132. });
  133. SetDialogReady(false);
  134. }
  135. QString AddRemoteProjectDialog::GetRepoPath()
  136. {
  137. return m_repoPath->lineEdit()->text();
  138. }
  139. QString AddRemoteProjectDialog::GetInstallPath()
  140. {
  141. return m_installPath->lineEdit()->text();
  142. }
  143. bool AddRemoteProjectDialog::ShouldBuild()
  144. {
  145. return m_autoBuild->isChecked();
  146. }
  147. void AddRemoteProjectDialog::SetCurrentProject(const ProjectInfo& projectInfo)
  148. {
  149. m_currentProject = projectInfo;
  150. m_downloadProjectLabel->setText(projectInfo.m_displayName);
  151. m_installPath->lineEdit()->setText(QDir::toNativeSeparators(ProjectUtils::GetDefaultProjectPath() + "/" + projectInfo.m_projectName));
  152. }
  153. void AddRemoteProjectDialog::SetDialogReady(bool isReady)
  154. {
  155. m_downloadProjectLabel->setEnabled(isReady);
  156. m_installPath->setEnabled(isReady);
  157. m_autoBuild->setEnabled(isReady);
  158. m_buildToggleLabel->setEnabled(isReady);
  159. m_requirementsTitleLabel->setEnabled(isReady);
  160. m_licensesTitleLabel->setEnabled(isReady);
  161. m_requirementsContentLabel->setEnabled(isReady);
  162. m_licensesContentLabel->setEnabled(isReady);
  163. m_dialogButtons->setEnabled(isReady);
  164. }
  165. } // namespace O3DE::ProjectManager