ProjectButtonWidget.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. namespace O3DE::ProjectManager
  23. {
  24. inline constexpr static int s_projectImageWidth = 210;
  25. inline constexpr static int s_projectImageHeight = 280;
  26. LabelButton::LabelButton(QWidget* parent)
  27. : QLabel(parent)
  28. {
  29. setObjectName("labelButton");
  30. m_overlayLabel = new QLabel("", this);
  31. m_overlayLabel->setObjectName("labelButtonOverlay");
  32. m_overlayLabel->setWordWrap(true);
  33. m_overlayLabel->setAlignment(Qt::AlignCenter);
  34. m_overlayLabel->setVisible(false);
  35. }
  36. void LabelButton::mousePressEvent([[maybe_unused]] QMouseEvent* event)
  37. {
  38. if(m_enabled)
  39. {
  40. emit triggered();
  41. }
  42. }
  43. void LabelButton::SetEnabled(bool enabled)
  44. {
  45. m_enabled = enabled;
  46. m_overlayLabel->setVisible(!enabled);
  47. }
  48. void LabelButton::SetOverlayText(const QString& text)
  49. {
  50. m_overlayLabel->setText(text);
  51. }
  52. ProjectButton::ProjectButton(const ProjectInfo& projectInfo, QWidget* parent)
  53. : QFrame(parent)
  54. , m_projectInfo(projectInfo)
  55. {
  56. if (m_projectInfo.m_imagePath.isEmpty())
  57. {
  58. m_projectInfo.m_imagePath = ":/DefaultProjectImage.png";
  59. }
  60. Setup();
  61. }
  62. void ProjectButton::Setup()
  63. {
  64. setObjectName("projectButton");
  65. QVBoxLayout* vLayout = new QVBoxLayout();
  66. vLayout->setSpacing(0);
  67. vLayout->setContentsMargins(0, 0, 0, 0);
  68. setLayout(vLayout);
  69. m_projectImageLabel = new LabelButton(this);
  70. m_projectImageLabel->setFixedSize(s_projectImageWidth, s_projectImageHeight);
  71. m_projectImageLabel->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
  72. connect(m_projectImageLabel, &LabelButton::triggered, [this]() { emit OpenProject(m_projectInfo.m_path); });
  73. vLayout->addWidget(m_projectImageLabel);
  74. m_projectImageLabel->setPixmap(
  75. QPixmap(m_projectInfo.m_imagePath).scaled(m_projectImageLabel->size(), Qt::KeepAspectRatioByExpanding));
  76. QMenu* menu = new QMenu(this);
  77. menu->addAction(tr("Edit Project Settings..."), this, [this]() { emit EditProject(m_projectInfo.m_path); });
  78. menu->addSeparator();
  79. menu->addAction(tr("Open Project folder..."), this, [this]()
  80. {
  81. AzQtComponents::ShowFileOnDesktop(m_projectInfo.m_path);
  82. });
  83. menu->addSeparator();
  84. menu->addAction(tr("Duplicate"), this, [this]() { emit CopyProject(m_projectInfo.m_path); });
  85. menu->addSeparator();
  86. menu->addAction(tr("Remove from O3DE"), this, [this]() { emit RemoveProject(m_projectInfo.m_path); });
  87. menu->addAction(tr("Delete this Project"), this, [this]() { emit DeleteProject(m_projectInfo.m_path); });
  88. QFrame* footer = new QFrame(this);
  89. QHBoxLayout* hLayout = new QHBoxLayout();
  90. hLayout->setContentsMargins(0, 0, 0, 0);
  91. footer->setLayout(hLayout);
  92. {
  93. QLabel* projectNameLabel = new QLabel(m_projectInfo.m_displayName, this);
  94. hLayout->addWidget(projectNameLabel);
  95. QPushButton* projectMenuButton = new QPushButton(this);
  96. projectMenuButton->setObjectName("projectMenuButton");
  97. projectMenuButton->setMenu(menu);
  98. hLayout->addWidget(projectMenuButton);
  99. }
  100. vLayout->addWidget(footer);
  101. }
  102. void ProjectButton::SetButtonEnabled(bool enabled)
  103. {
  104. m_projectImageLabel->SetEnabled(enabled);
  105. }
  106. void ProjectButton::SetButtonOverlayText(const QString& text)
  107. {
  108. m_projectImageLabel->SetOverlayText(text);
  109. }
  110. } // namespace O3DE::ProjectManager