From e2181f1ed9753294db91666e32e43dd7536c1609 Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Thu, 9 Mar 2023 13:09:56 +0200 Subject: [PATCH] addItem for table grid view --- shadPS4/gui/game_list_grid.cpp | 48 ++++++++++++++++++++++++++++++++-- shadPS4/gui/game_list_table.h | 2 ++ 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/shadPS4/gui/game_list_grid.cpp b/shadPS4/gui/game_list_grid.cpp index 02d48816..aeef3e50 100644 --- a/shadPS4/gui/game_list_grid.cpp +++ b/shadPS4/gui/game_list_grid.cpp @@ -37,7 +37,6 @@ game_list_grid::game_list_grid(const QSize& icon_size, QColor icon_color, const verticalHeader()->setVisible(false); horizontalHeader()->setVisible(false); setShowGrid(false); - setMouseTracking(true); } void game_list_grid::enableText(const bool& enabled) @@ -59,7 +58,52 @@ void game_list_grid::setIconSize(const QSize& size) const QTableWidgetItem* game_list_grid::addItem(const game_info& app, const QString& name, const QString& movie_path, const int& row, const int& col) { - throw std::exception("TODO"); + const qreal device_pixel_ratio = devicePixelRatioF(); + + // define size of expanded image, which is raw image size + margins + QSizeF exp_size_f; + if (m_text_enabled) + { + exp_size_f = m_icon_size + QSizeF(m_icon_size.width() * m_margin_factor * 2, m_icon_size.height() * m_margin_factor * (m_text_factor + 1)); + } + else + { + exp_size_f = m_icon_size + m_icon_size * m_margin_factor * 2; + } + + // define offset for raw image placement + QPoint offset(m_icon_size.width() * m_margin_factor, m_icon_size.height() * m_margin_factor); + const QSize exp_size = (exp_size_f * device_pixel_ratio).toSize(); + + // create empty canvas for expanded image + QImage exp_img(exp_size, QImage::Format_ARGB32); + exp_img.setDevicePixelRatio(device_pixel_ratio); + exp_img.fill(Qt::transparent); + + // create background for image + QImage bg_img(app->pxmap.size(), QImage::Format_ARGB32); + bg_img.setDevicePixelRatio(device_pixel_ratio); + bg_img.fill(m_icon_color); + + // place raw image inside expanded image + QPainter painter(&exp_img); + painter.setRenderHint(QPainter::SmoothPixmapTransform); + painter.drawImage(offset, bg_img); + painter.drawPixmap(offset, app->pxmap); + app->pxmap = {}; + painter.end(); + + // create item with expanded image, title and position + QTableWidgetItem* item = new QTableWidgetItem(); + item->setData(Qt::ItemDataRole::DecorationRole, QPixmap::fromImage(exp_img)); + + if (m_text_enabled) + { + item->setData(Qt::ItemDataRole::DisplayRole, name); + } + + setItem(row, col, item); + return item; } qreal game_list_grid::getMarginFactor() const diff --git a/shadPS4/gui/game_list_table.h b/shadPS4/gui/game_list_table.h index db0d7296..3678a08c 100644 --- a/shadPS4/gui/game_list_table.h +++ b/shadPS4/gui/game_list_table.h @@ -7,6 +7,8 @@ struct gui_game_info { GameInfo info{}; + QPixmap icon; + QPixmap pxmap; }; typedef std::shared_ptr game_info;