Web: Added an Open Link In External Browser context menu option - fixes #1017

This commit is contained in:
Yorik van Havre 2014-09-16 14:16:44 -03:00
parent 302fcde1e0
commit 9f7956b17e
2 changed files with 31 additions and 0 deletions

View File

@ -48,6 +48,7 @@
# include <QTimer>
# include <QFileInfo>
# include <QDesktopServices>
# include <QMenu>
#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 */
/**

View File

@ -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);
};
/**