From bbf833bceb23aa4185b11042357b04b1733b4418 Mon Sep 17 00:00:00 2001 From: Tobias Date: Wed, 12 Jul 2023 23:17:16 +0200 Subject: [PATCH] citra_qt\game_list: Make columns hideable (#6467) --- src/citra_qt/configuration/config.cpp | 10 ++++++ src/citra_qt/game_list.cpp | 45 +++++++++++++++++++++++++++ src/citra_qt/game_list.h | 2 ++ src/citra_qt/uisettings.h | 6 ++++ 4 files changed, 63 insertions(+) diff --git a/src/citra_qt/configuration/config.cpp b/src/citra_qt/configuration/config.cpp index 60b641397..b9967eb68 100644 --- a/src/citra_qt/configuration/config.cpp +++ b/src/citra_qt/configuration/config.cpp @@ -772,6 +772,11 @@ void Config::ReadUIGameListValues() { ReadBasicSetting(UISettings::values.game_list_hide_no_icon); ReadBasicSetting(UISettings::values.game_list_single_line_mode); + ReadBasicSetting(UISettings::values.show_compat_column); + ReadBasicSetting(UISettings::values.show_region_column); + ReadBasicSetting(UISettings::values.show_type_column); + ReadBasicSetting(UISettings::values.show_size_column); + qt_config->endGroup(); } @@ -1230,6 +1235,11 @@ void Config::SaveUIGameListValues() { WriteBasicSetting(UISettings::values.game_list_hide_no_icon); WriteBasicSetting(UISettings::values.game_list_single_line_mode); + WriteBasicSetting(UISettings::values.show_compat_column); + WriteBasicSetting(UISettings::values.show_region_column); + WriteBasicSetting(UISettings::values.show_type_column); + WriteBasicSetting(UISettings::values.show_size_column); + qt_config->endGroup(); } diff --git a/src/citra_qt/game_list.cpp b/src/citra_qt/game_list.cpp index 19ad5f75f..bfb0c2b20 100644 --- a/src/citra_qt/game_list.cpp +++ b/src/citra_qt/game_list.cpp @@ -2,6 +2,7 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. +#include #include #include #include @@ -307,6 +308,9 @@ GameList::GameList(GMainWindow* parent) : QWidget{parent} { tree_view->setEditTriggers(QHeaderView::NoEditTriggers); tree_view->setContextMenuPolicy(Qt::CustomContextMenu); tree_view->setStyleSheet(QStringLiteral("QTreeView{ border: none; }")); + tree_view->header()->setContextMenuPolicy(Qt::CustomContextMenu); + + UpdateColumnVisibility(); item_model->insertColumns(0, COLUMN_COUNT); RetranslateUI(); @@ -317,6 +321,8 @@ GameList::GameList(GMainWindow* parent) : QWidget{parent} { connect(tree_view, &QTreeView::customContextMenuRequested, this, &GameList::PopupContextMenu); connect(tree_view, &QTreeView::expanded, this, &GameList::OnItemExpanded); connect(tree_view, &QTreeView::collapsed, this, &GameList::OnItemExpanded); + connect(tree_view->header(), &QHeaderView::customContextMenuRequested, this, + &GameList::PopupHeaderContextMenu); // We must register all custom types with the Qt Automoc system so that we are able to use // it with signals/slots. In this case, QList falls under the umbrells of custom types. @@ -471,6 +477,41 @@ void GameList::PopupContextMenu(const QPoint& menu_location) { context_menu.exec(tree_view->viewport()->mapToGlobal(menu_location)); } +void GameList::PopupHeaderContextMenu(const QPoint& menu_location) { + const QModelIndex item = tree_view->indexAt(menu_location); + if (!item.isValid()) { + return; + } + + QMenu context_menu; + static const QMap*> columns{ + {tr("Compatibility"), &UISettings::values.show_compat_column}, + {tr("Region"), &UISettings::values.show_region_column}, + {tr("File type"), &UISettings::values.show_type_column}, + {tr("Size"), &UISettings::values.show_size_column}}; + + QActionGroup* column_group = new QActionGroup(this); + column_group->setExclusive(false); + for (const auto& key : columns.keys()) { + QAction* action = column_group->addAction(context_menu.addAction(key)); + action->setCheckable(true); + action->setChecked(columns[key]->GetValue()); + connect(action, &QAction::toggled, [this, key](bool value) { + *columns[key] = !columns[key]->GetValue(); + UpdateColumnVisibility(); + }); + } + + context_menu.exec(tree_view->viewport()->mapToGlobal(menu_location)); +} + +void GameList::UpdateColumnVisibility() { + tree_view->setColumnHidden(COLUMN_COMPATIBILITY, !UISettings::values.show_compat_column); + tree_view->setColumnHidden(COLUMN_REGION, !UISettings::values.show_region_column); + tree_view->setColumnHidden(COLUMN_FILE_TYPE, !UISettings::values.show_type_column); + tree_view->setColumnHidden(COLUMN_SIZE, !UISettings::values.show_size_column); +} + void ForEachOpenGLCacheFile(u64 program_id, auto func) { for (const std::string_view cache_type : {"separable", "conventional"}) { const std::string path = fmt::format("{}opengl/precompiled/{}/{:016X}.bin", @@ -750,6 +791,10 @@ QStandardItemModel* GameList::GetModel() const { void GameList::PopulateAsync(QVector& game_dirs) { tree_view->setEnabled(false); + + // Update the columns in case UISettings has changed + UpdateColumnVisibility(); + // Delete any rows that might already exist if we're repopulating item_model->removeRows(0, item_model->rowCount()); search_field->clear(); diff --git a/src/citra_qt/game_list.h b/src/citra_qt/game_list.h index fced8f9e3..92a501676 100644 --- a/src/citra_qt/game_list.h +++ b/src/citra_qt/game_list.h @@ -104,9 +104,11 @@ private: void DonePopulating(const QStringList& watch_list); void PopupContextMenu(const QPoint& menu_location); + void PopupHeaderContextMenu(const QPoint& menu_location); void AddGamePopup(QMenu& context_menu, const QString& path, u64 program_id, u64 extdata_id); void AddCustomDirPopup(QMenu& context_menu, QModelIndex selected); void AddPermDirPopup(QMenu& context_menu, QModelIndex selected); + void UpdateColumnVisibility(); QString FindGameByProgramID(QStandardItem* current_item, u64 program_id, int role); diff --git a/src/citra_qt/uisettings.h b/src/citra_qt/uisettings.h index 3bee8ffcb..a0e7559c0 100644 --- a/src/citra_qt/uisettings.h +++ b/src/citra_qt/uisettings.h @@ -97,6 +97,12 @@ struct Values { Settings::Setting game_list_hide_no_icon{false, "hideNoIcon"}; Settings::Setting game_list_single_line_mode{false, "singleLineMode"}; + // Compatibility List + Settings::Setting show_compat_column{true, "show_compat_column"}; + Settings::Setting show_region_column{true, "show_region_column"}; + Settings::Setting show_type_column{true, "show_type_column"}; + Settings::Setting show_size_column{true, "show_size_column"}; + Settings::Setting screenshot_resolution_factor{0, "screenshot_resolution_factor"}; Settings::SwitchableSetting screenshot_path{"", "screenshotPath"};