Qt: add copy name and description to trophy context menu

This commit is contained in:
Megamouse 2022-12-06 00:38:30 +01:00
parent 6155207407
commit ab873129f8

View File

@ -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>
@ -714,14 +716,15 @@ void trophy_manager_dialog::ApplyFilter()
void trophy_manager_dialog::ShowContextMenu(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();
@ -732,6 +735,50 @@ 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));
}