From c9b7f50778a48f4f8bcc76468cdfa3c8d27018e8 Mon Sep 17 00:00:00 2001
From: Samuli Piippo <samuli.piippo@theqtcompany.com>
Date: Wed, 4 Feb 2015 14:57:02 +0200
Subject: [PATCH] Enable PlatformInputContext in QNX platform plugin

Disable QNX's own input context and create input context using the
PlatformInputContext plugin system. This allows QtVirtualKeyboard
to be used also in QNX when QT_IM_MODULE environment variable is
set to qtvirtualkeyboard.

Change-Id: I92e999b750906a687adcb3b42425a8ccbb642712
---
 src/plugins/platforms/qnx/qqnxintegration.cpp | 45 ++++-----------------------
 src/plugins/platforms/qnx/qqnxintegration.h   |  3 +-
 2 files changed, 7 insertions(+), 41 deletions(-)

diff --git a/src/plugins/platforms/qnx/qqnxintegration.cpp b/src/plugins/platforms/qnx/qqnxintegration.cpp
index 1110eb5..1b1aec2 100644
--- a/src/plugins/platforms/qnx/qqnxintegration.cpp
+++ b/src/plugins/platforms/qnx/qqnxintegration.cpp
@@ -74,13 +74,9 @@
 #if defined(QQNX_PPS)
 #  include "qqnxbuttoneventnotifier.h"
 #  include "qqnxclipboard.h"
-
-#  if defined(QQNX_IMF)
-#    include "qqnxinputcontext_imf.h"
-#  else
-#    include "qqnxinputcontext_noimf.h"
-#  endif
 #endif
+#include <qpa/qplatforminputcontextfactory_p.h>
+#include <qpa/qplatforminputcontext.h>
 
 #include "private/qgenericunixfontdatabase_p.h"
 
@@ -148,12 +144,11 @@ QQnxIntegration::QQnxIntegration(const QStringList &paramList)
     , m_screenEventThread(0)
 #endif
     , m_navigatorEventHandler(new QQnxNavigatorEventHandler())
-    , m_virtualKeyboard(0)
 #if defined(QQNX_PPS)
     , m_navigatorEventNotifier(0)
-    , m_inputContext(0)
     , m_buttonsNotifier(new QQnxButtonEventNotifier())
 #endif
+    , m_inputContext(0)
     , m_services(0)
     , m_fontDatabase(new QGenericUnixFontDatabase())
 #if defined(Q_OS_BLACKBERRY)
@@ -199,16 +194,6 @@ QQnxIntegration::QQnxIntegration(const QStringList &paramList)
     m_screenEventThread->start();
 #endif
 
-    // Not on BlackBerry, it has specialized event dispatcher which also handles virtual keyboard events
-#if !defined(Q_OS_BLACKBERRY) && defined(QQNX_PPS)
-    // Create/start the keyboard class.
-    m_virtualKeyboard = new QQnxVirtualKeyboardPps();
-
-    // delay invocation of start() to the time the event loop is up and running
-    // needed to have the QThread internals of the main thread properly initialized
-    QMetaObject::invokeMethod(m_virtualKeyboard, "start", Qt::QueuedConnection);
-#endif
-
 #if defined(Q_OS_BLACKBERRY)
     m_navigator = new QQnxNavigatorBps();
 #elif defined(QQNX_PPS)
@@ -229,8 +214,6 @@ QQnxIntegration::QQnxIntegration(const QStringList &paramList)
 #endif
 
     m_bpsEventFilter->installOnEventDispatcher(m_eventDispatcher);
-
-    m_virtualKeyboard = virtualKeyboardBps;
 #endif
 
     // Create displays for all possible screens (which may not be attached). We have to do this
@@ -247,19 +230,8 @@ QQnxIntegration::QQnxIntegration(const QStringList &paramList)
         m_bpsEventFilter->registerForScreenEvents(screen);
 #endif
 
-    if (m_virtualKeyboard) {
-        // TODO check if we need to do this for all screens or only the primary one
-        QObject::connect(m_virtualKeyboard, SIGNAL(heightChanged(int)),
-                         primaryDisplay(), SLOT(keyboardHeightChanged(int)));
-
-#if defined(QQNX_PPS)
-        // Set up the input context
-        m_inputContext = new QQnxInputContext(this, *m_virtualKeyboard);
-#if defined(QQNX_IMF)
-        m_screenEventHandler->addScreenEventFilter(m_inputContext);
-#endif
-#endif
-    }
+    // Set up the input context
+    m_inputContext = QPlatformInputContextFactory::create();
 
 #if defined(QQNX_PPS)
     // delay invocation of start() to the time the event loop is up and running
@@ -321,12 +293,9 @@ QQnxIntegration::~QQnxIntegration()
     // Destroy the hardware button notifier
     delete m_buttonsNotifier;
 
+#endif
     // Destroy input context
     delete m_inputContext;
-#endif
-
-    // Destroy the keyboard class.
-    delete m_virtualKeyboard;
 
     // Destroy services class
     delete m_services;
@@ -387,13 +356,11 @@ QPlatformOpenGLContext *QQnxIntegration::createPlatformOpenGLContext(QOpenGLCont
 }
 #endif
 
-#if defined(QQNX_PPS)
 QPlatformInputContext *QQnxIntegration::inputContext() const
 {
     qIntegrationDebug() << Q_FUNC_INFO;
     return m_inputContext;
 }
-#endif
 
 void QQnxIntegration::moveToScreen(QWindow *window, int screen)
 {
diff --git a/src/plugins/platforms/qnx/qqnxintegration.h b/src/plugins/platforms/qnx/qqnxintegration.h
index 70c95ae..81dd664 100644
--- a/src/plugins/platforms/qnx/qqnxintegration.h
+++ b/src/plugins/platforms/qnx/qqnxintegration.h
@@ -155,12 +155,11 @@ private:
     QQnxScreenEventThread *m_screenEventThread;
 #endif
     QQnxNavigatorEventHandler *m_navigatorEventHandler;
-    QQnxAbstractVirtualKeyboard *m_virtualKeyboard;
 #if defined(QQNX_PPS)
     QQnxNavigatorEventNotifier *m_navigatorEventNotifier;
-    QQnxInputContext *m_inputContext;
     QQnxButtonEventNotifier *m_buttonsNotifier;
 #endif
+    QPlatformInputContext *m_inputContext;
     QQnxServices *m_services;
     QPlatformFontDatabase *m_fontDatabase;
     mutable QAbstractEventDispatcher *m_eventDispatcher;
-- 
1.9.1

