summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarcel Schuette <marcel.schuette@nokia.com>2012-05-25 14:46:29 (GMT)
committerQt by Nokia <qt-info@nokia.com>2012-05-30 19:47:09 (GMT)
commit6c20d552b9917ea736c52a7d436dafbf542bff30 (patch)
tree9e8803159831ef9b52c16c24742df9c04eae84b2
parentfc1802a17bc5c074673cbd2778334cc7ddae9cd8 (diff)
downloadQt-6c20d552b9917ea736c52a7d436dafbf542bff30.zip
Qt-6c20d552b9917ea736c52a7d436dafbf542bff30.tar.gz
Qt-6c20d552b9917ea736c52a7d436dafbf542bff30.tar.bz2
Propagate left key presses to the parent item when TextInput is empty.
Don't overwrite the ignore value once it's been set to true. Backport from Qt 5.0 to Qt 4.8 (commit a7017465152d544a4217d5ce4f6f84b80cb9b8b9) Task-number: QTBUG-25447 Change-Id: I2232806b1235b0c901aab21116b5bc70c65d0500 Reviewed-by: Andrew den Exter <andrew.den-exter@nokia.com>
-rw-r--r--src/declarative/graphicsitems/qdeclarativetextinput.cpp2
-rw-r--r--tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp12
-rw-r--r--tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp12
3 files changed, 24 insertions, 2 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativetextinput.cpp b/src/declarative/graphicsitems/qdeclarativetextinput.cpp
index 4264587..d8d2ac9 100644
--- a/src/declarative/graphicsitems/qdeclarativetextinput.cpp
+++ b/src/declarative/graphicsitems/qdeclarativetextinput.cpp
@@ -1073,7 +1073,7 @@ void QDeclarativeTextInput::keyPressEvent(QKeyEvent* ev)
int cursorPosition = d->control->cursor();
if (cursorPosition == 0)
ignore = ev->key() == (d->control->layoutDirection() == Qt::LeftToRight ? Qt::Key_Left : Qt::Key_Right);
- if (cursorPosition == d->control->text().length())
+ if (!ignore && cursorPosition == d->control->text().length())
ignore = ev->key() == (d->control->layoutDirection() == Qt::LeftToRight ? Qt::Key_Right : Qt::Key_Left);
}
if (ignore) {
diff --git a/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp b/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp
index 31da832..6a1bb43 100644
--- a/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp
+++ b/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp
@@ -1895,7 +1895,7 @@ void tst_qdeclarativetextedit::navigation()
QVERIFY(canvas->rootObject() != 0);
- QDeclarativeItem *input = qobject_cast<QDeclarativeItem *>(qvariant_cast<QObject *>(canvas->rootObject()->property("myInput")));
+ QDeclarativeTextEdit *input = qobject_cast<QDeclarativeTextEdit *>(qvariant_cast<QObject *>(canvas->rootObject()->property("myInput")));
QVERIFY(input != 0);
QTRY_VERIFY(input->hasActiveFocus() == true);
@@ -1910,6 +1910,16 @@ void tst_qdeclarativetextedit::navigation()
simulateKey(canvas, Qt::Key_Left);
QVERIFY(input->hasActiveFocus() == true);
+ // Test left and right navigation works if the TextEdit is empty (QTBUG-25447).
+ input->setText(QString());
+ QCOMPARE(input->cursorPosition(), 0);
+ simulateKey(canvas, Qt::Key_Right);
+ QCOMPARE(input->hasActiveFocus(), false);
+ simulateKey(canvas, Qt::Key_Left);
+ QCOMPARE(input->hasActiveFocus(), true);
+ simulateKey(canvas, Qt::Key_Left);
+ QCOMPARE(input->hasActiveFocus(), false);
+
delete canvas;
}
diff --git a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp
index df598be..55b4b89 100644
--- a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp
+++ b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp
@@ -1613,6 +1613,18 @@ void tst_qdeclarativetextinput::navigation()
simulateKey(canvas, Qt::Key_Down);
QCOMPARE(input->cursorPosition(),2);
+ // Test left and right navigation works if the TextInput is empty (QTBUG-25447).
+ input->setText(QString());
+ QCOMPARE(input->cursorPosition(), 0);
+ simulateKey(canvas, Qt::Key_Left);
+ QCOMPARE(input->hasActiveFocus(), false);
+ simulateKey(canvas, Qt::Key_Right);
+ QCOMPARE(input->hasActiveFocus(), true);
+ simulateKey(canvas, Qt::Key_Right);
+ QCOMPARE(input->hasActiveFocus(), false);
+ simulateKey(canvas, Qt::Key_Left);
+ QCOMPARE(input->hasActiveFocus(), true);
+
delete canvas;
}