Maliit: Fix enter on VKB not resulting in text input field acceptance
authorSimon Hausmann <simon.hausmann@nokia.com>
Tue, 31 Jan 2012 11:28:52 +0000 (12:28 +0100)
committerQt by Nokia <qt-info@nokia.com>
Tue, 31 Jan 2012 18:57:33 +0000 (19:57 +0100)
Pressing enter on the VKB should result in the emission of the accepted()
for text input fields in QML or the returnPressed() signal in QLineEdit.
In that case the Maliit input server calls our keyEvent method over DBus,
which this patch implements.

Change-Id: I46170c30315adaf21db0e232f53780ccaa67e4bf
Reviewed-by: Jan Arne Petersen <jpetersen@openismus.com>
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@nokia.com>
src/plugins/platforminputcontexts/maliit/qmaliitplatforminputcontext.cpp
src/plugins/platforminputcontexts/maliit/qmaliitplatforminputcontext.h

index 9db07af..724f50d 100644 (file)
@@ -127,6 +127,13 @@ static TextContentType contentTypeFromHints(Qt::InputMethodHints hints)
     return type;
 }
 
+/// From Maliit's namespace.h
+enum MaliitEventRequestType {
+    EventRequestBoth,         //!< Both a Qt::KeyEvent and a signal
+    EventRequestSignalOnly,   //!< Only a signal
+    EventRequestEventOnly     //!< Only a Qt::KeyEvent
+};
+
 static QString maliitServerAddress()
 {
     org::maliit::Server::Address serverAddress(QStringLiteral("org.maliit.server"), QStringLiteral("/org/maliit/server/address"), QDBusConnection::sessionBus());
@@ -383,9 +390,27 @@ void QMaliitPlatformInputContext::imInitiatedHide()
     // ### clear focus
 }
 
-void QMaliitPlatformInputContext::keyEvent(int, int, int, const QString &, bool, int, uchar)
+void QMaliitPlatformInputContext::keyEvent(int type, int key, int modifiers, const QString &text,
+                                          bool autoRepeat, int count, uchar requestType_)
 {
-    // Not supported at the moment.
+    MaliitEventRequestType requestType = MaliitEventRequestType(requestType_);
+    if (requestType == EventRequestSignalOnly) {
+        qWarning() << "Maliit: Signal emitted key events are not supported.";
+        return;
+    }
+
+    // HACK: This code relies on QEvent::Type for key events and modifiers to be binary compatible between
+    // Qt 4 and 5.
+    QEvent::Type eventType = static_cast<QEvent::Type>(type);
+    if (type != QEvent::KeyPress && type != QEvent::KeyRelease) {
+        qWarning() << "Maliit: Unknown key event type" << type;
+        return;
+    }
+
+    QKeyEvent event(eventType, key, static_cast<Qt::KeyboardModifiers>(modifiers),
+                    text, autoRepeat, count);
+    if (d->window)
+        QCoreApplication::sendEvent(d->window.data(), &event);
 }
 
 void QMaliitPlatformInputContext::paste()
index 61960e8..3760885 100644 (file)
@@ -76,7 +76,7 @@ public Q_SLOTS:
     void updatePreedit(const QDBusMessage &message);
     void copy();
     void imInitiatedHide();
-    void keyEvent(int , int , int , const QString &, bool , int , uchar );
+    void keyEvent(int type, int key, int modifiers, const QString &text, bool autoRepeat, int count, uchar requestType_);
     void paste();
     bool preeditRectangle(int &x, int &y, int &width, int &height);
     bool selection(QString &selection);