ProjectButtonWidget.cpp 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746
  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 <ProjectButtonWidget.h>
  9. #include <ProjectManagerDefs.h>
  10. #include <ProjectUtils.h>
  11. #include <ProjectManager_Traits_Platform.h>
  12. #include <AzQtComponents/Utilities/DesktopUtilities.h>
  13. #include <AzQtComponents/Components/Widgets/ElidingLabel.h>
  14. #include <AzCore/IO/SystemFile.h>
  15. #include <AzCore/IO/Path/Path.h>
  16. #include <QVBoxLayout>
  17. #include <QHBoxLayout>
  18. #include <QEvent>
  19. #include <QResizeEvent>
  20. #include <QLabel>
  21. #include <QPushButton>
  22. #include <QPixmap>
  23. #include <QMenu>
  24. #include <QSpacerItem>
  25. #include <QProgressBar>
  26. #include <QDebug>
  27. #include <QDir>
  28. #include <QFileInfo>
  29. #include <QDesktopServices>
  30. #include <QMessageBox>
  31. #include <QMouseEvent>
  32. #include <QMovie>
  33. namespace O3DE::ProjectManager
  34. {
  35. LabelButton::LabelButton(QWidget* parent)
  36. : QLabel(parent)
  37. {
  38. // Space for content excluding borders
  39. constexpr int contentSpaceWidth = ProjectPreviewImageWidth - 2;
  40. // The height of a third of the button split into 3 sections, top, middle and bottom
  41. constexpr int threeWaySplitHeight = (ProjectPreviewImageHeight - 2) / 3;
  42. setObjectName("labelButton");
  43. // Use GridLayout so widgets can be overlapped
  44. QGridLayout* overlayLayout = new QGridLayout();
  45. overlayLayout->setContentsMargins(0, 0, 0, 0);
  46. overlayLayout->setSpacing(0);
  47. setLayout(overlayLayout);
  48. m_darkenOverlay = new QLabel(this);
  49. m_darkenOverlay->setObjectName("labelButtonOverlay");
  50. m_darkenOverlay->setVisible(true);
  51. overlayLayout->addWidget(m_darkenOverlay, 0, 0);
  52. m_projectOverlayLayout = new QVBoxLayout();
  53. m_projectOverlayLayout->setContentsMargins(0, 0, 0, 0);
  54. m_projectOverlayLayout->setSpacing(0);
  55. m_projectOverlayLayout->setAlignment(Qt::AlignCenter);
  56. // Split the button into 3 fixed size sections so content alignment is easier to manage
  57. // If widgets in other sections are shown or hidden it will not offset alignment in other sections
  58. QWidget* topWidget = new QWidget();
  59. topWidget->setFixedSize(contentSpaceWidth, threeWaySplitHeight);
  60. QVBoxLayout* verticalMessageLayout = new QVBoxLayout();
  61. verticalMessageLayout->setContentsMargins(0, 0, 0, 0);
  62. verticalMessageLayout->setSpacing(4);
  63. verticalMessageLayout->setAlignment(Qt::AlignCenter);
  64. topWidget->setLayout(verticalMessageLayout);
  65. verticalMessageLayout->addSpacing(10);
  66. QHBoxLayout* horizontalWarningMessageLayout = new QHBoxLayout();
  67. horizontalWarningMessageLayout->setContentsMargins(0, 0, 0, 0);
  68. horizontalWarningMessageLayout->setSpacing(0);
  69. horizontalWarningMessageLayout->setAlignment(Qt::AlignRight | Qt::AlignTop);
  70. m_warningSpacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Fixed);
  71. horizontalWarningMessageLayout->addSpacerItem(m_warningSpacer);
  72. horizontalWarningMessageLayout->addSpacing(10);
  73. m_warningIcon = new QLabel(this);
  74. m_warningIcon->setObjectName("projectWarningIconOverlay");
  75. m_warningIcon->setPixmap(QIcon(":/Warning.svg").pixmap(32, 32));
  76. m_warningIcon->setAlignment(Qt::AlignCenter);
  77. m_warningIcon->setVisible(false);
  78. horizontalWarningMessageLayout->addWidget(m_warningIcon);
  79. m_cloudIcon = new QLabel(this);
  80. m_cloudIcon->setObjectName("projectCloudIconOverlay");
  81. m_cloudIcon->setPixmap(QIcon(":/Download.svg").pixmap(32, 32));
  82. m_cloudIcon->setVisible(false);
  83. horizontalWarningMessageLayout->addWidget(m_cloudIcon);
  84. horizontalWarningMessageLayout->addSpacing(15);
  85. verticalMessageLayout->addLayout(horizontalWarningMessageLayout);
  86. m_messageLabel = new QLabel("", this);
  87. m_messageLabel->setObjectName("projectMessageOverlay");
  88. m_messageLabel->setAlignment(Qt::AlignCenter);
  89. m_messageLabel->setVisible(true);
  90. verticalMessageLayout->addWidget(m_messageLabel);
  91. m_subMessageLabel = new QLabel("", this);
  92. m_subMessageLabel->setObjectName("projectSubMessageOverlay");
  93. m_subMessageLabel->setAlignment(Qt::AlignCenter);
  94. m_subMessageLabel->setVisible(true);
  95. verticalMessageLayout->addWidget(m_subMessageLabel);
  96. verticalMessageLayout->addStretch();
  97. m_projectOverlayLayout->addWidget(topWidget);
  98. QWidget* middleWidget = new QWidget();
  99. middleWidget->setFixedSize(contentSpaceWidth, threeWaySplitHeight);
  100. QVBoxLayout* verticalCenterLayout = new QVBoxLayout();
  101. verticalCenterLayout->setContentsMargins(0, 0, 0, 0);
  102. verticalCenterLayout->setSpacing(0);
  103. verticalCenterLayout->setAlignment(Qt::AlignCenter);
  104. middleWidget->setLayout(verticalCenterLayout);
  105. m_buildingAnimation = new QLabel("", this);
  106. m_buildingAnimation->setObjectName("buildingAnimationOverlay");
  107. m_buildingAnimation->setAlignment(Qt::AlignCenter);
  108. m_buildingAnimation->setVisible(false);
  109. m_buildingAnimation->setMovie(new QMovie(":/SpinningGears.webp"));
  110. m_buildingAnimation->movie()->start();
  111. verticalCenterLayout->addWidget(m_buildingAnimation);
  112. // Download Progress
  113. QWidget* m_downloadProgress = new QWidget(this);
  114. m_progessBar = new QProgressBar(this);
  115. m_progessBar->setVisible(false);
  116. QVBoxLayout* downloadProgressLayout = new QVBoxLayout();
  117. QHBoxLayout* downloadProgressTextLayout = new QHBoxLayout();
  118. m_downloadMessageLabel = new QLabel(tr("Downloading Project"), this);
  119. m_downloadMessageLabel->setAlignment(Qt::AlignCenter);
  120. m_downloadMessageLabel->setVisible(false);
  121. verticalCenterLayout->addWidget(m_downloadMessageLabel);
  122. downloadProgressTextLayout->addSpacing(25);
  123. m_progressMessageLabel = new QLabel(tr("0%"), this);
  124. m_progressMessageLabel->setAlignment(Qt::AlignRight);
  125. m_progressMessageLabel->setVisible(false);
  126. downloadProgressTextLayout->addWidget(m_progressMessageLabel);
  127. downloadProgressTextLayout->addSpacing(25);
  128. verticalCenterLayout->addLayout(downloadProgressTextLayout);
  129. QHBoxLayout* progressbarLayout = new QHBoxLayout();
  130. downloadProgressLayout->addLayout(progressbarLayout);
  131. m_downloadProgress->setLayout(downloadProgressLayout);
  132. progressbarLayout->addSpacing(20);
  133. progressbarLayout->addWidget(m_progessBar);
  134. progressbarLayout->addSpacing(20);
  135. verticalCenterLayout->addWidget(m_downloadProgress);
  136. m_projectOverlayLayout->addWidget(middleWidget);
  137. QWidget* bottomWidget = new QWidget();
  138. bottomWidget->setFixedSize(contentSpaceWidth, threeWaySplitHeight);
  139. QVBoxLayout* verticalButtonLayout = new QVBoxLayout();
  140. verticalButtonLayout->setContentsMargins(0, 0, 0, 0);
  141. verticalButtonLayout->setSpacing(5);
  142. verticalButtonLayout->setAlignment(Qt::AlignHCenter | Qt::AlignBottom);
  143. bottomWidget->setLayout(verticalButtonLayout);
  144. m_openEditorButton = new QPushButton(tr("Open Editor"), this);
  145. m_openEditorButton->setObjectName("openEditorButton");
  146. m_openEditorButton->setDefault(true);
  147. m_openEditorButton->setVisible(false);
  148. verticalButtonLayout->addWidget(m_openEditorButton);
  149. m_actionButton = new QPushButton(tr("Project Action"), this);
  150. m_actionButton->setObjectName("projectActionButton");
  151. m_actionButton->setVisible(false);
  152. verticalButtonLayout->addWidget(m_actionButton);
  153. // This button has seperate styling with a red button instead of a blue button as for m_actionButton
  154. // Seperate buttons are used to avoid stutter from reloading style after changing object name
  155. m_actionCancelButton = new QPushButton(tr("Cancel Project Action"), this);
  156. m_actionCancelButton->setObjectName("projectActionCancelButton");
  157. m_actionCancelButton->setProperty("danger", true);
  158. m_actionCancelButton->setVisible(false);
  159. verticalButtonLayout->addWidget(m_actionCancelButton);
  160. m_showLogsButton = new QPushButton(tr("Show logs"), this);
  161. m_showLogsButton->setObjectName("projectShowLogsButton");
  162. m_showLogsButton->setVisible(false);
  163. verticalButtonLayout->addWidget(m_showLogsButton);
  164. verticalButtonLayout->addSpacing(20);
  165. m_projectOverlayLayout->addWidget(bottomWidget);
  166. overlayLayout->addLayout(m_projectOverlayLayout, 0, 0);
  167. }
  168. void LabelButton::mousePressEvent(QMouseEvent* event)
  169. {
  170. emit triggered(event);
  171. }
  172. QLabel* LabelButton::GetMessageLabel()
  173. {
  174. return m_messageLabel;
  175. }
  176. QLabel* LabelButton::GetSubMessageLabel()
  177. {
  178. return m_subMessageLabel;
  179. }
  180. QLabel* LabelButton::GetWarningIcon()
  181. {
  182. return m_warningIcon;
  183. }
  184. QLabel* LabelButton::GetCloudIcon()
  185. {
  186. return m_cloudIcon;
  187. }
  188. QSpacerItem* LabelButton::GetWarningSpacer()
  189. {
  190. return m_warningSpacer;
  191. }
  192. QLabel* LabelButton::GetBuildingAnimationLabel()
  193. {
  194. return m_buildingAnimation;
  195. }
  196. QPushButton* LabelButton::GetOpenEditorButton()
  197. {
  198. return m_openEditorButton;
  199. }
  200. QPushButton* LabelButton::GetActionButton()
  201. {
  202. return m_actionButton;
  203. }
  204. QPushButton* LabelButton::GetActionCancelButton()
  205. {
  206. return m_actionCancelButton;
  207. }
  208. QPushButton* LabelButton::GetShowLogsButton()
  209. {
  210. return m_showLogsButton;
  211. }
  212. QLabel* LabelButton::GetDarkenOverlay()
  213. {
  214. return m_darkenOverlay;
  215. }
  216. QProgressBar* LabelButton::GetProgressBar()
  217. {
  218. return m_progessBar;
  219. }
  220. QLabel* LabelButton::GetProgressPercentage()
  221. {
  222. return m_progressMessageLabel;
  223. }
  224. QLabel* LabelButton::GetDownloadMessageLabel()
  225. {
  226. return m_downloadMessageLabel;
  227. }
  228. ProjectButton::ProjectButton(const ProjectInfo& projectInfo, const EngineInfo& engineInfo, QWidget* parent)
  229. : QFrame(parent)
  230. , m_engineInfo(engineInfo)
  231. , m_projectInfo(projectInfo)
  232. , m_isProjectBuilding(false)
  233. {
  234. setObjectName("projectButton");
  235. QVBoxLayout* vLayout = new QVBoxLayout();
  236. vLayout->setSpacing(0);
  237. vLayout->setContentsMargins(0, 0, 0, 0);
  238. setLayout(vLayout);
  239. m_projectImageLabel = new LabelButton(this);
  240. m_projectImageLabel->setFixedSize(ProjectPreviewImageWidth, ProjectPreviewImageHeight);
  241. m_projectImageLabel->setAlignment(Qt::AlignCenter);
  242. vLayout->addWidget(m_projectImageLabel);
  243. QString projectPreviewPath = QDir(m_projectInfo.m_path).filePath(m_projectInfo.m_iconPath);
  244. QFileInfo doesPreviewExist(projectPreviewPath);
  245. if (!doesPreviewExist.exists() || !doesPreviewExist.isFile())
  246. {
  247. projectPreviewPath = ":/DefaultProjectImage.png";
  248. }
  249. m_projectImageLabel->setPixmap(QPixmap(projectPreviewPath).scaled(m_projectImageLabel->size(), Qt::KeepAspectRatioByExpanding));
  250. QFrame* projectFooter = new QFrame(this);
  251. QVBoxLayout* projectFooterLayout = new QVBoxLayout();
  252. projectFooterLayout->setContentsMargins(0, 0, 0, 0);
  253. projectFooter->setLayout(projectFooterLayout);
  254. {
  255. // row 1
  256. QHBoxLayout* hLayout = new QHBoxLayout();
  257. hLayout->setContentsMargins(0, 0, 0, 0);
  258. QString projectName = m_projectInfo.GetProjectDisplayName();
  259. if (!m_projectInfo.m_version.isEmpty())
  260. {
  261. projectName +=" " + m_projectInfo.m_version;
  262. }
  263. m_projectNameLabel = new AzQtComponents::ElidingLabel(projectName, this);
  264. m_projectNameLabel->setObjectName("projectNameLabel");
  265. m_projectNameLabel->setToolTip(m_projectInfo.m_path);
  266. m_projectNameLabel->refreshStyle();
  267. hLayout->addWidget(m_projectNameLabel);
  268. m_projectMenuButton = new QPushButton(this);
  269. m_projectMenuButton->setObjectName("projectMenuButton");
  270. m_projectMenuButton->setMenu(CreateProjectMenu());
  271. hLayout->addWidget(m_projectMenuButton);
  272. projectFooterLayout->addLayout(hLayout);
  273. // row 2
  274. m_engineNameLabel = new AzQtComponents::ElidingLabel(m_engineInfo.m_name + " " + m_engineInfo.m_version, this);
  275. SetEngine(m_engineInfo);
  276. projectFooterLayout->addWidget(m_engineNameLabel);
  277. }
  278. vLayout->addWidget(projectFooter);
  279. connect(m_projectImageLabel->GetOpenEditorButton(), &QPushButton::clicked, [this]() {
  280. emit OpenProject(m_projectInfo.m_path);
  281. });
  282. connect(m_projectImageLabel, &LabelButton::triggered, [this](QMouseEvent* event) {
  283. if (!m_isProjectBuilding && event->button() == Qt::RightButton)
  284. {
  285. m_projectMenuButton->menu()->move(event->globalPos());
  286. m_projectMenuButton->menu()->show();
  287. }
  288. });
  289. connect(m_projectImageLabel->GetShowLogsButton(), &QPushButton::pressed, this, &ProjectButton::ShowLogs);
  290. SetState(ProjectButtonState::ReadyToLaunch);
  291. }
  292. ProjectButton::~ProjectButton() = default;
  293. QMenu* ProjectButton::CreateProjectMenu()
  294. {
  295. QMenu* menu = new QMenu(this);
  296. menu->addAction(tr("Edit Project Settings..."), this, [this]() { emit EditProject(m_projectInfo.m_path); });
  297. menu->addAction(tr("Configure Gems..."), this, [this]() { emit EditProjectGems(m_projectInfo.m_path); });
  298. menu->addAction(tr("Build"), this, [this]() { emit BuildProject(m_projectInfo); });
  299. menu->addAction(tr("Open CMake GUI..."), this, [this]() { emit OpenCMakeGUI(m_projectInfo); });
  300. menu->addAction(tr("Open Android Project Generator..."), this, [this]() { emit OpenAndroidProjectGenerator(m_projectInfo.m_path); });
  301. menu->addSeparator();
  302. menu->addAction(tr("Open Project folder..."), this, [this]()
  303. {
  304. AzQtComponents::ShowFileOnDesktop(m_projectInfo.m_path);
  305. });
  306. #if AZ_TRAIT_PROJECT_MANAGER_CREATE_DESKTOP_SHORTCUT
  307. menu->addAction(tr("Create Editor desktop shortcut..."), this, [this]()
  308. {
  309. AZ::IO::FixedMaxPath editorExecutablePath = ProjectUtils::GetEditorExecutablePath(m_projectInfo.m_path.toUtf8().constData());
  310. const QString shortcutName = QString("%1 Editor").arg(m_projectInfo.m_displayName);
  311. const QString arg = QString("--regset=\"/Amazon/AzCore/Bootstrap/project_path=%1\"").arg(m_projectInfo.m_path);
  312. auto result = ProjectUtils::CreateDesktopShortcut(shortcutName, editorExecutablePath.c_str(), { arg });
  313. if(result.IsSuccess())
  314. {
  315. QMessageBox::information(this, tr("Desktop Shortcut Created"), result.GetValue());
  316. }
  317. else
  318. {
  319. QMessageBox::critical(this, tr("Failed to create shortcut"), result.GetError());
  320. }
  321. });
  322. #endif // AZ_TRAIT_PROJECT_MANAGER_CREATE_DESKTOP_SHORTCUT
  323. menu->addSeparator();
  324. menu->addAction(tr("Duplicate"), this, [this]() { emit CopyProject(m_projectInfo); });
  325. menu->addSeparator();
  326. menu->addAction(tr("Remove from O3DE"), this, [this]() { emit RemoveProject(m_projectInfo.m_path); });
  327. menu->addAction(tr("Delete this Project"), this, [this]() { emit DeleteProject(m_projectInfo.m_path); });
  328. return menu;
  329. }
  330. const ProjectInfo& ProjectButton::GetProjectInfo() const
  331. {
  332. return m_projectInfo;
  333. }
  334. void ProjectButton::ShowLogs()
  335. {
  336. if (!QDesktopServices::openUrl(m_projectInfo.m_logUrl))
  337. {
  338. qDebug() << "QDesktopServices::openUrl failed to open " << m_projectInfo.m_logUrl.toString() << "\n";
  339. }
  340. }
  341. void ProjectButton::SetEngine(const EngineInfo& engine)
  342. {
  343. m_engineInfo = engine;
  344. if (m_engineInfo.m_name.isEmpty() && !m_projectInfo.m_engineName.isEmpty())
  345. {
  346. // this project wants to use an engine that wasn't found, display the qualifier
  347. m_engineInfo.m_name = m_projectInfo.m_engineName;
  348. m_engineInfo.m_version = "";
  349. }
  350. m_engineNameLabel->SetText(m_engineInfo.m_name + " " + m_engineInfo.m_version);
  351. m_engineNameLabel->update();
  352. m_engineNameLabel->setObjectName(m_engineInfo.m_thisEngine ? "thisEngineLabel" : "otherEngineLabel");
  353. m_engineNameLabel->setToolTip(m_engineInfo.m_name + " " + m_engineInfo.m_version + " " + m_engineInfo.m_path);
  354. m_engineNameLabel->refreshStyle(); // important for styles to work correctly
  355. }
  356. void ProjectButton::SetProject(const ProjectInfo& project)
  357. {
  358. m_projectInfo = project;
  359. if (!m_projectInfo.m_version.isEmpty())
  360. {
  361. m_projectNameLabel->SetText(m_projectInfo.GetProjectDisplayName() + " " + m_projectInfo.m_version);
  362. }
  363. else
  364. {
  365. m_projectNameLabel->SetText(m_projectInfo.GetProjectDisplayName());
  366. }
  367. m_projectNameLabel->update();
  368. m_projectNameLabel->setToolTip(m_projectInfo.m_path);
  369. m_projectNameLabel->refreshStyle(); // important for styles to work correctly
  370. }
  371. void ProjectButton::SetState(ProjectButtonState state)
  372. {
  373. m_currentState = state;
  374. ResetButtonWidgets();
  375. switch (state)
  376. {
  377. default:
  378. case ProjectButtonState::ReadyToLaunch:
  379. ShowReadyState();
  380. break;
  381. case ProjectButtonState::Launching:
  382. ShowLaunchingState();
  383. break;
  384. case ProjectButtonState::NeedsToBuild:
  385. ShowBuildRequiredState();
  386. break;
  387. case ProjectButtonState::Building:
  388. ShowBuildingState();
  389. break;
  390. case ProjectButtonState::BuildFailed:
  391. ShowBuildFailedState();
  392. break;
  393. case ProjectButtonState::NotDownloaded:
  394. ShowNotDownloadedState();
  395. break;
  396. case ProjectButtonState::DownloadingBuildQueued:
  397. case ProjectButtonState::Downloading:
  398. ShowDownloadingState();
  399. break;
  400. }
  401. }
  402. void ProjectButton::ShowReadyState()
  403. {
  404. HideContextualLabelButtonWidgets();
  405. if (m_actionButtonConnection)
  406. {
  407. disconnect(m_actionButtonConnection);
  408. }
  409. m_projectMenuButton->setVisible(true);
  410. SetLaunchingEnabled(true);
  411. SetProjectBuilding(false);
  412. }
  413. void ProjectButton::ShowLaunchingState()
  414. {
  415. // Hide button in-case it is still showing
  416. m_projectImageLabel->GetOpenEditorButton()->hide();
  417. SetLaunchingEnabled(false);
  418. ShowMessage(tr("Opening Editor..."));
  419. }
  420. void ProjectButton::ShowBuildRequiredState()
  421. {
  422. ShowBuildButton();
  423. SetProjectBuilding(false);
  424. ShowWarning(tr("Project build required."));
  425. }
  426. void ProjectButton::ShowBuildingState()
  427. {
  428. m_projectImageLabel->GetShowLogsButton()->show();
  429. // Setting project to building also disables launching
  430. SetProjectBuilding(true);
  431. ShowMessage(tr("Building Project..."));
  432. }
  433. void ProjectButton::ShowBuildFailedState()
  434. {
  435. ShowBuildButton();
  436. SetProjectBuilding(false);
  437. // Show, show logs button if avaliable
  438. m_projectImageLabel->GetShowLogsButton()->setVisible(!m_projectInfo.m_logUrl.isEmpty());
  439. ShowWarning(tr("Failed to build"));
  440. }
  441. void ProjectButton::ShowNotDownloadedState()
  442. {
  443. m_projectImageLabel->GetCloudIcon()->setVisible(true);
  444. m_projectImageLabel->GetWarningSpacer()->changeSize(0, 0, QSizePolicy::Expanding, QSizePolicy::Fixed);
  445. m_projectMenuButton->setVisible(false);
  446. SetLaunchingEnabled(false);
  447. }
  448. void ProjectButton::ShowDownloadingState()
  449. {
  450. m_projectImageLabel->GetCloudIcon()->setVisible(true);
  451. m_projectImageLabel->GetWarningSpacer()->changeSize(0, 0, QSizePolicy::Expanding, QSizePolicy::Fixed);
  452. m_projectMenuButton->setVisible(false);
  453. m_projectImageLabel->GetDownloadMessageLabel()->setVisible(true);
  454. m_projectImageLabel->GetProgressPercentage()->setVisible(true);
  455. m_projectImageLabel->GetProgressBar()->setVisible(true);
  456. SetLaunchingEnabled(false);
  457. }
  458. void ProjectButton::SetProjectButtonAction(const QString& text, AZStd::function<void()> lambda)
  459. {
  460. QPushButton* projectActionButton;
  461. QPushButton* projectOtherActionButton;
  462. if (text.contains("Cancel", Qt::CaseInsensitive))
  463. {
  464. // Use red button is action involves cancelling
  465. projectActionButton = m_projectImageLabel->GetActionCancelButton();
  466. projectOtherActionButton = m_projectImageLabel->GetActionButton();
  467. }
  468. else
  469. {
  470. projectActionButton = m_projectImageLabel->GetActionButton();
  471. projectOtherActionButton = m_projectImageLabel->GetActionCancelButton();
  472. }
  473. if (m_actionButtonConnection)
  474. {
  475. disconnect(m_actionButtonConnection);
  476. }
  477. projectActionButton->setVisible(true);
  478. projectOtherActionButton->setVisible(false);
  479. projectActionButton->setText(text);
  480. projectActionButton->setMenu(nullptr);
  481. m_actionButtonConnection = connect(projectActionButton, &QPushButton::clicked, lambda);
  482. }
  483. void ProjectButton::SetBuildLogsLink(const QUrl& logUrl)
  484. {
  485. m_projectInfo.m_logUrl = logUrl;
  486. }
  487. void ProjectButton::SetProgressBarPercentage(const float percent)
  488. {
  489. m_projectImageLabel->GetProgressBar()->setValue(static_cast<int>(percent*100));
  490. m_projectImageLabel->GetProgressPercentage()->setText(QString("%1%").arg(static_cast<int>(percent*100)));
  491. }
  492. void ProjectButton::SetContextualText(const QString& text)
  493. {
  494. if (m_currentState == ProjectButtonState::Building)
  495. {
  496. // Don't update for empty build progress messages
  497. if (!text.isEmpty())
  498. {
  499. // Show info about what's currently building
  500. ShowMessage({}, text);
  501. }
  502. }
  503. else
  504. {
  505. ShowMessage(text);
  506. }
  507. }
  508. void ProjectButton::ShowBuildButton()
  509. {
  510. QPushButton* projectActionButton = m_projectImageLabel->GetActionButton();
  511. projectActionButton->setVisible(true);
  512. projectActionButton->setText(tr("Build Project"));
  513. disconnect(m_actionButtonConnection);
  514. QMenu* menu = new QMenu(this);
  515. QAction* autoBuildAction = menu->addAction(tr("Build Now"));
  516. connect( autoBuildAction, &QAction::triggered, this, [this](){ emit BuildProject(m_projectInfo); });
  517. QAction* openCMakeAction = menu->addAction(tr("Open CMake GUI..."));
  518. connect( openCMakeAction, &QAction::triggered, this, [this](){ emit OpenCMakeGUI(m_projectInfo); });
  519. projectActionButton->setMenu(menu);
  520. }
  521. void ProjectButton::ResetButtonWidgets()
  522. {
  523. HideContextualLabelButtonWidgets();
  524. SetProjectBuilding(false);
  525. SetProgressBarPercentage(0);
  526. m_projectImageLabel->GetDownloadMessageLabel()->setVisible(false);
  527. m_projectImageLabel->GetProgressPercentage()->setVisible(false);
  528. m_projectImageLabel->GetProgressBar()->setVisible(false);
  529. }
  530. // Only setting message without setting submessage will hide submessage
  531. void ProjectButton::ShowMessage(const QString& message, const QString& submessage)
  532. {
  533. bool showMessage = !message.isEmpty();
  534. bool showSubmessage = !submessage.isEmpty();
  535. QLabel* messageLabel = m_projectImageLabel->GetMessageLabel();
  536. QLabel* submessageLabel = m_projectImageLabel->GetSubMessageLabel();
  537. if (showMessage || showSubmessage)
  538. {
  539. // Hide any warning text, we cannot show the warning and a message at the same time
  540. ShowWarning();
  541. }
  542. // Keep main message if only submessage is set
  543. if (showMessage || showMessage == showSubmessage)
  544. {
  545. messageLabel->setText(message);
  546. }
  547. submessageLabel->setText(submessage);
  548. // Darken background if there is a message to make it easier to read
  549. m_projectImageLabel->GetDarkenOverlay()->setVisible(showMessage || showSubmessage);
  550. messageLabel->setVisible(showMessage || showSubmessage);
  551. submessageLabel->setVisible(showSubmessage);
  552. }
  553. void ProjectButton::ShowWarning(const QString& warning)
  554. {
  555. bool show = !warning.isEmpty();
  556. QLabel* warningIcon = m_projectImageLabel->GetWarningIcon();
  557. if (show)
  558. {
  559. // Hide any message text, we cannot show the warning and a message at the same time
  560. ShowMessage();
  561. m_projectImageLabel->GetWarningSpacer()->changeSize(0, 0, QSizePolicy::Expanding, QSizePolicy::Fixed);
  562. }
  563. else
  564. {
  565. m_projectImageLabel->GetWarningSpacer()->changeSize(0, 0, QSizePolicy::Fixed, QSizePolicy::Fixed);
  566. }
  567. warningIcon->setToolTip(warning);
  568. warningIcon->setVisible(show);
  569. }
  570. void ProjectButton::SetLaunchingEnabled(bool enabled)
  571. {
  572. m_canLaunch = enabled;
  573. }
  574. void ProjectButton::SetProjectBuilding(bool isBuilding)
  575. {
  576. m_isProjectBuilding = isBuilding;
  577. QLabel* buildingAnimation = m_projectImageLabel->GetBuildingAnimationLabel();
  578. if (isBuilding)
  579. {
  580. SetLaunchingEnabled(false);
  581. m_projectImageLabel->GetActionCancelButton()->show();
  582. }
  583. buildingAnimation->movie()->setPaused(!isBuilding);
  584. buildingAnimation->setVisible(isBuilding);
  585. m_projectMenuButton->setVisible(!isBuilding);
  586. }
  587. void ProjectButton::HideContextualLabelButtonWidgets()
  588. {
  589. ShowMessage();
  590. ShowWarning();
  591. m_projectImageLabel->GetActionButton()->hide();
  592. m_projectImageLabel->GetActionCancelButton()->hide();
  593. m_projectImageLabel->GetShowLogsButton()->hide();
  594. }
  595. void ProjectButton::enterEvent(QEvent* /*event*/)
  596. {
  597. if (m_canLaunch)
  598. {
  599. m_projectImageLabel->GetOpenEditorButton()->setVisible(true);
  600. }
  601. }
  602. void ProjectButton::leaveEvent(QEvent* /*event*/)
  603. {
  604. m_projectImageLabel->GetOpenEditorButton()->setVisible(false);
  605. }
  606. LabelButton* ProjectButton::GetLabelButton()
  607. {
  608. return m_projectImageLabel;
  609. }
  610. } // namespace O3DE::ProjectManager