From d5e978c6f2a3aaccaa60004af06d3a1dc2bc3fff Mon Sep 17 00:00:00 2001 From: DanielSvoboda Date: Mon, 19 Aug 2024 01:25:15 -0300 Subject: [PATCH] Copy submenu --- src/qt_gui/gui_context_menus.h | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/qt_gui/gui_context_menus.h b/src/qt_gui/gui_context_menus.h index 146d5c34..2f4b884c 100644 --- a/src/qt_gui/gui_context_menus.h +++ b/src/qt_gui/gui_context_menus.h @@ -3,6 +3,7 @@ #pragma once +#include #include #include #include @@ -53,6 +54,18 @@ public: menu.addAction(&openSfoViewer); menu.addAction(&openTrophyViewer); + // "Copy" submenu. + QMenu* copyMenu = new QMenu("Copy info", widget); + QAction* copyName = new QAction("Copy Name", widget); + QAction* copySerial = new QAction("Copy Serial", widget); + QAction* copyNameAll = new QAction("Copy All", widget); + + copyMenu->addAction(copyName); + copyMenu->addAction(copySerial); + copyMenu->addAction(copyNameAll); + + menu.addMenu(copyMenu); + // Show menu. auto selected = menu.exec(global_pos); if (!selected) { @@ -191,6 +204,27 @@ public: } } } + + // Handle the "Copy" actions + if (selected == copyName) { + QClipboard* clipboard = QGuiApplication::clipboard(); + clipboard->setText(QString::fromStdString(m_games[itemID].name)); + } + + if (selected == copySerial) { + QClipboard* clipboard = QGuiApplication::clipboard(); + clipboard->setText(QString::fromStdString(m_games[itemID].serial)); + } + + if (selected == copyNameAll) { + QClipboard* clipboard = QGuiApplication::clipboard(); + QString combinedText = QString("Name:%1 | Serial:%2 | Version:%3 | Size:%4") + .arg(QString::fromStdString(m_games[itemID].name)) + .arg(QString::fromStdString(m_games[itemID].serial)) + .arg(QString::fromStdString(m_games[itemID].version)) + .arg(QString::fromStdString(m_games[itemID].size)); + clipboard->setText(combinedText); + } } int GetRowIndex(QTreeWidget* treeWidget, QTreeWidgetItem* item) {