From 6a4bf73c07b034a0f9d07cb617d23e92ca778dd1 Mon Sep 17 00:00:00 2001 From: Pekka Vuorela Date: Thu, 23 Feb 2012 15:57:14 +0200 Subject: Added some convenience API for platform input contexts QPlatformInputContext now gets notified on changed focus and has inputMethodAccepted() telling whether current focus object accepts input method events. Also adapted IBus plugin to use this. Key event filtering for focused objects without input method support got fixed by the change. Change-Id: I6910aa6af2459d752a5763f0ae88fa8c34e5b165 Reviewed-by: Joona Petrell --- src/gui/kernel/qguiapplication.cpp | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) (limited to 'src/gui/kernel/qguiapplication.cpp') diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index f5856918af..0f5c218e52 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -69,7 +69,8 @@ #include #include #include - +#include +#include #include #include "private/qwindowsysteminterface_qpa_p.h" @@ -1180,7 +1181,7 @@ void QGuiApplicationPrivate::processActivatedEvent(QWindowSystemInterfacePrivate QFocusEvent focusOut(QEvent::FocusOut); QCoreApplication::sendSpontaneousEvent(previous, &focusOut); QObject::disconnect(previous, SIGNAL(focusObjectChanged(QObject*)), - qApp, SIGNAL(focusObjectChanged(QObject*))); + qApp, SLOT(q_updateFocusObject(QObject*))); } else { QEvent appActivate(QEvent::ApplicationActivate); qApp->sendSpontaneousEvent(qApp, &appActivate); @@ -1190,17 +1191,18 @@ void QGuiApplicationPrivate::processActivatedEvent(QWindowSystemInterfacePrivate QFocusEvent focusIn(QEvent::FocusIn); QCoreApplication::sendSpontaneousEvent(QGuiApplicationPrivate::focus_window, &focusIn); QObject::connect(QGuiApplicationPrivate::focus_window, SIGNAL(focusObjectChanged(QObject*)), - qApp, SIGNAL(focusObjectChanged(QObject*))); + qApp, SLOT(q_updateFocusObject(QObject*))); } else { QEvent appActivate(QEvent::ApplicationDeactivate); qApp->sendSpontaneousEvent(qApp, &appActivate); } - if (self) + if (self) { self->notifyActiveWindowChange(previous); - if (previousFocusObject != qApp->focusObject()) - emit qApp->focusObjectChanged(qApp->focusObject()); + if (previousFocusObject != qApp->focusObject()) + self->q_updateFocusObject(qApp->focusObject()); + } } void QGuiApplicationPrivate::processWindowStateChangedEvent(QWindowSystemInterfacePrivate::WindowStateChangedEvent *wse) @@ -2186,4 +2188,24 @@ const QDrawHelperGammaTables *QGuiApplicationPrivate::gammaTables() return result; } +void QGuiApplicationPrivate::q_updateFocusObject(QObject *object) +{ + Q_Q(QGuiApplication); + + bool enabled = false; + if (object) { + QInputMethodQueryEvent query(Qt::ImEnabled); + QGuiApplication::sendEvent(object, &query); + enabled = query.value(Qt::ImEnabled).toBool(); + } + + QPlatformInputContextPrivate::setInputMethodAccepted(enabled); + QPlatformInputContext *inputContext = platformIntegration()->inputContext(); + if (inputContext) + inputContext->setFocusObject(object); + emit q->focusObjectChanged(object); +} + +#include "moc_qguiapplication.cpp" + QT_END_NAMESPACE -- cgit v1.2.3