void GameList::ShowContextMenu(const QPoint&) { const auto game = GetSelectedGame(); if (game.isEmpty()) return; QMenu* menu = new QMenu(this); DiscIO::Platform platform = GameFile(game).GetPlatformID(); menu->addAction(tr("Properties"), this, SLOT(OpenProperties())); menu->addAction(tr("Wiki"), this, SLOT(OpenWiki())); menu->addSeparator(); if (platform == DiscIO::Platform::GAMECUBE_DISC || platform == DiscIO::Platform::WII_DISC) { menu->addAction(tr("Default ISO"), this, SLOT(SetDefaultISO())); const auto blob_type = GameFile(game).GetBlobType(); if (blob_type == DiscIO::BlobType::GCZ) menu->addAction(tr("Decompress ISO"), this, SLOT(DecompressISO())); else if (blob_type == DiscIO::BlobType::PLAIN) menu->addAction(tr("Compress ISO"), this, SLOT(CompressISO())); menu->addSeparator(); } if (platform == DiscIO::Platform::WII_WAD) { menu->addAction(tr("Install to the NAND"), this, SLOT(InstallWAD())); if (GameFile(game).IsInstalled()) menu->addAction(tr("Uninstall from the NAND"), this, SLOT(UninstallWAD())); menu->addSeparator(); } if (platform == DiscIO::Platform::WII_WAD || platform == DiscIO::Platform::WII_DISC) { menu->addAction(tr("Open Wii save folder"), this, SLOT(OpenSaveFolder())); menu->addAction(tr("Export Wii save (Experimental)"), this, SLOT(ExportWiiSave())); menu->addSeparator(); } menu->addAction(tr("Open Containing Folder"), this, SLOT(OpenContainingFolder())); menu->addAction(tr("Remove File"), this, SLOT(DeleteFile())); menu->exec(QCursor::pos()); }
void ResultsTree::contextMenuEvent(QContextMenuEvent * e) { QModelIndex index = indexAt(e->pos()); if (index.isValid()) { bool multipleSelection = false; mSelectionModel = selectionModel(); if (mSelectionModel->selectedRows().count() > 1) multipleSelection = true; mContextItem = mModel.itemFromIndex(index); //Create a new context menu QMenu menu(this); //Store all applications in a list QList<QAction*> actions; //Create a signal mapper so we don't have to store data to class //member variables QSignalMapper *signalMapper = new QSignalMapper(this); if (mContextItem && mApplications->GetApplicationCount() > 0 && mContextItem->parent()) { //Go through all applications and add them to the context menu for (int i = 0; i < mApplications->GetApplicationCount(); i++) { //Create an action for the application const Application& app = mApplications->GetApplication(i); QAction *start = new QAction(app.getName(), &menu); if (multipleSelection) start->setDisabled(true); //Add it to our list so we can disconnect later on actions << start; //Add it to context menu menu.addAction(start); //Connect the signal to signal mapper connect(start, SIGNAL(triggered()), signalMapper, SLOT(map())); //Add a new mapping signalMapper->setMapping(start, i); } connect(signalMapper, SIGNAL(mapped(int)), this, SLOT(Context(int))); } // Add menuitems to copy full path/filename to clipboard if (mContextItem) { if (mApplications->GetApplicationCount() > 0) { menu.addSeparator(); } //Create an action for the application QAction *copyfilename = new QAction(tr("Copy filename"), &menu); QAction *copypath = new QAction(tr("Copy full path"), &menu); QAction *copymessage = new QAction(tr("Copy message"), &menu); QAction *copymessageid = new QAction(tr("Copy message id"), &menu); QAction *hide = new QAction(tr("Hide"), &menu); QAction *hideallid = new QAction(tr("Hide all with id"), &menu); QAction *opencontainingfolder = new QAction(tr("Open containing folder"), &menu); if (multipleSelection) { copyfilename->setDisabled(true); copypath->setDisabled(true); copymessage->setDisabled(true); copymessageid->setDisabled(true); hideallid->setDisabled(true); opencontainingfolder->setDisabled(true); } menu.addAction(copyfilename); menu.addAction(copypath); menu.addAction(copymessage); menu.addAction(copymessageid); menu.addAction(hide); menu.addAction(hideallid); menu.addAction(opencontainingfolder); connect(copyfilename, SIGNAL(triggered()), this, SLOT(CopyFilename())); connect(copypath, SIGNAL(triggered()), this, SLOT(CopyFullPath())); connect(copymessage, SIGNAL(triggered()), this, SLOT(CopyMessage())); connect(copymessageid, SIGNAL(triggered()), this, SLOT(CopyMessageId())); connect(hide, SIGNAL(triggered()), this, SLOT(HideResult())); connect(hideallid, SIGNAL(triggered()), this, SLOT(HideAllIdResult())); connect(opencontainingfolder, SIGNAL(triggered()), this, SLOT(OpenContainingFolder())); } //Start the menu menu.exec(e->globalPos()); if (mContextItem && mApplications->GetApplicationCount() > 0 && mContextItem->parent()) { //Disconnect all signals for (int i = 0; i < actions.size(); i++) { disconnect(actions[i], SIGNAL(triggered()), signalMapper, SLOT(map())); } disconnect(signalMapper, SIGNAL(mapped(int)), this, SLOT(Context(int))); //And remove the signal mapper delete signalMapper; } }