From de5ae6917c819ff23f7d9c5742b50b15e0824877 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Str=C3=B8mme?= Date: Mon, 17 Feb 2014 15:48:31 +0100 Subject: Android: Enable text selection only when ImhNoPredictiveText is set. Mouse selection does not work well with Android and text will be randomly copied, pasted or deleted. This behavior is especially bad when predictive text is enabled. Task-number: QTBUG-34616 Change-Id: I732ad7db52169bfb5735c237cf24597a3d6d64ba Reviewed-by: Paul Olav Tvete --- src/widgets/widgets/qlineedit.cpp | 12 ++++++++++-- src/widgets/widgets/qlineedit_p.cpp | 7 ++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/widgets/widgets/qlineedit.cpp b/src/widgets/widgets/qlineedit.cpp index 1833dce40b..ba4dbcc878 100644 --- a/src/widgets/widgets/qlineedit.cpp +++ b/src/widgets/widgets/qlineedit.cpp @@ -1493,6 +1493,9 @@ void QLineEdit::mousePressEvent(QMouseEvent* e) return; } bool mark = e->modifiers() & Qt::ShiftModifier; +#ifdef Q_OS_ANDROID + mark = mark && (d->imHints & Qt::ImhNoPredictiveText); +#endif // Q_OS_ANDROID int cursor = d->xToPos(e->pos().x()); #ifndef QT_NO_DRAGANDDROP if (!mark && d->dragEnabled && d->control->echoMode() == Normal && @@ -1520,14 +1523,19 @@ void QLineEdit::mouseMoveEvent(QMouseEvent * e) } else #endif { - if (d->control->composeMode()) { +#ifndef Q_OS_ANDROID + const bool select = true; +#else + const bool select = (d->imHints & Qt::ImhNoPredictiveText); +#endif + if (d->control->composeMode() && select) { int startPos = d->xToPos(d->mousePressPos.x()); int currentPos = d->xToPos(e->pos().x()); if (startPos != currentPos) d->control->setSelection(startPos, currentPos - startPos); } else { - d->control->moveCursor(d->xToPos(e->pos().x()), true); + d->control->moveCursor(d->xToPos(e->pos().x()), select); } } } diff --git a/src/widgets/widgets/qlineedit_p.cpp b/src/widgets/widgets/qlineedit_p.cpp index 891839ed56..9ff77c87de 100644 --- a/src/widgets/widgets/qlineedit_p.cpp +++ b/src/widgets/widgets/qlineedit_p.cpp @@ -95,7 +95,12 @@ void QLineEditPrivate::_q_completionHighlighted(QString newText) QString text = control->text(); q->setText(text.left(c) + newText.mid(c)); control->moveCursor(control->end(), false); - control->moveCursor(c, true); +#ifndef Q_OS_ANDROID + const bool mark = true; +#else + const bool mark = (imHints & Qt::ImhNoPredictiveText); +#endif + control->moveCursor(c, mark); } } -- cgit v1.2.3