Qt: Fix cover spacing not updating on resize

Closes #9869.
This commit is contained in:
Stenzek 2023-09-09 14:02:43 +10:00 committed by Connor McLaughlin
parent 9dde599e00
commit d25700e241
4 changed files with 27 additions and 23 deletions

View File

@ -127,12 +127,12 @@ const char* GameListModel::getColumnName(Column col)
return s_column_names[static_cast<int>(col)]; return s_column_names[static_cast<int>(col)];
} }
GameListModel::GameListModel(QObject* parent /* = nullptr */) GameListModel::GameListModel(float cover_scale, bool show_cover_titles, QObject* parent /* = nullptr */)
: QAbstractTableModel(parent) : QAbstractTableModel(parent)
, m_cover_pixmap_cache(MIN_COVER_CACHE_SIZE) , m_show_titles_for_covers(show_cover_titles)
{ {
loadCommonImages(); loadCommonImages();
setCoverScale(1.0f); setCoverScale(cover_scale);
setColumnDisplayNames(); setColumnDisplayNames();
} }
GameListModel::~GameListModel() = default; GameListModel::~GameListModel() = default;
@ -153,6 +153,8 @@ void GameListModel::setCoverScale(float scale)
m_cover_scale_counter.fetch_add(1, std::memory_order_release); m_cover_scale_counter.fetch_add(1, std::memory_order_release);
m_loading_pixmap = QPixmap(getCoverArtWidth(), getCoverArtHeight()); m_loading_pixmap = QPixmap(getCoverArtWidth(), getCoverArtHeight());
m_loading_pixmap.fill(QColor(0, 0, 0, 0)); m_loading_pixmap.fill(QColor(0, 0, 0, 0));
emit coverScaleChanged();
} }
void GameListModel::refreshCovers() void GameListModel::refreshCovers()
@ -386,7 +388,7 @@ QVariant GameListModel::data(const QModelIndex& index, int role) const
return m_compatibility_pixmaps[static_cast<u32>( return m_compatibility_pixmaps[static_cast<u32>(
(static_cast<u32>(ge->compatibility_rating) >= GameList::CompatibilityRatingCount) ? (static_cast<u32>(ge->compatibility_rating) >= GameList::CompatibilityRatingCount) ?
GameList::CompatibilityRating::Unknown : GameList::CompatibilityRating::Unknown :
ge->compatibility_rating)]; ge->compatibility_rating)];
} }
case Column_Cover: case Column_Cover:

View File

@ -55,7 +55,7 @@ public:
static QIcon getIconForType(GameList::EntryType type); static QIcon getIconForType(GameList::EntryType type);
static QIcon getIconForRegion(GameList::Region region); static QIcon getIconForRegion(GameList::Region region);
GameListModel(QObject* parent = nullptr); GameListModel(float cover_scale, bool show_cover_titles, QObject* parent = nullptr);
~GameListModel(); ~GameListModel();
int rowCount(const QModelIndex& parent = QModelIndex()) const override; int rowCount(const QModelIndex& parent = QModelIndex()) const override;
@ -83,6 +83,9 @@ public:
void refreshCovers(); void refreshCovers();
void updateCacheSize(int width, int height); void updateCacheSize(int width, int height);
Q_SIGNALS:
void coverScaleChanged();
private: private:
void loadCommonImages(); void loadCommonImages();
void loadThemeSpecificImages(); void loadThemeSpecificImages();

View File

@ -115,9 +115,9 @@ GameListWidget::~GameListWidget() = default;
void GameListWidget::initialize() void GameListWidget::initialize()
{ {
m_model = new GameListModel(this); const float cover_scale = Host::GetBaseFloatSettingValue("UI", "GameListCoverArtScale", 0.45f);
m_model->setCoverScale(Host::GetBaseFloatSettingValue("UI", "GameListCoverArtScale", 0.45f)); const bool show_cover_titles = Host::GetBaseBoolSettingValue("UI", "GameListShowCoverTitles", true);
m_model->setShowCoverTitles(Host::GetBaseBoolSettingValue("UI", "GameListShowCoverTitles", true)); m_model = new GameListModel(cover_scale, show_cover_titles, this);
m_model->updateCacheSize(width(), height()); m_model->updateCacheSize(width(), height());
m_sort_model = new GameListSortModel(m_model); m_sort_model = new GameListSortModel(m_model);
@ -189,11 +189,9 @@ void GameListWidget::initialize()
m_list_view->setItemAlignment(Qt::AlignHCenter); m_list_view->setItemAlignment(Qt::AlignHCenter);
m_list_view->setContextMenuPolicy(Qt::CustomContextMenu); m_list_view->setContextMenuPolicy(Qt::CustomContextMenu);
m_list_view->setFrameStyle(QFrame::NoFrame); m_list_view->setFrameStyle(QFrame::NoFrame);
m_list_view->setSpacing(m_model->getCoverArtSpacing());
m_list_view->setVerticalScrollMode(QAbstractItemView::ScrollMode::ScrollPerPixel); m_list_view->setVerticalScrollMode(QAbstractItemView::ScrollMode::ScrollPerPixel);
m_list_view->verticalScrollBar()->setSingleStep(15); m_list_view->verticalScrollBar()->setSingleStep(15);
onCoverScaleChanged();
updateListFont();
connect(m_list_view->selectionModel(), &QItemSelectionModel::currentChanged, this, connect(m_list_view->selectionModel(), &QItemSelectionModel::currentChanged, this,
&GameListWidget::onSelectionModelCurrentChanged); &GameListWidget::onSelectionModelCurrentChanged);
@ -201,6 +199,7 @@ void GameListWidget::initialize()
connect(m_list_view, &GameListGridListView::zoomOut, this, &GameListWidget::gridZoomOut); connect(m_list_view, &GameListGridListView::zoomOut, this, &GameListWidget::gridZoomOut);
connect(m_list_view, &QListView::activated, this, &GameListWidget::onListViewItemActivated); connect(m_list_view, &QListView::activated, this, &GameListWidget::onListViewItemActivated);
connect(m_list_view, &QListView::customContextMenuRequested, this, &GameListWidget::onListViewContextMenuRequested); connect(m_list_view, &QListView::customContextMenuRequested, this, &GameListWidget::onListViewContextMenuRequested);
connect(m_model, &GameListModel::coverScaleChanged, this, &GameListWidget::onCoverScaleChanged);
m_ui.stack->insertWidget(1, m_list_view); m_ui.stack->insertWidget(1, m_list_view);
@ -354,14 +353,23 @@ void GameListWidget::onTableViewHeaderSortIndicatorChanged(int, Qt::SortOrder)
saveTableViewColumnSortSettings(); saveTableViewColumnSortSettings();
} }
void GameListWidget::onCoverScaleChanged()
{
m_model->updateCacheSize(width(), height());
m_list_view->setSpacing(m_model->getCoverArtSpacing());
QFont font;
font.setPointSizeF(16.0f * m_model->getCoverScale());
m_list_view->setFont(font);
}
void GameListWidget::listZoom(float delta) void GameListWidget::listZoom(float delta)
{ {
const float new_scale = std::clamp(m_model->getCoverScale() + delta, MIN_SCALE, MAX_SCALE); const float new_scale = std::clamp(m_model->getCoverScale() + delta, MIN_SCALE, MAX_SCALE);
Host::SetBaseFloatSettingValue("UI", "GameListCoverArtScale", new_scale); Host::SetBaseFloatSettingValue("UI", "GameListCoverArtScale", new_scale);
Host::CommitBaseSettingChanges(); Host::CommitBaseSettingChanges();
m_model->setCoverScale(new_scale); m_model->setCoverScale(new_scale);
m_model->updateCacheSize(width(), height());
updateListFont();
updateToolbar(); updateToolbar();
} }
@ -382,8 +390,6 @@ void GameListWidget::gridIntScale(int int_scale)
Host::SetBaseFloatSettingValue("UI", "GameListCoverArtScale", new_scale); Host::SetBaseFloatSettingValue("UI", "GameListCoverArtScale", new_scale);
Host::CommitBaseSettingChanges(); Host::CommitBaseSettingChanges();
m_model->setCoverScale(new_scale); m_model->setCoverScale(new_scale);
m_model->updateCacheSize(width(), height());
updateListFont();
updateToolbar(); updateToolbar();
} }
@ -439,13 +445,6 @@ void GameListWidget::setShowCoverTitles(bool enabled)
emit layoutChange(); emit layoutChange();
} }
void GameListWidget::updateListFont()
{
QFont font;
font.setPointSizeF(16.0f * m_model->getCoverScale());
m_list_view->setFont(font);
}
void GameListWidget::updateToolbar() void GameListWidget::updateToolbar()
{ {
const bool grid_view = isShowingGameGrid(); const bool grid_view = isShowingGameGrid();

View File

@ -92,6 +92,7 @@ private Q_SLOTS:
void onTableViewHeaderSortIndicatorChanged(int, Qt::SortOrder); void onTableViewHeaderSortIndicatorChanged(int, Qt::SortOrder);
void onListViewItemActivated(const QModelIndex& index); void onListViewItemActivated(const QModelIndex& index);
void onListViewContextMenuRequested(const QPoint& point); void onListViewContextMenuRequested(const QPoint& point);
void onCoverScaleChanged();
public Q_SLOTS: public Q_SLOTS:
void showGameList(); void showGameList();
@ -112,7 +113,6 @@ private:
void loadTableViewColumnSortSettings(); void loadTableViewColumnSortSettings();
void saveTableViewColumnSortSettings(); void saveTableViewColumnSortSettings();
void listZoom(float delta); void listZoom(float delta);
void updateListFont();
void updateToolbar(); void updateToolbar();
Ui::GameListWidget m_ui; Ui::GameListWidget m_ui;