-
Notifications
You must be signed in to change notification settings - Fork 1
/
WebPage.cpp
89 lines (79 loc) · 1.58 KB
/
WebPage.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include "WebPage.h"
WebPage::WebPage(QString url, QWidget *parent) : QWebView(parent)
{
this->page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks);
this->page()->setForwardUnsupportedContent(true);
if (url.isEmpty())
{
load(QUrl(QCoreApplication::applicationDirPath() + "/data/html/newTab.html"));
}
else
{
load(QUrl(url));
}
// Init
wheelClic = false;
cPress = false;
}
bool WebPage::isWheelClicked()
{
return wheelClic;
}
bool WebPage::isCtrlPressed()
{
// Getter
return cPress;
}
// Events
void WebPage::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::MidButton)
{
wheelClic = true;
event->accept();
}
else
{
wheelClic = false;
event->ignore();
}
QWebView::mousePressEvent(event);
}
void WebPage::keyPressEvent(QKeyEvent *event)
{
if (event->modifiers() == Qt::ControlModifier)
{
cPress = true;
event->accept();
}
else
{
cPress = false;
}
QWebView::keyPressEvent(event);
}
void WebPage::keyReleaseEvent(QKeyEvent *event)
{
if (event->modifiers() == Qt::ControlModifier)
{
cPress = false;
event->accept();
}
QWebView::keyReleaseEvent(event); ;
}
void WebPage::wheelEvent(QWheelEvent *event)
{
if (event->modifiers() == Qt::ControlModifier)
{
if (event->delta() > 0)
{
emit zoomRequired();
}
else
{
emit unZoomRequired();
}
event->accept();
}
QWebView::wheelEvent(event);
}