1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2024-11-22 10:42:36 +01:00

Qt: optimize game list repaint with new logic

We now pass a shared pointer to the icon items, so there is no need to trigger a full refresh of the list anymore.
Sadly this doesn't apply to the game grid.
This commit is contained in:
Megamouse 2021-04-16 02:02:47 +02:00
parent 53f317e076
commit bff938ccf5
4 changed files with 45 additions and 15 deletions

View File

@ -826,7 +826,6 @@ void game_list_frame::SaveSettings()
} }
m_gui_settings->SetValue(gui::gl_sortCol, m_sort_column); m_gui_settings->SetValue(gui::gl_sortCol, m_sort_column);
m_gui_settings->SetValue(gui::gl_sortAsc, m_col_sort_order == Qt::AscendingOrder); m_gui_settings->SetValue(gui::gl_sortAsc, m_col_sort_order == Qt::AscendingOrder);
m_gui_settings->SetValue(gui::gl_state, m_game_list->horizontalHeader()->saveState()); m_gui_settings->SetValue(gui::gl_state, m_game_list->horizontalHeader()->saveState());
} }
@ -1991,7 +1990,32 @@ void game_list_frame::RepaintIcons(const bool& from_settings)
game->pxmap = PaintedPixmap(game->icon, game->hasCustomConfig, game->hasCustomPadConfig, color); game->pxmap = PaintedPixmap(game->icon, game->hasCustomConfig, game->hasCustomPadConfig, color);
}); });
Refresh(); if (m_is_list_layout)
{
// We don't need a full Refresh just for the icons, so let's just trigger the icon callback of each icon.
for (int row = 0; row < m_game_list->rowCount(); ++row)
{
if (const auto item = static_cast<custom_table_widget_item*>(m_game_list->item(row, gui::column_icon)))
{
item->call_icon_func();
}
}
// Fixate vertical header and row height
m_game_list->verticalHeader()->setMinimumSectionSize(m_icon_size.height());
m_game_list->verticalHeader()->setMaximumSectionSize(m_icon_size.height());
// Resize the icon column
m_game_list->resizeColumnToContents(gui::column_icon);
// Shorten the last section to remove horizontal scrollbar if possible
m_game_list->resizeColumnToContents(gui::column_count - 1);
}
else
{
// The game grid needs to be recreated from scratch
Refresh();
}
} }
void game_list_frame::SetShowHidden(bool show) void game_list_frame::SetShowHidden(bool show)
@ -2263,15 +2287,15 @@ void game_list_frame::PopulateGameGrid(int maxCols, const QSize& image_size, con
m_game_grid->deleteLater(); m_game_grid->deleteLater();
const bool showText = m_icon_size_index > gui::gl_max_slider_pos * 2 / 5; const bool show_text = m_icon_size_index > gui::gl_max_slider_pos * 2 / 5;
if (m_icon_size_index < gui::gl_max_slider_pos * 2 / 3) if (m_icon_size_index < gui::gl_max_slider_pos * 2 / 3)
{ {
m_game_grid = new game_list_grid(image_size, image_color, m_margin_factor, m_text_factor * 2, showText); m_game_grid = new game_list_grid(image_size, image_color, m_margin_factor, m_text_factor * 2, show_text);
} }
else else
{ {
m_game_grid = new game_list_grid(image_size, image_color, m_margin_factor, m_text_factor, showText); m_game_grid = new game_list_grid(image_size, image_color, m_margin_factor, m_text_factor, show_text);
} }
// Get list of matching apps // Get list of matching apps
@ -2308,21 +2332,22 @@ void game_list_frame::PopulateGameGrid(int maxCols, const QSize& image_size, con
const QString title = m_titles.value(serial, qstr(app->info.name)); const QString title = m_titles.value(serial, qstr(app->info.name));
const QString notes = m_notes.value(serial); const QString notes = m_notes.value(serial);
m_game_grid->addItem(app, title, (m_play_hover_movies && app->has_hover_gif) ? (game_icon_path % serial % "/hover.gif") : QStringLiteral(""), r, c); QTableWidgetItem* item = m_game_grid->addItem(app, title, (m_play_hover_movies && app->has_hover_gif) ? (game_icon_path % serial % "/hover.gif") : QStringLiteral(""), r, c);
m_game_grid->item(r, c)->setData(gui::game_role, QVariant::fromValue(app)); ensure(item);
item->setData(gui::game_role, QVariant::fromValue(app));
if (!notes.isEmpty()) if (!notes.isEmpty())
{ {
m_game_grid->item(r, c)->setToolTip(tr("%0 [%1]\n\nNotes:\n%2").arg(title).arg(serial).arg(notes)); item->setToolTip(tr("%0 [%1]\n\nNotes:\n%2").arg(title).arg(serial).arg(notes));
} }
else else
{ {
m_game_grid->item(r, c)->setToolTip(tr("%0 [%1]").arg(title).arg(serial)); item->setToolTip(tr("%0 [%1]").arg(title).arg(serial));
} }
if (selected_item == app->info.path + app->info.icon_path) if (selected_item == app->info.path + app->info.icon_path)
{ {
m_game_grid->setCurrentCell(r, c); m_game_grid->setCurrentItem(item);
} }
if (++c >= maxCols) if (++c >= maxCols)

View File

@ -73,7 +73,7 @@ void game_list_grid::setIconSize(const QSize& size) const
} }
} }
void game_list_grid::addItem(const game_info& app, const QString& name, const QString& movie_path, const int& row, const int& col) QTableWidgetItem* game_list_grid::addItem(const game_info& app, const QString& name, const QString& movie_path, const int& row, const int& col)
{ {
// create item with expanded image, title and position // create item with expanded image, title and position
movie_item* item = new movie_item; movie_item* item = new movie_item;
@ -151,6 +151,7 @@ void game_list_grid::addItem(const game_info& app, const QString& name, const QS
} }
setItem(row, col, item); setItem(row, col, item);
return item;
} }
qreal game_list_grid::getMarginFactor() const qreal game_list_grid::getMarginFactor() const

View File

@ -19,7 +19,7 @@ public:
void enableText(const bool& enabled); void enableText(const bool& enabled);
void setIconSize(const QSize& size) const; void setIconSize(const QSize& size) const;
void addItem(const game_info& app, const QString& name, const QString& movie_path, const int& row, const int& col); QTableWidgetItem* addItem(const game_info& app, const QString& name, const QString& movie_path, const int& row, const int& col);
[[nodiscard]] qreal getMarginFactor() const; [[nodiscard]] qreal getMarginFactor() const;

View File

@ -66,16 +66,20 @@ public:
QObject::connect(m_movie, &QMovie::frameChanged, m_movie, m_icon_callback); QObject::connect(m_movie, &QMovie::frameChanged, m_movie, m_icon_callback);
} }
void set_icon_func(const icon_callback_t& func) void call_icon_func() const
{ {
m_icon_callback = func;
if (m_icon_callback) if (m_icon_callback)
{ {
m_icon_callback(0); m_icon_callback(0);
} }
} }
void set_icon_func(const icon_callback_t& func)
{
m_icon_callback = func;
call_icon_func();
}
private: private:
QMovie* m_movie = nullptr; QMovie* m_movie = nullptr;
bool m_active = false; bool m_active = false;