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 <shawn.rutledge@digia.com>
bb10
Friedemann Kleint 2014-11-10 10:52:22 +01:00 committed by Shawn Rutledge
parent cf0d96f4c8
commit 2ffa46054d
1 changed files with 21 additions and 2 deletions

View File

@ -38,6 +38,7 @@
#include "qwidget.h"
#include "qabstractscrollarea.h"
#include <qgraphicssceneevent.h>
#include <QtGui/QTouchDevice>
#include "qdebug.h"
#ifndef QT_NO_GESTURES
@ -67,8 +68,26 @@ static QPointF panOffset(const QList<QTouchEvent::TouchPoint> &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<QPanGesture *>(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: {