From a3a0b0373540fa2ee9a2b85e5d394fb03e879483 Mon Sep 17 00:00:00 2001 From: Pekka Vuorela Date: Tue, 17 Jan 2012 16:19:34 +0200 Subject: [PATCH] QWidget editors to return correct value for Qt::ImEnabled Qt::ImEnabled input method query was added for Qt5. Enhancing source compatibility with Qt4 by setting query value in QWidget if widget does not return any valid value. Change-Id: I274c1f6c47a5cb08ecf550b25e5b358622e21d90 Reviewed-by: Lars Knoll Reviewed-by: Joona Petrell --- src/widgets/kernel/qwidget.cpp | 2 ++ tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp | 13 +++++++++++++ tests/auto/widgets/widgets/qtextedit/tst_qtextedit.cpp | 7 ++++++- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index 531a217..d6e85be 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -7929,6 +7929,8 @@ bool QWidget::event(QEvent *event) Qt::InputMethodQuery q = (Qt::InputMethodQuery)(int)(queries & (1<setValue(q, v); } } diff --git a/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp b/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp index 1fabc45..0e7186d 100644 --- a/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp +++ b/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp @@ -273,6 +273,7 @@ private slots: void bidiLogicalMovement(); void selectAndCursorPosition(); + void inputMethod(); void inputMethodSelection(); void inputMethodTentativeCommit(); @@ -3805,6 +3806,18 @@ void tst_QLineEdit::selectAndCursorPosition() QCOMPARE(testWidget->cursorPosition(), 0); } +void tst_QLineEdit::inputMethod() +{ + // widget accepts input + QInputMethodQueryEvent queryEvent(Qt::ImEnabled); + QApplication::sendEvent(testWidget, &queryEvent); + QCOMPARE(queryEvent.value(Qt::ImEnabled).toBool(), true); + + testWidget->setEnabled(false); + QApplication::sendEvent(testWidget, &queryEvent); + QCOMPARE(queryEvent.value(Qt::ImEnabled).toBool(), false); +} + void tst_QLineEdit::inputMethodSelection() { testWidget->setText("Lorem ipsum dolor sit amet, consectetur adipiscing elit."); diff --git a/tests/auto/widgets/widgets/qtextedit/tst_qtextedit.cpp b/tests/auto/widgets/widgets/qtextedit/tst_qtextedit.cpp index a350f4d..1782233 100644 --- a/tests/auto/widgets/widgets/qtextedit/tst_qtextedit.cpp +++ b/tests/auto/widgets/widgets/qtextedit/tst_qtextedit.cpp @@ -2407,11 +2407,16 @@ void tst_QTextEdit::inputMethodQuery() ed->setText(text); ed->selectAll(); - QInputMethodQueryEvent event(Qt::ImQueryInput); + QInputMethodQueryEvent event(Qt::ImQueryInput | Qt::ImEnabled); QGuiApplication::sendEvent(ed, &event); int anchor = event.value(Qt::ImAnchorPosition).toInt(); int position = event.value(Qt::ImCursorPosition).toInt(); QCOMPARE(qAbs(position - anchor), text.length()); + QCOMPARE(event.value(Qt::ImEnabled).toBool(), true); + + ed->setEnabled(false); + QGuiApplication::sendEvent(ed, &event); + QCOMPARE(event.value(Qt::ImEnabled).toBool(), false); } QTEST_MAIN(tst_QTextEdit) -- 2.7.4