summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKevin Krammer <kevin.krammer.qnx@kdab.com>2012-03-23 16:35:33 (GMT)
committerQt by Nokia <qt-info@nokia.com>2012-03-30 12:40:19 (GMT)
commitacbdd48f4401f2cc9b48eb3bd79d957b1c4e2949 (patch)
tree1ba3d566175d22dd00f67d200e2c1ad0751b460a /src
parent69a50ee68bb870b3ba0d95a35ab8b6bc4e1a461f (diff)
downloadQt-acbdd48f4401f2cc9b48eb3bd79d957b1c4e2949.zip
Qt-acbdd48f4401f2cc9b48eb3bd79d957b1c4e2949.tar.gz
Qt-acbdd48f4401f2cc9b48eb3bd79d957b1c4e2949.tar.bz2
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. Backport of 5d117fd427e3e727df5d3f417a2b91366f2a31c1 Change-Id: I49c1a6af5decca47a5ab3ba382430a2b25578d40 Reviewed-by: Sean Harmer <sean.harmer@kdab.com> Reviewed-by: Thomas McGuire <thomas.mcguire@kdab.com> Reviewed-by: Robin Burchell <robin+qt@viroteck.net>
Diffstat (limited to 'src')
-rw-r--r--src/plugins/platforms/blackberry/qbbinputcontext_imf.cpp15
-rw-r--r--src/plugins/platforms/blackberry/qbbinputcontext_imf.h5
-rw-r--r--src/plugins/platforms/blackberry/qbbinputcontext_noimf.cpp29
-rw-r--r--src/plugins/platforms/blackberry/qbbinputcontext_noimf.h5
-rw-r--r--src/plugins/platforms/blackberry/qbbintegration.cpp17
-rw-r--r--src/plugins/platforms/blackberry/qbbintegration.h2
-rw-r--r--src/plugins/platforms/blackberry/qbbscreen.cpp18
-rw-r--r--src/plugins/platforms/blackberry/qbbscreen.h5
-rw-r--r--src/plugins/platforms/blackberry/qbbvirtualkeyboard.cpp46
-rw-r--r--src/plugins/platforms/blackberry/qbbvirtualkeyboard.h15
10 files changed, 93 insertions, 64 deletions
diff --git a/src/plugins/platforms/blackberry/qbbinputcontext_imf.cpp b/src/plugins/platforms/blackberry/qbbinputcontext_imf.cpp
index 95a0441..5a87777 100644
--- a/src/plugins/platforms/blackberry/qbbinputcontext_imf.cpp
+++ b/src/plugins/platforms/blackberry/qbbinputcontext_imf.cpp
@@ -676,10 +676,13 @@ static bool imfAvailable()
return s_imfReady;
}
-QBBInputContext::QBBInputContext(QObject* parent):
+QT_BEGIN_NAMESPACE
+
+QBBInputContext::QBBInputContext(QBBVirtualKeyboard &keyboard, QObject* parent):
QInputContext(parent),
mLastCaretPos(0),
- mIsComposing(false)
+ mIsComposing(false),
+ mVirtualKeyboard(keyboard)
{
#if defined(QBBINPUTCONTEXT_DEBUG)
qDebug() << TAG;
@@ -890,7 +893,7 @@ QString QBBInputContext::identifierName()
QString QBBInputContext::language()
{
- return QBBVirtualKeyboard::instance().languageId();
+ return mVirtualKeyboard.languageId();
}
bool QBBInputContext::filterEvent( const QEvent *event )
@@ -1044,7 +1047,7 @@ bool QBBInputContext::hasSelectedText()
bool QBBInputContext::dispatchRequestSoftwareInputPanel()
{
- QBBVirtualKeyboard::instance().showKeyboard();
+ mVirtualKeyboard.showKeyboard();
#if defined(QBBINPUTCONTEXT_DEBUG)
qDebug() << "QBB: requesting virtual keyboard";
#endif
@@ -1065,7 +1068,7 @@ bool QBBInputContext::dispatchRequestSoftwareInputPanel()
bool QBBInputContext::dispatchCloseSoftwareInputPanel()
{
- QBBVirtualKeyboard::instance().hideKeyboard();
+ mVirtualKeyboard.hideKeyboard();
#if defined(QBBINPUTCONTEXT_DEBUG)
qDebug() << "QBB: hiding virtual keyboard";
#endif
@@ -1656,4 +1659,4 @@ int32_t QBBInputContext::onSetSelection(input_session_t* ic, int32_t start, int3
return 0;
}
-
+QT_END_NAMESPACE
diff --git a/src/plugins/platforms/blackberry/qbbinputcontext_imf.h b/src/plugins/platforms/blackberry/qbbinputcontext_imf.h
index 6d18ddd..ddbe912 100644
--- a/src/plugins/platforms/blackberry/qbbinputcontext_imf.h
+++ b/src/plugins/platforms/blackberry/qbbinputcontext_imf.h
@@ -48,10 +48,12 @@
QT_BEGIN_NAMESPACE
+class QBBVirtualKeyboard;
+
class QBBInputContext : public QInputContext
{
public:
- explicit QBBInputContext(QObject* parent = 0);
+ explicit QBBInputContext(QBBVirtualKeyboard &keyboard, QObject* parent = 0);
~QBBInputContext();
virtual QList<QAction *> actions();
@@ -110,6 +112,7 @@ private:
int mLastCaretPos;
bool mIsComposing;
QString mComposingText;
+ QBBVirtualKeyboard &mVirtualKeyboard;
};
QT_END_NAMESPACE
diff --git a/src/plugins/platforms/blackberry/qbbinputcontext_noimf.cpp b/src/plugins/platforms/blackberry/qbbinputcontext_noimf.cpp
index a5b959b..ef39aba 100644
--- a/src/plugins/platforms/blackberry/qbbinputcontext_noimf.cpp
+++ b/src/plugins/platforms/blackberry/qbbinputcontext_noimf.cpp
@@ -43,9 +43,13 @@
#include <qbbvirtualkeyboard.h>
#include <QDebug>
+#include <QAbstractSpinBox>
-QBBInputContext::QBBInputContext(QObject* parent):
- QInputContext(parent)
+QT_BEGIN_NAMESPACE
+
+QBBInputContext::QBBInputContext(QBBVirtualKeyboard &keyboard, QObject* parent)
+ : QInputContext(parent),
+ mVirtualKeyboard(keyboard)
{
}
@@ -56,7 +60,7 @@ QBBInputContext::~QBBInputContext()
QString QBBInputContext::language()
{
// Once we enable full IMF support, we need to hook that up here.
- return QBBVirtualKeyboard::instance().languageId();
+ return mVirtualKeyboard.languageId();
}
bool QBBInputContext::hasPhysicalKeyboard()
@@ -75,7 +79,7 @@ bool QBBInputContext::filterEvent( const QEvent *event )
return false;
if (event->type() == QEvent::CloseSoftwareInputPanel) {
- QBBVirtualKeyboard::instance().hideKeyboard();
+ mVirtualKeyboard.hideKeyboard();
#if defined(QBBINPUTCONTEXT_DEBUG)
qDebug() << "QBB: hiding virtual keyboard";
#endif
@@ -83,7 +87,7 @@ bool QBBInputContext::filterEvent( const QEvent *event )
}
if (event->type() == QEvent::RequestSoftwareInputPanel) {
- QBBVirtualKeyboard::instance().showKeyboard();
+ mVirtualKeyboard.showKeyboard();
#if defined(QBBINPUTCONTEXT_DEBUG)
qDebug() << "QBB: requesting virtual keyboard";
#endif
@@ -106,9 +110,16 @@ void QBBInputContext::setFocusWidget(QWidget *w)
#endif
QInputContext::setFocusWidget(w);
- if (w)
- QBBVirtualKeyboard::instance().showKeyboard();
- else
- QBBVirtualKeyboard::instance().hideKeyboard();
+ if (w) {
+ if (qobject_cast<QAbstractSpinBox*>(w))
+ mVirtualKeyboard.setKeyboardMode(QBBVirtualKeyboard::Phone);
+ else
+ mVirtualKeyboard.setKeyboardMode(QBBVirtualKeyboard::Default);
+
+ mVirtualKeyboard.showKeyboard();
+ } else {
+ mVirtualKeyboard.hideKeyboard();
+ }
}
+QT_END_NAMESPACE
diff --git a/src/plugins/platforms/blackberry/qbbinputcontext_noimf.h b/src/plugins/platforms/blackberry/qbbinputcontext_noimf.h
index 6332ee7..3c416c8 100644
--- a/src/plugins/platforms/blackberry/qbbinputcontext_noimf.h
+++ b/src/plugins/platforms/blackberry/qbbinputcontext_noimf.h
@@ -45,10 +45,12 @@
QT_BEGIN_NAMESPACE
+class QBBVirtualKeyboard;
+
class QBBInputContext : public QInputContext
{
public:
- explicit QBBInputContext(QObject* parent = 0);
+ explicit QBBInputContext(QBBVirtualKeyboard &keyboard, QObject* parent = 0);
~QBBInputContext();
QString identifierName() { return QString("BlackBerry IMF"); }
QString language();
@@ -63,6 +65,7 @@ public:
private:
bool hasPhysicalKeyboard();
+ QBBVirtualKeyboard &mVirtualKeyboard;
};
QT_END_NAMESPACE
diff --git a/src/plugins/platforms/blackberry/qbbintegration.cpp b/src/plugins/platforms/blackberry/qbbintegration.cpp
index a180ac9..f68f92e 100644
--- a/src/plugins/platforms/blackberry/qbbintegration.cpp
+++ b/src/plugins/platforms/blackberry/qbbintegration.cpp
@@ -71,7 +71,8 @@ QT_BEGIN_NAMESPACE
QBBIntegration::QBBIntegration() :
mFontDb(new QGenericUnixFontDatabase()),
- mPaintUsingOpenGL(getenv("QBB_USE_OPENGL") != NULL)
+ mPaintUsingOpenGL(getenv("QBB_USE_OPENGL") != NULL),
+ mVirtualKeyboard(0)
{
if (mPaintUsingOpenGL) {
// Set default window API to OpenGL
@@ -118,10 +119,18 @@ QBBIntegration::QBBIntegration() :
#endif
// create/start the keyboard class.
- QBBVirtualKeyboard::instance();
+ mVirtualKeyboard = new QBBVirtualKeyboard();
+
+ // 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(mVirtualKeyboard, "start", Qt::QueuedConnection);
+
+ // TODO check if we need to do this for all screens or only the primary one
+ QObject::connect(mVirtualKeyboard, SIGNAL(heightChanged(int)),
+ QBBScreen::primaryDisplay(), SLOT(keyboardHeightChanged(int)));
// Set up the input context
- qApp->setInputContext(new QBBInputContext(qApp));
+ qApp->setInputContext(new QBBInputContext(*mVirtualKeyboard, qApp));
}
QBBIntegration::~QBBIntegration()
@@ -130,7 +139,7 @@ QBBIntegration::~QBBIntegration()
qDebug() << "QBB: platform plugin shutdown begin";
#endif
// destroy the keyboard class.
- QBBVirtualKeyboard::destroy();
+ delete mVirtualKeyboard;
#ifdef QBBLOCALETHREAD_ENABLED
// stop/destroy the locale thread.
diff --git a/src/plugins/platforms/blackberry/qbbintegration.h b/src/plugins/platforms/blackberry/qbbintegration.h
index 2a9fceb..2866b19 100644
--- a/src/plugins/platforms/blackberry/qbbintegration.h
+++ b/src/plugins/platforms/blackberry/qbbintegration.h
@@ -49,6 +49,7 @@ QT_BEGIN_NAMESPACE
class QBBEventThread;
class QBBNavigatorEventHandler;
class QBBLocaleThread;
+class QBBVirtualKeyboard;
class QBBIntegration : public QPlatformIntegration
{
@@ -81,6 +82,7 @@ private:
QBBLocaleThread *mLocaleThread;
QPlatformFontDatabase *mFontDb;
bool mPaintUsingOpenGL;
+ QBBVirtualKeyboard *mVirtualKeyboard;
};
QT_END_NAMESPACE
diff --git a/src/plugins/platforms/blackberry/qbbscreen.cpp b/src/plugins/platforms/blackberry/qbbscreen.cpp
index 3ea0e40..60969fc 100644
--- a/src/plugins/platforms/blackberry/qbbscreen.cpp
+++ b/src/plugins/platforms/blackberry/qbbscreen.cpp
@@ -40,12 +40,12 @@
// #define QBBSCREEN_DEBUG
#include "qbbscreen.h"
-#include "qbbvirtualkeyboard.h"
#include "qbbrootwindow.h"
#include "qbbwindow.h"
#include <QUuid>
#include <QDebug>
+#include <QtGui/QWindowSystemInterface>
#include <errno.h>
#include <unistd.h>
@@ -62,7 +62,8 @@ QBBScreen::QBBScreen(screen_context_t context, screen_display_t display, bool pr
mDisplay(display),
mPosted(false),
mUsingOpenGL(false),
- mPrimaryDisplay(primary)
+ mPrimaryDisplay(primary),
+ mKeyboardHeight(0)
{
#if defined(QBBSCREEN_DEBUG)
qDebug() << "QBBScreen::QBBScreen";
@@ -183,9 +184,8 @@ void QBBScreen::ensureDisplayCreated()
QRect QBBScreen::availableGeometry() const
{
// available geometry = total geometry - keyboard
- int keyboardHeight = QBBVirtualKeyboard::instance().getHeight();
return QRect(mCurrentGeometry.x(), mCurrentGeometry.y(),
- mCurrentGeometry.width(), mCurrentGeometry.height() - keyboardHeight);
+ mCurrentGeometry.width(), mCurrentGeometry.height() - mKeyboardHeight);
}
/*!
@@ -322,4 +322,14 @@ void QBBScreen::onWindowPost(QBBWindow* window)
}
}
+void QBBScreen::keyboardHeightChanged(int height)
+{
+ if (height == mKeyboardHeight)
+ return;
+
+ mKeyboardHeight = height;
+
+ QWindowSystemInterface::handleScreenAvailableGeometryChange(screens().indexOf(this));
+}
+
QT_END_NAMESPACE
diff --git a/src/plugins/platforms/blackberry/qbbscreen.h b/src/plugins/platforms/blackberry/qbbscreen.h
index cb71b78..9d2b815 100644
--- a/src/plugins/platforms/blackberry/qbbscreen.h
+++ b/src/plugins/platforms/blackberry/qbbscreen.h
@@ -53,6 +53,7 @@ class QBBWindow;
class QBBScreen : public QPlatformScreen
{
+ Q_OBJECT
public:
static QList<QPlatformScreen *> screens() { return sScreens; }
static void createDisplays(screen_context_t context);
@@ -86,6 +87,9 @@ public:
QSharedPointer<QBBRootWindow> rootWindow() const { return mRootWindow; }
+private Q_SLOTS:
+ void keyboardHeightChanged(int height);
+
private:
screen_context_t mContext;
screen_display_t mDisplay;
@@ -96,6 +100,7 @@ private:
int mStartRotation;
int mCurrentRotation;
+ int mKeyboardHeight;
QSize mStartPhysicalSize;
QSize mCurrentPhysicalSize;
QRect mStartGeometry;
diff --git a/src/plugins/platforms/blackberry/qbbvirtualkeyboard.cpp b/src/plugins/platforms/blackberry/qbbvirtualkeyboard.cpp
index 3022dc8..0f1a16e 100644
--- a/src/plugins/platforms/blackberry/qbbvirtualkeyboard.cpp
+++ b/src/plugins/platforms/blackberry/qbbvirtualkeyboard.cpp
@@ -37,7 +37,7 @@
**
****************************************************************************/
-//#define QBBVIRTUALKEYBOARD_DEBUG
+#define QBBVIRTUALKEYBOARD_DEBUG
#include "qbbvirtualkeyboard.h"
@@ -58,11 +58,12 @@
#include <sys/types.h>
#include <unistd.h>
+
+QT_BEGIN_NAMESPACE
+
const char *QBBVirtualKeyboard::sPPSPath = "/pps/services/input/control?wait";
const size_t QBBVirtualKeyboard::sBufferSize = 2048;
-static QBBVirtualKeyboard* s_instance = NULL;
-
// Huge hack for keyboard shadow (see QNX PR 88400). Should be removed ASAP.
#define KEYBOARD_SHADOW_HEIGHT 8
@@ -85,20 +86,6 @@ QBBVirtualKeyboard::~QBBVirtualKeyboard()
close();
}
-/* static */
-QBBVirtualKeyboard& QBBVirtualKeyboard::instance()
-{
- if (!s_instance) {
- s_instance = new QBBVirtualKeyboard();
-
- // 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 QBBVirtualKeyboard::start()
{
#ifdef QBBVIRTUALKEYBOARD_DEBUG
@@ -109,15 +96,6 @@ void QBBVirtualKeyboard::start()
return;
}
-/* static */
-void QBBVirtualKeyboard::destroy()
-{
- if (s_instance) {
- delete s_instance;
- s_instance = 0;
- }
-}
-
void QBBVirtualKeyboard::close()
{
delete mReadNotifier;
@@ -289,7 +267,8 @@ void QBBVirtualKeyboard::handleKeyboardInfoMessage()
if (newHeight != mHeight) {
mHeight = newHeight;
- handleKeyboardStateChangeMessage(true);
+ if (mVisible)
+ emit heightChanged(mHeight);
}
#ifdef QBBVIRTUALKEYBOARD_DEBUG
@@ -304,10 +283,8 @@ void QBBVirtualKeyboard::handleKeyboardStateChangeMessage(bool visible)
qDebug() << "QBB: handleKeyboardStateChangeMessage " << visible;
#endif
- // TODO: What screen index should be used? I assume 0 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.
- QWindowSystemInterface::handleScreenAvailableGeometryChange(0);
+ if (mVisible != visible)
+ emit heightChanged(getHeight());
}
bool QBBVirtualKeyboard::showKeyboard()
@@ -375,7 +352,12 @@ bool QBBVirtualKeyboard::hideKeyboard()
void QBBVirtualKeyboard::setKeyboardMode(KeyboardMode mode)
{
+ if (mKeyboardMode == mode)
+ return;
+
mKeyboardMode = mode;
+ if (mVisible)
+ applyKeyboardModeOptions();
}
void QBBVirtualKeyboard::applyKeyboardModeOptions()
@@ -472,3 +454,5 @@ void QBBVirtualKeyboard::addSymbolModeOptions()
pps_encoder_add_string(mEncoder, "enter", "enter.default");
pps_encoder_add_string(mEncoder, "type", "symbol");
}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/platforms/blackberry/qbbvirtualkeyboard.h b/src/plugins/platforms/blackberry/qbbvirtualkeyboard.h
index c0c13d1..6a8c332 100644
--- a/src/plugins/platforms/blackberry/qbbvirtualkeyboard.h
+++ b/src/plugins/platforms/blackberry/qbbvirtualkeyboard.h
@@ -41,7 +41,6 @@
#define VIRTUALKEYBOARD_H_
#include <QtGui/QPlatformScreen>
-#include <QtGui/QWindowSystemInterface>
#include <QObject>
#include <stddef.h>
@@ -49,10 +48,10 @@
#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 QBBVirtualKeyboard : public QObject
{
@@ -71,8 +70,8 @@ public:
//
enum KeyboardMode { Default, Url, Email, Web, NumPunc, Symbol, Phone, Pin };
- static QBBVirtualKeyboard& instance();
- static void destroy();
+ QBBVirtualKeyboard();
+ ~QBBVirtualKeyboard();
bool showKeyboard();
bool hideKeyboard();
@@ -86,13 +85,13 @@ public:
public Q_SLOTS:
void start();
+Q_SIGNALS:
+ void heightChanged(int height);
+
private Q_SLOTS:
void ppsDataReady();
private:
- QBBVirtualKeyboard();
- virtual ~QBBVirtualKeyboard();
-
pps_encoder_t *mEncoder;
pps_decoder_t *mDecoder;
char *mBuffer;