Move input panel visibility ownership from QInputPanel to QPlatformInputContext
authorJoona Petrell <joona.t.petrell@nokia.com>
Tue, 11 Oct 2011 10:10:50 +0000 (13:10 +0300)
committerQt by Nokia <qt-info@nokia.com>
Tue, 11 Oct 2011 14:03:25 +0000 (16:03 +0200)
Now QInputPanel::visible() can be set true even when platform doesn't provide
a virtual keyboard. Like keyboard geometry, visibility should be dictated by
the platform plugin and not QInputPanel, whose role is more like that of a mediator.
QInputPanel::show() and ::hide() calls should be treated as requests that may fail.
Changed the QInputPanel's visible property to read-only as a setter that may
fail is not really a setter, show() and hide() should be used instead.

Enabling the new functionality cannot be activated immediatelly without breaking
existing keyboards, added a temporary function handlesInputPanelVisibility that
handovers the responsiblity of updating input panel visibility to QInputContextPlatform
only once QInputContextPlatform says that it is able to handle it.

Change-Id: Ideecaf7225cc3971f33a0ac976bd92cf7767475b
Reviewed-on: http://codereview.qt-project.org/6429
Sanity-Review: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Pekka Vuorela <pekka.ta.vuorela@nokia.com>
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
src/gui/kernel/qinputpanel.cpp
src/gui/kernel/qinputpanel.h
src/gui/kernel/qplatforminputcontext_qpa.cpp
src/gui/kernel/qplatforminputcontext_qpa.h
src/plugins/platforminputcontexts/ibus/qibusplatforminputcontext.cpp
src/plugins/platforminputcontexts/ibus/qibusplatforminputcontext.h
tests/auto/gui/kernel/qinputpanel/tst_qinputpanel.cpp

index a024a82..a7978c6 100644 (file)
@@ -118,29 +118,42 @@ QRectF QInputPanel::keyboardRectangle()
 
 void QInputPanel::show()
 {
-    setVisible(true);
+    Q_D(QInputPanel);
+    QPlatformInputContext *ic = d->platformInputContext();
+    if (ic && ic->handlesInputPanelVisibility())
+        ic->showInputPanel();
+    else if (!d->visible) {
+        d->visible = true;
+        emit visibleChanged();
+    }
 }
 
 void QInputPanel::hide()
 {
-    setVisible(false);
+    Q_D(QInputPanel);
+    QPlatformInputContext *ic = d->platformInputContext();
+    if (ic && ic->handlesInputPanelVisibility())
+        ic->hideInputPanel();
+    else if (d->visible) {
+        d->visible = false;
+        emit visibleChanged();
+    }
 }
 
 bool QInputPanel::visible() const
 {
     Q_D(const QInputPanel);
-
-    return d->visible;
+    QPlatformInputContext *ic = d->platformInputContext();
+    if (ic && ic->handlesInputPanelVisibility())
+        return ic->isInputPanelVisible();
+    else
+        return d->visible;
+    return false;
 }
 
 void QInputPanel::setVisible(bool visible)
 {
-    Q_D(QInputPanel);
-    if (d->visible == visible)
-        return;
-
-    d->visible = visible;
-    emit visibleChanged();
+    visible ? show() : hide();
 }
 
 bool QInputPanel::isAnimating() const
@@ -152,7 +165,6 @@ bool QInputPanel::isAnimating() const
     return false;
 }
 
-
 void QInputPanel::update(Qt::InputMethodQueries queries)
 {
     Q_D(QInputPanel);
index 292b01a..4edc902 100644 (file)
@@ -62,7 +62,7 @@ class Q_GUI_EXPORT QInputPanel : public QObject
     Q_PROPERTY(QObject *inputItem READ inputItem WRITE setInputItem NOTIFY inputItemChanged)
     Q_PROPERTY(QRectF cursorRectangle READ cursorRectangle NOTIFY cursorRectangleChanged)
     Q_PROPERTY(QRectF keyboardRectangle READ keyboardRectangle NOTIFY keyboardRectangleChanged)
-    Q_PROPERTY(bool visible READ visible WRITE setVisible NOTIFY visibleChanged)
+    Q_PROPERTY(bool visible READ visible NOTIFY visibleChanged)
     Q_PROPERTY(bool animating READ isAnimating NOTIFY animatingChanged)
 
     Q_ENUMS(Action)
index 0313f69..55b6027 100644 (file)
@@ -90,12 +90,12 @@ QRectF QPlatformInputContext::keyboardRect() const
     return QRectF();
 }
 
-void QPlatformInputContext::emitKeyboardRectChanged() const
+void QPlatformInputContext::emitKeyboardRectChanged()
 {
     emit qApp->inputPanel()->keyboardRectangleChanged();
 }
 
-bool QPlatformInputContext::isAnimating()
+bool QPlatformInputContext::isAnimating() const
 {
     return false;
 }
@@ -105,5 +105,28 @@ void QPlatformInputContext::emitAnimatingChanged()
     emit qApp->inputPanel()->animatingChanged();
 }
 
+void QPlatformInputContext::showInputPanel()
+{
+}
+
+void QPlatformInputContext::hideInputPanel()
+{
+}
+
+bool QPlatformInputContext::isInputPanelVisible() const
+{
+    return false;
+}
+
+void QPlatformInputContext::emitInputPanelVisibleChanged()
+{
+    emit qApp->inputPanel()->visibleChanged();
+}
+
+//  temporary function added to retain compatibility to old functionality, will be deprecated
+bool QPlatformInputContext::handlesInputPanelVisibility() const
+{
+    return false;
+}
 
 QT_END_NAMESPACE
index 8321c0a..ab5b672 100644 (file)
@@ -68,10 +68,18 @@ public:
     virtual void invokeAction(QInputPanel::Action, int cursorPosition);
     virtual bool filterEvent(const QEvent *event);
     virtual QRectF keyboardRect() const;
-    void emitKeyboardRectChanged() const;
+    void emitKeyboardRectChanged();
 
-    virtual bool isAnimating();
+    virtual bool isAnimating() const;
     void emitAnimatingChanged();
+
+    virtual void showInputPanel();
+    virtual void hideInputPanel();
+    virtual bool isInputPanelVisible() const;
+    void emitInputPanelVisibleChanged();
+
+    // temporary function added to retain compatibility to old functionality, will be deprecated
+    virtual bool handlesInputPanelVisibility() const;
 };
 
 QT_END_NAMESPACE
index 0d0e240..67ee9da 100644 (file)
@@ -155,6 +155,11 @@ void QIBusPlatformInputContext::inputItemChanged()
         d->context->FocusOut();
 }
 
+// temporary function added to retain compatibility to old functionality, will be deprecated
+bool QIBusPlatformInputContext::handlesInputPanelVisibility() const
+{
+    return true;
+}
 
 void QIBusPlatformInputContext::commitText(const QDBusVariant &text)
 {
index 6008fc3..303b6f7 100644 (file)
@@ -63,6 +63,8 @@ public:
 
     Q_INVOKABLE bool x11FilterEvent(uint keyval, uint keycode, uint state, bool press);
 
+    virtual bool handlesInputPanelVisibility() const;
+
 public Q_SLOTS:
     void commitText(const QDBusVariant &text);
     void updatePreeditText(const QDBusVariant &text, uint cursor_pos, bool visible);
index 32215eb..e7f5e84 100644 (file)
@@ -50,6 +50,8 @@ class PlatformInputContext : public QPlatformInputContext
 public:
     PlatformInputContext() :
         m_animating(false),
+        m_visible(false),
+        m_handlesInputPanelVisibility(false),
         m_updateCallCount(0),
         m_resetCallCount(0),
         m_commitCallCount(0),
@@ -60,7 +62,7 @@ public:
     {}
 
     virtual QRectF keyboardRect() const { return m_keyboardRect; }
-    virtual bool isAnimating() { return m_animating; }
+    virtual bool isAnimating() const { return m_animating; }
     virtual void reset() { m_resetCallCount++; }
     virtual void commit() { m_commitCallCount++; }
 
@@ -78,8 +80,26 @@ public:
     {
         m_lastEventType = event->type(); return false;
     }
+    virtual void showInputPanel()
+    {
+        m_visible = true;
+    }
+    virtual void hideInputPanel()
+    {
+        m_visible = false;
+    }
+    virtual bool isInputPanelVisible() const
+    {
+        return m_visible;
+    }
+    virtual bool handlesInputPanelVisibility() const
+    {
+        return m_handlesInputPanelVisibility;
+    }
 
     bool m_animating;
+    bool m_visible;
+    bool m_handlesInputPanelVisibility;
     int m_updateCallCount;
     int m_resetCallCount;
     int m_commitCallCount;
@@ -143,17 +163,22 @@ void tst_qinputpanel::initTestCase()
 
 void tst_qinputpanel::visible()
 {
-    qApp->inputPanel()->show();
-    QCOMPARE(qApp->inputPanel()->visible(), true);
+    QCOMPARE(m_platformInputContext.m_handlesInputPanelVisibility, false);
+    for (int index = 0; index < 2; index++) {
+        m_platformInputContext.m_handlesInputPanelVisibility = index;
+        QCOMPARE(qApp->inputPanel()->visible(), false);
+        qApp->inputPanel()->show();
+        QCOMPARE(qApp->inputPanel()->visible(), true);
 
-    qApp->inputPanel()->hide();
-    QCOMPARE(qApp->inputPanel()->visible(), false);
+        qApp->inputPanel()->hide();
+        QCOMPARE(qApp->inputPanel()->visible(), false);
 
-    qApp->inputPanel()->setVisible(true);
-    QCOMPARE(qApp->inputPanel()->visible(), true);
+        qApp->inputPanel()->setVisible(true);
+        QCOMPARE(qApp->inputPanel()->visible(), true);
 
-    qApp->inputPanel()->setVisible(false);
-    QCOMPARE(qApp->inputPanel()->visible(), false);
+        qApp->inputPanel()->setVisible(false);
+        QCOMPARE(qApp->inputPanel()->visible(), false);
+    }
 }
 
 void tst_qinputpanel::animating()