GemRepoItemDelegate.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 <GemRepo/GemRepoInfo.h>
  12. #endif
  13. QT_FORWARD_DECLARE_CLASS(QAbstractItemModel)
  14. QT_FORWARD_DECLARE_CLASS(QEvent)
  15. namespace O3DE::ProjectManager
  16. {
  17. QT_FORWARD_DECLARE_CLASS(AdjustableHeaderWidget)
  18. class GemRepoItemDelegate
  19. : public QStyledItemDelegate
  20. {
  21. Q_OBJECT
  22. public:
  23. explicit GemRepoItemDelegate(QAbstractItemModel* model, AdjustableHeaderWidget* header, QObject* parent = nullptr);
  24. ~GemRepoItemDelegate() = default;
  25. void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& modelIndex) const override;
  26. bool editorEvent(QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& modelIndex) override;
  27. QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& modelIndex) const override;
  28. // Colors
  29. const QColor m_textColor = QColor("#FFFFFF");
  30. const QColor m_backgroundColor = QColor("#333333"); // Outside of the actual repo item
  31. const QColor m_itemBackgroundColor = QColor("#404040"); // Background color of the repo item
  32. const QColor m_borderColor = QColor("#1E70EB");
  33. // Item
  34. inline constexpr static int s_height = 72; // Repo item total height
  35. inline constexpr static qreal s_fontSize = 12.0;
  36. // Margin and borders
  37. inline constexpr static QMargins s_itemMargins = QMargins(/*left=*/0, /*top=*/8, /*right=*/0, /*bottom=*/8); // Item border distances
  38. inline constexpr static QMargins s_contentMargins = QMargins(/*left=*/20, /*top=*/20, /*right=*/20, /*bottom=*/20); // Distances of the elements within an item to the item borders
  39. inline constexpr static int s_borderWidth = 4;
  40. // Content TableView is ~842px minimum
  41. inline constexpr static int s_nameDefaultWidth = 200;
  42. inline constexpr static int s_creatorDefaultWidth = 240;
  43. inline constexpr static int s_badgeDefaultWidth = 150;
  44. inline constexpr static int s_updatedDefaultWidth = 130;
  45. inline constexpr static int s_buttonsDefaultWidth = 80;
  46. // Icon
  47. inline constexpr static int s_iconSize = 20;
  48. inline constexpr static int s_iconSpacing = 16;
  49. inline constexpr static int s_refreshIconSize = 16;
  50. inline constexpr static int s_refreshIconSpacing = 10;
  51. inline constexpr static int s_badgeWidth = 130;
  52. inline constexpr static int s_badgeHeight = 30;
  53. inline constexpr static int s_badgeLeftMargin = 25;
  54. enum class HeaderOrder
  55. {
  56. Name,
  57. Creator,
  58. Badge,
  59. Updated,
  60. Buttons
  61. };
  62. signals:
  63. void RemoveRepo(const QModelIndex& modelIndex);
  64. void RefreshRepo(const QModelIndex& modelIndex);
  65. protected:
  66. void CalcRects(const QStyleOptionViewItem& option, QRect& outFullRect, QRect& outItemRect, QRect& outContentRect) const;
  67. QRect GetTextRect(QFont& font, const QString& text, qreal fontSize) const;
  68. QPair<int, int> CalcColumnXBounds(HeaderOrder header) const;
  69. QRect CalcBadgeRect(const QRect& contentRect) const;
  70. QRect CalcVisibilityButtonRect(const QRect& contentRect) const;
  71. QRect CalcRefreshButtonRect(const QRect& contentRect) const;
  72. QAbstractItemModel* m_model = nullptr;
  73. AdjustableHeaderWidget* m_headerWidget = nullptr;
  74. QPixmap m_refreshIcon;
  75. QPixmap m_editIcon;
  76. QPixmap m_deleteIcon;
  77. QPixmap m_hiddenIcon;
  78. QPixmap m_visibleIcon;
  79. QPixmap m_blueBadge;
  80. QPixmap m_greenBadge;
  81. };
  82. } // namespace O3DE::ProjectManager