From 82840fcce074658bd39ad6425fd50022b9250dcf Mon Sep 17 00:00:00 2001 From: axis Date: Fri, 17 Apr 2009 13:58:37 +0200 Subject: Close the input panel when focusing a non-inputmethods aware widget. AutoTest: Included RevBy: denis --- src/gui/kernel/qapplication.cpp | 10 ++++++++ tests/auto/qinputcontext/tst_qinputcontext.cpp | 35 ++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/src/gui/kernel/qapplication.cpp b/src/gui/kernel/qapplication.cpp index 28e152a..c8fedfc 100644 --- a/src/gui/kernel/qapplication.cpp +++ b/src/gui/kernel/qapplication.cpp @@ -2098,6 +2098,16 @@ void QApplicationPrivate::setFocusWidget(QWidget *focus, Qt::FocusReason reason) prev->setEditFocus(false); } #endif +#ifndef QT_NO_IM + if (focus) { + QInputContext *prevIc; + prevIc = prev->inputContext(); + if (prevIc && prevIc != focus->inputContext()) { + QEvent closeSIPEvent(QEvent::CloseSoftwareInputPanel); + QApplication::sendEvent(prev, &closeSIPEvent); + } + } +#endif QFocusEvent out(QEvent::FocusOut, reason); QPointer that = prev; QApplication::sendEvent(prev, &out); diff --git a/tests/auto/qinputcontext/tst_qinputcontext.cpp b/tests/auto/qinputcontext/tst_qinputcontext.cpp index 5fdd931..444b400 100644 --- a/tests/auto/qinputcontext/tst_qinputcontext.cpp +++ b/tests/auto/qinputcontext/tst_qinputcontext.cpp @@ -46,6 +46,7 @@ #include #include #include +#include class tst_QInputContext : public QObject { @@ -64,6 +65,7 @@ private slots: void maximumTextLength(); void filterMouseEvents(); void requestSoftwareInputPanel(); + void closeSoftwareInputPanel(); }; void tst_QInputContext::maximumTextLength() @@ -156,5 +158,38 @@ void tst_QInputContext::requestSoftwareInputPanel() QVERIFY(ic1->lastType != QEvent::RequestSoftwareInputPanel); } +void tst_QInputContext::closeSoftwareInputPanel() +{ + QWidget w; + QLayout *layout = new QVBoxLayout; + QLineEdit *le1, *le2; + QRadioButton *rb; + le1 = new QLineEdit; + le2 = new QLineEdit; + rb = new QRadioButton; + layout->addWidget(le1); + layout->addWidget(le2); + layout->addWidget(rb); + w.setLayout(layout); + + QFilterInputContext *ic1, *ic2; + ic1 = new QFilterInputContext; + ic2 = new QFilterInputContext; + le1->setInputContext(ic1); + le2->setInputContext(ic2); + + w.show(); + QApplication::setActiveWindow(&w); + + // Testing that panel doesn't close between two input methods aware widgets. + QTest::mouseClick(le1, Qt::LeftButton, Qt::NoModifier, QPoint(5, 5)); + QTest::mouseClick(le2, Qt::LeftButton, Qt::NoModifier, QPoint(5, 5)); + QVERIFY(ic2->lastType != QEvent::CloseSoftwareInputPanel); + + // Testing that panel closes when focusing non-aware widget. + QTest::mouseClick(rb, Qt::LeftButton, Qt::NoModifier, QPoint(5, 5)); + QCOMPARE(ic2->lastType, QEvent::CloseSoftwareInputPanel); +} + QTEST_MAIN(tst_QInputContext) #include "tst_qinputcontext.moc" -- cgit v0.12