aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Arve Sæther <jan-arve.saether@qt.io>2019-08-09 12:49:04 +0200
committerJan Arve Sæther <jan-arve.saether@qt.io>2019-08-29 13:38:14 +0200
commit98f29914e4e233358ef31068542fceeea92eda97 (patch)
tree2f96ba01b9e92d99ddbbf1967febfefd03653648
parent1dc3f4c24583e14dee3c5fa650a8ac239b953458 (diff)
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 <shawn.rutledge@qt.io>
-rw-r--r--src/quick/items/qquicktextcontrol.cpp8
-rw-r--r--src/quick/items/qquicktextcontrol_p_p.h2
2 files changed, 4 insertions, 6 deletions
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)
diff --git a/src/quick/items/qquicktextcontrol_p_p.h b/src/quick/items/qquicktextcontrol_p_p.h
index 0582e6d113..431bf1b6c4 100644
--- a/src/quick/items/qquicktextcontrol_p_p.h
+++ b/src/quick/items/qquicktextcontrol_p_p.h
@@ -141,7 +141,7 @@ public:
QString hoveredLink;
QBasicTimer cursorBlinkTimer;
- QBasicTimer tripleClickTimer;
+ ulong timestampAtLastDoubleClick = 0; // will only be set at a double click
#if QT_CONFIG(im)
int preeditCursor;