Ported use of QInputContext to QPlatformInputContext for now
authorGunnar Sletta <gunnar.sletta@nokia.com>
Fri, 5 Aug 2011 08:25:58 +0000 (10:25 +0200)
committerSamuel Rødal <samuel.rodal@nokia.com>
Fri, 5 Aug 2011 08:48:12 +0000 (10:48 +0200)
Change-Id: I2e0e62cffd04c3a096d1402028a9be92d8b0a27c
Reviewed-on: http://codereview.qt.nokia.com/2677
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Samuel Rødal <samuel.rodal@nokia.com>
src/declarative/items/qsgcanvas.cpp
src/declarative/items/qsgcanvas_p.h
src/declarative/items/qsgitem.cpp
src/declarative/items/qsgtextedit.cpp
src/declarative/items/qsgtextinput.cpp

index 4f76184..4257650 100644 (file)
 #include <private/qsgrenderer_p.h>
 #include <private/qsgflashnode_p.h>
 
+#include <private/qguiapplication_p.h>
+#include <QtGui/QPlatformInputContext>
+
 #include <private/qabstractanimation_p.h>
 
 #include <QtGui/qpainter.h>
 #include <QtWidgets/qgraphicssceneevent.h>
 #include <QtGui/qmatrix4x4.h>
-#include <QtWidgets/qinputcontext.h>
 #include <QtCore/qvarlengtharray.h>
 #include <QtCore/qabstractanimation.h>
 
@@ -253,6 +255,27 @@ bool QSGCanvas::vsyncAnimations() const
     return d->vsyncAnimations;
 }
 
+/*!
+    This function is an attempt to localize all uses of QInputContext::update in
+    one place up until the point where we have public API for the QInputContext API.
+ */
+void QSGCanvasPrivate::updateInputContext()
+{
+   QPlatformInputContext *ic = QGuiApplicationPrivate::platformIntegration()->inputContext();
+   if (ic)
+       ic->update();
+}
+/*!
+    This function is an attempt to localize all uses of QInputContext::reset in
+    one place up until the point where we have public API for the QInputContext API.
+ */
+void QSGCanvasPrivate::resetInputContext()
+{
+    QPlatformInputContext *ic = QGuiApplicationPrivate::platformIntegration()->inputContext();
+    if (ic)
+        ic->reset();
+}
+
 
 void QSGCanvasPrivate::initializeSceneGraph()
 {
@@ -350,11 +373,14 @@ void QSGCanvasPrivate::init(QSGCanvas *c)
     Q_Q(QSGCanvas);
 
     rootItem = new QSGRootItem;
-    rootItem->setFocus(true);
     QSGItemPrivate *rootItemPrivate = QSGItemPrivate::get(rootItem);
     rootItemPrivate->canvas = q;
     rootItemPrivate->flags |= QSGItem::ItemIsFocusScope;
 
+    // QML always has focus. It is important that this call happens after the rootItem
+    // has a canvas..
+    rootItem->setFocus(true);
+
     thread = new QSGCanvasRenderThread;
     thread->renderer = q;
     thread->d = this;
@@ -516,10 +542,7 @@ void QSGCanvasPrivate::setFocusInScope(QSGItem *scope, QSGItem *item, FocusOptio
 
         if (oldActiveFocusItem) {
 #ifndef QT_NO_IM
-            // ### refactor: port properly...
-            qDebug("QSGCanvas: input context resetting is not implemented");
-//            if (QInputContext *ic = inputContext())
-//                ic->reset();
+            resetInputContext();
 #endif
 
             activeFocusItem = 0;
@@ -628,10 +651,7 @@ void QSGCanvasPrivate::clearFocusInScope(QSGItem *scope, QSGItem *item, FocusOpt
         Q_ASSERT(oldActiveFocusItem);
 
 #ifndef QT_NO_IM
-        // ### refactor: port properly
-        qDebug("QSGCanvas: clear focus in scope, not implemented");
-//        if (QInputContext *ic = inputContext())
-//            ic->reset();
+        resetInputContext();
 #endif
 
         activeFocusItem = 0;
index b147bb3..bb2c0f8 100644 (file)
@@ -143,6 +143,9 @@ public:
     void syncSceneGraph();
     void renderSceneGraph(const QSize &size);
 
+    void updateInputContext();
+    void resetInputContext();
+
     QSGItem::UpdatePaintNodeData updatePaintNodeData;
 
     QSGItem *dirtyItemList;
index cf521d9..6769489 100644 (file)
@@ -53,7 +53,6 @@
 #include <QtDeclarative/qdeclarativeinfo.h>
 #include <QtWidgets/qgraphicstransform.h>
 #include <QtGui/qpen.h>
-#include <QtWidgets/qinputcontext.h>
 #include <QtCore/qdebug.h>
 #include <QtCore/qcoreevent.h>
 #include <QtCore/qnumeric.h>
@@ -1723,12 +1722,10 @@ void QSGItem::setInputMethodHints(Qt::InputMethodHints hints)
     if (!d->canvas || d->canvas->activeFocusItem() != this)
         return;
 
-    QSGCanvasPrivate::get(d->canvas)->updateInputMethodData();
+    QSGCanvasPrivate *cd = QSGCanvasPrivate::get(d->canvas);
+    cd->updateInputMethodData();
 #ifndef QT_NO_IM
-    // ### refactor: port properly
-    qDebug("QSGItem: setInputMethodHints: not implemented");
-//    if (QInputContext *inputContext = d->canvas->inputContext())
-//        inputContext->update();
+    cd->updateInputContext();
 #endif
 }
 
@@ -1736,12 +1733,8 @@ void QSGItem::updateMicroFocus()
 {
 #ifndef QT_NO_IM
     Q_D(QSGItem);
-    if (d->canvas) {
-        // ### refactor: port properly
-        qDebug("QSGItem: setInputMethodHints: not implemented");
-        //    if (QInputContext *inputContext = d->canvas->inputContext())
-        //        inputContext->update();
-    }
+    if (d->canvas)
+        QSGCanvasPrivate::get(d->canvas)->updateInputContext();
 #endif
 }
 
index 6c529db..4ba5bec 100644 (file)
@@ -1193,24 +1193,20 @@ void QSGTextEditPrivate::updateDefaultTextOption()
 void QSGTextEdit::openSoftwareInputPanel()
 {
     if (qApp) {
-        // ### refactor:port properly
-        qDebug("QSGTextEdit: opening of virtual keyboard not implemented");
-//        if (canvas() && canvas() == qApp->focusWidget()) {
-//            QEvent event(QEvent::RequestSoftwareInputPanel);
-//            QApplication::sendEvent(canvas(), &event);
-//        }
+        if (canvas()) {
+            QEvent event(QEvent::RequestSoftwareInputPanel);
+            QApplication::sendEvent(canvas(), &event);
+        }
     }
 }
 
 void QSGTextEdit::closeSoftwareInputPanel()
 {  
     if (qApp) {
-        // ### refactor: port properly
-        qDebug("QSGTextEdit: closing of virtual keyboard not implemented...");
-//        if (canvas() && canvas() == qApp->focusWidget()) {
-//            QEvent event(QEvent::CloseSoftwareInputPanel);
-//            QApplication::sendEvent(canvas(), &event);
-//        }
+        if (canvas()) {
+            QEvent event(QEvent::CloseSoftwareInputPanel);
+            QApplication::sendEvent(canvas(), &event);
+        }
     }
 }
 
index d55bdc8..405540d 100644 (file)
@@ -1056,9 +1056,8 @@ void QSGTextInput::moveCursorSelection(int pos, SelectionMode mode)
 
 void QSGTextInput::openSoftwareInputPanel()
 {
-    QEvent event(QEvent::RequestSoftwareInputPanel);
     if (qApp) {
-        if (canvas() && canvas() == QGuiApplication::activeWindow()) {
+        if (canvas()) {
             QEvent event(QEvent::RequestSoftwareInputPanel);
             QApplication::sendEvent(canvas(), &event);
         }
@@ -1068,11 +1067,9 @@ void QSGTextInput::openSoftwareInputPanel()
 void QSGTextInput::closeSoftwareInputPanel()
 {
     if (qApp) {
-        if (canvas() && canvas() == QGuiApplication::activeWindow()) {
-            // ### refactor: port properly
-            qDebug("QSGTextInput: closing virtual keyboard not implemented");
-//            QEvent event(QEvent::CloseSoftwareInputPanel);
-//            QApplication::sendEvent(canvas(), &event);
+        if (canvas()) {
+            QEvent event(QEvent::CloseSoftwareInputPanel);
+            QApplication::sendEvent(canvas(), &event);
         }
     }
 }