Inform android input method when cursor is moved

Google Japanese Input Beta keeps track of the cursor position, and
bails out if the cursor is not where it thinks it should be. We
have to tell the IM every time we move the cursor, not only when
we are composing.

Change-Id: I9cdb28f81c76e76d3b0125d08bf0595616ca443f
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@digia.com>
This commit is contained in:
Paul Olav Tvete 2013-03-22 10:53:40 +01:00 committed by The Qt Project
parent 1f180e9690
commit 0c645f1345
2 changed files with 11 additions and 0 deletions

View File

@ -337,7 +337,10 @@ void QAndroidInputContext::reset()
void QAndroidInputContext::commit()
{
finishComposingText();
}
void QAndroidInputContext::updateCursorPosition()
{
QSharedPointer<QInputMethodQueryEvent> query = focusObjectInputMethodQuery();
if (!query.isNull()) {
const int cursorPos = query->value(Qt::ImCursorPosition).toInt();
@ -378,6 +381,12 @@ void QAndroidInputContext::showInputPanel()
QSharedPointer<QInputMethodQueryEvent> query = focusObjectInputMethodQuery();
if (query.isNull())
return;
disconnect(m_updateCursorPosConnection);
if (qGuiApp->focusObject()->metaObject()->indexOfSignal("cursorPositionChanged(int,int)") >= 0) // QLineEdit breaks the pattern
m_updateCursorPosConnection = connect(qGuiApp->focusObject(), SIGNAL(cursorPositionChanged(int,int)), this, SLOT(updateCursorPosition()));
else
m_updateCursorPosConnection = connect(qGuiApp->focusObject(), SIGNAL(cursorPositionChanged()), this, SLOT(updateCursorPosition()));
QRectF itemRect = qGuiApp->inputMethod()->inputItemRectangle();
QRect rect = qGuiApp->inputMethod()->inputItemTransform().mapRect(itemRect).toRect();
QWindow *window = qGuiApp->focusWindow();

View File

@ -119,10 +119,12 @@ private:
private slots:
virtual void sendEvent(QObject *receiver, QInputMethodEvent *event);
virtual void sendEvent(QObject *receiver, QInputMethodQueryEvent *event);
void updateCursorPosition();
private:
ExtractedText m_extractedText;
QString m_composingText;
QMetaObject::Connection m_updateCursorPosConnection;
};
QT_END_NAMESPACE