diff options
Diffstat (limited to 'src/gui/widgets/qabstractscrollarea.cpp')
-rw-r--r-- | src/gui/widgets/qabstractscrollarea.cpp | 55 |
1 files changed, 32 insertions, 23 deletions
diff --git a/src/gui/widgets/qabstractscrollarea.cpp b/src/gui/widgets/qabstractscrollarea.cpp index 0896256..7d81d5a 100644 --- a/src/gui/widgets/qabstractscrollarea.cpp +++ b/src/gui/widgets/qabstractscrollarea.cpp @@ -293,13 +293,16 @@ void QAbstractScrollAreaPrivate::init() q->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken); q->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); layoutChildren(); + viewport->grabGesture(Qt::PanGesture); } #ifdef Q_WS_WIN void QAbstractScrollAreaPrivate::setSingleFingerPanEnabled(bool on) { singleFingerPanEnabled = on; - winSetupGestures(); + QWidgetPrivate *dd = static_cast<QWidgetPrivate *>(QObjectPrivate::get(viewport)); + if (dd) + dd->winSetupGestures(); } #endif // Q_WS_WIN @@ -539,6 +542,7 @@ void QAbstractScrollArea::setViewport(QWidget *widget) d->viewport->setParent(this); d->viewport->setFocusProxy(this); d->viewport->installEventFilter(d->viewportFilter.data()); + d->viewport->grabGesture(Qt::PanGesture); d->layoutChildren(); if (isVisible()) d->viewport->show(); @@ -935,6 +939,26 @@ bool QAbstractScrollArea::event(QEvent *e) case QEvent::TouchUpdate: case QEvent::TouchEnd: return false; + case QEvent::Gesture: + { + QGestureEvent *ge = static_cast<QGestureEvent *>(e); + QPanGesture *g = static_cast<QPanGesture *>(ge->gesture(Qt::PanGesture)); + if (g) { + QScrollBar *hBar = horizontalScrollBar(); + QScrollBar *vBar = verticalScrollBar(); + QPointF delta = g->lastOffset(); + if (!delta.isNull()) { + if (QApplication::isRightToLeft()) + delta.rx() *= -1; + int newX = hBar->value() - delta.x(); + int newY = vBar->value() - delta.y(); + hBar->setValue(newX); + vBar->setValue(newY); + } + return true; + } + return false; + } case QEvent::StyleChange: case QEvent::LayoutDirectionChange: case QEvent::ApplicationLayoutDirectionChange: @@ -990,6 +1014,8 @@ bool QAbstractScrollArea::viewportEvent(QEvent *e) #endif return QFrame::event(e); case QEvent::LayoutRequest: + case QEvent::Gesture: + case QEvent::GestureOverride: return event(e); default: break; @@ -1266,11 +1292,13 @@ void QAbstractScrollAreaPrivate::_q_vslide(int y) void QAbstractScrollAreaPrivate::_q_showOrHideScrollBars() { layoutChildren(); -#ifdef Q_OS_WIN +#ifdef Q_WS_WIN // Need to re-subscribe to gestures as the content changes to make sure we // enable/disable panning when needed. - winSetupGestures(); -#endif // Q_OS_WIN + QWidgetPrivate *dd = static_cast<QWidgetPrivate *>(QObjectPrivate::get(viewport)); + if (dd) + dd->winSetupGestures(); +#endif // Q_WS_WIN } QPoint QAbstractScrollAreaPrivate::contentsOffset() const @@ -1335,25 +1363,6 @@ void QAbstractScrollArea::setupViewport(QWidget *viewport) Q_UNUSED(viewport); } -//void QAbstractScrollAreaPrivate::_q_gestureTriggered() -//{ -// Q_Q(QAbstractScrollArea); -// QPanGesture *g = qobject_cast<QPanGesture*>(q->sender()); -// if (!g) -// return; -// QScrollBar *hBar = q->horizontalScrollBar(); -// QScrollBar *vBar = q->verticalScrollBar(); -// QSizeF delta = g->lastOffset(); -// if (!delta.isNull()) { -// if (QApplication::isRightToLeft()) -// delta.rwidth() *= -1; -// int newX = hBar->value() - delta.width(); -// int newY = vBar->value() - delta.height(); -// hbar->setValue(newX); -// vbar->setValue(newY); -// } -//} - QT_END_NAMESPACE #include "moc_qabstractscrollarea.cpp" |