From: Lars Knoll Date: Wed, 7 Sep 2011 17:58:14 +0000 (+0200) Subject: Adapt to the input method changes in qtbase X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=70cc5c9b7b420ecaf099d5d08fb1b4e8ad81a920;p=konrad%2Fqtdeclarative.git Adapt to the input method changes in qtbase Start using the QInputPanel instead of the QPlatformInputContext. Make sure we do something with both QInputMethodEvent and QInputMethodQueryEvent. This gets input methods partially working on TextInput fields. Change-Id: I4655f5599673325ffb75207573635afccd069a65 Reviewed-on: http://codereview.qt-project.org/4404 Reviewed-by: Qt Sanity Bot Reviewed-by: Vesa Rantanen Reviewed-by: Andy Nichols Reviewed-by: Lars Knoll --- diff --git a/src/declarative/items/qsgcanvas.cpp b/src/declarative/items/qsgcanvas.cpp index 4707ad2..979fc16 100644 --- a/src/declarative/items/qsgcanvas.cpp +++ b/src/declarative/items/qsgcanvas.cpp @@ -51,7 +51,7 @@ #include #include -#include +#include #include @@ -335,9 +335,8 @@ bool QSGCanvas::vsyncAnimations() const */ void QSGCanvasPrivate::updateInputContext() { - QPlatformInputContext *ic = QGuiApplicationPrivate::platformIntegration()->inputContext(); - if (ic) - ic->update(); + // ### finer grained updates would be good + qApp->inputPanel()->update(Qt::ImQueryAll); } /*! This function is an attempt to localize all uses of QInputContext::reset in @@ -345,9 +344,7 @@ void QSGCanvasPrivate::updateInputContext() */ void QSGCanvasPrivate::resetInputContext() { - QPlatformInputContext *ic = QGuiApplicationPrivate::platformIntegration()->inputContext(); - if (ic) - ic->reset(); + qApp->inputPanel()->reset(); } @@ -731,12 +728,8 @@ void QSGCanvasPrivate::notifyFocusChangesRecur(QSGItem **items, int remaining) void QSGCanvasPrivate::updateInputMethodData() { - // Q_Q(QSGCanvas); - // ### refactor: port.. -// bool enabled = activeFocusItem -// && (QSGItemPrivate::get(activeFocusItem)->flags & QSGItem::ItemAcceptsInputMethod); -// q->setAttribute(Qt::WA_InputMethodEnabled, enabled); -// q->setInputMethodHints(enabled ? activeFocusItem->inputMethodHints() : Qt::ImhNone); + qApp->inputPanel()->setInputItem(activeFocusItem); + qApp->inputPanel()->setInputItemTranform(QSGItemPrivate::get(activeFocusItem)->itemToCanvasTransform()); } QVariant QSGCanvas::inputMethodQuery(Qt::InputMethodQuery query) const diff --git a/src/declarative/items/qsgitem.cpp b/src/declarative/items/qsgitem.cpp index 765fe34..2a5486b 100644 --- a/src/declarative/items/qsgitem.cpp +++ b/src/declarative/items/qsgitem.cpp @@ -53,6 +53,8 @@ #include #include #include +#include +#include #include #include #include @@ -2926,20 +2928,16 @@ void QSGItem::setInputMethodHints(Qt::InputMethodHints hints) if (!d->canvas || d->canvas->activeFocusItem() != this) return; - QSGCanvasPrivate *cd = QSGCanvasPrivate::get(d->canvas); - cd->updateInputMethodData(); -#ifndef QT_NO_IM - cd->updateInputContext(); -#endif + QInputPanel *p = qApp->inputPanel(); + if (p->inputItem() == this) + qApp->inputPanel()->update(Qt::ImHints); } void QSGItem::updateMicroFocus() { -#ifndef QT_NO_IM - Q_D(QSGItem); - if (d->canvas) - QSGCanvasPrivate::get(d->canvas)->updateInputContext(); -#endif + QInputPanel *p = qApp->inputPanel(); + if (p->inputItem() == this) + qApp->inputPanel()->update(Qt::ImMicroFocus); } QVariant QSGItem::inputMethodQuery(Qt::InputMethodQuery query) const @@ -2947,8 +2945,26 @@ QVariant QSGItem::inputMethodQuery(Qt::InputMethodQuery query) const Q_D(const QSGItem); QVariant v; - if (d->keyHandler) - v = d->keyHandler->inputMethodQuery(query); + switch (query) { + case Qt::ImEnabled: + v = (bool)(flags() & ItemAcceptsInputMethod); + break; + case Qt::ImHints: + v = (int)inputMethodHints(); + break; + case Qt::ImMicroFocus: + case Qt::ImFont: + case Qt::ImCursorPosition: + case Qt::ImSurroundingText: + case Qt::ImCurrentSelection: + case Qt::ImMaximumTextLength: + case Qt::ImAnchorPosition: + case Qt::ImPreferredLanguage: + if (d->keyHandler) + v = d->keyHandler->inputMethodQuery(query); + default: + break; + } return v; } @@ -4876,8 +4892,6 @@ QRectF QSGItem::mapRectFromScene(const QRectF &rect) const bool QSGItem::event(QEvent *ev) { - return QObject::event(ev); - #if 0 if (ev->type() == QEvent::PolishRequest) { Q_D(QSGItem); @@ -4888,6 +4902,16 @@ bool QSGItem::event(QEvent *ev) return QObject::event(ev); } #endif + if (ev->type() == QEvent::InputMethodQuery) { + QInputMethodQueryEvent *query = static_cast(ev); + query->setValue(inputMethodQuery(query->query())); + ev->accept(); + return true; + } else if (ev->type() == QEvent::InputMethod) { + inputMethodEvent(static_cast(ev)); + return true; + } + return QObject::event(ev); } #ifndef QT_NO_DEBUG_STREAM diff --git a/src/declarative/items/qsgtextinput.cpp b/src/declarative/items/qsgtextinput.cpp index 22ee3c8..9974094 100644 --- a/src/declarative/items/qsgtextinput.cpp +++ b/src/declarative/items/qsgtextinput.cpp @@ -52,9 +52,8 @@ #include #include -#include -#include #include +#include QT_BEGIN_NAMESPACE @@ -1164,7 +1163,7 @@ void QSGTextInput::mouseReleaseEvent(QMouseEvent *event) bool QSGTextInputPrivate::sendMouseEventToInputContext(QMouseEvent *event) { #if !defined QT_NO_IM - if (control->composeMode()) { + if (control->composeMode() && event->type() == QEvent::KeyRelease) { int tmp_cursor = xToPos(event->localPos().x()); int mousePos = tmp_cursor - control->cursor(); if (mousePos < 0 || mousePos > control->preeditAreaText().length()) { @@ -1174,10 +1173,8 @@ bool QSGTextInputPrivate::sendMouseEventToInputContext(QMouseEvent *event) return true; } - QPlatformInputContext *ic = QGuiApplicationPrivate::platformIntegration()->inputContext(); - if (ic) - // may be causing reset() in some input methods - ic->mouseHandler(mousePos, event); + // may be causing reset() in some input methods + qApp->inputPanel()->invokeAction(QInputPanel::Click, mousePos); if (!control->preeditAreaText().isEmpty()) return true; }