From 8f51bd2fa04af094a9f66e61d19a692444bf3fab Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Thu, 9 Mar 2023 16:46:52 +0200 Subject: [PATCH] game list frame work --- shadPS4/gui/game_list_frame.cpp | 69 ++++++++++++++++++++++++++++++++- shadPS4/gui/game_list_frame.h | 10 +++++ shadPS4/gui/gui_settings.h | 17 ++++++++ 3 files changed, 95 insertions(+), 1 deletion(-) diff --git a/shadPS4/gui/game_list_frame.cpp b/shadPS4/gui/game_list_frame.cpp index 57eec70d..f01313e8 100644 --- a/shadPS4/gui/game_list_frame.cpp +++ b/shadPS4/gui/game_list_frame.cpp @@ -1,5 +1,5 @@ #include "game_list_frame.h" - +#include "gui_settings.h" void game_list_frame::FixNarrowColumns() const @@ -42,4 +42,71 @@ void game_list_frame::ResizeColumnsToContents(int spacing) const const int size = m_game_list->horizontalHeader()->sectionSize(i) + spacing; m_game_list->horizontalHeader()->resizeSection(i, size); } +} + +void game_list_frame::SortGameList() const +{ + // Back-up old header sizes to handle unwanted column resize in case of zero search results + QList column_widths; + const int old_row_count = m_game_list->rowCount(); + const int old_game_count = m_game_data.count(); + + for (int i = 0; i < m_game_list->columnCount(); i++) + { + column_widths.append(m_game_list->columnWidth(i)); + } + + // Sorting resizes hidden columns, so unhide them as a workaround + QList columns_to_hide; + + for (int i = 0; i < m_game_list->columnCount(); i++) + { + if (m_game_list->isColumnHidden(i)) + { + m_game_list->setColumnHidden(i, false); + columns_to_hide << i; + } + } + + // Sort the list by column and sort order + m_game_list->sortByColumn(m_sort_column, m_col_sort_order); + + // Hide columns again + for (auto i : columns_to_hide) + { + m_game_list->setColumnHidden(i, true); + } + + // Don't resize the columns if no game is shown to preserve the header settings + if (!m_game_list->rowCount()) + { + for (int i = 0; i < m_game_list->columnCount(); i++) + { + m_game_list->setColumnWidth(i, column_widths[i]); + } + + m_game_list->horizontalHeader()->setSectionResizeMode(gui::column_icon, QHeaderView::Fixed); + return; + } + + // Fixate vertical header and row height + m_game_list->verticalHeader()->setMinimumSectionSize(m_icon_size.height()); + m_game_list->verticalHeader()->setMaximumSectionSize(m_icon_size.height()); + m_game_list->resizeRowsToContents(); + + // Resize columns if the game list was empty before + if (!old_row_count && !old_game_count) + { + ResizeColumnsToContents(); + } + else + { + m_game_list->resizeColumnToContents(gui::column_icon); + } + + // Fixate icon column + m_game_list->horizontalHeader()->setSectionResizeMode(gui::column_icon, QHeaderView::Fixed); + + // Shorten the last section to remove horizontal scrollbar if possible + m_game_list->resizeColumnToContents(gui::column_count - 1); } \ No newline at end of file diff --git a/shadPS4/gui/game_list_frame.h b/shadPS4/gui/game_list_frame.h index 02b1142a..0443ed9f 100644 --- a/shadPS4/gui/game_list_frame.h +++ b/shadPS4/gui/game_list_frame.h @@ -15,9 +15,19 @@ public : void ResizeColumnsToContents(int spacing = 20) const; private: + void SortGameList() const; + // Game List game_list_table* m_game_list = nullptr; QList m_columnActs; + Qt::SortOrder m_col_sort_order; + int m_sort_column; + + // data + QList m_game_data; + + // Icons + QSize m_icon_size; }; diff --git a/shadPS4/gui/gui_settings.h b/shadPS4/gui/gui_settings.h index 9671ce0e..831b6183 100644 --- a/shadPS4/gui/gui_settings.h +++ b/shadPS4/gui/gui_settings.h @@ -2,6 +2,23 @@ #include +namespace gui +{ + enum game_list_columns + { + column_icon, + column_name, + column_serial, + column_firmware, + column_version, + column_category, + column_path, + + column_count + }; + +} + class gui_settings {