diff options
author | Alexis Menard <alexis.menard@nokia.com> | 2010-02-08 07:45:44 (GMT) |
---|---|---|
committer | Alexis Menard <alexis.menard@nokia.com> | 2010-02-08 07:45:44 (GMT) |
commit | 78fce53374d4aad0e51d7086268579913c19a1ac (patch) | |
tree | cce07d5037fc4f405ce8ca255d31faecfbe9fddd /tests | |
parent | e5c58224e1ebbfc6cdac3e2f611d71c6654b3642 (diff) | |
download | Qt-78fce53374d4aad0e51d7086268579913c19a1ac.zip Qt-78fce53374d4aad0e51d7086268579913c19a1ac.tar.gz Qt-78fce53374d4aad0e51d7086268579913c19a1ac.tar.bz2 |
The virtual keyboard is now working for TextEdit and TextInput components.
In order to show the virtual keyboard we need to send
RequestSoftwareInputPanel. I also fixed TextInput regarding the
inputQuery implementation.
Task-number:QTBUG-7602
Reviewed-by:akennedy
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/declarative/qmlgraphicstextedit/tst_qmlgraphicstextedit.cpp | 48 | ||||
-rw-r--r-- | tests/auto/declarative/qmlgraphicstextinput/tst_qmlgraphicstextinput.cpp | 50 |
2 files changed, 97 insertions, 1 deletions
diff --git a/tests/auto/declarative/qmlgraphicstextedit/tst_qmlgraphicstextedit.cpp b/tests/auto/declarative/qmlgraphicstextedit/tst_qmlgraphicstextedit.cpp index b684a43..99e8259 100644 --- a/tests/auto/declarative/qmlgraphicstextedit/tst_qmlgraphicstextedit.cpp +++ b/tests/auto/declarative/qmlgraphicstextedit/tst_qmlgraphicstextedit.cpp @@ -51,6 +51,8 @@ #include <private/qmlgraphicstextedit_p.h> #include <QFontMetrics> #include <QmlView> +#include <QStyle> +#include <QInputContext> class tst_qmlgraphicstextedit : public QObject @@ -79,6 +81,7 @@ private slots: void delegateLoading(); void navigation(); void readOnly(); + void sendRequestSoftwareInputPanelEvent(); private: void simulateKey(QmlView *, int key); @@ -735,11 +738,54 @@ QmlView *tst_qmlgraphicstextedit::createView(const QString &filename) file.open(QFile::ReadOnly); QString xml = file.readAll(); canvas->setQml(xml, filename); - return canvas; } +class MyInputContext : public QInputContext +{ +public: + MyInputContext() : softwareInputPanelEventReceived(false) {} + ~MyInputContext() {} + + QString identifierName() { return QString(); } + QString language() { return QString(); } + + void reset() {} + + bool isComposing() const { return false; } + bool filterEvent( const QEvent *event ) + { + if (event->type() == QEvent::RequestSoftwareInputPanel) + softwareInputPanelEventReceived = true; + return QInputContext::filterEvent(event); + } + bool softwareInputPanelEventReceived; +}; + +void tst_qmlgraphicstextedit::sendRequestSoftwareInputPanelEvent() +{ + QGraphicsScene scene; + QGraphicsView view(&scene); + MyInputContext ic; + view.viewport()->setInputContext(&ic); + QStyle::RequestSoftwareInputPanel behavior = QStyle::RequestSoftwareInputPanel( + view.style()->styleHint(QStyle::SH_RequestSoftwareInputPanel)); + if ((behavior != QStyle::RSIP_OnMouseClick)) + QSKIP("This test need to have a style with RSIP_OnMouseClick", SkipSingle); + QmlGraphicsTextEdit edit; + edit.setText("Hello world"); + edit.setPos(0, 0); + scene.addItem(&edit); + view.show(); + qApp->setAutoSipEnabled(true); + QApplication::setActiveWindow(&view); + QTest::qWaitForWindowShown(&view); + QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget *>(&view)); + QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(edit.scenePos())); + QApplication::processEvents(); + QCOMPARE(ic.softwareInputPanelEventReceived, true); +} QTEST_MAIN(tst_qmlgraphicstextedit) #include "tst_qmlgraphicstextedit.moc" diff --git a/tests/auto/declarative/qmlgraphicstextinput/tst_qmlgraphicstextinput.cpp b/tests/auto/declarative/qmlgraphicstextinput/tst_qmlgraphicstextinput.cpp index 02772ec..7223ff9 100644 --- a/tests/auto/declarative/qmlgraphicstextinput/tst_qmlgraphicstextinput.cpp +++ b/tests/auto/declarative/qmlgraphicstextinput/tst_qmlgraphicstextinput.cpp @@ -45,6 +45,8 @@ #include <QtDeclarative/qmlview.h> #include <private/qmlgraphicstextinput_p.h> #include <QDebug> +#include <QStyle> +#include <QInputContext> class tst_qmlgraphicstextinput : public QObject @@ -68,6 +70,8 @@ private slots: void navigation(); void readOnly(); + void sendRequestSoftwareInputPanelEvent(); + private: void simulateKey(QmlView *, int key); QmlView *createView(const QString &filename); @@ -501,6 +505,52 @@ QmlView *tst_qmlgraphicstextinput::createView(const QString &filename) return canvas; } +class MyInputContext : public QInputContext +{ +public: + MyInputContext() : softwareInputPanelEventReceived(false) {} + ~MyInputContext() {} + + QString identifierName() { return QString(); } + QString language() { return QString(); } + + void reset() {} + + bool isComposing() const { return false; } + + bool filterEvent( const QEvent *event ) + { + if (event->type() == QEvent::RequestSoftwareInputPanel) + softwareInputPanelEventReceived = true; + return QInputContext::filterEvent(event); + } + bool softwareInputPanelEventReceived; +}; + +void tst_qmlgraphicstextinput::sendRequestSoftwareInputPanelEvent() +{ + QGraphicsScene scene; + QGraphicsView view(&scene); + MyInputContext ic; + view.viewport()->setInputContext(&ic); + QStyle::RequestSoftwareInputPanel behavior = QStyle::RequestSoftwareInputPanel( + view.style()->styleHint(QStyle::SH_RequestSoftwareInputPanel)); + if ((behavior != QStyle::RSIP_OnMouseClick)) + QSKIP("This test need to have a style with RSIP_OnMouseClick", SkipSingle); + QmlGraphicsTextInput input; + input.setText("Hello world"); + input.setPos(0, 0); + scene.addItem(&input); + view.show(); + qApp->setAutoSipEnabled(true); + QApplication::setActiveWindow(&view); + QTest::qWaitForWindowShown(&view); + QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget *>(&view)); + QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(input.scenePos())); + QApplication::processEvents(); + QCOMPARE(ic.softwareInputPanelEventReceived, true); +} + QTEST_MAIN(tst_qmlgraphicstextinput) #include "tst_qmlgraphicstextinput.moc" |