GemRepoInspector.cpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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 <GemRepo/GemRepoInspector.h>
  9. #include <GemRepo/GemRepoItemDelegate.h>
  10. #include <QFrame>
  11. #include <QLabel>
  12. #include <QVBoxLayout>
  13. #include <QIcon>
  14. namespace O3DE::ProjectManager
  15. {
  16. GemRepoInspector::GemRepoInspector(GemRepoModel* model, QWidget* parent)
  17. : QScrollArea(parent)
  18. , m_model(model)
  19. {
  20. setObjectName("gemRepoInspector");
  21. setWidgetResizable(true);
  22. setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
  23. setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
  24. m_mainWidget = new QWidget();
  25. setWidget(m_mainWidget);
  26. m_mainLayout = new QVBoxLayout();
  27. m_mainLayout->setMargin(15);
  28. m_mainLayout->setAlignment(Qt::AlignTop);
  29. m_mainWidget->setLayout(m_mainLayout);
  30. InitMainWidget();
  31. connect(m_model->GetSelectionModel(), &QItemSelectionModel::selectionChanged, this, &GemRepoInspector::OnSelectionChanged);
  32. Update({});
  33. }
  34. void GemRepoInspector::OnSelectionChanged(const QItemSelection& selected, [[maybe_unused]] const QItemSelection& deselected)
  35. {
  36. const QModelIndexList selectedIndices = selected.indexes();
  37. if (selectedIndices.empty())
  38. {
  39. Update({});
  40. return;
  41. }
  42. Update(selectedIndices[0]);
  43. }
  44. void GemRepoInspector::Update(const QModelIndex& modelIndex)
  45. {
  46. if (!modelIndex.isValid())
  47. {
  48. m_mainWidget->hide();
  49. }
  50. // Repo name and url link
  51. m_nameLabel->setText(m_model->GetName(modelIndex));
  52. m_repoLinkLabel->setText(m_model->GetRepoLink(modelIndex));
  53. m_repoLinkLabel->SetUrl(m_model->GetRepoLink(modelIndex));
  54. // Repo summary
  55. m_summaryLabel->setText(m_model->GetSummary(modelIndex));
  56. m_summaryLabel->adjustSize();
  57. // Additional information
  58. if (m_model->HasAdditionalInfo(modelIndex))
  59. {
  60. m_addInfoTitleLabel->show();
  61. m_addInfoTextLabel->show();
  62. m_addInfoSpacer->changeSize(0, 20, QSizePolicy::Fixed, QSizePolicy::Fixed);
  63. m_addInfoTextLabel->setText(m_model->GetAdditionalInfo(modelIndex));
  64. }
  65. else
  66. {
  67. m_addInfoTitleLabel->hide();
  68. m_addInfoTextLabel->hide();
  69. m_addInfoSpacer->changeSize(0, 0, QSizePolicy::Fixed, QSizePolicy::Fixed);
  70. }
  71. // Included Gems
  72. m_includedGems->Update(tr("Included Gems"), "", m_model->GetIncludedGemNames(modelIndex));
  73. m_mainWidget->adjustSize();
  74. m_mainWidget->show();
  75. }
  76. void GemRepoInspector::InitMainWidget()
  77. {
  78. // Repo name and url link
  79. m_nameLabel = new QLabel();
  80. m_nameLabel->setObjectName("gemRepoInspectorNameLabel");
  81. m_mainLayout->addWidget(m_nameLabel);
  82. m_repoLinkLabel = new LinkLabel(tr("Repo Url"), QUrl(""), 12, this);
  83. m_mainLayout->addWidget(m_repoLinkLabel);
  84. m_mainLayout->addSpacing(5);
  85. // Repo summary
  86. m_summaryLabel = new QLabel();
  87. m_summaryLabel->setObjectName("gemRepoInspectorBodyLabel");
  88. m_summaryLabel->setWordWrap(true);
  89. m_summaryLabel->setTextInteractionFlags(Qt::TextBrowserInteraction);
  90. m_summaryLabel->setOpenExternalLinks(true);
  91. m_mainLayout->addWidget(m_summaryLabel);
  92. m_mainLayout->addSpacing(20);
  93. // Separating line
  94. QFrame* hLine = new QFrame();
  95. hLine->setFrameShape(QFrame::HLine);
  96. hLine->setObjectName("horizontalSeparatingLine");
  97. m_mainLayout->addWidget(hLine);
  98. m_mainLayout->addSpacing(10);
  99. // Additional information
  100. m_addInfoTitleLabel = new QLabel();
  101. m_addInfoTitleLabel->setObjectName("gemRepoInspectorAddInfoTitleLabel");
  102. m_addInfoTitleLabel->setText(tr("Additional Information"));
  103. m_mainLayout->addWidget(m_addInfoTitleLabel);
  104. m_addInfoTextLabel = new QLabel();
  105. m_addInfoTextLabel->setObjectName("gemRepoInspectorBodyLabel");
  106. m_addInfoTextLabel->setWordWrap(true);
  107. m_addInfoTextLabel->setTextInteractionFlags(Qt::TextBrowserInteraction);
  108. m_addInfoTextLabel->setOpenExternalLinks(true);
  109. m_mainLayout->addWidget(m_addInfoTextLabel);
  110. // Conditional spacing for additional info section
  111. m_addInfoSpacer = new QSpacerItem(0, 0, QSizePolicy::Expanding);
  112. m_mainLayout->addSpacerItem(m_addInfoSpacer);
  113. // Included Gems
  114. m_includedGems = new GemsSubWidget();
  115. m_mainLayout->addWidget(m_includedGems);
  116. m_mainLayout->addSpacing(20);
  117. }
  118. } // namespace O3DE::ProjectManager