1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2024-11-26 04:32:35 +01:00

Qt: add context menu to trophy game table

This commit is contained in:
Megamouse 2022-12-06 00:39:10 +01:00
parent ab873129f8
commit 8af4a94864
2 changed files with 46 additions and 4 deletions

View File

@ -92,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()->setDefaultAlignment(Qt::AlignLeft);
m_game_table->horizontalHeader()->setStretchLastSection(true); m_game_table->horizontalHeader()->setStretchLastSection(true);
m_game_table->verticalHeader()->setSectionResizeMode(QHeaderView::Fixed); m_game_table->verticalHeader()->setSectionResizeMode(QHeaderView::Fixed);
m_game_table->setContextMenuPolicy(Qt::CustomContextMenu);
m_game_table->verticalHeader()->setVisible(false); m_game_table->verticalHeader()->setVisible(false);
m_game_table->setAlternatingRowColors(true); m_game_table->setAlternatingRowColors(true);
m_game_table->installEventFilter(this); m_game_table->installEventFilter(this);
@ -318,7 +319,7 @@ trophy_manager_dialog::trophy_manager_dialog(std::shared_ptr<gui_settings> gui_s
m_gui_settings->SetValue(gui::tr_show_platinum, checked); 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] connect(m_game_combo, &QComboBox::currentTextChanged, this, [this]
{ {
@ -326,6 +327,8 @@ trophy_manager_dialog::trophy_manager_dialog(std::shared_ptr<gui_settings> gui_s
ApplyFilter(); ApplyFilter();
}); });
connect(m_game_table, &QTableWidget::customContextMenuRequested, this, &trophy_manager_dialog::ShowGameTableContextMenu);
connect(m_game_table, &QTableWidget::itemSelectionChanged, this, [this] connect(m_game_table, &QTableWidget::itemSelectionChanged, this, [this]
{ {
if (m_game_table->selectedItems().isEmpty()) if (m_game_table->selectedItems().isEmpty())
@ -714,7 +717,7 @@ void trophy_manager_dialog::ApplyFilter()
ReadjustTrophyTable(); ReadjustTrophyTable();
} }
void trophy_manager_dialog::ShowContextMenu(const QPoint& pos) void trophy_manager_dialog::ShowTrophyTableContextMenu(const QPoint& pos)
{ {
const int row = m_trophy_table->currentRow(); 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)); 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() void trophy_manager_dialog::StartTrophyLoadThreads()
{ {
if (m_game_repaint_watcher.isRunning()) if (m_game_repaint_watcher.isRunning())

View File

@ -75,10 +75,11 @@ private Q_SLOTS:
void ResizeGameIcons(); void ResizeGameIcons();
void ResizeTrophyIcons(); void ResizeTrophyIcons();
void ApplyFilter(); void ApplyFilter();
void ShowContextMenu(const QPoint& pos); void ShowTrophyTableContextMenu(const QPoint& pos);
void ShowGameTableContextMenu(const QPoint& pos);
private: private:
/** Loads a trophy folder. /** Loads a trophy folder.
Returns true if successful. Does not attempt to install if failure occurs, like sceNpTrophy. Returns true if successful. Does not attempt to install if failure occurs, like sceNpTrophy.
*/ */
bool LoadTrophyFolderToDB(const std::string& trop_name); bool LoadTrophyFolderToDB(const std::string& trop_name);