From 8f6254a88e4c634203df779aa385d9955e91b56f Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Mon, 12 May 2014 18:09:08 +0200 Subject: TextEdit: fix cursor rectangle positioning QQuickTextControl::cursorRectangleChanged() wasn't emitted as appropriate when dragging mouse => The cursor delegate was stuck in wrong position under certain circumstances, especially when selecting multiple lines. Task-number: QTBUG-38947 Change-Id: Ib5b0d2f6ea2a1b3712fbaba4a7ad1865d2b0a74e Reviewed-by: Pierre Rossi --- .../auto/quick/qquicktextedit/data/qtbug-38947.qml | 11 +++++++++ .../quick/qquicktextedit/tst_qquicktextedit.cpp | 28 ++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 tests/auto/quick/qquicktextedit/data/qtbug-38947.qml (limited to 'tests/auto/quick/qquicktextedit') diff --git a/tests/auto/quick/qquicktextedit/data/qtbug-38947.qml b/tests/auto/quick/qquicktextedit/data/qtbug-38947.qml new file mode 100644 index 0000000000..3c8254f4ce --- /dev/null +++ b/tests/auto/quick/qquicktextedit/data/qtbug-38947.qml @@ -0,0 +1,11 @@ +import QtQuick 2.0 + +TextEdit { + text: "Hello\nWorld!" + selectByMouse: true + cursorDelegate: Rectangle { + width: 10 + color: "transparent" + border.color: "red" + } +} diff --git a/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp b/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp index 45d23abbf6..32e4a99ef0 100644 --- a/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp +++ b/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp @@ -207,6 +207,7 @@ private slots: void embeddedImages_data(); void emptytags_QTBUG_22058(); + void cursorRectangle_QTBUG_38947(); private: void simulateKeys(QWindow *window, const QList &keys); @@ -5259,6 +5260,33 @@ void tst_qquicktextedit::emptytags_QTBUG_22058() QCOMPARE(input->text(), QString("Bold<>")); } +void tst_qquicktextedit::cursorRectangle_QTBUG_38947() +{ + QQuickView window(testFileUrl("qtbug-38947.qml")); + + window.show(); + window.requestActivate(); + QTest::qWaitForWindowExposed(&window); + QQuickTextEdit *edit = qobject_cast(window.rootObject()); + QVERIFY(edit); + + QPoint from = edit->positionToRectangle(0).center().toPoint(); + QTest::mousePress(&window, Qt::LeftButton, Qt::NoModifier, from); + + QSignalSpy spy(edit, SIGNAL(cursorRectangleChanged())); + QVERIFY(spy.isValid()); + + for (int i = i; i < edit->length() - 1; ++i) { + QRectF rect = edit->positionToRectangle(i); + QTest::mouseMove(&window, rect.center().toPoint()); + QCOMPARE(edit->cursorRectangle(), rect); + QCOMPARE(spy.count(), i); + } + + QPoint to = edit->positionToRectangle(edit->length() - 1).center().toPoint(); + QTest::mouseRelease(&window, Qt::LeftButton, Qt::NoModifier, to); +} + QTEST_MAIN(tst_qquicktextedit) #include "tst_qquicktextedit.moc" -- cgit v1.2.3 From 76679048013fc70d2cb7042e32f1dd0cb4d5dfa5 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Sat, 17 May 2014 12:42:43 +0200 Subject: Fix tst_qquicktextedit::cursorRectangle_QTBUG_38947() Fix the uninitialize variable and make sure the test creates a window that has a sensible (200x200) size. Change-Id: I02616ab3c832276921e84ae98b7ed926d8fc5f5e Reviewed-by: Friedemann Kleint Reviewed-by: Liang Qi --- tests/auto/quick/qquicktextedit/data/qtbug-38947.qml | 19 ++++++++++++------- .../auto/quick/qquicktextedit/tst_qquicktextedit.cpp | 4 ++-- 2 files changed, 14 insertions(+), 9 deletions(-) (limited to 'tests/auto/quick/qquicktextedit') diff --git a/tests/auto/quick/qquicktextedit/data/qtbug-38947.qml b/tests/auto/quick/qquicktextedit/data/qtbug-38947.qml index 3c8254f4ce..ebf8080e69 100644 --- a/tests/auto/quick/qquicktextedit/data/qtbug-38947.qml +++ b/tests/auto/quick/qquicktextedit/data/qtbug-38947.qml @@ -1,11 +1,16 @@ import QtQuick 2.0 -TextEdit { - text: "Hello\nWorld!" - selectByMouse: true - cursorDelegate: Rectangle { - width: 10 - color: "transparent" - border.color: "red" +Item { + height: 200 + width: 200 + TextEdit { + objectName: "textedit" + text: "Hello\nWorld!" + selectByMouse: true + cursorDelegate: Rectangle { + width: 10 + color: "transparent" + border.color: "red" + } } } diff --git a/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp b/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp index 32e4a99ef0..1ffd67cbf1 100644 --- a/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp +++ b/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp @@ -5267,7 +5267,7 @@ void tst_qquicktextedit::cursorRectangle_QTBUG_38947() window.show(); window.requestActivate(); QTest::qWaitForWindowExposed(&window); - QQuickTextEdit *edit = qobject_cast(window.rootObject()); + QQuickTextEdit *edit = window.rootObject()->findChild("textedit"); QVERIFY(edit); QPoint from = edit->positionToRectangle(0).center().toPoint(); @@ -5276,7 +5276,7 @@ void tst_qquicktextedit::cursorRectangle_QTBUG_38947() QSignalSpy spy(edit, SIGNAL(cursorRectangleChanged())); QVERIFY(spy.isValid()); - for (int i = i; i < edit->length() - 1; ++i) { + for (int i = 1; i < edit->length() - 1; ++i) { QRectF rect = edit->positionToRectangle(i); QTest::mouseMove(&window, rect.center().toPoint()); QCOMPARE(edit->cursorRectangle(), rect); -- cgit v1.2.3