summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorDenis Dzyubenko <denis.dzyubenko@nokia.com>2009-04-20 13:02:31 (GMT)
committerDenis Dzyubenko <denis.dzyubenko@nokia.com>2009-05-11 14:51:51 (GMT)
commit00353a9af82ac40c836a39ec5aa47a7284dea214 (patch)
treec09828f45e034870d291666aa8981b8292bdfcf6 /examples
parent62229907918ddf1b830a51c8a2613cf2492ae1c7 (diff)
downloadQt-00353a9af82ac40c836a39ec5aa47a7284dea214.zip
Qt-00353a9af82ac40c836a39ec5aa47a7284dea214.tar.gz
Qt-00353a9af82ac40c836a39ec5aa47a7284dea214.tar.bz2
Added pannablewebview example.
Diffstat (limited to 'examples')
-rw-r--r--examples/gestures/gestures.pro3
-rw-r--r--examples/gestures/pannablewebview/main.cpp44
-rw-r--r--examples/gestures/pannablewebview/pannablewebview.pro4
3 files changed, 50 insertions, 1 deletions
diff --git a/examples/gestures/gestures.pro b/examples/gestures/gestures.pro
index 35164ac..8bd0acc 100644
--- a/examples/gestures/gestures.pro
+++ b/examples/gestures/gestures.pro
@@ -3,7 +3,8 @@ TEMPLATE = \
SUBDIRS = \
imageviewer \
graphicsview \
- collidingmice
+ collidingmice \
+ pannablewebview
# install
target.path = $$[QT_INSTALL_EXAMPLES]/gestures
diff --git a/examples/gestures/pannablewebview/main.cpp b/examples/gestures/pannablewebview/main.cpp
new file mode 100644
index 0000000..5b7a67a
--- /dev/null
+++ b/examples/gestures/pannablewebview/main.cpp
@@ -0,0 +1,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();
+}
diff --git a/examples/gestures/pannablewebview/pannablewebview.pro b/examples/gestures/pannablewebview/pannablewebview.pro
new file mode 100644
index 0000000..07d8f91
--- /dev/null
+++ b/examples/gestures/pannablewebview/pannablewebview.pro
@@ -0,0 +1,4 @@
+SOURCES += \
+ main.cpp
+
+QT += webkit