GemCatalogHeaderWidget.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. #pragma once
  9. #if !defined(Q_MOC_RUN)
  10. #include <AzCore/std/function/function_fwd.h>
  11. #include <AzQtComponents/Components/SearchLineEdit.h>
  12. #include <GemCatalog/GemModel.h>
  13. #include <GemCatalog/GemSortFilterProxyModel.h>
  14. #include <TagWidget.h>
  15. #include <DownloadController.h>
  16. #include <QFrame>
  17. #include <QScrollArea>
  18. #endif
  19. QT_FORWARD_DECLARE_CLASS(QPushButton)
  20. QT_FORWARD_DECLARE_CLASS(QLabel)
  21. QT_FORWARD_DECLARE_CLASS(QVBoxLayout)
  22. QT_FORWARD_DECLARE_CLASS(QHBoxLayout)
  23. QT_FORWARD_DECLARE_CLASS(QHideEvent)
  24. QT_FORWARD_DECLARE_CLASS(QMoveEvent)
  25. QT_FORWARD_DECLARE_CLASS(QMovie)
  26. namespace O3DE::ProjectManager
  27. {
  28. class GemCartWidget
  29. : public QScrollArea
  30. {
  31. Q_OBJECT
  32. public:
  33. GemCartWidget(GemModel* gemModel, DownloadController* downloadController, QWidget* parent = nullptr);
  34. public slots:
  35. void ObjectDownloadAdded(const QString& gemName, DownloadController::DownloadObjectType objectType);
  36. void ObjectDownloadRemoved(const QString& gemName, DownloadController::DownloadObjectType objectType);
  37. void ObjectDownloadProgress(const QString& gemName, DownloadController::DownloadObjectType objectType, int bytesDownloaded, int totalBytes);
  38. private:
  39. QVector<Tag> GetTagsFromModelIndices(const QVector<QModelIndex>& gems) const;
  40. using GetTagIndicesCallback = AZStd::function<QVector<QModelIndex>()>;
  41. void CreateGemSection(const QString& singularTitle, const QString& pluralTitle, GetTagIndicesCallback getTagIndices);
  42. void CreateDownloadSection();
  43. void OnCancelDownloadActivated(const QString& link);
  44. QVBoxLayout* m_layout = nullptr;
  45. GemModel* m_gemModel = nullptr;
  46. DownloadController* m_downloadController = nullptr;
  47. QWidget* m_downloadSectionWidget = nullptr;
  48. QWidget* m_downloadingListWidget = nullptr;
  49. inline constexpr static int s_width = 240;
  50. };
  51. class CartButton
  52. : public QWidget
  53. {
  54. Q_OBJECT // AUTOMOC
  55. public:
  56. CartButton(GemModel* gemModel, DownloadController* downloadController, QWidget* parent = nullptr);
  57. ~CartButton();
  58. void ShowGemCart();
  59. signals:
  60. void UpdateGemCart(QWidget* gemCart);
  61. private:
  62. void mousePressEvent(QMouseEvent* event) override;
  63. void hideEvent(QHideEvent*) override;
  64. GemModel* m_gemModel = nullptr;
  65. QHBoxLayout* m_layout = nullptr;
  66. QLabel* m_countLabel = nullptr;
  67. QPushButton* m_dropDownButton = nullptr;
  68. GemCartWidget* m_gemCart = nullptr;
  69. DownloadController* m_downloadController = nullptr;
  70. inline constexpr static int s_iconSize = 24;
  71. inline constexpr static int s_arrowDownIconSize = 8;
  72. };
  73. class GemCatalogHeaderWidget
  74. : public QFrame
  75. {
  76. Q_OBJECT // AUTOMOC
  77. public:
  78. explicit GemCatalogHeaderWidget(GemModel* gemModel, GemSortFilterProxyModel* filterProxyModel, DownloadController* downloadController, QWidget* parent = nullptr);
  79. ~GemCatalogHeaderWidget() = default;
  80. void ReinitForProject();
  81. public slots:
  82. void GemDownloadAdded(const QString& gemName, DownloadController::DownloadObjectType objectType);
  83. void GemDownloadRemoved(const QString& gemName, DownloadController::DownloadObjectType objectType);
  84. void GemCartShown(bool state = false);
  85. signals:
  86. void AddGem();
  87. void CreateGem();
  88. void OpenGemsRepo();
  89. void RefreshGems(bool refreshRemoteRepos);
  90. void UpdateGemCart(QWidget* gemCart);
  91. protected slots:
  92. void paintEvent(QPaintEvent* event) override;
  93. private:
  94. AzQtComponents::SearchLineEdit* m_filterLineEdit = nullptr;
  95. inline constexpr static int s_height = 60;
  96. DownloadController* m_downloadController = nullptr;
  97. QLabel* m_downloadSpinner = nullptr;
  98. QLabel* m_downloadLabel = nullptr;
  99. QMovie* m_downloadSpinnerMovie = nullptr;
  100. CartButton* m_cartButton = nullptr;
  101. bool m_showGemCart = false;
  102. };
  103. } // namespace O3DE::ProjectManager