diff options
Diffstat (limited to 'tests/auto/quick/qquicktextedit')
-rw-r--r-- | tests/auto/quick/qquicktextedit/data/keys_shortcutoverride.qml | 34 | ||||
-rw-r--r-- | tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp | 60 |
2 files changed, 94 insertions, 0 deletions
diff --git a/tests/auto/quick/qquicktextedit/data/keys_shortcutoverride.qml b/tests/auto/quick/qquicktextedit/data/keys_shortcutoverride.qml new file mode 100644 index 0000000000..24bd434830 --- /dev/null +++ b/tests/auto/quick/qquicktextedit/data/keys_shortcutoverride.qml @@ -0,0 +1,34 @@ +import QtQuick 2.10 + +Item { + width: 320 + height: 200 + property string who : "nobody" + + Shortcut { + sequence: "Esc" + onActivated: who = "Shortcut" + } + + TextEdit { + id: txt + x: 100 + text: "enter text" + Keys.onShortcutOverride: { + who = "TextEdit" + event.accepted = (event.key === Qt.Key_Escape) + } + } + + Rectangle { + objectName: "rectangle" + width: 90 + height: width + focus: true + color: focus ? "red" : "gray" + Keys.onShortcutOverride: { + who = "Rectangle" + event.accepted = (event.key === Qt.Key_Escape) + } + } +} diff --git a/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp b/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp index da15ca6b48..ce2a8eb257 100644 --- a/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp +++ b/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp @@ -36,6 +36,7 @@ #include <QtQml/qqmlexpression.h> #include <QtQml/qqmlcomponent.h> #include <QtGui/qguiapplication.h> +#include <private/qquickrectangle_p.h> #include <private/qquicktextedit_p.h> #include <private/qquicktextedit_p_p.h> #include <private/qquicktext_p.h> @@ -205,6 +206,7 @@ private slots: void padding(); void QTBUG_51115_readOnlyResetsSelection(); + void keys_shortcutoverride(); private: void simulateKeys(QWindow *window, const QList<Key> &keys); @@ -1260,6 +1262,34 @@ void tst_qquicktextedit::persistentSelection() edit->setFocus(true); QCOMPARE(edit->property("selected").toString(), QLatin1String("ell")); + // QTBUG-50587 (persistentSelection with readOnly) + edit->setReadOnly(true); + + edit->setPersistentSelection(false); + QCOMPARE(edit->persistentSelection(), false); + QCOMPARE(spy.count(), 2); + + edit->select(1, 4); + QCOMPARE(edit->property("selected").toString(), QLatin1String("ell")); + + edit->setFocus(false); + QCOMPARE(edit->property("selected").toString(), QString()); + + edit->setFocus(true); + QCOMPARE(edit->property("selected").toString(), QString()); + + edit->setPersistentSelection(true); + QCOMPARE(edit->persistentSelection(), true); + QCOMPARE(spy.count(), 3); + + edit->select(1, 4); + QCOMPARE(edit->property("selected").toString(), QLatin1String("ell")); + + edit->setFocus(false); + QCOMPARE(edit->property("selected").toString(), QLatin1String("ell")); + + edit->setFocus(true); + QCOMPARE(edit->property("selected").toString(), QLatin1String("ell")); } void tst_qquicktextedit::selectionOnFocusOut() @@ -5671,6 +5701,36 @@ void tst_qquicktextedit::QTBUG_51115_readOnlyResetsSelection() QCOMPARE(obj->selectedText(), QString()); } +void tst_qquicktextedit::keys_shortcutoverride() +{ + // Tests that QML TextEdit receives Keys.onShortcutOverride (QTBUG-68711) + QQuickView view; + view.setSource(testFileUrl("keys_shortcutoverride.qml")); + view.show(); + view.requestActivate(); + QVERIFY(QTest::qWaitForWindowActive(&view)); + QObject *root = view.rootObject(); + QVERIFY(root); + + QQuickTextEdit *textEdit = root->findChild<QQuickTextEdit*>(); + QVERIFY(textEdit); + QQuickRectangle *rectangle = root->findChild<QQuickRectangle*>(QLatin1String("rectangle")); + QVERIFY(rectangle); + + // Precondition: check if its not already changed + QCOMPARE(root->property("who").value<QString>(), QLatin1String("nobody")); + + // send Key_Escape to the Rectangle + QVERIFY(rectangle->hasActiveFocus()); + QTest::keyPress(&view, Qt::Key_Escape); + QCOMPARE(root->property("who").value<QString>(), QLatin1String("Rectangle")); + + // send Key_Escape to TextEdit + textEdit->setFocus(true); + QTest::keyPress(&view, Qt::Key_Escape); + QCOMPARE(root->property("who").value<QString>(), QLatin1String("TextEdit")); +} + QTEST_MAIN(tst_qquicktextedit) #include "tst_qquicktextedit.moc" |