Skip to content

Commit e908fbe

Browse files
committed
GameList: Address review feedback for favorite indicator
1 parent 0077fa2 commit e908fbe

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed

pcsx2-qt/GameList/GameListModel.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ QVariant GameListModel::data(const QModelIndex& index, const int role) const
317317

318318
case NeedsFavoriteBadgeRole:
319319
{
320-
if (index.column() == Column_Cover || index.column() == Column_Favorite)
320+
if (index.column() == Column_Cover)
321321
return ge->is_favorite;
322322
return QVariant();
323323
}
@@ -410,6 +410,8 @@ bool GameListModel::lessThan(const QModelIndex& left_index, const QModelIndex& r
410410
return (StringUtil::Strcasecmp(left->serial.c_str(), right->serial.c_str()) < 0);
411411
}
412412

413+
case Column_Favorite:
414+
[[fallthrough]];
413415
case Column_Title:
414416
return titlesLessThan(left_row, right_row);
415417

@@ -472,9 +474,6 @@ bool GameListModel::lessThan(const QModelIndex& left_index, const QModelIndex& r
472474
return (left->last_played_time < right->last_played_time);
473475
}
474476

475-
case Column_Favorite:
476-
return titlesLessThan(left_row, right_row);
477-
478477
default:
479478
return false;
480479
}

pcsx2-qt/GameList/GameListModel.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class GameListModel final : public QAbstractTableModel
6767
bool lessThan(const QModelIndex& left_index, const QModelIndex& right_index, int column) const;
6868

6969
bool getShowCoverTitles() const { return m_show_titles_for_covers; }
70-
QPixmap getFavoritePixmap() const { return m_favorite_pixmap; }
70+
const QPixmap& getFavoritePixmap() const { return m_favorite_pixmap; }
7171
void setShowCoverTitles(bool enabled) { m_show_titles_for_covers = enabled; }
7272

7373
float getCoverScale() const { return m_cover_scale; }

pcsx2-qt/GameList/GameListWidget.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ static constexpr Qt::SortOrder DEFAULT_SORT_ORDER = Qt::AscendingOrder;
5252
static constexpr std::array<int, GameListModel::Column_Count> DEFAULT_COLUMN_WIDTHS = {{
5353
55, // type
5454
85, // code
55-
95, // favorite
55+
55, // favorite
5656
-1, // title
5757
-1, // file title
5858
75, // crc
@@ -139,8 +139,8 @@ namespace
139139
static constexpr int STAR_MARGIN = 4;
140140

141141
GameListIconStyleDelegate(QWidget* parent, const GameListModel* model)
142-
: QStyledItemDelegate(parent)
143-
, m_model(model)
142+
: QStyledItemDelegate(parent)
143+
, m_model(model)
144144
{
145145
}
146146
~GameListIconStyleDelegate() = default;
@@ -169,7 +169,7 @@ namespace
169169
// Determine starting location of icon (Qt uses top-left origin).
170170
const int icon_width = static_cast<int>(static_cast<qreal>(icon.width()) / icon.devicePixelRatio());
171171
const int icon_height = static_cast<int>(static_cast<qreal>(icon.height()) / icon.devicePixelRatio());
172-
const QPoint icon_top_left = QPoint((rect.width() - icon_width) / 2, (rect.height() - icon_height) / 2);
172+
const QPoint icon_top_left = rect.topLeft() + QPoint((rect.width() - icon_width) / 2, (rect.height() - icon_height) / 2);
173173

174174
// Change palette if the item is selected.
175175
if (option.state & QStyle::State_Selected)
@@ -195,20 +195,23 @@ namespace
195195
QPixmapCache::insert(key, highlighted_icon);
196196
}
197197

198-
painter->drawPixmap(rect.topLeft() + icon_top_left, highlighted_icon);
198+
painter->drawPixmap(icon_top_left, highlighted_icon);
199199
}
200200
else
201201
{
202-
painter->drawPixmap(rect.topLeft() + icon_top_left, icon);
202+
painter->drawPixmap(icon_top_left, icon);
203203
}
204204

205205
// Draw star overlay on bottom-right corner if game is favorited.
206206
const bool is_favorite = (index.column() == GameListModel::Column_Cover) &&
207207
index.data(GameListModel::NeedsFavoriteBadgeRole).toBool();
208208
if (is_favorite)
209209
{
210-
const QPoint star_pos = rect.bottomRight() - QPoint(STAR_SIZE + STAR_MARGIN, STAR_SIZE + STAR_MARGIN);
211-
painter->drawPixmap(star_pos, m_model->getFavoritePixmap());
210+
const QPixmap& star = m_model->getFavoritePixmap();
211+
const QPoint icon_bottom_right = icon_top_left + QPoint(icon_width, icon_height);
212+
const QSizeF size = star.deviceIndependentSize();
213+
const QPoint star_pos = icon_bottom_right - QPoint(size.width() + STAR_MARGIN, size.height() + STAR_MARGIN);
214+
painter->drawPixmap(star_pos, star);
212215
}
213216

214217
// Restore the old clip path.

0 commit comments

Comments
 (0)