DQT2: Added context menu to gamelist

This commit is contained in:
Rukai 2016-02-10 01:36:14 +11:00
parent 32dcb4c37c
commit 7cd1a233eb
2 changed files with 33 additions and 1 deletions

View File

@ -2,7 +2,10 @@
// Licensed under GPLv2+
// Refer to the license.txt file included.
#include <QDesktopServices>
#include <QHeaderView>
#include <QMenu>
#include <QUrl>
#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

View File

@ -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);