From 656391ecc0555b3462266b886434ae0f120a401c Mon Sep 17 00:00:00 2001 From: "Felix (xq) Queißner" Date: Wed, 10 Jun 2020 00:31:56 +0200 Subject: Adds some right click menus, fixes bug in gopher. --- src/mainwindow.cpp | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'src/mainwindow.cpp') diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index f735b2a..10302d2 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -84,6 +84,9 @@ MainWindow::MainWindow(QApplication * app, QWidget *parent) : global_settings.endGroup(); } + this->ui->favourites_view->setContextMenuPolicy(Qt::CustomContextMenu); + this->ui->history_view->setContextMenuPolicy(Qt::CustomContextMenu); + reloadTheme(); } @@ -402,3 +405,49 @@ void MainWindow::on_actionHelp_triggered() { this->addNewTab(true, QUrl("about:help")); } + +void MainWindow::on_history_view_customContextMenuRequested(const QPoint &pos) +{ + if(auto idx = this->ui->history_view->indexAt(pos); idx.isValid()) { + BrowserTab * tab = qobject_cast(this->ui->browser_tabs->currentWidget()); + if(tab != nullptr) { + if(QUrl url = tab->history.get(idx); url.isValid()) { + QMenu menu; + + connect(menu.addAction("Open here"), &QAction::triggered, [tab, idx]() { + // We do the same thing as a double click here + tab->navigateBack(idx); + }); + + connect(menu.addAction("Open in new tab"), &QAction::triggered, [this, url]() { + addNewTab(true, url); + }); + + menu.exec(this->ui->history_view->mapToGlobal(pos)); + } + } + } +} + +void MainWindow::on_favourites_view_customContextMenuRequested(const QPoint &pos) +{ + if(auto idx = this->ui->favourites_view->indexAt(pos); idx.isValid()) { + if(QUrl url = favourites.get(idx); url.isValid()) { + QMenu menu; + + BrowserTab * tab = qobject_cast(this->ui->browser_tabs->currentWidget()); + if(tab != nullptr) { + connect(menu.addAction("Open here"), &QAction::triggered, [tab, url]() { + tab->navigateTo(url, BrowserTab::PushImmediate); + }); + } + + connect(menu.addAction("Open in new tab"), &QAction::triggered, [this, url]() { + addNewTab(true, url); + }); + + menu.exec(this->ui->favourites_view->mapToGlobal(pos)); + + } + } +} -- cgit v1.2.3