diff options
author | Andrew den Exter <andrew.den-exter@nokia.com> | 2012-04-18 17:20:24 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-04-19 06:16:28 +0200 |
commit | 7bd68f6447c79aa58a9854bb6c44db00ea36a06a (patch) | |
tree | fd5145dda805cd19a2aa2541567a280a5d1fb915 /tests | |
parent | 458eb3cce93162dced2649e44c59f27bb088f07c (diff) |
Ensure the cursor delegate position is correct when wrapping.
When inserting text into a TextEdit with implicit width and wrapping
the cursor delegate position has to be updated after the width is
expanded to the implicit width otherwise it will be positioned in a
wrapped location.
Change-Id: Ibcb709ec1b4f6827ea8ae919f2e0c932c7372869
Reviewed-by: Martin Jones <martin.jones@nokia.com>
Diffstat (limited to 'tests')
8 files changed, 127 insertions, 20 deletions
diff --git a/tests/auto/quick/qquicktextedit/data/cursorTestExternal.qml b/tests/auto/quick/qquicktextedit/data/cursorTestExternal.qml index 7e916ec818..8eed022c2f 100644 --- a/tests/auto/quick/qquicktextedit/data/cursorTestExternal.qml +++ b/tests/auto/quick/qquicktextedit/data/cursorTestExternal.qml @@ -6,6 +6,7 @@ Rectangle { width: 300; height: 300; color: "white" text: "Hello world!" id: textEditObject; objectName: "textEditObject" + wrapMode: TextEdit.WordWrap cursorDelegate: Cursor { id:cursorInstance; objectName: "cursorInstance"; diff --git a/tests/auto/quick/qquicktextedit/data/cursorTestInline.qml b/tests/auto/quick/qquicktextedit/data/cursorTestInline.qml index 786f39113c..bda171018a 100644 --- a/tests/auto/quick/qquicktextedit/data/cursorTestInline.qml +++ b/tests/auto/quick/qquicktextedit/data/cursorTestInline.qml @@ -5,6 +5,7 @@ Rectangle { width: 300; height: 300; color: "white" TextEdit { text: "Hello world!" id: textEditObject + wrapMode: TextEdit.Wrap objectName: "textEditObject" cursorDelegate: Item { id:cursorInstance diff --git a/tests/auto/quick/qquicktextedit/data/inputMethodEvent.qml b/tests/auto/quick/qquicktextedit/data/inputMethodEvent.qml index e3f629ce3e..ab47368619 100644 --- a/tests/auto/quick/qquicktextedit/data/inputMethodEvent.qml +++ b/tests/auto/quick/qquicktextedit/data/inputMethodEvent.qml @@ -2,4 +2,8 @@ import QtQuick 2.0 TextEdit { focus: true + + cursorDelegate: Item { + objectName: "cursor" + } } diff --git a/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp b/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp index 7113141800..f218f64768 100644 --- a/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp +++ b/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp @@ -1944,10 +1944,6 @@ void tst_qquicktextedit::cursorDelegate() QCOMPARE(textEditObject->cursorRectangle().x(), delegateObject->x()); QCOMPARE(textEditObject->cursorRectangle().y(), delegateObject->y()); } - // Clear preedit text; - QInputMethodEvent event; - QGuiApplication::sendEvent(&view, &event); - // Test delegate gets moved on mouse press. textEditObject->setSelectByMouse(true); @@ -1992,6 +1988,25 @@ void tst_qquicktextedit::cursorDelegate() textEditObject->setCursorPosition(0); QCOMPARE(textEditObject->cursorRectangle().x(), delegateObject->x()); QCOMPARE(textEditObject->cursorRectangle().y(), delegateObject->y()); + + // Delegate moved when text is entered + textEditObject->setText(QString()); + for (int i = 0; i < 20; ++i) { + QTest::keyClick(&view, Qt::Key_A); + QCOMPARE(textEditObject->cursorRectangle().x(), delegateObject->x()); + QCOMPARE(textEditObject->cursorRectangle().y(), delegateObject->y()); + } + + // Delegate moved when text is entered by im. + textEditObject->setText(QString()); + for (int i = 0; i < 20; ++i) { + QInputMethodEvent event; + event.setCommitString("a"); + QGuiApplication::sendEvent(&view, &event); + QCOMPARE(textEditObject->cursorRectangle().x(), delegateObject->x()); + QCOMPARE(textEditObject->cursorRectangle().y(), delegateObject->y()); + } + //Test Delegate gets deleted textEditObject->setCursorDelegate(0); QVERIFY(!textEditObject->findChild<QQuickItem*>("cursorInstance")); @@ -2645,14 +2660,17 @@ void tst_qquicktextedit::preeditCursorRectangle() QQuickTextEdit *edit = qobject_cast<QQuickTextEdit *>(view.rootObject()); QVERIFY(edit); + QQuickItem *cursor = edit->findChild<QQuickItem *>("cursor"); + QVERIFY(cursor); + QSignalSpy editSpy(edit, SIGNAL(cursorRectangleChanged())); QSignalSpy panelSpy(qGuiApp->inputMethod(), SIGNAL(cursorRectangleChanged())); - QRect currentRect; + QRectF currentRect; QInputMethodQueryEvent query(Qt::ImCursorRectangle); QCoreApplication::sendEvent(qGuiApp->focusObject(), &query); - QRect previousRect = query.value(Qt::ImCursorRectangle).toRect(); + QRectF previousRect = query.value(Qt::ImCursorRectangle).toRectF(); // Verify that the micro focus rect is positioned the same for position 0 as // it would be if there was no preedit text. @@ -2660,10 +2678,12 @@ void tst_qquicktextedit::preeditCursorRectangle() << QInputMethodEvent::Attribute(QInputMethodEvent::Cursor, 0, preeditText.length(), QVariant())); QCoreApplication::sendEvent(qGuiApp->focusObject(), &imEvent); QCoreApplication::sendEvent(qGuiApp->focusObject(), &query); - currentRect = query.value(Qt::ImCursorRectangle).toRect(); + currentRect = query.value(Qt::ImCursorRectangle).toRectF(); + QCOMPARE(edit->cursorRectangle(), currentRect); + QCOMPARE(cursor->pos(), currentRect.topLeft()); QCOMPARE(currentRect, previousRect); - QCOMPARE(editSpy.count(), 0); - QCOMPARE(panelSpy.count(), 0); + QCOMPARE(editSpy.count(), 0); editSpy.clear(); + QCOMPARE(panelSpy.count(), 0); panelSpy.clear(); // Verify that the micro focus rect moves to the left as the cursor position // is incremented. @@ -2672,10 +2692,12 @@ void tst_qquicktextedit::preeditCursorRectangle() << QInputMethodEvent::Attribute(QInputMethodEvent::Cursor, i, preeditText.length(), QVariant())); QCoreApplication::sendEvent(qGuiApp->focusObject(), &imEvent); QCoreApplication::sendEvent(qGuiApp->focusObject(), &query); - currentRect = query.value(Qt::ImCursorRectangle).toRect(); + currentRect = query.value(Qt::ImCursorRectangle).toRectF(); + QCOMPARE(edit->cursorRectangle(), currentRect); + QCOMPARE(cursor->pos(), currentRect.topLeft()); QVERIFY(previousRect.left() < currentRect.left()); - QVERIFY(editSpy.count() > 0); editSpy.clear(); - QVERIFY(panelSpy.count() > 0); panelSpy.clear(); + QCOMPARE(editSpy.count(), 1); editSpy.clear(); + QCOMPARE(panelSpy.count(), 1); panelSpy.clear(); previousRect = currentRect; } @@ -2687,10 +2709,12 @@ void tst_qquicktextedit::preeditCursorRectangle() { QInputMethodEvent imEvent(preeditText, QList<QInputMethodEvent::Attribute>()); QCoreApplication::sendEvent(qGuiApp->focusObject(), &imEvent); } QCoreApplication::sendEvent(qGuiApp->focusObject(), &query); - currentRect = query.value(Qt::ImCursorRectangle).toRect(); + currentRect = query.value(Qt::ImCursorRectangle).toRectF(); + QCOMPARE(edit->cursorRectangle(), currentRect); + QCOMPARE(cursor->pos(), currentRect.topLeft()); QCOMPARE(currentRect, previousRect); - QVERIFY(editSpy.count() > 0); - QVERIFY(panelSpy.count() > 0); + QCOMPARE(editSpy.count(), 1); + QCOMPARE(panelSpy.count(), 1); } void tst_qquicktextedit::inputMethodComposing() diff --git a/tests/auto/quick/qquicktextinput/data/cursorTestExternal.qml b/tests/auto/quick/qquicktextinput/data/cursorTestExternal.qml index 9277dcc518..2f43449052 100644 --- a/tests/auto/quick/qquicktextinput/data/cursorTestExternal.qml +++ b/tests/auto/quick/qquicktextinput/data/cursorTestExternal.qml @@ -6,6 +6,7 @@ Rectangle { width: 300; height: 300; color: "white" text: "Hello world!" id: textInputObject; objectName: "textInputObject" + wrapMode: TextInput.Wrap cursorDelegate: Cursor { id:cursorInstance; objectName: "cursorInstance"; diff --git a/tests/auto/quick/qquicktextinput/data/cursorTestInline.qml b/tests/auto/quick/qquicktextinput/data/cursorTestInline.qml index efc4b191da..e51a2f3401 100644 --- a/tests/auto/quick/qquicktextinput/data/cursorTestInline.qml +++ b/tests/auto/quick/qquicktextinput/data/cursorTestInline.qml @@ -6,6 +6,7 @@ Rectangle { width: 300; height: 300; color: "white" text: "Hello world!" id: textInputObject objectName: "textInputObject" + wrapMode: TextInput.WordWrap cursorDelegate: Item { id:cursorInstance objectName: "cursorInstance" diff --git a/tests/auto/quick/qquicktextinput/data/inputMethodEvent.qml b/tests/auto/quick/qquicktextinput/data/inputMethodEvent.qml index 7aefdf28f4..907ea68b10 100644 --- a/tests/auto/quick/qquicktextinput/data/inputMethodEvent.qml +++ b/tests/auto/quick/qquicktextinput/data/inputMethodEvent.qml @@ -3,4 +3,6 @@ import QtQuick 2.0 TextInput { focus: true autoScroll: false + + cursorDelegate: Item { objectName: "cursor" } } diff --git a/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp b/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp index 4f2f3cbb62..925e4f9b0d 100644 --- a/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp +++ b/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp @@ -2359,6 +2359,70 @@ void tst_qquicktextinput::cursorDelegate() textInputObject->setCursorPosition(0); QCOMPARE(textInputObject->cursorRectangle().x(), delegateObject->x()); QCOMPARE(textInputObject->cursorRectangle().y(), delegateObject->y()); + + + // Test delegate gets moved on mouse press. + textInputObject->setSelectByMouse(true); + textInputObject->setCursorPosition(0); + const QPoint point1 = textInputObject->positionToRectangle(5).center().toPoint(); + QTest::qWait(400); //ensure this isn't treated as a double-click + QTest::mouseClick(&view, Qt::LeftButton, 0, point1); + QTest::qWait(50); + QTRY_VERIFY(textInputObject->cursorPosition() != 0); + QCOMPARE(textInputObject->cursorRectangle().x(), delegateObject->x()); + QCOMPARE(textInputObject->cursorRectangle().y(), delegateObject->y()); + + // Test delegate gets moved on mouse drag + textInputObject->setCursorPosition(0); + const QPoint point2 = textInputObject->positionToRectangle(10).center().toPoint(); + QTest::qWait(400); //ensure this isn't treated as a double-click + QTest::mousePress(&view, Qt::LeftButton, 0, point1); + QMouseEvent mv(QEvent::MouseMove, point2, Qt::LeftButton, Qt::LeftButton,Qt::NoModifier); + QGuiApplication::sendEvent(&view, &mv); + QTest::mouseRelease(&view, Qt::LeftButton, 0, point2); + QTest::qWait(50); + QTRY_COMPARE(textInputObject->cursorRectangle().x(), delegateObject->x()); + QCOMPARE(textInputObject->cursorRectangle().y(), delegateObject->y()); + + textInputObject->setReadOnly(true); + textInputObject->setCursorPosition(0); + QTest::qWait(400); //ensure this isn't treated as a double-click + QTest::mouseClick(&view, Qt::LeftButton, 0, textInputObject->positionToRectangle(5).center().toPoint()); + QTest::qWait(50); + QTRY_VERIFY(textInputObject->cursorPosition() != 0); + QCOMPARE(textInputObject->cursorRectangle().x(), delegateObject->x()); + QCOMPARE(textInputObject->cursorRectangle().y(), delegateObject->y()); + + textInputObject->setCursorPosition(0); + QTest::qWait(400); //ensure this isn't treated as a double-click + QTest::mouseClick(&view, Qt::LeftButton, 0, textInputObject->positionToRectangle(5).center().toPoint()); + QTest::qWait(50); + QTRY_VERIFY(textInputObject->cursorPosition() != 0); + QCOMPARE(textInputObject->cursorRectangle().x(), delegateObject->x()); + QCOMPARE(textInputObject->cursorRectangle().y(), delegateObject->y()); + + textInputObject->setCursorPosition(0); + QCOMPARE(textInputObject->cursorRectangle().x(), delegateObject->x()); + QCOMPARE(textInputObject->cursorRectangle().y(), delegateObject->y()); + + // Delegate moved when text is entered + textInputObject->setText(QString()); + for (int i = 0; i < 20; ++i) { + QTest::keyClick(&view, Qt::Key_A); + QCOMPARE(textInputObject->cursorRectangle().x(), delegateObject->x()); + QCOMPARE(textInputObject->cursorRectangle().y(), delegateObject->y()); + } + + // Delegate moved when text is entered by im. + textInputObject->setText(QString()); + for (int i = 0; i < 20; ++i) { + QInputMethodEvent event; + event.setCommitString("a"); + QGuiApplication::sendEvent(&view, &event); + QCOMPARE(textInputObject->cursorRectangle().x(), delegateObject->x()); + QCOMPARE(textInputObject->cursorRectangle().y(), delegateObject->y()); + } + //Test Delegate gets deleted textInputObject->setCursorDelegate(0); QVERIFY(!textInputObject->findChild<QQuickItem*>("cursorInstance")); @@ -3201,18 +3265,23 @@ void tst_qquicktextinput::preeditCursorRectangle() QQuickTextInput *input = qobject_cast<QQuickTextInput *>(view.rootObject()); QVERIFY(input); - QRect currentRect; + QQuickItem *cursor = input->findChild<QQuickItem *>("cursor"); + QVERIFY(cursor); + + QRectF currentRect; QInputMethodQueryEvent query(Qt::ImCursorRectangle); QCoreApplication::sendEvent(qGuiApp->focusObject(), &query); - QRect previousRect = query.value(Qt::ImCursorRectangle).toRect(); + QRectF previousRect = query.value(Qt::ImCursorRectangle).toRectF(); // Verify that the micro focus rect is positioned the same for position 0 as // it would be if there was no preedit text. sendPreeditText(preeditText, 0); QCoreApplication::sendEvent(qGuiApp->focusObject(), &query); - currentRect = query.value(Qt::ImCursorRectangle).toRect(); + currentRect = query.value(Qt::ImCursorRectangle).toRectF(); QCOMPARE(currentRect, previousRect); + QCOMPARE(input->cursorRectangle(), currentRect); + QCOMPARE(cursor->pos(), currentRect.topLeft()); QSignalSpy inputSpy(input, SIGNAL(cursorRectangleChanged())); QSignalSpy panelSpy(qGuiApp->inputMethod(), SIGNAL(cursorRectangleChanged())); @@ -3222,8 +3291,10 @@ void tst_qquicktextinput::preeditCursorRectangle() for (int i = 1; i <= 5; ++i) { sendPreeditText(preeditText, i); QCoreApplication::sendEvent(qGuiApp->focusObject(), &query); - currentRect = query.value(Qt::ImCursorRectangle).toRect(); + currentRect = query.value(Qt::ImCursorRectangle).toRectF(); QVERIFY(previousRect.left() < currentRect.left()); + QCOMPARE(input->cursorRectangle(), currentRect); + QCOMPARE(cursor->pos(), currentRect.topLeft()); QVERIFY(inputSpy.count() > 0); inputSpy.clear(); QVERIFY(panelSpy.count() > 0); panelSpy.clear(); previousRect = currentRect; @@ -3235,8 +3306,10 @@ void tst_qquicktextinput::preeditCursorRectangle() QInputMethodEvent imEvent(preeditText, QList<QInputMethodEvent::Attribute>()); QCoreApplication::sendEvent(qGuiApp->focusObject(), &imEvent); QCoreApplication::sendEvent(qGuiApp->focusObject(), &query); - currentRect = query.value(Qt::ImCursorRectangle).toRect(); + currentRect = query.value(Qt::ImCursorRectangle).toRectF(); QCOMPARE(currentRect, previousRect); + QCOMPARE(input->cursorRectangle(), currentRect); + QCOMPARE(cursor->pos(), currentRect.topLeft()); QVERIFY(inputSpy.count() > 0); QVERIFY(panelSpy.count() > 0); } |