aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/quick/qquicktextedit
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@qt.io>2016-09-14 10:48:36 +0200
committerMitch Curtis <mitch.curtis@qt.io>2016-11-12 16:15:30 +0000
commit769002ffe4a93995447a71393371579b1df41e12 (patch)
treea41a7e41131c563b1040f33b115254ea1fe7a6d4 /tests/auto/quick/qquicktextedit
parenta7c24b49fd7ac1a1c2ce7a5671cfae6c9f3351fa (diff)
TextEdit: set cursor delegate's height to match the selected font
RichText can have blocks of text with varying font sizes, so we must ensure that the cursor delegate's height is also set when it's moved to a different position in the text. Change-Id: I00691a94a2360c7d3272571fc4ba0da28b01006a Task-number: QTBUG-54934 Reviewed-by: J-P Nurmi <jpnurmi@qt.io>
Diffstat (limited to 'tests/auto/quick/qquicktextedit')
-rw-r--r--tests/auto/quick/qquicktextedit/data/cursorHeight.qml20
-rw-r--r--tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp38
2 files changed, 58 insertions, 0 deletions
diff --git a/tests/auto/quick/qquicktextedit/data/cursorHeight.qml b/tests/auto/quick/qquicktextedit/data/cursorHeight.qml
new file mode 100644
index 0000000000..b831a9eb6f
--- /dev/null
+++ b/tests/auto/quick/qquicktextedit/data/cursorHeight.qml
@@ -0,0 +1,20 @@
+import QtQuick 2.0
+
+Rectangle {
+ width: 300
+ height: 300
+ color: "white"
+
+ TextEdit {
+ objectName: "textEditObject"
+ width: 300
+ height: 300
+ text: "<span style=\"font-size:20pt;\">Blah</span><br>blah"
+ textFormat: TextEdit.RichText
+ cursorDelegate: Rectangle {
+ objectName: "cursorInstance"
+ color: "red"
+ width: 2
+ }
+ }
+}
diff --git a/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp b/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp
index cb2a7bfd83..fa5a0a254d 100644
--- a/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp
+++ b/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp
@@ -139,6 +139,7 @@ private slots:
void cursorVisible();
void delegateLoading_data();
void delegateLoading();
+ void cursorDelegateHeight();
void navigation();
void readOnly();
#ifndef QT_NO_CLIPBOARD
@@ -2779,6 +2780,43 @@ void tst_qquicktextedit::delegateLoading()
//QVERIFY(!delegate);
}
+void tst_qquicktextedit::cursorDelegateHeight()
+{
+ QQuickView view(testFileUrl("cursorHeight.qml"));
+ view.show();
+ view.requestActivate();
+ QTest::qWaitForWindowActive(&view);
+ QQuickTextEdit *textEditObject = view.rootObject()->findChild<QQuickTextEdit*>("textEditObject");
+ QVERIFY(textEditObject);
+ // Delegate creation is deferred until focus in or cursor visibility is forced.
+ QVERIFY(!textEditObject->findChild<QQuickItem*>("cursorInstance"));
+ QVERIFY(!textEditObject->isCursorVisible());
+
+ // Test that the delegate gets created.
+ textEditObject->setFocus(true);
+ QVERIFY(textEditObject->isCursorVisible());
+ QQuickItem* delegateObject = textEditObject->findChild<QQuickItem*>("cursorInstance");
+ QVERIFY(delegateObject);
+
+ const int largerHeight = textEditObject->cursorRectangle().height();
+
+ textEditObject->setCursorPosition(0);
+ QCOMPARE(delegateObject->x(), textEditObject->cursorRectangle().x());
+ QCOMPARE(delegateObject->y(), textEditObject->cursorRectangle().y());
+ QCOMPARE(delegateObject->height(), textEditObject->cursorRectangle().height());
+
+ // Move the cursor to the next line, which has a smaller font.
+ textEditObject->setCursorPosition(5);
+ QCOMPARE(delegateObject->x(), textEditObject->cursorRectangle().x());
+ QCOMPARE(delegateObject->y(), textEditObject->cursorRectangle().y());
+ QVERIFY(textEditObject->cursorRectangle().height() < largerHeight);
+ QCOMPARE(delegateObject->height(), textEditObject->cursorRectangle().height());
+
+ // Test that the delegate gets deleted
+ textEditObject->setCursorDelegate(0);
+ QVERIFY(!textEditObject->findChild<QQuickItem*>("cursorInstance"));
+}
+
/*
TextEdit element should only handle left/right keys until the cursor reaches
the extent of the text, then they should ignore the keys.