From d25700e2416089be45bc0b6af97e50e47f6f8247 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Sat, 9 Sep 2023 14:02:43 +1000 Subject: [PATCH] Qt: Fix cover spacing not updating on resize Closes #9869. --- pcsx2-qt/GameList/GameListModel.cpp | 10 +++++---- pcsx2-qt/GameList/GameListModel.h | 5 ++++- pcsx2-qt/GameList/GameListWidget.cpp | 33 ++++++++++++++-------------- pcsx2-qt/GameList/GameListWidget.h | 2 +- 4 files changed, 27 insertions(+), 23 deletions(-) diff --git a/pcsx2-qt/GameList/GameListModel.cpp b/pcsx2-qt/GameList/GameListModel.cpp index 5c712dbc03..14ccf5e7f1 100644 --- a/pcsx2-qt/GameList/GameListModel.cpp +++ b/pcsx2-qt/GameList/GameListModel.cpp @@ -127,12 +127,12 @@ const char* GameListModel::getColumnName(Column col) return s_column_names[static_cast(col)]; } -GameListModel::GameListModel(QObject* parent /* = nullptr */) +GameListModel::GameListModel(float cover_scale, bool show_cover_titles, QObject* parent /* = nullptr */) : QAbstractTableModel(parent) - , m_cover_pixmap_cache(MIN_COVER_CACHE_SIZE) + , m_show_titles_for_covers(show_cover_titles) { loadCommonImages(); - setCoverScale(1.0f); + setCoverScale(cover_scale); setColumnDisplayNames(); } GameListModel::~GameListModel() = default; @@ -153,6 +153,8 @@ void GameListModel::setCoverScale(float scale) m_cover_scale_counter.fetch_add(1, std::memory_order_release); m_loading_pixmap = QPixmap(getCoverArtWidth(), getCoverArtHeight()); m_loading_pixmap.fill(QColor(0, 0, 0, 0)); + + emit coverScaleChanged(); } void GameListModel::refreshCovers() @@ -386,7 +388,7 @@ QVariant GameListModel::data(const QModelIndex& index, int role) const return m_compatibility_pixmaps[static_cast( (static_cast(ge->compatibility_rating) >= GameList::CompatibilityRatingCount) ? GameList::CompatibilityRating::Unknown : - ge->compatibility_rating)]; + ge->compatibility_rating)]; } case Column_Cover: diff --git a/pcsx2-qt/GameList/GameListModel.h b/pcsx2-qt/GameList/GameListModel.h index c381b4ed07..d2a7707691 100644 --- a/pcsx2-qt/GameList/GameListModel.h +++ b/pcsx2-qt/GameList/GameListModel.h @@ -55,7 +55,7 @@ public: static QIcon getIconForType(GameList::EntryType type); static QIcon getIconForRegion(GameList::Region region); - GameListModel(QObject* parent = nullptr); + GameListModel(float cover_scale, bool show_cover_titles, QObject* parent = nullptr); ~GameListModel(); int rowCount(const QModelIndex& parent = QModelIndex()) const override; @@ -83,6 +83,9 @@ public: void refreshCovers(); void updateCacheSize(int width, int height); +Q_SIGNALS: + void coverScaleChanged(); + private: void loadCommonImages(); void loadThemeSpecificImages(); diff --git a/pcsx2-qt/GameList/GameListWidget.cpp b/pcsx2-qt/GameList/GameListWidget.cpp index 61d201d6fb..92bda95e05 100644 --- a/pcsx2-qt/GameList/GameListWidget.cpp +++ b/pcsx2-qt/GameList/GameListWidget.cpp @@ -115,9 +115,9 @@ GameListWidget::~GameListWidget() = default; void GameListWidget::initialize() { - m_model = new GameListModel(this); - m_model->setCoverScale(Host::GetBaseFloatSettingValue("UI", "GameListCoverArtScale", 0.45f)); - m_model->setShowCoverTitles(Host::GetBaseBoolSettingValue("UI", "GameListShowCoverTitles", true)); + const float cover_scale = Host::GetBaseFloatSettingValue("UI", "GameListCoverArtScale", 0.45f); + const bool show_cover_titles = Host::GetBaseBoolSettingValue("UI", "GameListShowCoverTitles", true); + m_model = new GameListModel(cover_scale, show_cover_titles, this); m_model->updateCacheSize(width(), height()); m_sort_model = new GameListSortModel(m_model); @@ -189,11 +189,9 @@ void GameListWidget::initialize() m_list_view->setItemAlignment(Qt::AlignHCenter); m_list_view->setContextMenuPolicy(Qt::CustomContextMenu); m_list_view->setFrameStyle(QFrame::NoFrame); - m_list_view->setSpacing(m_model->getCoverArtSpacing()); m_list_view->setVerticalScrollMode(QAbstractItemView::ScrollMode::ScrollPerPixel); m_list_view->verticalScrollBar()->setSingleStep(15); - - updateListFont(); + onCoverScaleChanged(); connect(m_list_view->selectionModel(), &QItemSelectionModel::currentChanged, this, &GameListWidget::onSelectionModelCurrentChanged); @@ -201,6 +199,7 @@ void GameListWidget::initialize() connect(m_list_view, &GameListGridListView::zoomOut, this, &GameListWidget::gridZoomOut); connect(m_list_view, &QListView::activated, this, &GameListWidget::onListViewItemActivated); 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); @@ -354,14 +353,23 @@ void GameListWidget::onTableViewHeaderSortIndicatorChanged(int, Qt::SortOrder) 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) { const float new_scale = std::clamp(m_model->getCoverScale() + delta, MIN_SCALE, MAX_SCALE); Host::SetBaseFloatSettingValue("UI", "GameListCoverArtScale", new_scale); Host::CommitBaseSettingChanges(); m_model->setCoverScale(new_scale); - m_model->updateCacheSize(width(), height()); - updateListFont(); updateToolbar(); } @@ -382,8 +390,6 @@ void GameListWidget::gridIntScale(int int_scale) Host::SetBaseFloatSettingValue("UI", "GameListCoverArtScale", new_scale); Host::CommitBaseSettingChanges(); m_model->setCoverScale(new_scale); - m_model->updateCacheSize(width(), height()); - updateListFont(); updateToolbar(); } @@ -439,13 +445,6 @@ void GameListWidget::setShowCoverTitles(bool enabled) emit layoutChange(); } -void GameListWidget::updateListFont() -{ - QFont font; - font.setPointSizeF(16.0f * m_model->getCoverScale()); - m_list_view->setFont(font); -} - void GameListWidget::updateToolbar() { const bool grid_view = isShowingGameGrid(); diff --git a/pcsx2-qt/GameList/GameListWidget.h b/pcsx2-qt/GameList/GameListWidget.h index 5a78c57918..49ee105980 100644 --- a/pcsx2-qt/GameList/GameListWidget.h +++ b/pcsx2-qt/GameList/GameListWidget.h @@ -92,6 +92,7 @@ private Q_SLOTS: void onTableViewHeaderSortIndicatorChanged(int, Qt::SortOrder); void onListViewItemActivated(const QModelIndex& index); void onListViewContextMenuRequested(const QPoint& point); + void onCoverScaleChanged(); public Q_SLOTS: void showGameList(); @@ -112,7 +113,6 @@ private: void loadTableViewColumnSortSettings(); void saveTableViewColumnSortSettings(); void listZoom(float delta); - void updateListFont(); void updateToolbar(); Ui::GameListWidget m_ui;