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 <paul.tvete@digia.com>
This commit is contained in:
Christian Strømme 2014-02-17 15:48:31 +01:00 committed by The Qt Project
parent a03a69efb9
commit de5ae6917c
2 changed files with 16 additions and 3 deletions

View File

@ -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);
}
}
}

View File

@ -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);
}
}