aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/quick/qquicktextedit
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@digia.com>2014-05-12 18:09:08 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-05-16 14:40:21 +0200
commit8f6254a88e4c634203df779aa385d9955e91b56f (patch)
tree6b6a629467163b5119a8e830708a753f5e3bc469 /tests/auto/quick/qquicktextedit
parentb24cc8dc5acf2ce79f942b28debc0feedb43ac19 (diff)
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 <pierre.rossi@gmail.com>
Diffstat (limited to 'tests/auto/quick/qquicktextedit')
-rw-r--r--tests/auto/quick/qquicktextedit/data/qtbug-38947.qml11
-rw-r--r--tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp28
2 files changed, 39 insertions, 0 deletions
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<Key> &keys);
@@ -5259,6 +5260,33 @@ void tst_qquicktextedit::emptytags_QTBUG_22058()
QCOMPARE(input->text(), QString("<b>Bold<>"));
}
+void tst_qquicktextedit::cursorRectangle_QTBUG_38947()
+{
+ QQuickView window(testFileUrl("qtbug-38947.qml"));
+
+ window.show();
+ window.requestActivate();
+ QTest::qWaitForWindowExposed(&window);
+ QQuickTextEdit *edit = qobject_cast<QQuickTextEdit *>(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"