From 7dfe73df0c26733d68abc576c3eefab1a69e2149 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Thu, 25 Jul 2019 01:02:30 +0200 Subject: NOISSUE add context menus to pages with toolbars --- application/pages/instance/VersionPage.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'application/pages/instance/VersionPage.cpp') diff --git a/application/pages/instance/VersionPage.cpp b/application/pages/instance/VersionPage.cpp index 8b95c8b2..eb918626 100644 --- a/application/pages/instance/VersionPage.cpp +++ b/application/pages/instance/VersionPage.cpp @@ -123,6 +123,8 @@ VersionPage::VersionPage(MinecraftInstance *inst, QWidget *parent) ui->packageView->setModel(proxy); ui->packageView->installEventFilter(this); ui->packageView->setSelectionMode(QAbstractItemView::SingleSelection); + ui->packageView->setContextMenuPolicy(Qt::CustomContextMenu); + connect(ui->packageView->selectionModel(), &QItemSelectionModel::currentChanged, this, &VersionPage::versionCurrent); auto smodel = ui->packageView->selectionModel(); connect(smodel, &QItemSelectionModel::currentChanged, this, &VersionPage::packageCurrent); @@ -132,6 +134,7 @@ VersionPage::VersionPage(MinecraftInstance *inst, QWidget *parent) updateVersionControls(); preselect(0); connect(m_inst, &BaseInstance::runningStatusChanged, this, &VersionPage::updateRunningStatus); + connect(ui->packageView, &ModListView::customContextMenuRequested, this, &VersionPage::ShowContextMenu); } VersionPage::~VersionPage() @@ -139,6 +142,13 @@ VersionPage::~VersionPage() delete ui; } +void VersionPage::ShowContextMenu(const QPoint& pos) +{ + auto menu = ui->toolBar->createContextMenu(this, tr("Context menu")); + menu->exec(ui->packageView->mapToGlobal(pos)); + delete menu; +} + void VersionPage::packageCurrent(const QModelIndex ¤t, const QModelIndex &previous) { if (!current.isValid()) -- cgit v1.2.3