ok we can display icons in columns now

This commit is contained in:
georgemoralis 2023-03-10 18:30:24 +02:00
parent 86be793306
commit 8b9f094420
3 changed files with 81 additions and 5 deletions

View File

@ -2,6 +2,7 @@
#include "gui_settings.h" #include "gui_settings.h"
#include "custom_table_widget_item.h" #include "custom_table_widget_item.h"
#include "../emulator/fileFormat/PSF.h" #include "../emulator/fileFormat/PSF.h"
#include <QPainter>
game_list_frame::game_list_frame(std::shared_ptr<gui_settings> gui_settings, QWidget* parent) game_list_frame::game_list_frame(std::shared_ptr<gui_settings> gui_settings, QWidget* parent)
: QWidget(parent) : QWidget(parent)
@ -323,7 +324,7 @@ void game_list_frame::Refresh(const bool from_drive, const bool scroll_after)
const int scroll_position = m_game_list->verticalScrollBar()->value(); const int scroll_position = m_game_list->verticalScrollBar()->value();
PopulateGameList(); PopulateGameList();
SortGameList(); SortGameList();
//RepaintIcons(); RepaintIcons();
if (scroll_after) if (scroll_after)
{ {
@ -336,7 +337,7 @@ void game_list_frame::Refresh(const bool from_drive, const bool scroll_after)
} }
else else
{ {
//RepaintIcons(); RepaintIcons();
} }
@ -367,6 +368,7 @@ void game_list_frame::PopulateGameList()
int row = 0; int row = 0;
int index = -1; int index = -1;
RepaintIcons();//hackish
for (const auto& game : m_game_data) for (const auto& game : m_game_data)
{ {
index++; index++;
@ -374,6 +376,7 @@ void game_list_frame::PopulateGameList()
// Icon // Icon
custom_table_widget_item* icon_item = new custom_table_widget_item; custom_table_widget_item* icon_item = new custom_table_widget_item;
icon_item->setData(Qt::DecorationRole, game->pxmap);
icon_item->setData(Qt::UserRole, index, true); icon_item->setData(Qt::UserRole, index, true);
icon_item->setData(gui::custom_roles::game_role, QVariant::fromValue(game)); icon_item->setData(gui::custom_roles::game_role, QVariant::fromValue(game));
@ -441,4 +444,72 @@ std::string game_list_frame::CurrentSelectionPath()
m_old_layout_is_list = m_is_list_layout; m_old_layout_is_list = m_is_list_layout;
return selection; return selection;
}
void game_list_frame::RepaintIcons(const bool& from_settings)
{
for (auto& game : m_game_data)
{
game->icon.load(QString::fromStdString(game->info.icon_path));
game->pxmap = PaintedPixmap(game->icon);
}
}
QPixmap game_list_frame::PaintedPixmap(const QPixmap& icon) const
{
const qreal device_pixel_ratio = devicePixelRatioF();
QSize canvas_size(320, 176);
QSize icon_size(icon.size());
QPoint target_pos;
if (!icon.isNull())
{
// Let's upscale the original icon to at least fit into the outer rect of the size of PS3's ICON0.PNG
if (icon_size.width() < 320 || icon_size.height() < 176)
{
icon_size.scale(320, 176, Qt::KeepAspectRatio);
}
canvas_size = icon_size;
// Calculate the centered size and position of the icon on our canvas.
if (icon_size.width() != 320 || icon_size.height() != 176)
{
constexpr double target_ratio = 320.0 / 176.0; // aspect ratio 20:11
if ((icon_size.width() / static_cast<double>(icon_size.height())) > target_ratio)
{
canvas_size.setHeight(std::ceil(icon_size.width() / target_ratio));
}
else
{
canvas_size.setWidth(std::ceil(icon_size.height() * target_ratio));
}
target_pos.setX(std::max<int>(0, (canvas_size.width() - icon_size.width()) / 2.0));
target_pos.setY(std::max<int>(0, (canvas_size.height() - icon_size.height()) / 2.0));
}
}
// Create a canvas large enough to fit our entire scaled icon
QPixmap canvas(canvas_size * device_pixel_ratio);
canvas.setDevicePixelRatio(device_pixel_ratio);
canvas.fill(m_icon_color);
// Create a painter for our canvas
QPainter painter(&canvas);
painter.setRenderHint(QPainter::SmoothPixmapTransform);
// Draw the icon onto our canvas
if (!icon.isNull())
{
painter.drawPixmap(target_pos.x(), target_pos.y(), icon_size.width(), icon_size.height(), icon);
}
// Finish the painting
painter.end();
// Scale and return our final image
return canvas.scaled(m_icon_size * device_pixel_ratio, Qt::KeepAspectRatio, Qt::TransformationMode::SmoothTransformation);
} }

View File

@ -30,9 +30,14 @@ public :
/** Refresh the gamelist with/without loading game data from files. Public so that main frame can refresh after vfs or install */ /** Refresh the gamelist with/without loading game data from files. Public so that main frame can refresh after vfs or install */
void Refresh(const bool from_drive = false, const bool scroll_after = true); void Refresh(const bool from_drive = false, const bool scroll_after = true);
/** Repaint Gamelist Icons with new background color */
void RepaintIcons(const bool& from_settings = false);
private Q_SLOTS: private Q_SLOTS:
void OnHeaderColumnClicked(int col); void OnHeaderColumnClicked(int col);
private: private:
QPixmap PaintedPixmap(const QPixmap& icon) const;
void SortGameList() const; void SortGameList() const;
std::string CurrentSelectionPath(); std::string CurrentSelectionPath();
void PopulateGameList(); void PopulateGameList();

View File

@ -6,9 +6,9 @@ visibility_column_serial=true
visibility_column_firmware=true visibility_column_firmware=true
visibility_column_version=true visibility_column_version=true
visibility_column_category=true visibility_column_category=true
sortCol=4 sortCol=1
sortAsc=false sortAsc=true
state="@ByteArray(\0\0\0\xff\0\0\0\0\0\0\0\x1\0\0\0\x1\0\0\0\x4\x1\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\x3\xfe\0\0\0\a\0\x1\0\x1\0\0\0\0\0\0\0\0\0\0\0\0\x96\xff\xff\xff\xff\0\0\0\x1\0\0\0\0\0\0\0\a\0\0\0'\0\0\0\x1\0\0\0\x2\0\0\0\xbc\0\0\0\x1\0\0\0\0\0\0\0\x42\0\0\0\x1\0\0\0\0\0\0\0=\0\0\0\x1\0\0\0\0\0\0\0\x96\0\0\0\x1\0\0\0\0\0\0\0\x96\0\0\0\x1\0\0\0\0\0\0\x1p\0\0\0\x1\0\0\0\0\0\0\x3\xe8\x1\0\0\0\x42\0\0\0\0)" state="@ByteArray(\0\0\0\xff\0\0\0\0\0\0\0\x1\0\0\0\0\0\0\0\x1\x1\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\x2\xe1\0\0\0\a\0\x1\0\x1\0\0\0\0\0\0\0\0\0\0\0\0\x96\xff\xff\xff\xff\0\0\0\x1\0\0\0\0\0\0\0\a\0\0\0.\0\0\0\x1\0\0\0\x2\0\0\0\xc6\0\0\0\x1\0\0\0\0\0\0\0\x42\0\0\0\x1\0\0\0\0\0\0\0=\0\0\0\x1\0\0\0\0\0\0\0\x96\0\0\0\x1\0\0\0\0\0\0\0\x96\0\0\0\x1\0\0\0\0\0\0\0\x42\0\0\0\x1\0\0\0\0\0\0\x3\xe8\x1\0\0\0\x42\0\0\0\0)"
iconColor=@Variant(\0\0\0\x43\x1\xff\xff\xf0\xf0\xf0\xf0\xf0\xf0\0\0) iconColor=@Variant(\0\0\0\x43\x1\xff\xff\xf0\xf0\xf0\xf0\xf0\xf0\0\0)
marginFactor=0.09 marginFactor=0.09
textFactor=2 textFactor=2