From f8dbed12266c42785c1e4758eed05833ec035f33 Mon Sep 17 00:00:00 2001 From: Paul Olav Tvete Date: Mon, 20 Jan 2014 12:30:35 +0100 Subject: Extending the inputMethodQuery API Currently, inputMethodQuery() only provides information about the current paragraph. On some platforms, such as Android, the input method needs information about the global cursor position, and more of the surrounding text. Some queries need to pass parameters. The current inputmethodQuery() implementation does not allow parameters to be passed. Changing this would require new or modified virtual functions, which is not possible until Qt 6. Therefore, a completely new mechanism is needed. Change-Id: Ic64fd90198ade70aa0fa6fa5ad3867dfa7ed763c Reviewed-by: Lars Knoll --- src/gui/kernel/qinputmethod.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'src/gui/kernel/qinputmethod.cpp') diff --git a/src/gui/kernel/qinputmethod.cpp b/src/gui/kernel/qinputmethod.cpp index 438c169f71..495ea8f6e7 100644 --- a/src/gui/kernel/qinputmethod.cpp +++ b/src/gui/kernel/qinputmethod.cpp @@ -45,6 +45,8 @@ #include #include +#include + QT_BEGIN_NAMESPACE /*! @@ -365,6 +367,29 @@ bool QInputMethodPrivate::objectAcceptsInputMethod(QObject *object) return enabled; } +/*! + Send \a query to the current focus object with parameters \a argument and return the result. + */ +QVariant QInputMethod::queryFocusObject(Qt::InputMethodQuery query, QVariant argument) +{ + QVariant retval; + QObject *focusObject = qGuiApp->focusObject(); + if (!focusObject) + return retval; + + bool newMethodWorks = QMetaObject::invokeMethod(focusObject, "inputMethodQuery", + Qt::DirectConnection, + Q_RETURN_ARG(QVariant, retval), + Q_ARG(Qt::InputMethodQuery, query), + Q_ARG(QVariant, argument)); + if (newMethodWorks) + return retval; + + QInputMethodQueryEvent queryEvent(query); + QCoreApplication::sendEvent(focusObject, &queryEvent); + return queryEvent.value(query); +} + QT_END_NAMESPACE #include "moc_qinputmethod.cpp" -- cgit v1.2.3