diff options
author | Rafael Brandao <rafael.lobo@openbossa.org> | 2011-09-29 10:53:15 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-09-29 03:00:38 +0200 |
commit | 40f63187a44fac0de25933484b84c659e0451f59 (patch) | |
tree | 05d8601611f3884d4ac597d09639f1365e99a5f6 /src | |
parent | 55b4b637779e1a6d88b969837aa106487e4c636e (diff) |
Added triple click on TextInput to select text.
Once it gets a double click, it'll start to monitor any other extra
click for a short duration. Once it is detected, the monitor stops
watching and all text is selected. It only works when selectByMouse
property is set, just like double click selecting current word.
Also added a test case that simulates clicking at the same point
and triggering the triple click, and another one that contemplates
movement of mouse between the second and the third click. Also test
timing between clicks.
Task-number: QTBUG-21038
Change-Id: I139f7ece2107f5dbfcba1836afb27aaa9b24fc57
Merge-request: 6
Reviewed-by: Andrew den Exter <andrew.den-exter@nokia.com>
Reviewed-on: http://codereview.qt-project.org/5761
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/declarative/items/qsgtextinput.cpp | 11 | ||||
-rw-r--r-- | src/declarative/items/qsgtextinput_p_p.h | 8 |
2 files changed, 19 insertions, 0 deletions
diff --git a/src/declarative/items/qsgtextinput.cpp b/src/declarative/items/qsgtextinput.cpp index ab6be666d8..cfb1c6fc8b 100644 --- a/src/declarative/items/qsgtextinput.cpp +++ b/src/declarative/items/qsgtextinput.cpp @@ -1088,6 +1088,10 @@ void QSGTextInput::mouseDoubleClickEvent(QMouseEvent *event) 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); } @@ -1116,6 +1120,13 @@ void QSGTextInput::mousePressEvent(QMouseEvent *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()); diff --git a/src/declarative/items/qsgtextinput_p_p.h b/src/declarative/items/qsgtextinput_p_p.h index 49680ced6d..7022dd734e 100644 --- a/src/declarative/items/qsgtextinput_p_p.h +++ b/src/declarative/items/qsgtextinput_p_p.h @@ -50,7 +50,10 @@ #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> // @@ -142,6 +145,8 @@ public: QPointer<QSGItem> cursorItem; QPointF pressPos; QSGTextNode *textNode; + QElapsedTimer tripleClickTimer; + QPoint tripleClickStartPoint; int lastSelectionStart; int lastSelectionEnd; @@ -166,6 +171,9 @@ public: static inline QSGTextInputPrivate *get(QSGTextInput *t) { return t->d_func(); } + bool hasPendingTripleClick() const { + return !tripleClickTimer.hasExpired(qApp->styleHints()->mouseDoubleClickInterval()); + } }; QT_END_NAMESPACE |