From 2ffa46054d13c639cf9f7846a74ad3ebd07b9f5c Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Mon, 10 Nov 2014 10:52:22 +0100 Subject: Use single finger pan to scroll text edits on touch screens. Change the number of pan points to 1 for these classes as a workaround until pan/tap gestures are fully fixed. Task-number: QTBUG-40461 Change-Id: I0d68726a545ee6148f3ab88f2ab7308b10464ecd Reviewed-by: Shawn Rutledge --- src/widgets/kernel/qstandardgestures.cpp | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/kernel/qstandardgestures.cpp b/src/widgets/kernel/qstandardgestures.cpp index 6656903e70..53e5d091fa 100644 --- a/src/widgets/kernel/qstandardgestures.cpp +++ b/src/widgets/kernel/qstandardgestures.cpp @@ -38,6 +38,7 @@ #include "qwidget.h" #include "qabstractscrollarea.h" #include +#include #include "qdebug.h" #ifndef QT_NO_GESTURES @@ -67,8 +68,26 @@ static QPointF panOffset(const QList &touchPoints, int return result / qreal(count); } +// ### fixme: Remove this +// Use single finger pan to scroll QPlainTextEdit/QTextEdit +// by changing the number of pan points to 1 for these classes. +// This used to be Qt 4's behavior on Windows which was achieved using native +// Windows gesture recognizers for these classes. +// The other classes inheriting QScrollArea still use standard 2 finger pan. +// In the long run, they should also use single finger pan to +// scroll on touch screens, however, this requires a distinct Tap&Hold-followed-by-pan +// type gesture to avoid clashes with item view selection and DnD. + +static inline int panTouchPoints(const QTouchEvent *event, const QObject *object, + int defaultTouchPoints) +{ + return event->device()->type() == QTouchDevice::TouchScreen && object && object->parent() + && (object->parent()->inherits("QPlainTextEdit") || object->parent()->inherits("QTextEdit")) + ? 1 : defaultTouchPoints; +} + QGestureRecognizer::Result QPanGestureRecognizer::recognize(QGesture *state, - QObject *, + QObject *object, QEvent *event) { QPanGesture *q = static_cast(state); @@ -81,7 +100,7 @@ QGestureRecognizer::Result QPanGestureRecognizer::recognize(QGesture *state, result = QGestureRecognizer::MayBeGesture; QTouchEvent::TouchPoint p = ev->touchPoints().at(0); d->lastOffset = d->offset = QPointF(); - d->pointCount = m_pointCount; + d->pointCount = panTouchPoints(ev, object, m_pointCount); break; } case QEvent::TouchEnd: { -- cgit v1.2.3