summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms
diff options
context:
space:
mode:
authorKevin Krammer <kevin.krammer.qnx@kdab.com>2012-03-23 12:50:22 +0100
committerQt by Nokia <qt-info@nokia.com>2012-03-28 19:34:42 +0200
commit5d117fd427e3e727df5d3f417a2b91366f2a31c1 (patch)
tree7ab2f4bffabd8af212e481c3563c2b8ecb48d12a /src/plugins/platforms
parenta80a2c6da241dac77f533bc702a1c7d94349a812 (diff)
Refactoring virtual keyboard class into non-singleton
Getting rid of the singleton gives us better control over when the virtual keyboard handling class is instantiated and configured. Also notify screens about keyboard height changes and let them notify through QWindowSystemInterface instead of "guessing" the screen in QQnxVirtualKeyboard. Change-Id: I71a7f6b5e9d5455563404f6abe7a0daec567a12d Reviewed-by: Sean Harmer <sh@theharmers.co.uk> Reviewed-by: Robin Burchell <robin+qt@viroteck.net>
Diffstat (limited to 'src/plugins/platforms')
-rw-r--r--src/plugins/platforms/qnx/qqnxinputcontext_imf.cpp24
-rw-r--r--src/plugins/platforms/qnx/qqnxinputcontext_imf.h5
-rw-r--r--src/plugins/platforms/qnx/qqnxinputcontext_noimf.cpp28
-rw-r--r--src/plugins/platforms/qnx/qqnxinputcontext_noimf.h5
-rw-r--r--src/plugins/platforms/qnx/qqnxintegration.cpp19
-rw-r--r--src/plugins/platforms/qnx/qqnxintegration.h2
-rw-r--r--src/plugins/platforms/qnx/qqnxscreen.cpp17
-rw-r--r--src/plugins/platforms/qnx/qqnxscreen.h9
-rw-r--r--src/plugins/platforms/qnx/qqnxvirtualkeyboard.cpp59
-rw-r--r--src/plugins/platforms/qnx/qqnxvirtualkeyboard.h14
10 files changed, 98 insertions, 84 deletions
diff --git a/src/plugins/platforms/qnx/qqnxinputcontext_imf.cpp b/src/plugins/platforms/qnx/qqnxinputcontext_imf.cpp
index 3f9d768ccc..3cf2d4ed62 100644
--- a/src/plugins/platforms/qnx/qqnxinputcontext_imf.cpp
+++ b/src/plugins/platforms/qnx/qqnxinputcontext_imf.cpp
@@ -674,12 +674,15 @@ static bool imfAvailable()
return s_imfReady;
}
-QQnxInputContext::QQnxInputContext():
+QT_BEGIN_NAMESPACE
+
+QQnxInputContext::QQnxInputContext(QQnxVirtualKeyboard &keyboard):
QPlatformInputContext(),
m_lastCaretPos(0),
m_isComposing(false),
m_inputPanelVisible(false),
- m_inputPanelLocale(QLocale::c())
+ m_inputPanelLocale(QLocale::c()),
+ m_virtualKeyboad(keyboard)
{
#if defined(QQNXINPUTCONTEXT_DEBUG)
qDebug() << Q_FUNC_INFO;
@@ -697,7 +700,6 @@ QQnxInputContext::QQnxInputContext():
// p_vkb_init_selection_service();
- QQnxVirtualKeyboard &keyboard = QQnxVirtualKeyboard::instance();
connect(&keyboard, SIGNAL(visibilityChanged(bool)), this, SLOT(keyboardVisibilityChanged(bool)));
connect(&keyboard, SIGNAL(localeChanged(QLocale)), this, SLOT(keyboardLocaleChanged(QLocale)));
keyboardVisibilityChanged(keyboard.isVisible());
@@ -959,7 +961,7 @@ bool QQnxInputContext::hasSelectedText()
bool QQnxInputContext::dispatchRequestSoftwareInputPanel()
{
- QQnxVirtualKeyboard::instance().showKeyboard();
+ m_virtualKeyboard.showKeyboard();
#if defined(QQNXINPUTCONTEXT_DEBUG)
qDebug() << "QQNX: requesting virtual keyboard";
#endif
@@ -986,7 +988,7 @@ bool QQnxInputContext::dispatchRequestSoftwareInputPanel()
bool QQnxInputContext::dispatchCloseSoftwareInputPanel()
{
- QQnxVirtualKeyboard::instance().hideKeyboard();
+ m_virtualKeyboard.hideKeyboard();
#if defined(QQNXINPUTCONTEXT_DEBUG)
qDebug() << "QQNX: hiding virtual keyboard";
#endif
@@ -1685,12 +1687,14 @@ void QQnxInputContext::inputItemChanged()
if (m_inputPanelVisible)
hideInputPanel();
} else {
- if (qobject_cast<QAbstractSpinBox*>(inputItem)) {
- QQnxVirtualKeyboard::instance().setKeyboardMode(QQnxVirtualKeyboard::NumPunc);
- } else {
- QQnxVirtualKeyboard::instance().setKeyboardMode(QQnxVirtualKeyboard::Default);
- }
+ if (qobject_cast<QAbstractSpinBox*>(inputItem))
+ m_virtualKeyboard.setKeyboardMode(QQnxVirtualKeyboard::Phone);
+ else
+ m_virtualKeyboard.setKeyboardMode(QQnxVirtualKeyboard::Default);
+
if (!m_inputPanelVisible)
showInputPanel();
}
}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/platforms/qnx/qqnxinputcontext_imf.h b/src/plugins/platforms/qnx/qqnxinputcontext_imf.h
index 1fb55296a6..2574e19527 100644
--- a/src/plugins/platforms/qnx/qqnxinputcontext_imf.h
+++ b/src/plugins/platforms/qnx/qqnxinputcontext_imf.h
@@ -53,11 +53,13 @@
QT_BEGIN_NAMESPACE
+class QQnxVirtualKeyboard;
+
class QQnxInputContext : public QPlatformInputContext
{
Q_OBJECT
public:
- QQnxInputContext();
+ QQnxInputContext(QQnxVirtualKeyboard &keyboard);
~QQnxInputContext();
virtual bool isValid() const;
@@ -123,6 +125,7 @@ private:
QString m_composingText;
bool m_inputPanelVisible;
QLocale m_inputPanelLocale;
+ QQnxVirtualKeyboard &m_virtualKeyboad;
};
Q_DECLARE_METATYPE(extracted_text_t*)
diff --git a/src/plugins/platforms/qnx/qqnxinputcontext_noimf.cpp b/src/plugins/platforms/qnx/qqnxinputcontext_noimf.cpp
index 33b6c0e6f3..6c8a0abe17 100644
--- a/src/plugins/platforms/qnx/qqnxinputcontext_noimf.cpp
+++ b/src/plugins/platforms/qnx/qqnxinputcontext_noimf.cpp
@@ -46,12 +46,14 @@
#include <QtGui/QGuiApplication>
#include <QtWidgets/QAbstractSpinBox>
-QQnxInputContext::QQnxInputContext() :
+QT_BEGIN_NAMESPACE
+
+QQnxInputContext::QQnxInputContext(QQnxVirtualKeyboard &keyboard) :
QPlatformInputContext(),
m_inputPanelVisible(false),
- m_inputPanelLocale(QLocale::c())
+ m_inputPanelLocale(QLocale::c()),
+ m_virtualKeyboard(keyboard)
{
- QQnxVirtualKeyboard &keyboard = QQnxVirtualKeyboard::instance();
connect(&keyboard, SIGNAL(visibilityChanged(bool)), this, SLOT(keyboardVisibilityChanged(bool)));
connect(&keyboard, SIGNAL(localeChanged(QLocale)), this, SLOT(keyboardLocaleChanged(QLocale)));
keyboardVisibilityChanged(keyboard.isVisible());
@@ -86,7 +88,7 @@ bool QQnxInputContext::filterEvent( const QEvent *event )
return false;
if (event->type() == QEvent::CloseSoftwareInputPanel) {
- QQnxVirtualKeyboard::instance().hideKeyboard();
+ m_virtualKeyboard.hideKeyboard();
#if defined(QQNXINPUTCONTEXT_DEBUG)
qDebug() << "QQNX: hiding virtual keyboard";
#endif
@@ -94,7 +96,7 @@ bool QQnxInputContext::filterEvent( const QEvent *event )
}
if (event->type() == QEvent::RequestSoftwareInputPanel) {
- QQnxVirtualKeyboard::instance().showKeyboard();
+ m_virtualKeyboard.showKeyboard();
#if defined(QQNXINPUTCONTEXT_DEBUG)
qDebug() << "QQNX: requesting virtual keyboard";
#endif
@@ -120,7 +122,7 @@ void QQnxInputContext::showInputPanel()
#if defined(QQNXINPUTCONTEXT_DEBUG)
qDebug() << Q_FUNC_INFO;
#endif
- QQnxVirtualKeyboard::instance().showKeyboard();
+ m_virtualKeyboard.showKeyboard();
}
void QQnxInputContext::hideInputPanel()
@@ -128,7 +130,7 @@ void QQnxInputContext::hideInputPanel()
#if defined(QQNXINPUTCONTEXT_DEBUG)
qDebug() << Q_FUNC_INFO;
#endif
- QQnxVirtualKeyboard::instance().hideKeyboard();
+ m_virtualKeyboard.hideKeyboard();
}
bool QQnxInputContext::isInputPanelVisible() const
@@ -176,12 +178,14 @@ void QQnxInputContext::inputItemChanged()
if (m_inputPanelVisible)
hideInputPanel();
} else {
- if (qobject_cast<QAbstractSpinBox*>(inputItem)) {
- QQnxVirtualKeyboard::instance().setKeyboardMode(QQnxVirtualKeyboard::NumPunc);
- } else {
- QQnxVirtualKeyboard::instance().setKeyboardMode(QQnxVirtualKeyboard::Default);
- }
+ if (qobject_cast<QAbstractSpinBox*>(inputItem))
+ m_virtualKeyboard.setKeyboardMode(QQnxVirtualKeyboard::Phone);
+ else
+ m_virtualKeyboard.setKeyboardMode(QQnxVirtualKeyboard::Default);
+
if (!m_inputPanelVisible)
showInputPanel();
}
}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/platforms/qnx/qqnxinputcontext_noimf.h b/src/plugins/platforms/qnx/qqnxinputcontext_noimf.h
index 33a4631d16..efc501b65f 100644
--- a/src/plugins/platforms/qnx/qqnxinputcontext_noimf.h
+++ b/src/plugins/platforms/qnx/qqnxinputcontext_noimf.h
@@ -48,11 +48,13 @@
QT_BEGIN_NAMESPACE
+class QQnxVirtualKeyboard;
+
class QQnxInputContext : public QPlatformInputContext
{
Q_OBJECT
public:
- explicit QQnxInputContext();
+ explicit QQnxInputContext(QQnxVirtualKeyboard &keyboard);
~QQnxInputContext();
virtual bool isValid() const;
@@ -77,6 +79,7 @@ private:
bool m_inputPanelVisible;
QLocale m_inputPanelLocale;
+ QQnxVirtualKeyboard &m_virtualKeyboard;
};
QT_END_NAMESPACE
diff --git a/src/plugins/platforms/qnx/qqnxintegration.cpp b/src/plugins/platforms/qnx/qqnxintegration.cpp
index 00ba7d825e..bb31de874b 100644
--- a/src/plugins/platforms/qnx/qqnxintegration.cpp
+++ b/src/plugins/platforms/qnx/qqnxintegration.cpp
@@ -79,6 +79,7 @@ QQnxIntegration::QQnxIntegration()
: QPlatformIntegration()
, m_eventThread(0)
, m_navigatorEventHandler(0)
+ , m_virtualKeyboard(0)
, m_inputContext(0)
, m_fontDatabase(new QGenericUnixFontDatabase())
, m_paintUsingOpenGL(false)
@@ -122,10 +123,18 @@ QQnxIntegration::QQnxIntegration()
#endif
// Create/start the keyboard class.
- QQnxVirtualKeyboard::instance();
+ m_virtualKeyboard = new QQnxVirtualKeyboard();
+
+ // 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);
+
+ // TODO check if we need to do this for all screens or only the primary one
+ QObject::connect(m_virtualKeyboard, SIGNAL(heightChanged(int)),
+ QQnxScreen::primaryDisplay(), SLOT(keyboardHeightChanged(int)));
// Set up the input context
- m_inputContext = new QQnxInputContext;
+ m_inputContext = new QQnxInputContext(*m_virtualKeyboard);
// Create services handling class
#ifdef Q_OS_BLACKBERRY
@@ -138,8 +147,12 @@ QQnxIntegration::~QQnxIntegration()
#if defined(QQNXINTEGRATION_DEBUG)
qDebug() << "QQnx: platform plugin shutdown begin";
#endif
+
+ // Destroy input context
+ delete m_inputContext;
+
// Destroy the keyboard class.
- QQnxVirtualKeyboard::destroy();
+ delete m_virtualKeyboard;
#ifndef QT_NO_CLIPBOARD
// Delete the clipboard
diff --git a/src/plugins/platforms/qnx/qqnxintegration.h b/src/plugins/platforms/qnx/qqnxintegration.h
index 6aa16100ad..6b4a4a1651 100644
--- a/src/plugins/platforms/qnx/qqnxintegration.h
+++ b/src/plugins/platforms/qnx/qqnxintegration.h
@@ -53,6 +53,7 @@ QT_BEGIN_NAMESPACE
class QQnxEventThread;
class QQnxInputContext;
class QQnxNavigatorEventHandler;
+class QQnxVirtualKeyboard;
class QQnxWindow;
class QQnxServices;
@@ -103,6 +104,7 @@ private:
screen_context_t m_screenContext;
QQnxEventThread *m_eventThread;
QQnxNavigatorEventHandler *m_navigatorEventHandler;
+ QQnxVirtualKeyboard *m_virtualKeyboard;
QQnxInputContext *m_inputContext;
QPlatformFontDatabase *m_fontDatabase;
bool m_paintUsingOpenGL;
diff --git a/src/plugins/platforms/qnx/qqnxscreen.cpp b/src/plugins/platforms/qnx/qqnxscreen.cpp
index cd77c3088a..1fef0bc0a7 100644
--- a/src/plugins/platforms/qnx/qqnxscreen.cpp
+++ b/src/plugins/platforms/qnx/qqnxscreen.cpp
@@ -40,11 +40,11 @@
****************************************************************************/
#include "qqnxscreen.h"
-#include "qqnxvirtualkeyboard.h"
#include "qqnxwindow.h"
#include <QtCore/QDebug>
#include <QtCore/QUuid>
+#include <QtGui/QWindowSystemInterface>
#include <errno.h>
@@ -59,6 +59,7 @@ QQnxScreen::QQnxScreen(screen_context_t screenContext, screen_display_t display,
m_rootWindow(),
m_primaryScreen(primaryScreen),
m_posted(false),
+ m_keyboardHeight(0),
m_platformContext(0)
{
#if defined(QQNXSCREEN_DEBUG)
@@ -182,9 +183,8 @@ QRect QQnxScreen::availableGeometry() const
qDebug() << Q_FUNC_INFO;
#endif
// available geometry = total geometry - keyboard
- int keyboardHeight = QQnxVirtualKeyboard::instance().height();
return QRect(m_currentGeometry.x(), m_currentGeometry.y(),
- m_currentGeometry.width(), m_currentGeometry.height() - keyboardHeight);
+ m_currentGeometry.width(), m_currentGeometry.height() - m_keyboardHeight);
}
/*!
@@ -312,4 +312,15 @@ void QQnxScreen::onWindowPost(QQnxWindow *window)
}
}
+void QQnxScreen::keyboardHeightChanged(int height)
+{
+ if (height == m_keyboardHeight)
+ return;
+
+ m_keyboardHeight = height;
+
+ QWindowSystemInterface::handleScreenAvailableGeometryChange(screen(), availableGeometry());
+}
+
+
QT_END_NAMESPACE
diff --git a/src/plugins/platforms/qnx/qqnxscreen.h b/src/plugins/platforms/qnx/qqnxscreen.h
index 5749a66f5d..4d1590349b 100644
--- a/src/plugins/platforms/qnx/qqnxscreen.h
+++ b/src/plugins/platforms/qnx/qqnxscreen.h
@@ -47,6 +47,7 @@
#include "qqnxrootwindow.h"
#include <QtCore/QByteArray>
+#include <QtCore/QObject>
#include <QtCore/QScopedPointer>
#include <screen/screen.h>
@@ -55,8 +56,9 @@ QT_BEGIN_NAMESPACE
class QQnxWindow;
-class QQnxScreen : public QPlatformScreen
+class QQnxScreen : public QObject, public QPlatformScreen
{
+ Q_OBJECT
public:
static QList<QPlatformScreen *> screens() { return ms_screens; }
static void createDisplays(screen_context_t context);
@@ -91,6 +93,9 @@ public:
QSharedPointer<QQnxRootWindow> rootWindow() const { return m_rootWindow; }
+private Q_SLOTS:
+ void keyboardHeightChanged(int height);
+
private:
QQnxScreen(screen_context_t context, screen_display_t display, bool primaryScreen);
virtual ~QQnxScreen();
@@ -102,10 +107,10 @@ private:
QSharedPointer<QQnxRootWindow> m_rootWindow;
bool m_primaryScreen;
bool m_posted;
- bool m_usingOpenGL;
int m_initialRotation;
int m_currentRotation;
+ int m_keyboardHeight;
QSize m_initialPhysicalSize;
QSize m_currentPhysicalSize;
QRect m_initialGeometry;
diff --git a/src/plugins/platforms/qnx/qqnxvirtualkeyboard.cpp b/src/plugins/platforms/qnx/qqnxvirtualkeyboard.cpp
index 20c89d3e32..afdd7715db 100644
--- a/src/plugins/platforms/qnx/qqnxvirtualkeyboard.cpp
+++ b/src/plugins/platforms/qnx/qqnxvirtualkeyboard.cpp
@@ -42,9 +42,6 @@
#include "qqnxvirtualkeyboard.h"
#include "qqnxscreen.h"
-#include <QtGui/QPlatformScreen>
-#include <QtGui/QPlatformWindow>
-
#include <QtCore/QDebug>
#include <QtCore/QSocketNotifier>
#include <QtCore/private/qcore_unix_p.h>
@@ -59,11 +56,11 @@
#include <sys/types.h>
#include <unistd.h>
+QT_BEGIN_NAMESPACE
+
const char *QQnxVirtualKeyboard::ms_PPSPath = "/pps/services/input/control?wait";
const size_t QQnxVirtualKeyboard::ms_bufferSize = 2048;
-static QQnxVirtualKeyboard *s_instance = 0;
-
// Huge hack for keyboard shadow (see QNX PR 88400). Should be removed ASAP.
#define KEYBOARD_SHADOW_HEIGHT 8
@@ -85,20 +82,6 @@ QQnxVirtualKeyboard::~QQnxVirtualKeyboard()
close();
}
-/* static */
-QQnxVirtualKeyboard& QQnxVirtualKeyboard::instance()
-{
- if (!s_instance) {
- s_instance = new QQnxVirtualKeyboard();
-
- // 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(s_instance, "start", Qt::QueuedConnection);
- }
-
- return *s_instance;
-}
-
void QQnxVirtualKeyboard::start()
{
#ifdef QQNXVIRTUALKEYBOARD_DEBUG
@@ -108,15 +91,6 @@ void QQnxVirtualKeyboard::start()
return;
}
-/* static */
-void QQnxVirtualKeyboard::destroy()
-{
- if (s_instance) {
- delete s_instance;
- s_instance = 0;
- }
-}
-
void QQnxVirtualKeyboard::close()
{
delete m_readNotifier;
@@ -292,7 +266,8 @@ void QQnxVirtualKeyboard::handleKeyboardInfoMessage()
if (newHeight != m_height) {
m_height = newHeight;
- updateAvailableScreenGeometry();
+ if (m_visible)
+ emit heightChanged(m_height);
}
const QLocale locale = QLocale(languageId + QLatin1Char('_') + countryId);
@@ -312,7 +287,8 @@ void QQnxVirtualKeyboard::handleKeyboardStateChangeMessage(bool visible)
#ifdef QQNXVIRTUALKEYBOARD_DEBUG
qDebug() << "QQNX: handleKeyboardStateChangeMessage " << visible;
#endif
- updateAvailableScreenGeometry();
+ if (visible != m_visible)
+ emit heightChanged(height());
if (visible)
showKeyboard();
@@ -320,19 +296,6 @@ void QQnxVirtualKeyboard::handleKeyboardStateChangeMessage(bool visible)
hideKeyboard();
}
-void QQnxVirtualKeyboard::updateAvailableScreenGeometry()
-{
-#ifdef QQNXVIRTUALKEYBOARD_DEBUG
- qDebug() << "QQNX: updateAvailableScreenGeometry: keyboard visible=" << m_visible << ", keyboard height=" << m_height;
-#endif
-
- // TODO: What screen index should be used? I assume primaryScreen here because it works, and
- // we do it for handleScreenGeometryChange elsewhere but since we have support
- // for more than one screen, that's not going to always work.
- QQnxScreen *platformScreen = QQnxScreen::primaryDisplay();
- QWindowSystemInterface::handleScreenAvailableGeometryChange(platformScreen->screen(), platformScreen->availableGeometry());
-}
-
bool QQnxVirtualKeyboard::showKeyboard()
{
#ifdef QQNXVIRTUALKEYBOARD_DEBUG
@@ -347,6 +310,9 @@ bool QQnxVirtualKeyboard::showKeyboard()
// hiding the keyboard wipes the setting.
applyKeyboardModeOptions();
+ if (m_visible)
+ return true;
+
pps_encoder_reset(m_encoder);
// Send the show message.
@@ -398,7 +364,12 @@ bool QQnxVirtualKeyboard::hideKeyboard()
void QQnxVirtualKeyboard::setKeyboardMode(KeyboardMode mode)
{
+ if (m_keyboardMode == mode)
+ return;
+
m_keyboardMode = mode;
+ if (m_visible)
+ applyKeyboardModeOptions();
}
void QQnxVirtualKeyboard::applyKeyboardModeOptions()
@@ -495,3 +466,5 @@ void QQnxVirtualKeyboard::addSymbolModeOptions()
pps_encoder_add_string(m_encoder, "enter", "enter.default");
pps_encoder_add_string(m_encoder, "type", "symbol");
}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/platforms/qnx/qqnxvirtualkeyboard.h b/src/plugins/platforms/qnx/qqnxvirtualkeyboard.h
index 73a296fb9f..9f29a077e6 100644
--- a/src/plugins/platforms/qnx/qqnxvirtualkeyboard.h
+++ b/src/plugins/platforms/qnx/qqnxvirtualkeyboard.h
@@ -45,17 +45,16 @@
#include <QtCore/QObject>
#include <QtCore/QLocale>
#include <QtGui/QPlatformScreen>
-#include <QtGui/QWindowSystemInterface>
#include <stddef.h>
#include <vector>
#include <string>
#include <sys/pps.h>
-class QSocketNotifier;
-
QT_BEGIN_NAMESPACE
+class QSocketNotifier;
+
/* Shamelessly copied from the browser - this should be rewritten once we have a proper PPS wrapper class */
class QQnxVirtualKeyboard : public QObject
{
@@ -74,8 +73,8 @@ public:
//
enum KeyboardMode { Default, Url, Email, Web, NumPunc, Symbol, Phone, Pin };
- static QQnxVirtualKeyboard& instance();
- static void destroy();
+ QQnxVirtualKeyboard();
+ ~QQnxVirtualKeyboard();
bool showKeyboard();
bool hideKeyboard();
@@ -91,21 +90,18 @@ public Q_SLOTS:
Q_SIGNALS:
void localeChanged(const QLocale &locale);
void visibilityChanged(bool visible);
+ void heightChanged(int height);
private Q_SLOTS:
void ppsDataReady();
private:
- QQnxVirtualKeyboard();
- virtual ~QQnxVirtualKeyboard();
-
// Will be called internally if needed.
bool connect();
void close();
bool queryPPSInfo();
void handleKeyboardInfoMessage();
void handleKeyboardStateChangeMessage(bool visible);
- void updateAvailableScreenGeometry();
void applyKeyboardModeOptions();
void addDefaultModeOptions();