blob: 5b7a67a9ed3e30584074f71f95c141ea8f402642 (
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
|
#include <QtGui>
#include <QtWebKit>
class PannableWebView : public QWebView
{
public:
PannableWebView(QWidget *parent = 0)
: QWebView(parent)
{
grabGesture(Qt::PanGesture);
}
protected:
bool event(QEvent *event)
{
if (event->type() == QEvent::Gesture)
{
QGestureEvent *ev = static_cast<QGestureEvent*>(event);
if (const QGesture *g = ev->gesture(Qt::PanGesture)) {
if (QWebFrame *frame = page()->mainFrame()) {
QPoint offset = g->pos() - g->lastPos();
frame->setScrollPosition(frame->scrollPosition() - offset);
}
event->accept();
}
return true;
}
return QWebView::event(event);
}
};
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QGraphicsScene scene;
QGraphicsView w(&scene);
QWebView *wv = new PannableWebView;
wv->resize(480, 800);
wv->setUrl(QUrl("http://www.trolltech.com"));
scene.addWidget(wv);
w.show();
return app.exec();
}
|