GemItemDelegate.h 6.2 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. #pragma once
  9. #if !defined(Q_MOC_RUN)
  10. #include <QStyledItemDelegate>
  11. #include "GemInfo.h"
  12. #include <QAbstractItemModel>
  13. #include <QHash>
  14. #endif
  15. QT_FORWARD_DECLARE_CLASS(QEvent)
  16. namespace O3DE::ProjectManager
  17. {
  18. QT_FORWARD_DECLARE_CLASS(AdjustableHeaderWidget)
  19. class GemItemDelegate
  20. : public QStyledItemDelegate
  21. {
  22. Q_OBJECT
  23. public:
  24. explicit GemItemDelegate(QAbstractItemModel* model, AdjustableHeaderWidget* header, bool readOnly, QObject* parent = nullptr);
  25. ~GemItemDelegate() = default;
  26. void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& modelIndex) const override;
  27. QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& modelIndex) const override;
  28. virtual QString anchorAt(const QString& html, const QPoint& position, const QRect& rect);
  29. // Colors
  30. const QColor m_textColor = QColor("#FFFFFF");
  31. const QColor m_linkColor = QColor("#94D2FF");
  32. const QColor m_backgroundColor = QColor("#333333"); // Outside of the actual gem item
  33. const QColor m_itemBackgroundColor = QColor("#404040"); // Background color of the gem item
  34. const QColor m_borderColor = QColor("#1E70EB");
  35. const QColor m_buttonEnabledColor = QColor("#00B931");
  36. const QColor m_buttonImplicitlyEnabledColor = QColor("#BCBCBE");
  37. // Item
  38. inline constexpr static int s_height = 105; // Gem item total height
  39. inline constexpr static qreal s_gemNameFontSize = 13.0;
  40. inline constexpr static qreal s_fontSize = 12.0;
  41. inline constexpr static int s_defaultSummaryStartX = 270;
  42. // Margin and borders
  43. inline constexpr static QMargins s_itemMargins = QMargins(/*left=*/16, /*top=*/5, /*right=*/16, /*bottom=*/5); // Item border distances
  44. inline constexpr static QMargins s_contentMargins = QMargins(/*left=*/10, /*top=*/12, /*right=*/30, /*bottom=*/12); // Distances of the elements within an item to the item borders
  45. inline constexpr static int s_borderWidth = 4;
  46. inline constexpr static int s_extraSummarySpacing = s_itemMargins.right();
  47. // Button
  48. inline constexpr static int s_buttonWidth = 32;
  49. inline constexpr static int s_buttonHeight = 16;
  50. inline constexpr static int s_buttonBorderRadius = s_buttonHeight / 2;
  51. inline constexpr static int s_buttonCircleRadius = s_buttonBorderRadius - 2;
  52. inline constexpr static qreal s_buttonFontSize = 10.0;
  53. // Feature tags
  54. inline constexpr static int s_featureTagFontSize = 10;
  55. inline constexpr static int s_featureTagBorderMarginX = 3;
  56. inline constexpr static int s_featureTagBorderMarginY = 3;
  57. inline constexpr static int s_featureTagSpacing = 7;
  58. // Platform text
  59. inline constexpr static int s_platformTextleftMarginCorrection = -3;
  60. inline constexpr static int s_platformTextHeightAdjustment = 25;
  61. inline constexpr static int s_platformTextWrapAroundMargin = 5;
  62. inline constexpr static int s_platformTextLineBottomMargin = 5;
  63. inline constexpr static int s_platformTextWrapAroundLineMaxCount = 2;
  64. // Version
  65. inline constexpr static int s_versionSize = 70;
  66. inline constexpr static int s_versionSizeSpacing = 25;
  67. // Status icon
  68. inline constexpr static int s_statusIconSize = 16;
  69. inline constexpr static int s_statusIconSizeLarge = 20;
  70. inline constexpr static int s_statusButtonSpacing = 5;
  71. enum class HeaderOrder
  72. {
  73. Preview,
  74. Name,
  75. Summary,
  76. Version,
  77. Status
  78. };
  79. signals:
  80. void MovieStartedPlaying(const QMovie* playingMovie) const;
  81. protected:
  82. bool editorEvent(QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& modelIndex) override;
  83. bool helpEvent(QHelpEvent* event, QAbstractItemView* view, const QStyleOptionViewItem& option, const QModelIndex& index) override;
  84. void CalcRects(const QStyleOptionViewItem& option, QRect& outFullRect, QRect& outItemRect, QRect& outContentRect) const;
  85. QRect GetTextRect(QFont& font, const QString& text, qreal fontSize) const;
  86. QPair<int, int> CalcColumnXBounds(HeaderOrder header) const;
  87. QRect CalcButtonRect(const QRect& contentRect) const;
  88. QRect CalcSummaryRect(const QRect& contentRect, bool hasTags) const;
  89. void DrawPlatformIcons(QPainter* painter, const QRect& contentRect, const QModelIndex& modelIndex) const;
  90. void DrawPlatformText(QPainter* painter, const QRect& contentRect, const QFont& standardFont, const QModelIndex& modelIndex) const;
  91. void DrawButton(QPainter* painter, const QRect& buttonRect, const QModelIndex& modelIndex) const;
  92. void DrawFeatureTags(
  93. QPainter* painter,
  94. const QRect& contentRect,
  95. const QStringList& featureTags,
  96. const QFont& standardFont,
  97. const QRect& summaryRect) const;
  98. void DrawText(const QString& text, QPainter* painter, const QRect& rect, const QFont& standardFont) const;
  99. void DrawDownloadStatusIcon(
  100. QPainter* painter, const QRect& contentRect, const QRect& buttonRect, const QModelIndex& modelIndex) const;
  101. QAbstractItemModel* m_model = nullptr;
  102. private:
  103. // Platform icons
  104. void AddPlatformIcon(GemInfo::Platform platform, const QString& iconPath);
  105. inline constexpr static int s_platformIconSize = 12;
  106. QHash<GemInfo::Platform, QPixmap> m_platformIcons;
  107. // Status icons
  108. void SetStatusIcon(QPixmap& m_iconPixmap, const QString& iconPath);
  109. QPixmap m_unknownStatusPixmap;
  110. QPixmap m_notDownloadedPixmap;
  111. QPixmap m_downloadedPixmap;
  112. QPixmap m_downloadSuccessfulPixmap;
  113. QPixmap m_downloadFailedPixmap;
  114. QMovie* m_downloadingMovie = nullptr;
  115. QPixmap m_updatePixmap;
  116. bool m_readOnly = false;
  117. AdjustableHeaderWidget* m_headerWidget = nullptr;
  118. };
  119. } // namespace O3DE::ProjectManager