mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-24 14:49:42 -06:00
Qt/GameList: Add option to show covers in grid mode
This commit is contained in:
@ -21,6 +21,7 @@
|
||||
#include <QMenu>
|
||||
#include <QMessageBox>
|
||||
#include <QProgressDialog>
|
||||
#include <QShortcut>
|
||||
#include <QSortFilterProxyModel>
|
||||
#include <QTableView>
|
||||
#include <QUrl>
|
||||
@ -73,6 +74,15 @@ GameList::GameList(QWidget* parent) : QStackedWidget(parent)
|
||||
addWidget(m_empty);
|
||||
m_prefer_list = Settings::Instance().GetPreferredView();
|
||||
ConsiderViewChange();
|
||||
|
||||
auto* zoom_in = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Plus), this);
|
||||
auto* zoom_out = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Minus), this);
|
||||
|
||||
connect(zoom_in, &QShortcut::activated, this, &GameList::ZoomIn);
|
||||
connect(zoom_out, &QShortcut::activated, this, &GameList::ZoomOut);
|
||||
|
||||
connect(&Settings::Instance(), &Settings::MetadataRefreshCompleted, this,
|
||||
[this] { m_grid_proxy->invalidate(); });
|
||||
}
|
||||
|
||||
void GameList::MakeListView()
|
||||
@ -854,3 +864,35 @@ void GameList::SetSearchTerm(const QString& term)
|
||||
|
||||
UpdateColumnVisibility();
|
||||
}
|
||||
|
||||
void GameList::ZoomIn()
|
||||
{
|
||||
m_model->SetScale(m_model->GetScale() + 0.1);
|
||||
|
||||
m_list_proxy->invalidate();
|
||||
m_grid_proxy->invalidate();
|
||||
|
||||
UpdateFont();
|
||||
}
|
||||
|
||||
void GameList::ZoomOut()
|
||||
{
|
||||
if (m_model->GetScale() <= 0.1)
|
||||
return;
|
||||
|
||||
m_model->SetScale(m_model->GetScale() - 0.1);
|
||||
|
||||
m_list_proxy->invalidate();
|
||||
m_grid_proxy->invalidate();
|
||||
|
||||
UpdateFont();
|
||||
}
|
||||
|
||||
void GameList::UpdateFont()
|
||||
{
|
||||
QFont f;
|
||||
|
||||
f.setPointSizeF(m_model->GetScale() * f.pointSize());
|
||||
|
||||
m_grid->setFont(f);
|
||||
}
|
||||
|
@ -62,6 +62,9 @@ private:
|
||||
void ChangeDisc();
|
||||
void UpdateColumnVisibility();
|
||||
|
||||
void ZoomIn();
|
||||
void ZoomOut();
|
||||
|
||||
void OnHeaderViewChanged();
|
||||
void OnSectionResized(int index, int, int);
|
||||
|
||||
@ -71,6 +74,7 @@ private:
|
||||
// We only have two views, just use a bool to distinguish.
|
||||
void SetPreferredView(bool list);
|
||||
void ConsiderViewChange();
|
||||
void UpdateFont();
|
||||
|
||||
GameListModel* m_model;
|
||||
QSortFilterProxyModel* m_list_proxy;
|
||||
|
@ -283,3 +283,13 @@ void GameListModel::SetSearchTerm(const QString& term)
|
||||
{
|
||||
m_term = term;
|
||||
}
|
||||
|
||||
void GameListModel::SetScale(float scale)
|
||||
{
|
||||
m_scale = scale;
|
||||
}
|
||||
|
||||
float GameListModel::GetScale() const
|
||||
{
|
||||
return m_scale;
|
||||
}
|
||||
|
@ -59,6 +59,9 @@ public:
|
||||
void UpdateGame(const std::shared_ptr<const UICommon::GameFile>& game);
|
||||
void RemoveGame(const std::string& path);
|
||||
|
||||
void SetScale(float scale);
|
||||
float GetScale() const;
|
||||
|
||||
private:
|
||||
// Index in m_games, or -1 if it isn't found
|
||||
int FindGame(const std::string& path) const;
|
||||
@ -67,4 +70,5 @@ private:
|
||||
QList<std::shared_ptr<const UICommon::GameFile>> m_games;
|
||||
Core::TitleDatabase m_title_database;
|
||||
QString m_term;
|
||||
float m_scale = 1.0;
|
||||
};
|
||||
|
@ -44,6 +44,10 @@ GameTracker::GameTracker(QObject* parent) : QFileSystemWatcher(parent)
|
||||
}
|
||||
});
|
||||
|
||||
connect(&Settings::Instance(), &Settings::MetadataRefreshRequested, this, [this] {
|
||||
m_load_thread.EmplaceItem(Command{CommandType::UpdateMetadata, {}});
|
||||
});
|
||||
|
||||
m_load_thread.Reset([this](Command command) {
|
||||
switch (command.type)
|
||||
{
|
||||
@ -64,6 +68,13 @@ GameTracker::GameTracker(QObject* parent) : QFileSystemWatcher(parent)
|
||||
case CommandType::UpdateFile:
|
||||
UpdateFileInternal(command.path);
|
||||
break;
|
||||
case CommandType::UpdateMetadata:
|
||||
m_cache.UpdateAdditionalMetadata(
|
||||
[this](const std::shared_ptr<const UICommon::GameFile>& game) {
|
||||
emit GameUpdated(game);
|
||||
});
|
||||
QueueOnObject(this, [this] { Settings::Instance().NotifyMetadataRefreshComplete(); });
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
@ -121,6 +132,8 @@ void GameTracker::StartInternal()
|
||||
cache_updated |= m_cache.UpdateAdditionalMetadata(emit_game_updated);
|
||||
if (cache_updated)
|
||||
m_cache.Save();
|
||||
|
||||
QueueOnObject(this, [this] { Settings::Instance().NotifyMetadataRefreshComplete(); });
|
||||
}
|
||||
|
||||
bool GameTracker::AddPath(const QString& dir)
|
||||
|
@ -70,6 +70,7 @@ private:
|
||||
RemoveDirectory,
|
||||
UpdateDirectory,
|
||||
UpdateFile,
|
||||
UpdateMetadata
|
||||
};
|
||||
|
||||
struct Command
|
||||
|
@ -4,11 +4,16 @@
|
||||
|
||||
#include "DolphinQt/GameList/GridProxyModel.h"
|
||||
|
||||
#include <QImage>
|
||||
#include <QPixmap>
|
||||
#include <QSize>
|
||||
|
||||
#include "DolphinQt/GameList/GameListModel.h"
|
||||
|
||||
#include "Core/Config/UISettings.h"
|
||||
|
||||
#include "UICommon/GameFile.h"
|
||||
|
||||
const QSize LARGE_BANNER_SIZE(144, 48);
|
||||
|
||||
GridProxyModel::GridProxyModel(QObject* parent) : QSortFilterProxyModel(parent)
|
||||
@ -27,12 +32,30 @@ QVariant GridProxyModel::data(const QModelIndex& i, int role) const
|
||||
}
|
||||
else if (role == Qt::DecorationRole)
|
||||
{
|
||||
auto pixmap = sourceModel()
|
||||
->data(sourceModel()->index(source_index.row(), GameListModel::COL_BANNER),
|
||||
Qt::DecorationRole)
|
||||
.value<QPixmap>();
|
||||
return pixmap.scaled(LARGE_BANNER_SIZE * pixmap.devicePixelRatio(), Qt::KeepAspectRatio,
|
||||
Qt::SmoothTransformation);
|
||||
auto* model = static_cast<GameListModel*>(sourceModel());
|
||||
|
||||
const auto& buffer = model->GetGameFile(source_index.row())->GetCoverImage().buffer;
|
||||
|
||||
QPixmap pixmap;
|
||||
|
||||
if (buffer.empty() || !Config::Get(Config::MAIN_USE_GAME_COVERS))
|
||||
{
|
||||
pixmap = model
|
||||
->data(model->index(source_index.row(), GameListModel::COL_BANNER),
|
||||
Qt::DecorationRole)
|
||||
.value<QPixmap>();
|
||||
|
||||
return pixmap.scaled(LARGE_BANNER_SIZE * model->GetScale() * pixmap.devicePixelRatio(),
|
||||
Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
||||
}
|
||||
else
|
||||
{
|
||||
pixmap = QPixmap::fromImage(QImage::fromData(
|
||||
reinterpret_cast<const unsigned char*>(&buffer[0]), static_cast<int>(buffer.size())));
|
||||
|
||||
return pixmap.scaled(QSize(160, 224) * model->GetScale() * pixmap.devicePixelRatio(),
|
||||
Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
||||
}
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
|
Reference in New Issue
Block a user