From d8d6186b66db713a2234e99ca7e1c98dab2936f6 Mon Sep 17 00:00:00 2001 From: Weng Xuetian Date: Sat, 4 Nov 2017 23:17:53 -0700 Subject: Remap the coordinates in QInputMethodQueryEvent based on widget Right now, we only obtain the coordinates from QQuickItem directly, it uses different QTransform to map to the global. The point and rect value need to be fixed to use the QQuickWidget coordinates system. Change-Id: Ia16a1a80f58c4c3bef1575a568f7e359bdaebef3 Reviewed-by: Laszlo Agocs Reviewed-by: Paul Olav Tvete --- src/quickwidgets/qquickwidget.cpp | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/quickwidgets/qquickwidget.cpp b/src/quickwidgets/qquickwidget.cpp index 76681c10d3..df28ff964a 100644 --- a/src/quickwidgets/qquickwidget.cpp +++ b/src/quickwidgets/qquickwidget.cpp @@ -1394,6 +1394,28 @@ static Qt::WindowState resolveWindowState(Qt::WindowStates states) return Qt::WindowNoState; } +static void remapInputMethodQueryEvent(QObject *object, QInputMethodQueryEvent *e) +{ + auto item = qobject_cast(object); + if (!item) + return; + + // Remap all QRectF values. + for (auto query : {Qt::ImCursorRectangle, Qt::ImAnchorRectangle, Qt::ImInputItemClipRectangle}) { + if (e->queries() & query) { + auto value = e->value(query); + if (value.canConvert()) + e->setValue(query, item->mapRectToScene(value.toRectF())); + } + } + // Remap all QPointF values. + if (e->queries() & Qt::ImCursorPosition) { + auto value = e->value(Qt::ImCursorPosition); + if (value.canConvert()) + e->setValue(Qt::ImCursorPosition, item->mapToScene(value.toPointF())); + } +} + /*! \reimp */ bool QQuickWidget::event(QEvent *e) { @@ -1410,8 +1432,17 @@ bool QQuickWidget::event(QEvent *e) return QCoreApplication::sendEvent(d->offscreenWindow, e); case QEvent::InputMethod: - case QEvent::InputMethodQuery: return QCoreApplication::sendEvent(d->offscreenWindow->focusObject(), e); + case QEvent::InputMethodQuery: + { + bool eventResult = QCoreApplication::sendEvent(d->offscreenWindow->focusObject(), e); + // The result in focusObject are based on offscreenWindow. But + // the inputMethodTransform won't get updated because the focus + // is on QQuickWidget. We need to remap the value based on the + // widget. + remapInputMethodQueryEvent(d->offscreenWindow->focusObject(), static_cast(e)); + return eventResult; + } case QEvent::WindowChangeInternal: d->handleWindowChange(); -- cgit v1.2.3