3
0

ProjectButtonWidget.cpp 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744
  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->addSeparator();
  301. menu->addAction(tr("Open Project folder..."), this, [this]()
  302. {
  303. AzQtComponents::ShowFileOnDesktop(m_projectInfo.m_path);
  304. });
  305. #if AZ_TRAIT_PROJECT_MANAGER_CREATE_DESKTOP_SHORTCUT
  306. menu->addAction(tr("Create Editor desktop shortcut..."), this, [this]()
  307. {
  308. AZ::IO::FixedMaxPath editorExecutablePath = ProjectUtils::GetEditorExecutablePath(m_projectInfo.m_path.toUtf8().constData());
  309. const QString shortcutName = QString("%1 Editor").arg(m_projectInfo.m_displayName);
  310. const QString arg = QString("--regset=\"/Amazon/AzCore/Bootstrap/project_path=%1\"").arg(m_projectInfo.m_path);
  311. auto result = ProjectUtils::CreateDesktopShortcut(shortcutName, editorExecutablePath.c_str(), { arg });
  312. if(result.IsSuccess())
  313. {
  314. QMessageBox::information(this, tr("Desktop Shortcut Created"), result.GetValue());
  315. }
  316. else
  317. {
  318. QMessageBox::critical(this, tr("Failed to create shortcut"), result.GetError());
  319. }
  320. });
  321. #endif // AZ_TRAIT_PROJECT_MANAGER_CREATE_DESKTOP_SHORTCUT
  322. menu->addSeparator();
  323. menu->addAction(tr("Duplicate"), this, [this]() { emit CopyProject(m_projectInfo); });
  324. menu->addSeparator();
  325. menu->addAction(tr("Remove from O3DE"), this, [this]() { emit RemoveProject(m_projectInfo.m_path); });
  326. menu->addAction(tr("Delete this Project"), this, [this]() { emit DeleteProject(m_projectInfo.m_path); });
  327. return menu;
  328. }
  329. const ProjectInfo& ProjectButton::GetProjectInfo() const
  330. {
  331. return m_projectInfo;
  332. }
  333. void ProjectButton::ShowLogs()
  334. {
  335. if (!QDesktopServices::openUrl(m_projectInfo.m_logUrl))
  336. {
  337. qDebug() << "QDesktopServices::openUrl failed to open " << m_projectInfo.m_logUrl.toString() << "\n";
  338. }
  339. }
  340. void ProjectButton::SetEngine(const EngineInfo& engine)
  341. {
  342. m_engineInfo = engine;
  343. if (m_engineInfo.m_name.isEmpty() && !m_projectInfo.m_engineName.isEmpty())
  344. {
  345. // this project wants to use an engine that wasn't found, display the qualifier
  346. m_engineInfo.m_name = m_projectInfo.m_engineName;
  347. m_engineInfo.m_version = "";
  348. }
  349. m_engineNameLabel->SetText(m_engineInfo.m_name + " " + m_engineInfo.m_version);
  350. m_engineNameLabel->update();
  351. m_engineNameLabel->setObjectName(m_engineInfo.m_thisEngine ? "thisEngineLabel" : "otherEngineLabel");
  352. m_engineNameLabel->setToolTip(m_engineInfo.m_name + " " + m_engineInfo.m_version + " " + m_engineInfo.m_path);
  353. m_engineNameLabel->refreshStyle(); // important for styles to work correctly
  354. }
  355. void ProjectButton::SetProject(const ProjectInfo& project)
  356. {
  357. m_projectInfo = project;
  358. if (!m_projectInfo.m_version.isEmpty())
  359. {
  360. m_projectNameLabel->SetText(m_projectInfo.GetProjectDisplayName() + " " + m_projectInfo.m_version);
  361. }
  362. else
  363. {
  364. m_projectNameLabel->SetText(m_projectInfo.GetProjectDisplayName());
  365. }
  366. m_projectNameLabel->update();
  367. m_projectNameLabel->setToolTip(m_projectInfo.m_path);
  368. m_projectNameLabel->refreshStyle(); // important for styles to work correctly
  369. }
  370. void ProjectButton::SetState(ProjectButtonState state)
  371. {
  372. m_currentState = state;
  373. ResetButtonWidgets();
  374. switch (state)
  375. {
  376. default:
  377. case ProjectButtonState::ReadyToLaunch:
  378. ShowReadyState();
  379. break;
  380. case ProjectButtonState::Launching:
  381. ShowLaunchingState();
  382. break;
  383. case ProjectButtonState::NeedsToBuild:
  384. ShowBuildRequiredState();
  385. break;
  386. case ProjectButtonState::Building:
  387. ShowBuildingState();
  388. break;
  389. case ProjectButtonState::BuildFailed:
  390. ShowBuildFailedState();
  391. break;
  392. case ProjectButtonState::NotDownloaded:
  393. ShowNotDownloadedState();
  394. break;
  395. case ProjectButtonState::DownloadingBuildQueued:
  396. case ProjectButtonState::Downloading:
  397. ShowDownloadingState();
  398. break;
  399. }
  400. }
  401. void ProjectButton::ShowReadyState()
  402. {
  403. HideContextualLabelButtonWidgets();
  404. if (m_actionButtonConnection)
  405. {
  406. disconnect(m_actionButtonConnection);
  407. }
  408. m_projectMenuButton->setVisible(true);
  409. SetLaunchingEnabled(true);
  410. SetProjectBuilding(false);
  411. }
  412. void ProjectButton::ShowLaunchingState()
  413. {
  414. // Hide button in-case it is still showing
  415. m_projectImageLabel->GetOpenEditorButton()->hide();
  416. SetLaunchingEnabled(false);
  417. ShowMessage(tr("Opening Editor..."));
  418. }
  419. void ProjectButton::ShowBuildRequiredState()
  420. {
  421. ShowBuildButton();
  422. SetProjectBuilding(false);
  423. ShowWarning(tr("Project build required."));
  424. }
  425. void ProjectButton::ShowBuildingState()
  426. {
  427. m_projectImageLabel->GetShowLogsButton()->show();
  428. // Setting project to building also disables launching
  429. SetProjectBuilding(true);
  430. ShowMessage(tr("Building Project..."));
  431. }
  432. void ProjectButton::ShowBuildFailedState()
  433. {
  434. ShowBuildButton();
  435. SetProjectBuilding(false);
  436. // Show, show logs button if avaliable
  437. m_projectImageLabel->GetShowLogsButton()->setVisible(!m_projectInfo.m_logUrl.isEmpty());
  438. ShowWarning(tr("Failed to build"));
  439. }
  440. void ProjectButton::ShowNotDownloadedState()
  441. {
  442. m_projectImageLabel->GetCloudIcon()->setVisible(true);
  443. m_projectImageLabel->GetWarningSpacer()->changeSize(0, 0, QSizePolicy::Expanding, QSizePolicy::Fixed);
  444. m_projectMenuButton->setVisible(false);
  445. SetLaunchingEnabled(false);
  446. }
  447. void ProjectButton::ShowDownloadingState()
  448. {
  449. m_projectImageLabel->GetCloudIcon()->setVisible(true);
  450. m_projectImageLabel->GetWarningSpacer()->changeSize(0, 0, QSizePolicy::Expanding, QSizePolicy::Fixed);
  451. m_projectMenuButton->setVisible(false);
  452. m_projectImageLabel->GetDownloadMessageLabel()->setVisible(true);
  453. m_projectImageLabel->GetProgressPercentage()->setVisible(true);
  454. m_projectImageLabel->GetProgressBar()->setVisible(true);
  455. SetLaunchingEnabled(false);
  456. }
  457. void ProjectButton::SetProjectButtonAction(const QString& text, AZStd::function<void()> lambda)
  458. {
  459. QPushButton* projectActionButton;
  460. QPushButton* projectOtherActionButton;
  461. if (text.contains("Cancel", Qt::CaseInsensitive))
  462. {
  463. // Use red button is action involves cancelling
  464. projectActionButton = m_projectImageLabel->GetActionCancelButton();
  465. projectOtherActionButton = m_projectImageLabel->GetActionButton();
  466. }
  467. else
  468. {
  469. projectActionButton = m_projectImageLabel->GetActionButton();
  470. projectOtherActionButton = m_projectImageLabel->GetActionCancelButton();
  471. }
  472. if (m_actionButtonConnection)
  473. {
  474. disconnect(m_actionButtonConnection);
  475. }
  476. projectActionButton->setVisible(true);
  477. projectOtherActionButton->setVisible(false);
  478. projectActionButton->setText(text);
  479. projectActionButton->setMenu(nullptr);
  480. m_actionButtonConnection = connect(projectActionButton, &QPushButton::clicked, lambda);
  481. }
  482. void ProjectButton::SetBuildLogsLink(const QUrl& logUrl)
  483. {
  484. m_projectInfo.m_logUrl = logUrl;
  485. }
  486. void ProjectButton::SetProgressBarPercentage(const float percent)
  487. {
  488. m_projectImageLabel->GetProgressBar()->setValue(static_cast<int>(percent*100));
  489. m_projectImageLabel->GetProgressPercentage()->setText(QString("%1%").arg(static_cast<int>(percent*100)));
  490. }
  491. void ProjectButton::SetContextualText(const QString& text)
  492. {
  493. if (m_currentState == ProjectButtonState::Building)
  494. {
  495. // Don't update for empty build progress messages
  496. if (!text.isEmpty())
  497. {
  498. // Show info about what's currently building
  499. ShowMessage({}, text);
  500. }
  501. }
  502. else
  503. {
  504. ShowMessage(text);
  505. }
  506. }
  507. void ProjectButton::ShowBuildButton()
  508. {
  509. QPushButton* projectActionButton = m_projectImageLabel->GetActionButton();
  510. projectActionButton->setVisible(true);
  511. projectActionButton->setText(tr("Build Project"));
  512. disconnect(m_actionButtonConnection);
  513. QMenu* menu = new QMenu(this);
  514. QAction* autoBuildAction = menu->addAction(tr("Build Now"));
  515. connect( autoBuildAction, &QAction::triggered, this, [this](){ emit BuildProject(m_projectInfo); });
  516. QAction* openCMakeAction = menu->addAction(tr("Open CMake GUI..."));
  517. connect( openCMakeAction, &QAction::triggered, this, [this](){ emit OpenCMakeGUI(m_projectInfo); });
  518. projectActionButton->setMenu(menu);
  519. }
  520. void ProjectButton::ResetButtonWidgets()
  521. {
  522. HideContextualLabelButtonWidgets();
  523. SetProjectBuilding(false);
  524. SetProgressBarPercentage(0);
  525. m_projectImageLabel->GetDownloadMessageLabel()->setVisible(false);
  526. m_projectImageLabel->GetProgressPercentage()->setVisible(false);
  527. m_projectImageLabel->GetProgressBar()->setVisible(false);
  528. }
  529. // Only setting message without setting submessage will hide submessage
  530. void ProjectButton::ShowMessage(const QString& message, const QString& submessage)
  531. {
  532. bool showMessage = !message.isEmpty();
  533. bool showSubmessage = !submessage.isEmpty();
  534. QLabel* messageLabel = m_projectImageLabel->GetMessageLabel();
  535. QLabel* submessageLabel = m_projectImageLabel->GetSubMessageLabel();
  536. if (showMessage || showSubmessage)
  537. {
  538. // Hide any warning text, we cannot show the warning and a message at the same time
  539. ShowWarning();
  540. }
  541. // Keep main message if only submessage is set
  542. if (showMessage || showMessage == showSubmessage)
  543. {
  544. messageLabel->setText(message);
  545. }
  546. submessageLabel->setText(submessage);
  547. // Darken background if there is a message to make it easier to read
  548. m_projectImageLabel->GetDarkenOverlay()->setVisible(showMessage || showSubmessage);
  549. messageLabel->setVisible(showMessage || showSubmessage);
  550. submessageLabel->setVisible(showSubmessage);
  551. }
  552. void ProjectButton::ShowWarning(const QString& warning)
  553. {
  554. bool show = !warning.isEmpty();
  555. QLabel* warningIcon = m_projectImageLabel->GetWarningIcon();
  556. if (show)
  557. {
  558. // Hide any message text, we cannot show the warning and a message at the same time
  559. ShowMessage();
  560. m_projectImageLabel->GetWarningSpacer()->changeSize(0, 0, QSizePolicy::Expanding, QSizePolicy::Fixed);
  561. }
  562. else
  563. {
  564. m_projectImageLabel->GetWarningSpacer()->changeSize(0, 0, QSizePolicy::Fixed, QSizePolicy::Fixed);
  565. }
  566. warningIcon->setToolTip(warning);
  567. warningIcon->setVisible(show);
  568. }
  569. void ProjectButton::SetLaunchingEnabled(bool enabled)
  570. {
  571. m_canLaunch = enabled;
  572. }
  573. void ProjectButton::SetProjectBuilding(bool isBuilding)
  574. {
  575. m_isProjectBuilding = isBuilding;
  576. QLabel* buildingAnimation = m_projectImageLabel->GetBuildingAnimationLabel();
  577. if (isBuilding)
  578. {
  579. SetLaunchingEnabled(false);
  580. m_projectImageLabel->GetActionCancelButton()->show();
  581. }
  582. buildingAnimation->movie()->setPaused(!isBuilding);
  583. buildingAnimation->setVisible(isBuilding);
  584. m_projectMenuButton->setVisible(!isBuilding);
  585. }
  586. void ProjectButton::HideContextualLabelButtonWidgets()
  587. {
  588. ShowMessage();
  589. ShowWarning();
  590. m_projectImageLabel->GetActionButton()->hide();
  591. m_projectImageLabel->GetActionCancelButton()->hide();
  592. m_projectImageLabel->GetShowLogsButton()->hide();
  593. }
  594. void ProjectButton::enterEvent(QEvent* /*event*/)
  595. {
  596. if (m_canLaunch)
  597. {
  598. m_projectImageLabel->GetOpenEditorButton()->setVisible(true);
  599. }
  600. }
  601. void ProjectButton::leaveEvent(QEvent* /*event*/)
  602. {
  603. m_projectImageLabel->GetOpenEditorButton()->setVisible(false);
  604. }
  605. LabelButton* ProjectButton::GetLabelButton()
  606. {
  607. return m_projectImageLabel;
  608. }
  609. } // namespace O3DE::ProjectManager