From 4ab22fd809a43a57bf401e68282b697d5e5fd008 Mon Sep 17 00:00:00 2001 From: Pekka Vuorela Date: Thu, 2 Feb 2012 14:58:49 +0200 Subject: [PATCH] Adapt to QGuiApplication::focusObject() for notifying input method Emitting focusObjectChanged() signal now instead of explicitly setting inputItem to QInputPanel. Also adapted from deprecated QInputPanel::inputItem() to QGuiApplication::focusObject(). Change-Id: I97460625cc8bb2820ec7716a06330aecd1b585ea Reviewed-by: Joona Petrell --- src/quick/items/qquickcanvas.cpp | 25 +++------- src/quick/items/qquickcanvas_p.h | 1 - src/quick/items/qquickitem.cpp | 3 +- .../tst_qdeclarativetextedit.cpp | 4 +- .../tst_qdeclarativetextinput.cpp | 10 ++-- .../qtquick2/qquicktextedit/tst_qquicktextedit.cpp | 49 ++++++++----------- .../qquicktextinput/tst_qquicktextinput.cpp | 56 ++++++++++------------ 7 files changed, 61 insertions(+), 87 deletions(-) diff --git a/src/quick/items/qquickcanvas.cpp b/src/quick/items/qquickcanvas.cpp index 8f4078d..ac7928f 100644 --- a/src/quick/items/qquickcanvas.cpp +++ b/src/quick/items/qquickcanvas.cpp @@ -73,7 +73,7 @@ void QQuickCanvasPrivate::updateFocusItemTransform() { Q_Q(QQuickCanvas); QQuickItem *focus = q->activeFocusItem(); - if (focus && qApp->inputPanel()->inputItem() == focus) + if (focus && qApp->focusObject() == focus) qApp->inputPanel()->setInputItemTransform(QQuickItemPrivate::get(focus)->itemToCanvasTransform()); } @@ -188,6 +188,7 @@ void QQuickCanvas::focusInEvent(QFocusEvent *) { Q_D(QQuickCanvas); d->rootItem->setFocus(true); + d->updateFocusItemTransform(); } @@ -379,7 +380,7 @@ void QQuickCanvasPrivate::setFocusInScope(QQuickItem *scope, QQuickItem *item, F QVarLengthArray changed; // Does this change the active focus? - if (item == rootItem || scopePrivate->activeFocus && item->isEnabled()) { + if (item == rootItem || (scopePrivate->activeFocus && item->isEnabled())) { oldActiveFocusItem = activeFocusItem; newActiveFocusItem = item; while (newActiveFocusItem->isFocusScope() @@ -455,14 +456,12 @@ void QQuickCanvasPrivate::setFocusInScope(QQuickItem *scope, QQuickItem *item, F afi = afi->parentItem(); } - updateInputMethodData(); - QFocusEvent event(QEvent::FocusIn, Qt::OtherFocusReason); q->sendEvent(newActiveFocusItem, &event); - } else { - updateInputMethodData(); } + emit q->focusObjectChanged(activeFocusItem); + if (!changed.isEmpty()) notifyFocusChangesRecur(changed.data(), changed.count() - 1); } @@ -541,14 +540,12 @@ void QQuickCanvasPrivate::clearFocusInScope(QQuickItem *scope, QQuickItem *item, Q_ASSERT(newActiveFocusItem == scope); activeFocusItem = scope; - updateInputMethodData(); - QFocusEvent event(QEvent::FocusIn, Qt::OtherFocusReason); q->sendEvent(newActiveFocusItem, &event); - } else { - updateInputMethodData(); } + emit q->focusObjectChanged(activeFocusItem); + if (!changed.isEmpty()) notifyFocusChangesRecur(changed.data(), changed.count() - 1); } @@ -576,14 +573,6 @@ void QQuickCanvasPrivate::notifyFocusChangesRecur(QQuickItem **items, int remain } } -void QQuickCanvasPrivate::updateInputMethodData() -{ - QQuickItem *inputItem = 0; - if (activeFocusItem && activeFocusItem->flags() & QQuickItem::ItemAcceptsInputMethod) - inputItem = activeFocusItem; - qApp->inputPanel()->setInputItem(inputItem); -} - void QQuickCanvasPrivate::dirtyItem(QQuickItem *) { Q_Q(QQuickCanvas); diff --git a/src/quick/items/qquickcanvas_p.h b/src/quick/items/qquickcanvas_p.h index fe57fd1..d5021d8 100644 --- a/src/quick/items/qquickcanvas_p.h +++ b/src/quick/items/qquickcanvas_p.h @@ -143,7 +143,6 @@ public: void clearFocusInScope(QQuickItem *scope, QQuickItem *item, FocusOptions = 0); void notifyFocusChangesRecur(QQuickItem **item, int remaining); - void updateInputMethodData(); void updateFocusItemTransform(); void dirtyItem(QQuickItem *); diff --git a/src/quick/items/qquickitem.cpp b/src/quick/items/qquickitem.cpp index 5151310..cc1705f 100644 --- a/src/quick/items/qquickitem.cpp +++ b/src/quick/items/qquickitem.cpp @@ -3077,8 +3077,7 @@ void QQuickItem::setInputMethodHints(Qt::InputMethodHints hints) if (!d->canvas || d->canvas->activeFocusItem() != this) return; - QInputPanel *p = qApp->inputPanel(); - if (p->inputItem() == this) + if (qApp->focusObject() == this) qApp->inputPanel()->update(Qt::ImHints); } diff --git a/tests/auto/qtquick1/qdeclarativetextedit/tst_qdeclarativetextedit.cpp b/tests/auto/qtquick1/qdeclarativetextedit/tst_qdeclarativetextedit.cpp index 0639157..4ad3efd 100644 --- a/tests/auto/qtquick1/qdeclarativetextedit/tst_qdeclarativetextedit.cpp +++ b/tests/auto/qtquick1/qdeclarativetextedit/tst_qdeclarativetextedit.cpp @@ -86,7 +86,7 @@ void sendPreeditText(const QString &text, int cursor) attributes.append(QInputMethodEvent::Attribute(QInputMethodEvent::Cursor, cursor, text.length(), QVariant())); QInputMethodEvent event(text, attributes); - QApplication::sendEvent(qApp->inputPanel()->inputItem(), &event); + QApplication::sendEvent(qApp->focusObject(), &event); } @@ -2433,7 +2433,7 @@ void tst_qdeclarativetextedit::preeditMicroFocus() sendPreeditText(preeditText, 0); ic.clear(); QInputMethodEvent imEvent(preeditText, QList()); - QApplication::sendEvent(qApp->inputPanel()->inputItem(), &imEvent); + QApplication::sendEvent(qApp->focusObject(), &imEvent); currentRect = edit.inputMethodQuery(Qt::ImMicroFocus).toRect(); QCOMPARE(currentRect, previousRect); #if defined(Q_WS_X11) || defined(Q_WS_QWS) diff --git a/tests/auto/qtquick1/qdeclarativetextinput/tst_qdeclarativetextinput.cpp b/tests/auto/qtquick1/qdeclarativetextinput/tst_qdeclarativetextinput.cpp index 221d38a..ece6818 100644 --- a/tests/auto/qtquick1/qdeclarativetextinput/tst_qdeclarativetextinput.cpp +++ b/tests/auto/qtquick1/qdeclarativetextinput/tst_qdeclarativetextinput.cpp @@ -79,7 +79,7 @@ void sendPreeditText(const QString &text, int cursor) attributes.append(QInputMethodEvent::Attribute(QInputMethodEvent::Cursor, cursor, text.length(), QVariant())); QInputMethodEvent event(text, attributes); - QApplication::sendEvent(qApp->inputPanel()->inputItem(), &event); + QApplication::sendEvent(qApp->focusObject(), &event); } @@ -2634,7 +2634,7 @@ void tst_qdeclarativetextinput::preeditMicroFocus() sendPreeditText(preeditText, 0); ic.clear(); QInputMethodEvent imEvent(preeditText, QList()); - QApplication::sendEvent(qApp->inputPanel()->inputItem(), &imEvent); + QApplication::sendEvent(qApp->focusObject(), &imEvent); currentRect = input.inputMethodQuery(Qt::ImMicroFocus).toRect(); QCOMPARE(currentRect, previousRect); #if defined(Q_WS_X11) || defined(Q_WS_QWS) @@ -2705,7 +2705,7 @@ void tst_qdeclarativetextinput::inputMethodComposing() { QInputMethodEvent inputEvent(text.mid(3), QList()); - QApplication::sendEvent(qApp->inputPanel()->inputItem(), &inputEvent); + QApplication::sendEvent(qApp->focusObject(), &inputEvent); } QCOMPARE(input.isInputMethodComposing(), true); @@ -2713,7 +2713,7 @@ void tst_qdeclarativetextinput::inputMethodComposing() { QInputMethodEvent inputEvent(text.mid(12), QList()); - QApplication::sendEvent(qApp->inputPanel()->inputItem(), &inputEvent); + QApplication::sendEvent(qApp->focusObject(), &inputEvent); } QCOMPARE(input.isInputMethodComposing(), true); @@ -2721,7 +2721,7 @@ void tst_qdeclarativetextinput::inputMethodComposing() { QInputMethodEvent inputEvent; - QApplication::sendEvent(qApp->inputPanel()->inputItem(), &inputEvent); + QApplication::sendEvent(qApp->focusObject(), &inputEvent); } QCOMPARE(input.isInputMethodComposing(), false); QCOMPARE(spy.count(), 2); diff --git a/tests/auto/qtquick2/qquicktextedit/tst_qquicktextedit.cpp b/tests/auto/qtquick2/qquicktextedit/tst_qquicktextedit.cpp index 07b8f10..7fd14fe 100644 --- a/tests/auto/qtquick2/qquicktextedit/tst_qquicktextedit.cpp +++ b/tests/auto/qtquick2/qquicktextedit/tst_qquicktextedit.cpp @@ -722,14 +722,14 @@ void tst_qquicktextedit::hAlign_RightToLeft() QTRY_COMPARE(&canvas, qGuiApp->focusWindow()); textEdit->setText(QString()); - { QInputMethodEvent ev(rtlText, QList()); QGuiApplication::sendEvent(qGuiApp->inputPanel()->inputItem(), &ev); } + { QInputMethodEvent ev(rtlText, QList()); QGuiApplication::sendEvent(qGuiApp->focusObject(), &ev); } QCOMPARE(textEdit->hAlign(), QQuickTextEdit::AlignRight); - { QInputMethodEvent ev("Hello world!", QList()); QGuiApplication::sendEvent(qGuiApp->inputPanel()->inputItem(), &ev); } + { QInputMethodEvent ev("Hello world!", QList()); QGuiApplication::sendEvent(qGuiApp->focusObject(), &ev); } QCOMPARE(textEdit->hAlign(), QQuickTextEdit::AlignLeft); // Clear pre-edit text. TextEdit should maybe do this itself on setText, but that may be // redundant as an actual input method may take care of it. - { QInputMethodEvent ev; QGuiApplication::sendEvent(qGuiApp->inputPanel()->inputItem(), &ev); } + { QInputMethodEvent ev; QGuiApplication::sendEvent(qGuiApp->focusObject(), &ev); } // empty text with implicit alignment follows the system locale-based // keyboard input direction from qApp->inputPanel()->inputDirection @@ -1738,7 +1738,7 @@ void tst_qquicktextedit::positionAt() texteditObject->setCursorPosition(0); QInputMethodEvent inputEvent(preeditText, QList()); - QGuiApplication::sendEvent(qGuiApp->inputPanel()->inputItem(), &inputEvent); + QGuiApplication::sendEvent(qGuiApp->focusObject(), &inputEvent); // Check all points within the preedit text return the same position. QCOMPARE(texteditObject->positionAt(0, y0), 0); @@ -2138,7 +2138,7 @@ void tst_qquicktextedit::textInput() QSignalSpy spy(edit, SIGNAL(textChanged())); QInputMethodEvent event; event.setCommitString( "Hello world!", 0, 0); - QGuiApplication::sendEvent(qGuiApp->inputPanel()->inputItem(), &event); + QGuiApplication::sendEvent(qGuiApp->focusObject(), &event); QCOMPARE(edit->text(), QString("Hello world!")); QCOMPARE(spy.count(), 1); @@ -2153,12 +2153,12 @@ void tst_qquicktextedit::textInput() QList attributes; QInputMethodEvent event2("preedit", attributes); event2.setTentativeCommitString("string"); - QGuiApplication::sendEvent(qGuiApp->inputPanel()->inputItem(), &event2); + QGuiApplication::sendEvent(qGuiApp->focusObject(), &event2); QCOMPARE(spy.count(), 1); QCOMPARE(edit->text(), QString("string")); QInputMethodQueryEvent queryEvent(Qt::ImEnabled); - QGuiApplication::sendEvent(qGuiApp->inputPanel()->inputItem(), &queryEvent); + QGuiApplication::sendEvent(qGuiApp->focusObject(), &queryEvent); QCOMPARE(queryEvent.value(Qt::ImEnabled).toBool(), true); edit->setReadOnly(true); @@ -2270,8 +2270,8 @@ void tst_qquicktextedit::openInputPanel() // check default values QVERIFY(edit->focusOnPress()); QVERIFY(!edit->hasActiveFocus()); - qDebug() << &edit << qApp->inputPanel()->inputItem(); - QCOMPARE(qApp->inputPanel()->inputItem(), static_cast(0)); + qDebug() << &edit << qApp->focusObject(); + QVERIFY(qApp->focusObject() != edit); QCOMPARE(qApp->inputPanel()->visible(), false); @@ -2281,7 +2281,7 @@ void tst_qquicktextedit::openInputPanel() QTest::mousePress(&view, Qt::LeftButton, noModifiers, centerPoint); QGuiApplication::processEvents(); QVERIFY(edit->hasActiveFocus()); - QCOMPARE(qApp->inputPanel()->inputItem(), edit); + QCOMPARE(qApp->focusObject(), edit); QCOMPARE(qApp->inputPanel()->visible(), true); QTest::mouseRelease(&view, Qt::LeftButton, noModifiers, centerPoint); @@ -2300,21 +2300,14 @@ void tst_qquicktextedit::openInputPanel() anotherEdit.setParentItem(view.rootObject()); anotherEdit.setFocus(true); QCOMPARE(qApp->inputPanel()->visible(), true); - QCOMPARE(qApp->inputPanel()->inputItem(), qobject_cast(&anotherEdit)); + QCOMPARE(qApp->focusObject(), qobject_cast(&anotherEdit)); QCOMPARE(inputPanelVisibilitySpy.count(), 0); anotherEdit.setFocus(false); - QCOMPARE(qApp->inputPanel()->inputItem(), static_cast(0)); + QVERIFY(qApp->focusObject() != &anotherEdit); QCOMPARE(view.activeFocusItem(), view.rootItem()); anotherEdit.setFocus(true); - // input item should be null if focus is lost to an item that doesn't accept inputs - QQuickItem item; - item.setParentItem(view.rootObject()); - item.setFocus(true); - QCOMPARE(qApp->inputPanel()->inputItem(), static_cast(0)); - QCOMPARE(view.activeFocusItem(), &item); - qApp->inputPanel()->hide(); // input panel should not be opened if TextEdit is read only @@ -2474,15 +2467,15 @@ void tst_qquicktextedit::preeditCursorRectangle() QRect currentRect; QInputMethodQueryEvent query(Qt::ImCursorRectangle); - QCoreApplication::sendEvent(qGuiApp->inputPanel()->inputItem(), &query); + QCoreApplication::sendEvent(qGuiApp->focusObject(), &query); QRect previousRect = query.value(Qt::ImCursorRectangle).toRect(); // Verify that the micro focus rect is positioned the same for position 0 as // it would be if there was no preedit text. QInputMethodEvent imEvent(preeditText, QList() << QInputMethodEvent::Attribute(QInputMethodEvent::Cursor, 0, preeditText.length(), QVariant())); - QCoreApplication::sendEvent(qGuiApp->inputPanel()->inputItem(), &imEvent); - QCoreApplication::sendEvent(qGuiApp->inputPanel()->inputItem(), &query); + QCoreApplication::sendEvent(qGuiApp->focusObject(), &imEvent); + QCoreApplication::sendEvent(qGuiApp->focusObject(), &query); currentRect = query.value(Qt::ImCursorRectangle).toRect(); QCOMPARE(currentRect, previousRect); QCOMPARE(editSpy.count(), 0); @@ -2493,8 +2486,8 @@ void tst_qquicktextedit::preeditCursorRectangle() for (int i = 1; i <= 5; ++i) { QInputMethodEvent imEvent(preeditText, QList() << QInputMethodEvent::Attribute(QInputMethodEvent::Cursor, i, preeditText.length(), QVariant())); - QCoreApplication::sendEvent(qGuiApp->inputPanel()->inputItem(), &imEvent); - QCoreApplication::sendEvent(qGuiApp->inputPanel()->inputItem(), &query); + QCoreApplication::sendEvent(qGuiApp->focusObject(), &imEvent); + QCoreApplication::sendEvent(qGuiApp->focusObject(), &query); currentRect = query.value(Qt::ImCursorRectangle).toRect(); QVERIFY(previousRect.left() < currentRect.left()); QVERIFY(editSpy.count() > 0); editSpy.clear(); @@ -2504,12 +2497,12 @@ void tst_qquicktextedit::preeditCursorRectangle() // Verify that if there is no preedit cursor then the micro focus rect is the // same as it would be if it were positioned at the end of the preedit text. - QCoreApplication::sendEvent(qGuiApp->inputPanel()->inputItem(), &imEvent); + QCoreApplication::sendEvent(qGuiApp->focusObject(), &imEvent); editSpy.clear(); panelSpy.clear(); { QInputMethodEvent imEvent(preeditText, QList()); - QCoreApplication::sendEvent(qGuiApp->inputPanel()->inputItem(), &imEvent); } - QCoreApplication::sendEvent(qGuiApp->inputPanel()->inputItem(), &query); + QCoreApplication::sendEvent(qGuiApp->focusObject(), &imEvent); } + QCoreApplication::sendEvent(qGuiApp->focusObject(), &query); currentRect = query.value(Qt::ImCursorRectangle).toRect(); QCOMPARE(currentRect, previousRect); QVERIFY(editSpy.count() > 0); @@ -2571,7 +2564,7 @@ void tst_qquicktextedit::cursorRectangleSize() QTest::qWaitForWindowShown(canvas); QInputMethodQueryEvent event(Qt::ImCursorRectangle); - qApp->sendEvent(qApp->inputPanel()->inputItem(), &event); + qApp->sendEvent(qApp->focusObject(), &event); QRectF cursorRectFromQuery = event.value(Qt::ImCursorRectangle).toRectF(); QRect cursorRectFromItem = textEdit->cursorRectangle(); diff --git a/tests/auto/qtquick2/qquicktextinput/tst_qquicktextinput.cpp b/tests/auto/qtquick2/qquicktextinput/tst_qquicktextinput.cpp index 5e45214..0ff3f79 100644 --- a/tests/auto/qtquick2/qquicktextinput/tst_qquicktextinput.cpp +++ b/tests/auto/qtquick2/qquicktextinput/tst_qquicktextinput.cpp @@ -1351,14 +1351,14 @@ void tst_qquicktextinput::horizontalAlignment_RightToLeft() // If there is no commited text, the preedit text should determine the alignment. textInput->setText(QString()); - { QInputMethodEvent ev(rtlText, QList()); QGuiApplication::sendEvent(qGuiApp->inputPanel()->inputItem(), &ev); } + { QInputMethodEvent ev(rtlText, QList()); QGuiApplication::sendEvent(qGuiApp->focusObject(), &ev); } QCOMPARE(textInput->hAlign(), QQuickTextInput::AlignRight); - { QInputMethodEvent ev("Hello world!", QList()); QGuiApplication::sendEvent(qGuiApp->inputPanel()->inputItem(), &ev); } + { QInputMethodEvent ev("Hello world!", QList()); QGuiApplication::sendEvent(qGuiApp->focusObject(), &ev); } QCOMPARE(textInput->hAlign(), QQuickTextInput::AlignLeft); // Clear pre-edit text. TextInput should maybe do this itself on setText, but that may be // redundant as an actual input method may take care of it. - { QInputMethodEvent ev; QGuiApplication::sendEvent(qGuiApp->inputPanel()->inputItem(), &ev); } + { QInputMethodEvent ev; QGuiApplication::sendEvent(qGuiApp->focusObject(), &ev); } // empty text with implicit alignment follows the system locale-based // keyboard input direction from QInputPanel::inputDirection() @@ -1520,7 +1520,7 @@ void tst_qquicktextinput::positionAt() textinputObject->setCursorPosition(0); { QInputMethodEvent inputEvent(preeditText, QList()); - QGuiApplication::sendEvent(qGuiApp->inputPanel()->inputItem(), &inputEvent); } + QGuiApplication::sendEvent(qGuiApp->focusObject(), &inputEvent); } // Check all points within the preedit text return the same position. QCOMPARE(evaluate(textinputObject, QString("positionAt(%1)").arg(0)), 0); @@ -1532,7 +1532,7 @@ void tst_qquicktextinput::positionAt() QCOMPARE(textinputObject->positionToRectangle(1).x(), x1); { QInputMethodEvent inputEvent; - QGuiApplication::sendEvent(qGuiApp->inputPanel()->inputItem(), &inputEvent); } + QGuiApplication::sendEvent(qGuiApp->focusObject(), &inputEvent); } // With wrapping. textinputObject->setWrapMode(QQuickTextInput::WrapAnywhere); @@ -1946,24 +1946,24 @@ void tst_qquicktextinput::inputMethods() // test that input method event is committed QInputMethodEvent event; event.setCommitString( "My ", -12, 0); - QGuiApplication::sendEvent(qGuiApp->inputPanel()->inputItem(), &event); + QGuiApplication::sendEvent(qGuiApp->focusObject(), &event); QCOMPARE(input->text(), QString("My Hello world!")); input->setCursorPosition(2); event.setCommitString("Your", -2, 2); - QGuiApplication::sendEvent(qGuiApp->inputPanel()->inputItem(), &event); + QGuiApplication::sendEvent(qGuiApp->focusObject(), &event); QCOMPARE(input->text(), QString("Your Hello world!")); QCOMPARE(input->cursorPosition(), 4); input->setCursorPosition(7); event.setCommitString("Goodbye", -2, 5); - QGuiApplication::sendEvent(qGuiApp->inputPanel()->inputItem(), &event); + QGuiApplication::sendEvent(qGuiApp->focusObject(), &event); QCOMPARE(input->text(), QString("Your Goodbye world!")); QCOMPARE(input->cursorPosition(), 12); input->setCursorPosition(8); event.setCommitString("Our", -8, 4); - QGuiApplication::sendEvent(qGuiApp->inputPanel()->inputItem(), &event); + QGuiApplication::sendEvent(qGuiApp->focusObject(), &event); QCOMPARE(input->text(), QString("Our Goodbye world!")); QCOMPARE(input->cursorPosition(), 7); @@ -1994,7 +1994,7 @@ void tst_qquicktextinput::inputMethods() input->setCursorPosition(0); input->moveCursorSelection(input->text().length()); event.setCommitString("replacement", -input->text().length(), input->text().length()); - QGuiApplication::sendEvent(qGuiApp->inputPanel()->inputItem(), &event); + QGuiApplication::sendEvent(qGuiApp->focusObject(), &event); QCOMPARE(input->selectionStart(), input->selectionEnd()); QInputMethodQueryEvent enabledQueryEvent(Qt::ImEnabled); @@ -2619,7 +2619,7 @@ void tst_qquicktextinput::passwordEchoDelay() QInputMethodEvent ev; ev.setCommitString(QLatin1String("7")); - QGuiApplication::sendEvent(qGuiApp->inputPanel()->inputItem(), &ev); + QGuiApplication::sendEvent(qGuiApp->focusObject(), &ev); QCOMPARE(input->displayText(), QString(7, fillChar) + QLatin1Char('7')); input->setCursorPosition(3); @@ -2660,7 +2660,7 @@ void tst_qquicktextinput::openInputPanel() // check default values QVERIFY(input->focusOnPress()); QVERIFY(!input->hasActiveFocus()); - QCOMPARE(qApp->inputPanel()->inputItem(), static_cast(0)); + QVERIFY(qApp->focusObject() != input); QCOMPARE(qApp->inputPanel()->visible(), false); // input panel should open on focus @@ -2669,7 +2669,7 @@ void tst_qquicktextinput::openInputPanel() QTest::mousePress(&view, Qt::LeftButton, noModifiers, centerPoint); QGuiApplication::processEvents(); QVERIFY(input->hasActiveFocus()); - QCOMPARE(qApp->inputPanel()->inputItem(), input); + QCOMPARE(qApp->focusObject(), input); QCOMPARE(qApp->inputPanel()->visible(), true); QTest::mouseRelease(&view, Qt::LeftButton, noModifiers, centerPoint); @@ -2689,21 +2689,14 @@ void tst_qquicktextinput::openInputPanel() anotherInput.setParentItem(view.rootObject()); anotherInput.setFocus(true); QCOMPARE(qApp->inputPanel()->visible(), true); - QCOMPARE(qApp->inputPanel()->inputItem(), qobject_cast(&anotherInput)); + QCOMPARE(qApp->focusObject(), qobject_cast(&anotherInput)); QCOMPARE(inputPanelVisibilitySpy.count(), 0); anotherInput.setFocus(false); - QCOMPARE(qApp->inputPanel()->inputItem(), static_cast(0)); + QVERIFY(qApp->focusObject() != &anotherInput); QCOMPARE(view.activeFocusItem(), view.rootItem()); anotherInput.setFocus(true); - // input item should be null if focus is lost to an item that doesn't accept inputs - QQuickItem item; - item.setParentItem(view.rootObject()); - item.setFocus(true); - QCOMPARE(qApp->inputPanel()->inputItem(), static_cast(0)); - QCOMPARE(view.activeFocusItem(), &item); - qApp->inputPanel()->hide(); // input panel should not be opened if TextInput is read only @@ -2846,7 +2839,7 @@ static void sendPreeditText(const QString &text, int cursor) { QInputMethodEvent event(text, QList() << QInputMethodEvent::Attribute(QInputMethodEvent::Cursor, cursor, text.length(), QVariant())); - QCoreApplication::sendEvent(qGuiApp->inputPanel()->inputItem(), &event); + QCoreApplication::sendEvent(qGuiApp->focusObject(), &event); } void tst_qquicktextinput::preeditAutoScroll() @@ -2875,7 +2868,7 @@ void tst_qquicktextinput::preeditAutoScroll() // test the text is scrolled back when the preedit is removed. QInputMethodEvent imEvent; - QCoreApplication::sendEvent(qGuiApp->inputPanel()->inputItem(), &imEvent); + QCoreApplication::sendEvent(qGuiApp->focusObject(), &imEvent); QCOMPARE(evaluate(input, QString("positionAt(%1)").arg(0)), 0); QCOMPARE(evaluate(input, QString("positionAt(%1)").arg(input->width())), 5); QCOMPARE(cursorRectangleSpy.count(), ++cursorRectangleChanges); @@ -2928,7 +2921,7 @@ void tst_qquicktextinput::preeditAutoScroll() } // Test disabling auto scroll. - QCoreApplication::sendEvent(qGuiApp->inputPanel()->inputItem(), &imEvent); + QCoreApplication::sendEvent(qGuiApp->focusObject(), &imEvent); input->setAutoScroll(false); sendPreeditText(preeditText.mid(0, 3), 1); @@ -2951,13 +2944,13 @@ void tst_qquicktextinput::preeditCursorRectangle() QRect currentRect; QInputMethodQueryEvent query(Qt::ImCursorRectangle); - QCoreApplication::sendEvent(qGuiApp->inputPanel()->inputItem(), &query); + QCoreApplication::sendEvent(qGuiApp->focusObject(), &query); QRect previousRect = query.value(Qt::ImCursorRectangle).toRect(); // Verify that the micro focus rect is positioned the same for position 0 as // it would be if there was no preedit text. sendPreeditText(preeditText, 0); - QCoreApplication::sendEvent(qGuiApp->inputPanel()->inputItem(), &query); + QCoreApplication::sendEvent(qGuiApp->focusObject(), &query); currentRect = query.value(Qt::ImCursorRectangle).toRect(); QCOMPARE(currentRect, previousRect); @@ -2968,7 +2961,7 @@ void tst_qquicktextinput::preeditCursorRectangle() // is incremented. for (int i = 1; i <= 5; ++i) { sendPreeditText(preeditText, i); - QCoreApplication::sendEvent(qGuiApp->inputPanel()->inputItem(), &query); + QCoreApplication::sendEvent(qGuiApp->focusObject(), &query); currentRect = query.value(Qt::ImCursorRectangle).toRect(); QVERIFY(previousRect.left() < currentRect.left()); QVERIFY(inputSpy.count() > 0); inputSpy.clear(); @@ -2980,8 +2973,8 @@ void tst_qquicktextinput::preeditCursorRectangle() // same as it would be if it were positioned at the end of the preedit text. sendPreeditText(preeditText, 0); QInputMethodEvent imEvent(preeditText, QList()); - QCoreApplication::sendEvent(qGuiApp->inputPanel()->inputItem(), &imEvent); - QCoreApplication::sendEvent(qGuiApp->inputPanel()->inputItem(), &query); + QCoreApplication::sendEvent(qGuiApp->focusObject(), &imEvent); + QCoreApplication::sendEvent(qGuiApp->focusObject(), &query); currentRect = query.value(Qt::ImCursorRectangle).toRect(); QCOMPARE(currentRect, previousRect); QVERIFY(inputSpy.count() > 0); @@ -3169,9 +3162,10 @@ void tst_qquicktextinput::cursorRectangleSize() canvas->show(); canvas->requestActivateWindow(); QTest::qWaitForWindowShown(canvas); + QTRY_VERIFY(qApp->focusObject()); QInputMethodQueryEvent event(Qt::ImCursorRectangle); - qApp->sendEvent(qApp->inputPanel()->inputItem(), &event); + qApp->sendEvent(qApp->focusObject(), &event); QRectF cursorRectFromQuery = event.value(Qt::ImCursorRectangle).toRectF(); QRect cursorRectFromItem = textInput->cursorRectangle(); -- 2.7.4