From bb9dbf9a33f94212ac6f2650c68305b107021896 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Sat, 27 Sep 2025 21:55:16 +1000 Subject: [PATCH] Qt: Avoid casts on animation delegate --- src/duckstation-qt/gamelistwidget.cpp | 34 ++++++++++----------------- 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/src/duckstation-qt/gamelistwidget.cpp b/src/duckstation-qt/gamelistwidget.cpp index f1a628233..903c843da 100644 --- a/src/duckstation-qt/gamelistwidget.cpp +++ b/src/duckstation-qt/gamelistwidget.cpp @@ -1342,10 +1342,7 @@ private: class GameListAnimatedIconDelegate final : public QStyledItemDelegate { public: - GameListAnimatedIconDelegate(QObject* parent, GameListModel* model, GameListCenterIconStyleDelegate* center_delegate, - GameListAchievementsStyleDelegate* achievements_delegate) - : QStyledItemDelegate(parent), m_model(model), m_center_delegate(center_delegate), - m_achievements_delegate(achievements_delegate) + GameListAnimatedIconDelegate(QObject* parent, GameListModel* model) : QStyledItemDelegate(parent), m_model(model) { connect(&m_animation_timer, &QTimer::timeout, this, &GameListAnimatedIconDelegate::nextAnimationFrame); } @@ -1353,19 +1350,18 @@ public: void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const override { const int column = index.column(); - if (column == GameListModel::Column_Region) + if (column != GameListModel::Column_Icon || m_frame_pixmaps.empty()) { - m_center_delegate->paint(painter, option, index); - return; - } - else if (column == GameListModel::Column_Achievements) - { - m_achievements_delegate->paint(painter, option, index); - return; - } - else if (column != GameListModel::Column_Icon || m_frame_pixmaps.empty()) - { - QStyledItemDelegate::paint(painter, option, index); + if (QAbstractItemDelegate* const delegate = + static_cast(parent())->itemDelegateForColumn(index.column())) + { + delegate->paint(painter, option, index); + } + else + { + QStyledItemDelegate::paint(painter, option, index); + } + return; } @@ -1462,8 +1458,6 @@ public: private: GameListModel* m_model; - GameListCenterIconStyleDelegate* m_center_delegate; - GameListAchievementsStyleDelegate* m_achievements_delegate; std::vector m_frame_pixmaps; u32 m_current_frame = 0; @@ -2272,9 +2266,7 @@ void GameListListView::setAnimateGameIcons(bool enabled) if (m_animated_game_icon_delegate) return; - m_animated_game_icon_delegate = new GameListAnimatedIconDelegate( - this, m_model, static_cast(itemDelegateForColumn(GameListModel::Column_Icon)), - static_cast(itemDelegateForColumn(GameListModel::Column_Achievements))); + m_animated_game_icon_delegate = new GameListAnimatedIconDelegate(this, m_model); } void GameListListView::updateAnimatedGameIconDelegate()