Skip to content
Permalink
Browse files

Config/GeckoCodeWidget: Add option for alphabetical sorting

  • Loading branch information...
spycrab committed Jun 21, 2019
1 parent 93393a2 commit 1d43d9afc11cc7294040a0a7018e1dbf7bc84c88
Showing with 23 additions and 0 deletions.
  1. +21 −0 Source/Core/DolphinQt/Config/GeckoCodeWidget.cpp
  2. +2 −0 Source/Core/DolphinQt/Config/GeckoCodeWidget.h
@@ -4,11 +4,13 @@

#include "DolphinQt/Config/GeckoCodeWidget.h"

#include <QCursor>
#include <QFontDatabase>
#include <QFormLayout>
#include <QHBoxLayout>
#include <QLabel>
#include <QListWidget>
#include <QMenu>
#include <QPushButton>
#include <QTextEdit>
#include <QVBoxLayout>
@@ -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
@@ -37,6 +37,7 @@ class GeckoCodeWidget : public QWidget
void OnSelectionChanged();
void OnItemChanged(QListWidgetItem* item);
void OnListReordered();
void OnContextMenuRequested();

void CreateWidgets();
void ConnectWidgets();
@@ -46,6 +47,7 @@ class GeckoCodeWidget : public QWidget
void RemoveCode();
void DownloadCodes();
void SaveCodes();
void SortAlphabetically();

const UICommon::GameFile& m_game;
std::string m_game_id;

0 comments on commit 1d43d9a

Please sign in to comment.
You can’t perform that action at this time.