mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2024-12-28 02:26:07 +00:00
addItem for table grid view
This commit is contained in:
parent
0c5380d78d
commit
e2181f1ed9
|
@ -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
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
struct gui_game_info
|
||||
{
|
||||
GameInfo info{};
|
||||
QPixmap icon;
|
||||
QPixmap pxmap;
|
||||
};
|
||||
|
||||
typedef std::shared_ptr<gui_game_info> game_info;
|
||||
|
|
Loading…
Reference in a new issue