1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
#include <QApplication>
#include <QHeaderView>
#include <QScroller>
#include <QScrollerProperties>
#include "qt_common/config/uisettings.h"
#include "qt_common/game_list/game_list_p.h"
#include "qt_common/game_list/model.h"
#include "yuzu/game/common.h"
#include "yuzu/game/game_tree.h"
GameTree::GameTree(QWidget* parent) : QTreeView{parent} {
setAlternatingRowColors(true);
setSelectionMode(QHeaderView::SingleSelection);
setSelectionBehavior(QHeaderView::SelectRows);
setVerticalScrollMode(QHeaderView::ScrollPerPixel);
setHorizontalScrollMode(QHeaderView::ScrollPerPixel);
setSortingEnabled(true);
setEditTriggers(QHeaderView::NoEditTriggers);
setContextMenuPolicy(Qt::CustomContextMenu);
setAttribute(Qt::WA_AcceptTouchEvents, true);
setStyleSheet(QStringLiteral("QTreeView{ border: none; }"));
connect(this, &QTreeView::expanded, this, &GameTree::OnItemExpanded);
connect(this, &QTreeView::collapsed, this, &GameTree::OnItemExpanded);
}
void GameTree::SetModel(GameListModel* model) {
QTreeView::setModel(model);
LoadInterfaceLayout();
UpdateColumnVisibility(model);
}
void GameTree::OnItemExpanded(const QModelIndex& item) {
const auto type = item.data(GameListItem::TypeRole).value<GameListItemType>();
const bool is_dir = type == GameListItemType::CustomDir || type == GameListItemType::SdmcDir ||
type == GameListItemType::UserNandDir ||
type == GameListItemType::SysNandDir;
const bool is_fave = type == GameListItemType::Favorites;
if (!is_dir && !is_fave) {
return;
}
const bool is_expanded = isExpanded(item);
if (is_fave) {
UISettings::values.favorites_expanded = is_expanded;
return;
}
const int item_dir_index = item.data(GameListDir::GameDirRole).toInt();
UISettings::values.game_dirs[item_dir_index].expanded = is_expanded;
}
void GameTree::SaveInterfaceLayout() {
UISettings::values.gamelist_header_state = header()->saveState();
}
void GameTree::LoadInterfaceLayout() {
auto* hdr = header();
if (hdr->restoreState(UISettings::values.gamelist_header_state))
return;
hdr->resizeSection(GameListModel::COLUMN_NAME, 840);
}
void GameTree::UpdateColumnVisibility(GameListModel* model) {
Q_UNUSED(model)
setColumnHidden(GameListModel::COLUMN_ADD_ONS, !UISettings::values.show_add_ons);
setColumnHidden(GameListModel::COLUMN_FILE_TYPE, !UISettings::values.show_types);
setColumnHidden(GameListModel::COLUMN_SIZE, !UISettings::values.show_size);
setColumnHidden(GameListModel::COLUMN_PLAY_TIME, !UISettings::values.show_play_time);
}
QString GameTree::GetLastFilterResultItem() const {
QString file_path;
auto* model = qobject_cast<GameListModel*>(QTreeView::model());
if (!model)
return {};
for (int i = 1; i < model->rowCount() - 1; ++i) {
const QStandardItem* folder = model->item(i, 0);
const QModelIndex folder_index = folder->index();
const int children_count = folder->rowCount();
for (int j = 0; j < children_count; ++j) {
if (isRowHidden(j, folder_index)) {
continue;
}
const QStandardItem* child = folder->child(j, 0);
file_path = child->data(GameListItemPath::FullPathRole).toString();
}
}
return file_path;
}
int GameTree::FilterClosedResultCount(GameListModel* model) {
int children_total = 0;
auto hide_favorites_row = UISettings::values.favorited_ids.size() == 0;
setRowHidden(0, model->invisibleRootItem()->index(), hide_favorites_row);
for (int i = 1; i < model->rowCount() - 1; ++i) {
auto* folder = model->item(i, 0);
const QModelIndex folder_index = folder->index();
const int children_count = folder->rowCount();
for (int j = 0; j < children_count; ++j) {
++children_total;
setRowHidden(j, folder_index, false);
}
}
return children_total;
}
void GameTree::ApplyFilter(const QString& edit_filter_text, GameListModel* model) {
int children_total = 0;
int result_count = 0;
if (edit_filter_text.isEmpty()) {
children_total = FilterClosedResultCount(model);
emit FilterResultReady(children_total, children_total);
return;
}
setRowHidden(0, model->invisibleRootItem()->index(), true);
for (int i = 1; i < model->rowCount() - 1; ++i) {
auto* folder = model->item(i, 0);
const QModelIndex folder_index = folder->index();
const int children_count = folder->rowCount();
for (int j = 0; j < children_count; ++j) {
++children_total;
const QStandardItem* child = folder->child(j, 0);
if (Yuzu::FilterMatches(edit_filter_text, child)) {
setRowHidden(j, folder_index, false);
++result_count;
} else {
setRowHidden(j, folder_index, true);
}
}
}
emit FilterResultReady(result_count, children_total);
}
|