From 7cd1a233eb0ab8c1b88c9ad24a8d67183941ddfd Mon Sep 17 00:00:00 2001 From: Rukai Date: Wed, 10 Feb 2016 01:36:14 +1100 Subject: [PATCH] DQT2: Added context menu to gamelist --- Source/Core/DolphinQt2/GameList/GameList.cpp | 28 ++++++++++++++++++++ Source/Core/DolphinQt2/GameList/GameList.h | 6 ++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/Source/Core/DolphinQt2/GameList/GameList.cpp b/Source/Core/DolphinQt2/GameList/GameList.cpp index 5c10100f78..aec5308846 100644 --- a/Source/Core/DolphinQt2/GameList/GameList.cpp +++ b/Source/Core/DolphinQt2/GameList/GameList.cpp @@ -2,7 +2,10 @@ // Licensed under GPLv2+ // Refer to the license.txt file included. +#include #include +#include +#include #include "DolphinQt2/Settings.h" #include "DolphinQt2/GameList/GameList.h" @@ -45,6 +48,8 @@ void GameList::MakeTableView() m_table->setShowGrid(false); m_table->setSortingEnabled(true); m_table->setCurrentIndex(QModelIndex()); + m_table->setContextMenuPolicy(Qt::CustomContextMenu); + connect(m_table, &QTableView::customContextMenuRequested, this, &GameList::ShowContextMenu); // TODO load from config m_table->setColumnHidden(GameListModel::COL_PLATFORM, false); @@ -84,6 +89,29 @@ void GameList::MakeListView() m_list->setViewMode(QListView::IconMode); m_list->setResizeMode(QListView::Adjust); m_list->setUniformItemSizes(true); + m_list->setContextMenuPolicy(Qt::CustomContextMenu); + connect(m_list, &QTableView::customContextMenuRequested, this, &GameList::ShowContextMenu); +} + +void GameList::ShowContextMenu(const QPoint&) +{ + QMenu* menu = new QMenu(this); + menu->addAction(tr("Properties")); + menu->addAction(tr("Open Wiki Page"), this, SLOT(OpenWiki())); + menu->addAction(tr("Set as Default ISO"), this, SLOT(SetDefaultISO())); + menu->exec(QCursor::pos()); +} + +void GameList::OpenWiki() +{ + QString game_id = GameFile(GetSelectedGame()).GetUniqueID(); + QString url = QStringLiteral("https://wiki.dolphin-emu.org/index.php?title=").append(game_id); + QDesktopServices::openUrl(QUrl(url)); +} + +void GameList::SetDefaultISO() +{ + Settings().SetDefaultGame(GetSelectedGame()); } QString GameList::GetSelectedGame() const diff --git a/Source/Core/DolphinQt2/GameList/GameList.h b/Source/Core/DolphinQt2/GameList/GameList.h index 8b6e7628aa..32c8c2292d 100644 --- a/Source/Core/DolphinQt2/GameList/GameList.h +++ b/Source/Core/DolphinQt2/GameList/GameList.h @@ -19,7 +19,6 @@ class GameList final : public QStackedWidget public: explicit GameList(QWidget* parent = nullptr); - QString GetSelectedGame() const; public slots: @@ -27,6 +26,11 @@ public slots: void SetListView() { SetPreferredView(false); } void SetViewColumn(int col, bool view) { m_table->setColumnHidden(col, !view); } +private slots: + void ShowContextMenu(const QPoint&); + void OpenWiki(); + void SetDefaultISO(); + signals: void GameSelected(); void DirectoryAdded(const QString& dir);