From 1d43d9afc11cc7294040a0a7018e1dbf7bc84c88 Mon Sep 17 00:00:00 2001 From: spycrab Date: Fri, 21 Jun 2019 09:28:24 +0200 Subject: [PATCH] Config/GeckoCodeWidget: Add option for alphabetical sorting --- .../Core/DolphinQt/Config/GeckoCodeWidget.cpp | 21 +++++++++++++++++++ .../Core/DolphinQt/Config/GeckoCodeWidget.h | 2 ++ 2 files changed, 23 insertions(+) diff --git a/Source/Core/DolphinQt/Config/GeckoCodeWidget.cpp b/Source/Core/DolphinQt/Config/GeckoCodeWidget.cpp index c82b127235..71972b5c66 100644 --- a/Source/Core/DolphinQt/Config/GeckoCodeWidget.cpp +++ b/Source/Core/DolphinQt/Config/GeckoCodeWidget.cpp @@ -4,11 +4,13 @@ #include "DolphinQt/Config/GeckoCodeWidget.h" +#include #include #include #include #include #include +#include #include #include #include @@ -51,6 +53,8 @@ void GeckoCodeWidget::CreateWidgets() m_name_label = new QLabel; m_creator_label = new QLabel; + m_code_list->setContextMenuPolicy(Qt::CustomContextMenu); + QFont monospace(QFontDatabase::systemFont(QFontDatabase::FixedFont).family()); const auto line_height = QFontMetrics(font()).lineSpacing(); @@ -118,6 +122,8 @@ void GeckoCodeWidget::ConnectWidgets() connect(m_code_list, &QListWidget::itemChanged, this, &GeckoCodeWidget::OnItemChanged); connect(m_code_list->model(), &QAbstractItemModel::rowsMoved, this, &GeckoCodeWidget::OnListReordered); + connect(m_code_list, &QListWidget::customContextMenuRequested, this, + &GeckoCodeWidget::OnContextMenuRequested); connect(m_add_code, &QPushButton::pressed, this, &GeckoCodeWidget::AddCode); connect(m_remove_code, &QPushButton::pressed, this, &GeckoCodeWidget::RemoveCode); @@ -231,6 +237,21 @@ void GeckoCodeWidget::SaveCodes() game_ini_local.Save(File::GetUserPath(D_GAMESETTINGS_IDX) + m_game_id + ".ini"); } +void GeckoCodeWidget::OnContextMenuRequested() +{ + QMenu menu; + + menu.addAction(tr("Sort Alphabetically"), this, &GeckoCodeWidget::SortAlphabetically); + + menu.exec(QCursor::pos()); +} + +void GeckoCodeWidget::SortAlphabetically() +{ + m_code_list->sortItems(); + OnListReordered(); +} + void GeckoCodeWidget::OnListReordered() { // Reorder codes based on the indices of table item diff --git a/Source/Core/DolphinQt/Config/GeckoCodeWidget.h b/Source/Core/DolphinQt/Config/GeckoCodeWidget.h index 1c3619b2a8..6a8de9e12d 100644 --- a/Source/Core/DolphinQt/Config/GeckoCodeWidget.h +++ b/Source/Core/DolphinQt/Config/GeckoCodeWidget.h @@ -37,6 +37,7 @@ private: void OnSelectionChanged(); void OnItemChanged(QListWidgetItem* item); void OnListReordered(); + void OnContextMenuRequested(); void CreateWidgets(); void ConnectWidgets(); @@ -46,6 +47,7 @@ private: void RemoveCode(); void DownloadCodes(); void SaveCodes(); + void SortAlphabetically(); const UICommon::GameFile& m_game; std::string m_game_id;