diff options
author | J-P Nurmi <jpnurmi@digia.com> | 2014-05-16 14:35:23 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-05-21 13:11:18 +0200 |
commit | dc5f86c8ffc2d6d13d00f2bb68373f66c91525c0 (patch) | |
tree | 9f3e869f8b1e10b27b85ba7f3f3c4be957ca4abc /tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp | |
parent | a7122f3b2832ad65cfd0ab0ce0315a7042ee9f92 (diff) |
Introduce TextInput::ensureVisible(int position)
This is required for TextField to be able to implement text selection
handles. TextField needs to be able to ensure that the appropriate
character position becomes visible when the handles are moved around.
[ChangeLog][QtQuick][TextInput] Added TextInput::ensureVisible(int pos)
method to be able to control the scrolling position of a TextInput that
has automatic scrolling enabled.
Task-number: QTBUG-38934
Change-Id: Id77eafcda6324d10868e0798519e5b712a0d33ed
Reviewed-by: Alan Alpert <aalpert@blackberry.com>
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@digia.com>
Diffstat (limited to 'tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp')
-rw-r--r-- | tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp b/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp index 8451b527ce..fc1be16bc8 100644 --- a/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp +++ b/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp @@ -232,6 +232,8 @@ private slots: void baselineOffset_data(); void baselineOffset(); + void ensureVisible(); + private: void simulateKey(QWindow *, int key); @@ -6464,6 +6466,50 @@ void tst_qquicktextinput::baselineOffset() } } +void tst_qquicktextinput::ensureVisible() +{ + QQmlComponent component(&engine); + component.setData("import QtQuick 2.0\n TextInput {}", QUrl()); + QScopedPointer<QObject> object(component.create()); + QQuickTextInput *input = qobject_cast<QQuickTextInput *>(object.data()); + QVERIFY(input); + + input->setWidth(QFontMetrics(input->font()).averageCharWidth() * 3); + input->setText("Hello World"); + + QTextLayout layout; + layout.setText(input->text()); + layout.setFont(input->font()); + + if (!qmlDisableDistanceField()) { + QTextOption option; + option.setUseDesignMetrics(true); + layout.setTextOption(option); + } + layout.beginLayout(); + QTextLine line = layout.createLine(); + layout.endLayout(); + + input->ensureVisible(0); + + QCOMPARE(input->boundingRect().x(), qreal(0)); + QCOMPARE(input->boundingRect().y(), qreal(0)); + QCOMPARE(input->boundingRect().width(), line.naturalTextWidth() + input->cursorRectangle().width()); + QCOMPARE(input->boundingRect().height(), line.height()); + + QSignalSpy cursorSpy(input, SIGNAL(cursorRectangleChanged())); + QVERIFY(cursorSpy.isValid()); + + input->ensureVisible(input->length()); + + QCOMPARE(cursorSpy.count(), 1); + + QCOMPARE(input->boundingRect().x(), input->width() - line.naturalTextWidth()); + QCOMPARE(input->boundingRect().y(), qreal(0)); + QCOMPARE(input->boundingRect().width(), line.naturalTextWidth() + input->cursorRectangle().width()); + QCOMPARE(input->boundingRect().height(), line.height()); +} + QTEST_MAIN(tst_qquicktextinput) #include "tst_qquicktextinput.moc" |