diff options
author | Paul Olav Tvete <[email protected]> | 2014-01-20 12:30:35 +0100 |
---|---|---|
committer | The Qt Project <[email protected]> | 2014-02-15 10:38:35 +0100 |
commit | f8dbed12266c42785c1e4758eed05833ec035f33 (patch) | |
tree | 85067c8722cfc3854d9e22845fcd633f06cb4422 /src/gui/kernel/qinputmethod.cpp | |
parent | 25e7fe16504ad4784ea2d75204ffa855ca6d3e1b (diff) |
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 <[email protected]>
Diffstat (limited to 'src/gui/kernel/qinputmethod.cpp')
-rw-r--r-- | src/gui/kernel/qinputmethod.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/gui/kernel/qinputmethod.cpp b/src/gui/kernel/qinputmethod.cpp index 438c169f718..495ea8f6e7d 100644 --- a/src/gui/kernel/qinputmethod.cpp +++ b/src/gui/kernel/qinputmethod.cpp @@ -45,6 +45,8 @@ #include <qtimer.h> #include <qpa/qplatforminputcontext_p.h> +#include <QDebug> + 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" |