Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trophy manager: add more context menu actions #13019

Merged
merged 3 commits into from
Dec 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 93 additions & 5 deletions rpcs3/rpcs3qt/trophy_manager_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#include "Emu/system_utils.hpp"
#include "Emu/Cell/Modules/sceNpTrophy.h"

#include <QApplication>
#include <QClipboard>
#include <QtConcurrent>
#include <QFutureWatcher>
#include <QHeaderView>
Expand Down Expand Up @@ -90,6 +92,7 @@ trophy_manager_dialog::trophy_manager_dialog(std::shared_ptr<gui_settings> gui_s
m_game_table->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft);
m_game_table->horizontalHeader()->setStretchLastSection(true);
m_game_table->verticalHeader()->setSectionResizeMode(QHeaderView::Fixed);
m_game_table->setContextMenuPolicy(Qt::CustomContextMenu);
m_game_table->verticalHeader()->setVisible(false);
m_game_table->setAlternatingRowColors(true);
m_game_table->installEventFilter(this);
Expand Down Expand Up @@ -316,14 +319,16 @@ trophy_manager_dialog::trophy_manager_dialog(std::shared_ptr<gui_settings> gui_s
m_gui_settings->SetValue(gui::tr_show_platinum, checked);
});

connect(m_trophy_table, &QTableWidget::customContextMenuRequested, this, &trophy_manager_dialog::ShowContextMenu);
connect(m_trophy_table, &QTableWidget::customContextMenuRequested, this, &trophy_manager_dialog::ShowTrophyTableContextMenu);

connect(m_game_combo, &QComboBox::currentTextChanged, this, [this]
{
PopulateTrophyTable();
ApplyFilter();
});

connect(m_game_table, &QTableWidget::customContextMenuRequested, this, &trophy_manager_dialog::ShowGameTableContextMenu);

connect(m_game_table, &QTableWidget::itemSelectionChanged, this, [this]
{
if (m_game_table->selectedItems().isEmpty())
Expand Down Expand Up @@ -712,16 +717,17 @@ void trophy_manager_dialog::ApplyFilter()
ReadjustTrophyTable();
}

void trophy_manager_dialog::ShowContextMenu(const QPoint& pos)
void trophy_manager_dialog::ShowTrophyTableContextMenu(const QPoint& pos)
{
QTableWidgetItem* item = m_trophy_table->item(m_trophy_table->currentRow(), TrophyColumns::Icon);
if (!item)
const int row = m_trophy_table->currentRow();

if (!m_trophy_table->item(row, TrophyColumns::Icon))
{
return;
}

QMenu* menu = new QMenu();
QAction* show_trophy_dir = new QAction(tr("Open Trophy Directory"), menu);
QAction* show_trophy_dir = new QAction(tr("&Open Trophy Directory"), menu);

const int db_ind = m_game_combo->currentData().toInt();

Expand All @@ -732,9 +738,91 @@ void trophy_manager_dialog::ShowContextMenu(const QPoint& pos)
});

menu->addAction(show_trophy_dir);

const QTableWidgetItem* name_item = m_trophy_table->item(row, TrophyColumns::Name);
const QTableWidgetItem* desc_item = m_trophy_table->item(row, TrophyColumns::Description);

const QString name = name_item ? name_item->text() : "";
const QString desc = desc_item ? desc_item->text() : "";

if (!name.isEmpty() || !desc.isEmpty())
{
QMenu* copy_menu = new QMenu(tr("&Copy Info"), menu);

if (!name.isEmpty() && !desc.isEmpty())
{
QAction* copy_both = new QAction(tr("&Copy Name + Description"), copy_menu);
connect(copy_both, &QAction::triggered, this, [this, name, desc]()
{
QApplication::clipboard()->setText(name % QStringLiteral("\n\n") % desc);
});
copy_menu->addAction(copy_both);
}

if (!name.isEmpty())
{
QAction* copy_name = new QAction(tr("&Copy Name"), copy_menu);
connect(copy_name, &QAction::triggered, this, [this, name]()
{
QApplication::clipboard()->setText(name);
});
copy_menu->addAction(copy_name);
}

if (!desc.isEmpty())
{
QAction* copy_desc = new QAction(tr("&Copy Description"), copy_menu);
connect(copy_desc, &QAction::triggered, this, [this, desc]()
{
QApplication::clipboard()->setText(desc);
});
copy_menu->addAction(copy_desc);
}

menu->addMenu(copy_menu);
}

menu->exec(m_trophy_table->viewport()->mapToGlobal(pos));
}

void trophy_manager_dialog::ShowGameTableContextMenu(const QPoint& pos)
{
const int row = m_game_table->currentRow();

if (!m_game_table->item(row, GameColumns::GameIcon))
{
return;
}

QMenu* menu = new QMenu();
QAction* show_trophy_dir = new QAction(tr("&Open Trophy Directory"), menu);

const int db_ind = m_game_combo->currentData().toInt();

connect(show_trophy_dir, &QAction::triggered, this, [this, db_ind]()
{
const QString path = qstr(m_trophies_db[db_ind]->path);
QDesktopServices::openUrl(QUrl::fromLocalFile(path));
});

menu->addAction(show_trophy_dir);

const QTableWidgetItem* name_item = m_game_table->item(row, GameColumns::GameName);
const QString name = name_item ? name_item->text() : "";

if (!name.isEmpty())
{
QAction* copy_name = new QAction(tr("&Copy Name"), menu);
connect(copy_name, &QAction::triggered, this, [this, name]()
{
QApplication::clipboard()->setText(name);
});
menu->addAction(copy_name);
}

menu->exec(m_game_table->viewport()->mapToGlobal(pos));
}

void trophy_manager_dialog::StartTrophyLoadThreads()
{
if (m_game_repaint_watcher.isRunning())
Expand Down
5 changes: 3 additions & 2 deletions rpcs3/rpcs3qt/trophy_manager_dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,11 @@ private Q_SLOTS:
void ResizeGameIcons();
void ResizeTrophyIcons();
void ApplyFilter();
void ShowContextMenu(const QPoint& pos);
void ShowTrophyTableContextMenu(const QPoint& pos);
void ShowGameTableContextMenu(const QPoint& pos);

private:
/** Loads a trophy folder.
/** Loads a trophy folder.
Returns true if successful. Does not attempt to install if failure occurs, like sceNpTrophy.
*/
bool LoadTrophyFolderToDB(const std::string& trop_name);
Expand Down