ProjectButtonWidget.cpp 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /*
  2. * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
  3. * its licensors.
  4. *
  5. * For complete copyright and license terms please see the LICENSE at the root of this
  6. * distribution (the "License"). All use of this software is governed by the License,
  7. * or, if provided, by the license below or the license accompanying this file. Do not
  8. * remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
  9. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. *
  11. */
  12. #include <ProjectButtonWidget.h>
  13. #include <AzQtComponents/Utilities/DesktopUtilities.h>
  14. #include <QVBoxLayout>
  15. #include <QHBoxLayout>
  16. #include <QResizeEvent>
  17. #include <QLabel>
  18. #include <QPushButton>
  19. #include <QPixmap>
  20. #include <QMenu>
  21. #include <QSpacerItem>
  22. #include <QProgressBar>
  23. namespace O3DE::ProjectManager
  24. {
  25. inline constexpr static int s_projectImageWidth = 210;
  26. inline constexpr static int s_projectImageHeight = 280;
  27. LabelButton::LabelButton(QWidget* parent)
  28. : QLabel(parent)
  29. {
  30. setObjectName("labelButton");
  31. QVBoxLayout* vLayout = new QVBoxLayout(this);
  32. vLayout->setContentsMargins(0, 0, 0, 0);
  33. vLayout->setSpacing(5);
  34. setLayout(vLayout);
  35. m_overlayLabel = new QLabel("", this);
  36. m_overlayLabel->setObjectName("labelButtonOverlay");
  37. m_overlayLabel->setWordWrap(true);
  38. m_overlayLabel->setAlignment(Qt::AlignCenter);
  39. m_overlayLabel->setVisible(false);
  40. vLayout->addWidget(m_overlayLabel);
  41. m_buildButton = new QPushButton(tr("Build Project"), this);
  42. m_buildButton->setVisible(false);
  43. m_progressBar = new QProgressBar(this);
  44. m_progressBar->setObjectName("labelButtonProgressBar");
  45. m_progressBar->setVisible(false);
  46. vLayout->addWidget(m_progressBar);
  47. }
  48. void LabelButton::mousePressEvent([[maybe_unused]] QMouseEvent* event)
  49. {
  50. if(m_enabled)
  51. {
  52. emit triggered();
  53. }
  54. }
  55. void LabelButton::SetEnabled(bool enabled)
  56. {
  57. m_enabled = enabled;
  58. m_overlayLabel->setVisible(!enabled);
  59. }
  60. void LabelButton::SetOverlayText(const QString& text)
  61. {
  62. m_overlayLabel->setText(text);
  63. }
  64. QLabel* LabelButton::GetOverlayLabel()
  65. {
  66. return m_overlayLabel;
  67. }
  68. QProgressBar* LabelButton::GetProgressBar()
  69. {
  70. return m_progressBar;
  71. }
  72. QPushButton* LabelButton::GetBuildButton()
  73. {
  74. return m_buildButton;
  75. }
  76. ProjectButton::ProjectButton(const ProjectInfo& projectInfo, QWidget* parent, bool processing)
  77. : QFrame(parent)
  78. , m_projectInfo(projectInfo)
  79. {
  80. if (m_projectInfo.m_imagePath.isEmpty())
  81. {
  82. m_projectInfo.m_imagePath = ":/DefaultProjectImage.png";
  83. }
  84. BaseSetup();
  85. if (processing)
  86. {
  87. ProcessingSetup();
  88. }
  89. else
  90. {
  91. ReadySetup();
  92. }
  93. }
  94. void ProjectButton::BaseSetup()
  95. {
  96. setObjectName("projectButton");
  97. QVBoxLayout* vLayout = new QVBoxLayout();
  98. vLayout->setSpacing(0);
  99. vLayout->setContentsMargins(0, 0, 0, 0);
  100. setLayout(vLayout);
  101. m_projectImageLabel = new LabelButton(this);
  102. m_projectImageLabel->setFixedSize(s_projectImageWidth, s_projectImageHeight);
  103. m_projectImageLabel->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
  104. connect(m_projectImageLabel, &LabelButton::triggered, [this]() { emit OpenProject(m_projectInfo.m_path); });
  105. vLayout->addWidget(m_projectImageLabel);
  106. m_projectImageLabel->setPixmap(
  107. QPixmap(m_projectInfo.m_imagePath).scaled(m_projectImageLabel->size(), Qt::KeepAspectRatioByExpanding));
  108. m_projectFooter = new QFrame(this);
  109. QHBoxLayout* hLayout = new QHBoxLayout();
  110. hLayout->setContentsMargins(0, 0, 0, 0);
  111. m_projectFooter->setLayout(hLayout);
  112. {
  113. QLabel* projectNameLabel = new QLabel(m_projectInfo.m_displayName, this);
  114. hLayout->addWidget(projectNameLabel);
  115. }
  116. vLayout->addWidget(m_projectFooter);
  117. }
  118. void ProjectButton::ProcessingSetup()
  119. {
  120. m_projectImageLabel->GetOverlayLabel()->setAlignment(Qt::AlignHCenter | Qt::AlignBottom);
  121. m_projectImageLabel->SetEnabled(false);
  122. m_projectImageLabel->SetOverlayText(tr("Processing...\n\n"));
  123. QProgressBar* progressBar = m_projectImageLabel->GetProgressBar();
  124. progressBar->setVisible(true);
  125. progressBar->setValue(0);
  126. }
  127. void ProjectButton::ReadySetup()
  128. {
  129. connect(m_projectImageLabel, &LabelButton::triggered, [this]() { emit OpenProject(m_projectInfo.m_path); });
  130. connect(m_projectImageLabel->GetBuildButton(), &QPushButton::clicked, [this](){ emit BuildProject(m_projectInfo); });
  131. QMenu* menu = new QMenu(this);
  132. menu->addAction(tr("Edit Project Settings..."), this, [this]() { emit EditProject(m_projectInfo.m_path); });
  133. menu->addAction(tr("Build"), this, [this]() { emit BuildProject(m_projectInfo); });
  134. menu->addSeparator();
  135. menu->addAction(tr("Open Project folder..."), this, [this]()
  136. {
  137. AzQtComponents::ShowFileOnDesktop(m_projectInfo.m_path);
  138. });
  139. menu->addSeparator();
  140. menu->addAction(tr("Duplicate"), this, [this]() { emit CopyProject(m_projectInfo.m_path); });
  141. menu->addSeparator();
  142. menu->addAction(tr("Remove from O3DE"), this, [this]() { emit RemoveProject(m_projectInfo.m_path); });
  143. menu->addAction(tr("Delete this Project"), this, [this]() { emit DeleteProject(m_projectInfo.m_path); });
  144. QPushButton* projectMenuButton = new QPushButton(this);
  145. projectMenuButton->setObjectName("projectMenuButton");
  146. projectMenuButton->setMenu(menu);
  147. m_projectFooter->layout()->addWidget(projectMenuButton);
  148. }
  149. void ProjectButton::SetLaunchButtonEnabled(bool enabled)
  150. {
  151. m_projectImageLabel->SetEnabled(enabled);
  152. }
  153. void ProjectButton::ShowBuildButton(bool show)
  154. {
  155. QSpacerItem* buttonSpacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Expanding);
  156. m_projectImageLabel->layout()->addItem(buttonSpacer);
  157. m_projectImageLabel->layout()->addWidget(m_projectImageLabel->GetBuildButton());
  158. m_projectImageLabel->GetBuildButton()->setVisible(show);
  159. }
  160. void ProjectButton::SetButtonOverlayText(const QString& text)
  161. {
  162. m_projectImageLabel->SetOverlayText(text);
  163. }
  164. void ProjectButton::SetProgressBarValue(int progress)
  165. {
  166. m_projectImageLabel->GetProgressBar()->setValue(progress);
  167. }
  168. } // namespace O3DE::ProjectManager