blob: 9d12010a576f6a2d9096a971ac84a53545f3b775 (
plain)
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
|
/*
* Copyright (c) 2010 Kevin Smith
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
#include "QtWebView.h"
#include <QKeyEvent>
#include <QFocusEvent>
#include <QMenu>
namespace Swift {
QtWebView::QtWebView(QWidget* parent) : QWebView(parent) {
setRenderHint(QPainter::SmoothPixmapTransform);
filteredActions.push_back(QWebPage::CopyLinkToClipboard);
filteredActions.push_back(QWebPage::CopyImageToClipboard);
filteredActions.push_back(QWebPage::Copy);
}
void QtWebView::keyPressEvent(QKeyEvent* event) {
Qt::KeyboardModifiers modifiers = event->modifiers();
int key = event->key();
if (modifiers == Qt::ShiftModifier && (key == Qt::Key_PageUp || key == Qt::Key_PageDown)) {
modifiers = Qt::NoModifier;
}
QKeyEvent* translatedEvent = new QKeyEvent(QEvent::KeyPress,
key,
modifiers,
event->text(),
event->isAutoRepeat(),
event->count());
QWebView::keyPressEvent(translatedEvent);
delete translatedEvent;
}
void QtWebView::dragEnterEvent(QDragEnterEvent*) {
}
void QtWebView::contextMenuEvent(QContextMenuEvent* ev) {
// Filter out the relevant actions from the standard actions
QMenu* menu = page()->createStandardContextMenu();
QList<QAction*> actions(menu->actions());
for (int i = 0; i < actions.size(); ++i) {
QAction* action = actions.at(i);
bool removeAction = true;
for(size_t j = 0; j < filteredActions.size(); ++j) {
if (action == pageAction(filteredActions[j])) {
removeAction = false;
break;
}
}
if (removeAction) {
menu->removeAction(action);
}
}
// Add our own custom actions
menu->addAction(tr("Clear"), this, SIGNAL(clearRequested()));
menu->exec(ev->globalPos());
delete menu;
}
void QtWebView::focusInEvent(QFocusEvent* event) {
QWebView::focusInEvent(event);
emit gotFocus();
}
}
|