From 8af4a948648c550b51c3f937a44cbab9b5d04b6d Mon Sep 17 00:00:00 2001 From: Megamouse Date: Tue, 6 Dec 2022 00:39:10 +0100 Subject: [PATCH] Qt: add context menu to trophy game table --- rpcs3/rpcs3qt/trophy_manager_dialog.cpp | 45 +++++++++++++++++++++++-- rpcs3/rpcs3qt/trophy_manager_dialog.h | 5 +-- 2 files changed, 46 insertions(+), 4 deletions(-) diff --git a/rpcs3/rpcs3qt/trophy_manager_dialog.cpp b/rpcs3/rpcs3qt/trophy_manager_dialog.cpp index 073eafaa7f..bc66e3dfe7 100644 --- a/rpcs3/rpcs3qt/trophy_manager_dialog.cpp +++ b/rpcs3/rpcs3qt/trophy_manager_dialog.cpp @@ -92,6 +92,7 @@ trophy_manager_dialog::trophy_manager_dialog(std::shared_ptr 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); @@ -318,7 +319,7 @@ trophy_manager_dialog::trophy_manager_dialog(std::shared_ptr 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] { @@ -326,6 +327,8 @@ trophy_manager_dialog::trophy_manager_dialog(std::shared_ptr gui_s 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()) @@ -714,7 +717,7 @@ void trophy_manager_dialog::ApplyFilter() ReadjustTrophyTable(); } -void trophy_manager_dialog::ShowContextMenu(const QPoint& pos) +void trophy_manager_dialog::ShowTrophyTableContextMenu(const QPoint& pos) { const int row = m_trophy_table->currentRow(); @@ -782,6 +785,44 @@ void trophy_manager_dialog::ShowContextMenu(const QPoint& pos) 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()) diff --git a/rpcs3/rpcs3qt/trophy_manager_dialog.h b/rpcs3/rpcs3qt/trophy_manager_dialog.h index c709a9ab3c..210cb738f8 100644 --- a/rpcs3/rpcs3qt/trophy_manager_dialog.h +++ b/rpcs3/rpcs3qt/trophy_manager_dialog.h @@ -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);