From f79b7b7c87ad69b9e07057a92c6628315b540a0e Mon Sep 17 00:00:00 2001 From: Andrew den Exter Date: Tue, 26 Jul 2011 10:10:50 +1000 Subject: [PATCH] Move the cursor position to the end when TextInput.readOnly is cleared. Improves consistency with TextEdit. Task-number: QTBUG-18747 Change-Id: Ieb0a332441557fc6ba4c5ddaafea5c634aff1ee4 Reviewed-on: http://codereview.qt.nokia.com/2131 Reviewed-by: Qt Sanity Bot Reviewed-by: Martin Jones --- src/declarative/items/qsgtextinput.cpp | 2 ++ .../declarative/qsgtextedit/tst_qsgtextedit.cpp | 5 +++++ .../declarative/qsgtextinput/tst_qsgtextinput.cpp | 5 +++++ 3 files changed, 12 insertions(+), 0 deletions(-) diff --git a/src/declarative/items/qsgtextinput.cpp b/src/declarative/items/qsgtextinput.cpp index e73237e..fe70705 100644 --- a/src/declarative/items/qsgtextinput.cpp +++ b/src/declarative/items/qsgtextinput.cpp @@ -264,6 +264,8 @@ void QSGTextInput::setReadOnly(bool ro) setFlag(QSGItem::ItemAcceptsInputMethod, !ro); d->control->setReadOnly(ro); + if (!ro) + d->control->setCursorPosition(d->control->end()); emit readOnlyChanged(ro); } diff --git a/tests/auto/declarative/qsgtextedit/tst_qsgtextedit.cpp b/tests/auto/declarative/qsgtextedit/tst_qsgtextedit.cpp index 409af72..3492ac2 100644 --- a/tests/auto/declarative/qsgtextedit/tst_qsgtextedit.cpp +++ b/tests/auto/declarative/qsgtextedit/tst_qsgtextedit.cpp @@ -1785,6 +1785,11 @@ void tst_qsgtextedit::readOnly() simulateKey(&canvas, Qt::Key_Space); simulateKey(&canvas, Qt::Key_Escape); QCOMPARE(edit->text(), initial); + + edit->setCursorPosition(3); + edit->setReadOnly(false); + QCOMPARE(edit->isReadOnly(), false); + QCOMPARE(edit->cursorPosition(), edit->text().length()); } void tst_qsgtextedit::simulateKey(QSGView *view, int key, Qt::KeyboardModifiers modifiers) diff --git a/tests/auto/declarative/qsgtextinput/tst_qsgtextinput.cpp b/tests/auto/declarative/qsgtextinput/tst_qsgtextinput.cpp index c6c93c1..497c12f 100644 --- a/tests/auto/declarative/qsgtextinput/tst_qsgtextinput.cpp +++ b/tests/auto/declarative/qsgtextinput/tst_qsgtextinput.cpp @@ -1767,6 +1767,11 @@ void tst_qsgtextinput::readOnly() simulateKey(&canvas, Qt::Key_Space); simulateKey(&canvas, Qt::Key_Escape); QCOMPARE(input->text(), initial); + + input->setCursorPosition(3); + input->setReadOnly(false); + QCOMPARE(input->isReadOnly(), false); + QCOMPARE(input->cursorPosition(), input->text().length()); } void tst_qsgtextinput::echoMode() -- 1.7.2.5