-
Notifications
You must be signed in to change notification settings - Fork 2
/
webview.cpp
executable file
·41 lines (41 loc) · 1.61 KB
/
webview.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include "webview.h"
#include <QMessageBox>
webview::webview(QWidget *parent) :
QWebView(parent)
{
openlinkinnewtab = new QAction("open link in new tab" , this);
connect(openlinkinnewtab , SIGNAL(triggered()) , this , SLOT(linknewtab()));
}
void webview::contextMenuEvent(QContextMenuEvent * event)
{
QMenu * menu = new QMenu();
menu->setVisible(true);
QWebElement element = this->page()->mainFrame()->hitTestContent(event->pos()).element();
QString tagname = this->page()->mainFrame()->hitTestContent(event->pos()).element().tagName().toLower();
if(tagname == "img")
{
menu->addAction(this->pageAction(QWebPage::DownloadImageToDisk));
menu->addAction(this->pageAction(QWebPage::CopyImageToClipboard));
menu->addAction(this->pageAction(QWebPage::CopyImageUrlToClipboard));
}
if(tagname == "")
{
menu->addAction(this->pageAction(QWebPage::DownloadLinkToDisk));
menu->addAction(this->pageAction(QWebPage::CopyLinkToClipboard));
menu->addAction(this->pageAction(QWebPage::OpenLinkInNewWindow));
}
if(tagname == "input" || tagname == "textarea")
{
menu->addAction(this->pageAction(QWebPage::Copy));
menu->addAction(this->pageAction(QWebPage::Cut));
menu->addAction(this->pageAction(QWebPage::Paste));
menu->addAction(this->pageAction(QWebPage::Undo));
menu->addAction(this->pageAction(QWebPage::Redo));
menu->addAction(this->pageAction(QWebPage::SelectAll));
}
menu->exec(event->globalPos());
}
void webview::linknewtab()
{
emit linkinnewtab(openlinkinnewtab->data().toString());
}