ProjectButtonWidget.cpp 25 KB

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