AddRemoteProjectDialog.cpp 7.6 KB

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