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/browsertab.cpp | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'src/browsertab.cpp') diff --git a/src/browsertab.cpp b/src/browsertab.cpp index cde8fc7..2cd4fff 100644 --- a/src/browsertab.cpp +++ b/src/browsertab.cpp @@ -64,6 +64,8 @@ BrowserTab::BrowserTab(MainWindow * mainWindow) : this->ui->graphics_browser->setVisible(false); this->ui->text_browser->setVisible(true); + this->ui->text_browser->setContextMenuPolicy(Qt::CustomContextMenu); + this->ui->graphics_browser->setScene(&graphics_scene); } @@ -591,3 +593,37 @@ void BrowserTab::updateUI() this->ui->fav_button->setEnabled(this->successfully_loaded); this->ui->fav_button->setChecked(this->mainWindow->favourites.contains(this->current_location)); } + +#include + +void BrowserTab::on_text_browser_customContextMenuRequested(const QPoint &pos) +{ + QMenu menu; + + QString anchor = ui->text_browser->anchorAt(pos); + if(not anchor.isEmpty()) { + QUrl real_url { anchor }; + if(real_url.isRelative()) + real_url = this->current_location.resolved(real_url); + + connect(menu.addAction("Follow link…"), &QAction::triggered, [this,real_url]() { + this->navigateTo(real_url, PushImmediate); + }); + + connect(menu.addAction("Open in new tab…"), &QAction::triggered, [this,real_url]() { + mainWindow->addNewTab(false, real_url); + }); + + connect(menu.addAction("Copy link"), &QAction::triggered, [this,real_url]() { + global_clipboard->setText(real_url.toString(QUrl::FullyEncoded)); + }); + + menu.addSeparator(); + } + + connect(menu.addAction("Select all"), &QAction::triggered, [this]() { + this->ui->text_browser->selectAll(); + }); + + menu.exec(ui->text_browser->mapToGlobal(pos)); +} -- cgit v1.2.3