diff options
author | Denis Dzyubenko <denis.dzyubenko@nokia.com> | 2009-04-24 09:34:44 (GMT) |
---|---|---|
committer | Denis Dzyubenko <denis.dzyubenko@nokia.com> | 2009-05-11 14:51:57 (GMT) |
commit | c0dc85f18230c338187b3a5f0eb1f17d1f570d05 (patch) | |
tree | e87655f4e2eaad0cd07ff30bdb8cfcb2c5094c24 /examples/gestures | |
parent | e8f57e06eb21f51a6283f7a18d66aa8ca2c6b38a (diff) | |
download | Qt-c0dc85f18230c338187b3a5f0eb1f17d1f570d05.zip Qt-c0dc85f18230c338187b3a5f0eb1f17d1f570d05.tar.gz Qt-c0dc85f18230c338187b3a5f0eb1f17d1f570d05.tar.bz2 |
Added support to pan frames inside browser window.
Diffstat (limited to 'examples/gestures')
-rw-r--r-- | examples/gestures/browser/webview.cpp | 22 | ||||
-rw-r--r-- | examples/gestures/browser/webview.h | 3 |
2 files changed, 16 insertions, 9 deletions
diff --git a/examples/gestures/browser/webview.cpp b/examples/gestures/browser/webview.cpp index 95a96e7..310c7d8 100644 --- a/examples/gestures/browser/webview.cpp +++ b/examples/gestures/browser/webview.cpp @@ -186,6 +186,7 @@ WebView::WebView(QWidget* parent) : QWebView(parent) , m_progress(0) , m_page(new WebPage(this)) + , m_currentPanFrame(0) { grabGesture(Qt::PanGesture); setPage(m_page); @@ -317,13 +318,18 @@ void WebView::gestureEvent(QGestureEvent *event) { if (const QGesture *g = event->gesture(Qt::PanGesture)) { if (g->state() == Qt::GestureUpdated) { - if (QWebFrame *frame = page()->mainFrame()) { - QPoint offset = g->pos() - g->lastPos(); - frame->setScrollPosition(frame->scrollPosition() - offset); + if (m_currentPanFrame) { + m_panSpeed = g->pos() - g->lastPos(); + m_currentPanFrame->scroll(-m_panSpeed.x(), -m_panSpeed.y()); } - speed = g->pos() - g->lastPos(); } else if (g->state() == Qt::GestureStarted) { startTimer(20); + m_currentPanFrame = 0; + if (QWebFrame *frame = page()->mainFrame()) { + QWebHitTestResult result = frame->hitTestContent(g->startPos()); + if (!result.isNull()) + m_currentPanFrame = result.frame(); + } } else { } event->accept(); @@ -341,9 +347,9 @@ static QPoint deaccelerate(const QPoint &speed, int a = 1, int max = 64) void WebView::timerEvent(QTimerEvent *event) { - speed = deaccelerate(speed); - if (speed.isNull()) + m_panSpeed = deaccelerate(m_panSpeed); + if (m_panSpeed.isNull()) killTimer(event->timerId()); - if (QWebFrame *frame = page()->mainFrame()) - frame->setScrollPosition(frame->scrollPosition() - speed); + if (m_currentPanFrame) + m_currentPanFrame->scroll(-m_panSpeed.x(), -m_panSpeed.y()); } diff --git a/examples/gestures/browser/webview.h b/examples/gestures/browser/webview.h index 15fb40c..af137b8 100644 --- a/examples/gestures/browser/webview.h +++ b/examples/gestures/browser/webview.h @@ -117,7 +117,8 @@ private: QUrl m_initialUrl; int m_progress; WebPage *m_page; - QPoint speed; + QPoint m_panSpeed; + QWebFrame *m_currentPanFrame; }; #endif |