int cursor = d->xToPos(event->localPos().x());
d->control->selectWordAtPos(cursor);
event->setAccepted(true);
+ if (!d->hasPendingTripleClick()) {
+ d->tripleClickStartPoint = event->localPos().toPoint();
+ d->tripleClickTimer.start();
+ }
} else {
QSGImplicitSizeItem::mouseDoubleClickEvent(event);
}
setKeepMouseGrab(false);
d->selectPressed = true;
d->pressPos = event->localPos();
+ QPoint distanceVector = d->pressPos.toPoint() - d->tripleClickStartPoint;
+ if (d->hasPendingTripleClick()
+ && distanceVector.manhattanLength() < qApp->styleHints()->startDragDistance()) {
+ event->setAccepted(true);
+ selectAll();
+ return;
+ }
}
bool mark = (event->modifiers() & Qt::ShiftModifier) && d->selectByMouse;
int cursor = d->xToPos(event->localPos().x());
#include <private/qlinecontrol_p.h>
#include <QtDeclarative/qdeclarative.h>
+#include <QtCore/qelapsedtimer.h>
#include <QtCore/qpointer.h>
+#include <QtGui/qguiapplication.h>
+#include <QtGui/qstylehints.h>
//
QPointer<QSGItem> cursorItem;
QPointF pressPos;
QSGTextNode *textNode;
+ QElapsedTimer tripleClickTimer;
+ QPoint tripleClickStartPoint;
int lastSelectionStart;
int lastSelectionEnd;
static inline QSGTextInputPrivate *get(QSGTextInput *t) {
return t->d_func();
}
+ bool hasPendingTripleClick() const {
+ return !tripleClickTimer.hasExpired(qApp->styleHints()->mouseDoubleClickInterval());
+ }
};
QT_END_NAMESPACE
void dragMouseSelection();
void mouseSelectionMode_data();
void mouseSelectionMode();
+ void tripleClickSelectsAll();
void horizontalAlignment_data();
void horizontalAlignment();
#endif
}
+void tst_qsgtextinput::tripleClickSelectsAll()
+{
+ QString qmlfile = SRCDIR "/data/positionAt.qml";
+ QSGView view(QUrl::fromLocalFile(qmlfile));
+ view.requestActivateWindow();
+ view.show();
+ QTest::qWaitForWindowShown(&view);
+
+ QEXPECT_FAIL("", QTBUG_21489_MESSAGE, Continue);
+ QTRY_COMPARE(view.windowState(), Qt::WindowActive);
+
+ QSGTextInput* input = qobject_cast<QSGTextInput*>(view.rootObject());
+ QVERIFY(input);
+
+ QLatin1String hello("Hello world!");
+ input->setSelectByMouse(true);
+ input->setText(hello);
+
+ // Clicking on the same point inside TextInput three times in a row
+ // should trigger a triple click, thus selecting all the text.
+ QPoint pointInside = input->pos().toPoint() + QPoint(2,2);
+ QTest::mouseDClick(&view, Qt::LeftButton, 0, pointInside);
+ QTest::mouseClick(&view, Qt::LeftButton, 0, pointInside);
+ QGuiApplication::processEvents();
+ QCOMPARE(input->selectedText(), hello);
+
+ // Now it simulates user moving the mouse between the second and the third click.
+ // In this situation, we don't expect a triple click.
+ QPoint pointInsideButFar = QPoint(input->width(),input->height()) - QPoint(2,2);
+ QTest::mouseDClick(&view, Qt::LeftButton, 0, pointInside);
+ QTest::mouseClick(&view, Qt::LeftButton, 0, pointInsideButFar);
+ QGuiApplication::processEvents();
+ QVERIFY(input->selectedText().isEmpty());
+
+ // And now we press the third click too late, so no triple click event is triggered.
+ QTest::mouseDClick(&view, Qt::LeftButton, 0, pointInside);
+ QGuiApplication::processEvents();
+ QTest::qWait(QApplication::doubleClickInterval() + 1);
+ QTest::mouseClick(&view, Qt::LeftButton, 0, pointInside);
+ QGuiApplication::processEvents();
+ QVERIFY(input->selectedText().isEmpty());
+}
+
QTEST_MAIN(tst_qsgtextinput)
#include "tst_qsgtextinput.moc"