From 98f29914e4e233358ef31068542fceeea92eda97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Arve=20S=C3=A6ther?= Date: Fri, 9 Aug 2019 12:49:04 +0200 Subject: Fix QQuickTextEdit triple click detection It should use the events own timestamps instead of a QTimer. It should give a more accurate measurement of tripleclicks, in addition to that qtestlib synthesized events (with timestamps) are respected. Task-number: QTBUG-77389 Change-Id: I4f553ec17b53a00b55519bb8082f1373aa9d130d Reviewed-by: Shawn Rutledge --- src/quick/items/qquicktextcontrol.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'src/quick/items/qquicktextcontrol.cpp') diff --git a/src/quick/items/qquicktextcontrol.cpp b/src/quick/items/qquicktextcontrol.cpp index ac8093e10b..5c55f4f43f 100644 --- a/src/quick/items/qquicktextcontrol.cpp +++ b/src/quick/items/qquicktextcontrol.cpp @@ -790,8 +790,6 @@ void QQuickTextControl::timerEvent(QTimerEvent *e) d->cursorOn = !d->cursorOn; d->repaintCursor(); - } else if (e->timerId() == d->tripleClickTimer.timerId()) { - d->tripleClickTimer.stop(); } } @@ -1046,7 +1044,7 @@ void QQuickTextControlPrivate::mousePressEvent(QMouseEvent *e, const QPointF &po commitPreedit(); #endif - if (tripleClickTimer.isActive() + if ((e->timestamp() < (timestampAtLastDoubleClick + QGuiApplication::styleHints()->mouseDoubleClickInterval())) && ((pos - tripleClickPoint).toPoint().manhattanLength() < QGuiApplication::styleHints()->startDragDistance())) { cursor.movePosition(QTextCursor::StartOfBlock); @@ -1056,7 +1054,7 @@ void QQuickTextControlPrivate::mousePressEvent(QMouseEvent *e, const QPointF &po anchorOnMousePress = QString(); - tripleClickTimer.stop(); + timestampAtLastDoubleClick = 0; // do not enter this condition in case of 4(!) rapid clicks } else { int cursorPos = q->hitTest(pos, Qt::FuzzyHit); if (cursorPos == -1) { @@ -1245,7 +1243,7 @@ void QQuickTextControlPrivate::mouseDoubleClickEvent(QMouseEvent *e, const QPoin selectedWordOnDoubleClick = cursor; tripleClickPoint = pos; - tripleClickTimer.start(QGuiApplication::styleHints()->mouseDoubleClickInterval(), q); + timestampAtLastDoubleClick = e->timestamp(); if (doEmit) { selectionChanged(); #if QT_CONFIG(clipboard) -- cgit v1.2.3