diff --git a/src/Mod/Web/Gui/BrowserView.cpp b/src/Mod/Web/Gui/BrowserView.cpp index 476cb4c43..908338d0e 100644 --- a/src/Mod/Web/Gui/BrowserView.cpp +++ b/src/Mod/Web/Gui/BrowserView.cpp @@ -48,6 +48,7 @@ # include # include # include +# include #endif #include "BrowserView.h" @@ -87,6 +88,33 @@ void WebView::wheelEvent(QWheelEvent *event) QWebView::wheelEvent(event); } +void WebView::contextMenuEvent(QContextMenuEvent *event) +{ + QWebHitTestResult r = page()->mainFrame()->hitTestContent(event->pos()); + if (!r.linkUrl().isEmpty()) { + QMenu menu(this); + menu.addAction(pageAction(QWebPage::OpenLink)); + + // building a custom signal for external browser action + QSignalMapper* signalMapper = new QSignalMapper (this); + QAction* extAction = menu.addAction(tr("Open in External Browser")); + connect (extAction, SIGNAL(triggered()), signalMapper, SLOT(map())); + signalMapper->setMapping(extAction,r.linkUrl().toString()); + connect (signalMapper, SIGNAL(mapped(const QString &)), this, SLOT(openLinkInExternalBrowser(const QString &))); + + menu.addAction(pageAction(QWebPage::DownloadLinkToDisk)); + menu.addAction(pageAction(QWebPage::CopyLinkToClipboard)); + menu.exec(mapToGlobal(event->pos())); + return; + } + QWebView::contextMenuEvent(event); +} + +void WebView::openLinkInExternalBrowser(const QString& url) +{ + QDesktopServices::openUrl(QUrl(url)); +} + /* TRANSLATOR Gui::BrowserView */ /** diff --git a/src/Mod/Web/Gui/BrowserView.h b/src/Mod/Web/Gui/BrowserView.h index 64bcbd4b7..afb4de11b 100644 --- a/src/Mod/Web/Gui/BrowserView.h +++ b/src/Mod/Web/Gui/BrowserView.h @@ -46,6 +46,9 @@ class WebGuiExport WebView : public QWebView public: WebView(QWidget *parent = 0); void wheelEvent(QWheelEvent *event); + void contextMenuEvent(QContextMenuEvent *event); +protected Q_SLOTS: + void openLinkInExternalBrowser(const QString& url); }; /**