[LYN-2515] Project Manager Gem List (#642)
* [LYN-2515] Project Manager Gem List Base * Added gem model based on a standard item model * Added list view using the gem model * Added item delegate for a gem according to the UX design * Removed th gem catalog ui file and replaced it with code * Moved the gem catalog files into a sub folder * Added drawing the Added/Get button and the platform icons
This commit is contained in:
@@ -22,6 +22,18 @@ namespace O3DE::ProjectManager
|
||||
: QStyledItemDelegate(parent)
|
||||
, m_gemModel(gemModel)
|
||||
{
|
||||
AddPlatformIcon(GemInfo::Android, ":/Resources/Android.svg");
|
||||
AddPlatformIcon(GemInfo::iOS, ":/Resources/iOS.svg");
|
||||
AddPlatformIcon(GemInfo::Linux, ":/Resources/Linux.svg");
|
||||
AddPlatformIcon(GemInfo::macOS, ":/Resources/macOS.svg");
|
||||
AddPlatformIcon(GemInfo::Windows, ":/Resources/Windows.svg");
|
||||
}
|
||||
|
||||
void GemItemDelegate::AddPlatformIcon(GemInfo::Platform platform, const QString& iconPath)
|
||||
{
|
||||
QPixmap pixmap(iconPath);
|
||||
qreal aspectRatio = static_cast<qreal>(pixmap.width()) / pixmap.height();
|
||||
m_platformIcons.insert(platform, QIcon(iconPath).pixmap(s_platformIconSize * aspectRatio, s_platformIconSize));
|
||||
}
|
||||
|
||||
void GemItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& modelIndex) const
|
||||
@@ -87,7 +99,7 @@ namespace O3DE::ProjectManager
|
||||
painter->drawText(gemCreatorRect, Qt::TextSingleLine, gemCreator);
|
||||
|
||||
// Gem summary
|
||||
const QSize summarySize = QSize(contentRect.width() - s_summaryStartX - s_itemMargins.right() * 4, contentRect.height());
|
||||
const QSize summarySize = QSize(contentRect.width() - s_summaryStartX - s_buttonWidth - s_itemMargins.right() * 4, contentRect.height());
|
||||
const QRect summaryRect = QRect(/*topLeft=*/QPoint(contentRect.left() + s_summaryStartX, contentRect.top()), summarySize);
|
||||
|
||||
painter->setFont(standardFont);
|
||||
@@ -96,6 +108,10 @@ namespace O3DE::ProjectManager
|
||||
const QString summary = m_gemModel->GetSummary(modelIndex);
|
||||
painter->drawText(summaryRect, Qt::AlignLeft | Qt::TextWordWrap, summary);
|
||||
|
||||
|
||||
DrawButton(painter, contentRect, modelIndex);
|
||||
DrawPlatformIcons(painter, contentRect, modelIndex);
|
||||
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
@@ -105,7 +121,7 @@ namespace O3DE::ProjectManager
|
||||
initStyleOption(&options, modelIndex);
|
||||
|
||||
int marginsHorizontal = s_itemMargins.left() + s_itemMargins.right() + s_contentMargins.left() + s_contentMargins.right();
|
||||
return QSize(marginsHorizontal + s_summaryStartX, s_height);
|
||||
return QSize(marginsHorizontal + s_buttonWidth + s_summaryStartX, s_height);
|
||||
}
|
||||
|
||||
bool GemItemDelegate::editorEvent(QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& modelIndex)
|
||||
@@ -132,4 +148,85 @@ namespace O3DE::ProjectManager
|
||||
font.setPixelSize(fontSize);
|
||||
return QFontMetrics(font).boundingRect(text);
|
||||
}
|
||||
|
||||
QRect GemItemDelegate::CalcButtonRect(const QRect& contentRect) const
|
||||
{
|
||||
const QPoint topLeft = QPoint(contentRect.right() - s_buttonWidth - s_itemMargins.right(), contentRect.top() + contentRect.height() / 2 - s_buttonHeight / 2);
|
||||
const QSize size = QSize(s_buttonWidth, s_buttonHeight);
|
||||
return QRect(topLeft, size);
|
||||
}
|
||||
|
||||
void GemItemDelegate::DrawPlatformIcons(QPainter* painter, const QRect& contentRect, const QModelIndex& modelIndex) const
|
||||
{
|
||||
const GemInfo::Platforms platforms = m_gemModel->GetPlatforms(modelIndex);
|
||||
int startX = 0;
|
||||
|
||||
// Iterate and draw the platforms in the order they are defined in the enum.
|
||||
for (int i = 0; i < GemInfo::NumPlatforms; ++i)
|
||||
{
|
||||
// Check if the platform is supported by the given gem.
|
||||
const GemInfo::Platform platform = static_cast<GemInfo::Platform>(1 << i);
|
||||
if (platforms & platform)
|
||||
{
|
||||
// Get the icon for the platform and draw it.
|
||||
const auto iterator = m_platformIcons.find(platform);
|
||||
if (iterator != m_platformIcons.end())
|
||||
{
|
||||
const QPixmap& pixmap = iterator.value();
|
||||
painter->drawPixmap(contentRect.left() + startX, contentRect.bottom() - s_platformIconSize, pixmap);
|
||||
qreal aspectRatio = static_cast<qreal>(pixmap.width()) / pixmap.height();
|
||||
startX += s_platformIconSize * aspectRatio + s_platformIconSize / 2.5;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GemItemDelegate::DrawButton(QPainter* painter, const QRect& contentRect, const QModelIndex& modelIndex) const
|
||||
{
|
||||
painter->save();
|
||||
const QRect buttonRect = CalcButtonRect(contentRect);
|
||||
QPoint circleCenter;
|
||||
QString buttonText;
|
||||
|
||||
const bool isAdded = m_gemModel->IsAdded(modelIndex);
|
||||
if (isAdded)
|
||||
{
|
||||
painter->setBrush(m_buttonEnabledColor);
|
||||
painter->setPen(m_buttonEnabledColor);
|
||||
|
||||
circleCenter = buttonRect.center() + QPoint(buttonRect.width() / 2 - s_buttonBorderRadius, 1);
|
||||
buttonText = "Added";
|
||||
}
|
||||
else
|
||||
{
|
||||
circleCenter = buttonRect.center() + QPoint(-buttonRect.width() / 2 + s_buttonBorderRadius + 1, 1);
|
||||
buttonText = "Get";
|
||||
}
|
||||
|
||||
// Rounded rect
|
||||
painter->drawRoundedRect(buttonRect, s_buttonBorderRadius, s_buttonBorderRadius);
|
||||
|
||||
// Text
|
||||
QFont font;
|
||||
QRect textRect = GetTextRect(font, buttonText, s_buttonFontSize);
|
||||
if (isAdded)
|
||||
{
|
||||
textRect = QRect(buttonRect.left(), buttonRect.top(), buttonRect.width() - s_buttonCircleRadius * 2.0, buttonRect.height());
|
||||
}
|
||||
else
|
||||
{
|
||||
textRect = QRect(buttonRect.left() + s_buttonCircleRadius * 2.0, buttonRect.top(), buttonRect.width() - s_buttonCircleRadius * 2.0, buttonRect.height());
|
||||
}
|
||||
|
||||
font.setPixelSize(s_buttonFontSize);
|
||||
painter->setFont(font);
|
||||
painter->setPen(m_textColor);
|
||||
painter->drawText(textRect, Qt::AlignCenter, buttonText);
|
||||
|
||||
// Circle
|
||||
painter->setBrush(m_textColor);
|
||||
painter->drawEllipse(circleCenter, s_buttonCircleRadius, s_buttonCircleRadius);
|
||||
|
||||
painter->restore();
|
||||
}
|
||||
} // namespace O3DE::ProjectManager
|
||||
|
||||
Reference in New Issue
Block a user