From 2aad5a7f3a8159b061a6acb1e920bee038f95491 Mon Sep 17 00:00:00 2001 From: Megamouse Date: Tue, 12 Mar 2024 23:43:03 +0100 Subject: [PATCH] Qt: add search bar to save manager --- rpcs3/rpcs3qt/save_manager_dialog.cpp | 45 +++++++++++++++++++++++++++ rpcs3/rpcs3qt/save_manager_dialog.h | 1 + 2 files changed, 46 insertions(+) diff --git a/rpcs3/rpcs3qt/save_manager_dialog.cpp b/rpcs3/rpcs3qt/save_manager_dialog.cpp index e7a5485170..100fe0ce0d 100644 --- a/rpcs3/rpcs3qt/save_manager_dialog.cpp +++ b/rpcs3/rpcs3qt/save_manager_dialog.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -99,6 +100,8 @@ void save_manager_dialog::Init() slider_icon_size->setMinimum(60); slider_icon_size->setMaximum(225); slider_icon_size->setValue(icon_size); + QLabel* label_search_bar = new QLabel(tr("Search:"), this); + QLineEdit* search_bar = new QLineEdit(this); QPushButton* push_close = new QPushButton(tr("&Close"), this); push_close->setAutoDefault(true); @@ -141,6 +144,8 @@ void save_manager_dialog::Init() // Items below list QHBoxLayout* hbox_buttons = new QHBoxLayout(); + hbox_buttons->addWidget(label_search_bar); + hbox_buttons->addWidget(search_bar); hbox_buttons->addWidget(label_icon_size); hbox_buttons->addWidget(slider_icon_size); hbox_buttons->addStretch(); @@ -204,6 +209,7 @@ void save_manager_dialog::Init() icon_item->setData(Qt::DecorationRole, pixmap); } }); + connect(search_bar, &QLineEdit::textChanged, this, &save_manager_dialog::text_changed); } /** @@ -659,3 +665,42 @@ void save_manager_dialog::WaitForRepaintThreads(bool abort) } } } + +void save_manager_dialog::text_changed(const QString& text) +{ + const auto check_text = [&](int row) + { + if (text.isEmpty()) + return true; + + for (int col = SaveColumns::Name; col < SaveColumns::Count; col++) + { + const QTableWidgetItem* item = m_list->item(row, col); + + if (item && item->text().contains(text, Qt::CaseInsensitive)) + return true; + } + + return false; + }; + + bool new_row_visible = false; + + for (int i = 0; i < m_list->rowCount(); i++) + { + // only show items filtered for search text + const bool is_hidden = m_list->isRowHidden(i); + const bool hide = !check_text(i); + + if (is_hidden != hide) + { + m_list->setRowHidden(i, hide); + new_row_visible = !hide; + } + } + + if (new_row_visible) + { + UpdateIcons(); + } +} diff --git a/rpcs3/rpcs3qt/save_manager_dialog.h b/rpcs3/rpcs3qt/save_manager_dialog.h index 95e0c10a58..e0f94c2a8f 100644 --- a/rpcs3/rpcs3qt/save_manager_dialog.h +++ b/rpcs3/rpcs3qt/save_manager_dialog.h @@ -30,6 +30,7 @@ private Q_SLOTS: void OnSort(int logicalIndex); void SetIconSize(int size); void UpdateDetails(); + void text_changed(const QString& text); Q_SIGNALS: void IconReady(int index, const QPixmap& new_icon);