Adapt to the input method changes in qtbase
authorLars Knoll <lars.knoll@nokia.com>
Wed, 7 Sep 2011 17:58:14 +0000 (19:58 +0200)
committerLars Knoll <lars.knoll@nokia.com>
Thu, 8 Sep 2011 08:33:31 +0000 (10:33 +0200)
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 <qt_sanity_bot@ovi.com>
Reviewed-by: Vesa Rantanen <vesa.rantanen@nokia.com>
Reviewed-by: Andy Nichols
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>

src/declarative/items/qsgcanvas.cpp
src/declarative/items/qsgitem.cpp
src/declarative/items/qsgtextinput.cpp

index 4707ad2..979fc16 100644 (file)
@@ -51,7 +51,7 @@
 #include <private/qsgflashnode_p.h>
 
 #include <private/qguiapplication_p.h>
-#include <QtGui/QPlatformInputContext>
+#include <QtGui/QInputPanel>
 
 #include <private/qabstractanimation_p.h>
 
@@ -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
index 765fe34..2a5486b 100644 (file)
@@ -53,6 +53,8 @@
 #include <QtDeclarative/qdeclarativeinfo.h>
 #include <QtGui/qpen.h>
 #include <QtGui/qcursor.h>
+#include <QtGui/qguiapplication.h>
+#include <QtGui/qinputpanel.h>
 #include <QtCore/qdebug.h>
 #include <QtCore/qcoreevent.h>
 #include <QtCore/qnumeric.h>
@@ -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<QInputMethodQueryEvent *>(ev);
+        query->setValue(inputMethodQuery(query->query()));
+        ev->accept();
+        return true;
+    } else if (ev->type() == QEvent::InputMethod) {
+        inputMethodEvent(static_cast<QInputMethodEvent *>(ev));
+        return true;
+    }
+    return QObject::event(ev);
 }
 
 #ifndef QT_NO_DEBUG_STREAM
index 22ee3c8..9974094 100644 (file)
@@ -52,9 +52,8 @@
 #include <qsgtextnode_p.h>
 #include <qsgsimplerectnode.h>
 
-#include <QtGui/qplatforminputcontext_qpa.h>
-#include <private/qguiapplication_p.h>
 #include <QtGui/qstylehints.h>
+#include <QtGui/qinputpanel.h>
 
 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;
     }