Separate virtual keyboard interface and implementation

Allows us to create a BPS based implementation and drop it in
without further changes to users of the interface.

Change-Id: I16313717e1200d717c330cbb18c3314567af51c2
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Reviewed-by: Thomas McGuire <thomas.mcguire@kdab.com>
Reviewed-by: Robin Burchell <robin+qt@viroteck.net>
This commit is contained in:
Kevin Krammer 2012-03-27 17:43:43 +02:00 committed by Qt by Nokia
parent 724e0e20ae
commit 831943d7f1
10 changed files with 241 additions and 111 deletions

View File

@ -37,7 +37,8 @@ SOURCES = main.cpp \
qqnxvirtualkeyboard.cpp \
qqnxclipboard.cpp \
qqnxrootwindow.cpp \
qqnxscreeneventhandler.cpp
qqnxscreeneventhandler.cpp \
qqnxabstractvirtualkeyboard.cpp
HEADERS = qqnxbuffer.h \
@ -53,7 +54,8 @@ HEADERS = qqnxbuffer.h \
qqnxvirtualkeyboard.h \
qqnxclipboard.h \
qqnxrootwindow.h \
qqnxscreeneventhandler.h
qqnxscreeneventhandler.h \
qqnxabstractvirtualkeyboard.h
CONFIG(blackberry) {
SOURCES += qqnxservices.cpp

View File

@ -0,0 +1,103 @@
/***************************************************************************
**
** Copyright (C) 2011 - 2012 Research In Motion
** Contact: http://www.qt-project.org/
**
** This file is part of the plugins of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** GNU Lesser General Public License Usage
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this
** file. Please review the following information to ensure the GNU Lesser
** General Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU General
** Public License version 3.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of this
** file. Please review the following information to ensure the GNU General
** Public License version 3.0 requirements will be met:
** http://www.gnu.org/copyleft/gpl.html.
**
** Other Usage
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "qqnxabstractvirtualkeyboard.h"
QT_BEGIN_NAMESPACE
QQnxAbstractVirtualKeyboard::QQnxAbstractVirtualKeyboard(QObject *parent)
: QObject(parent)
, m_height(0)
, m_visible(false)
, m_locale(QLocale::system())
, m_keyboardMode(Default)
{
}
void QQnxAbstractVirtualKeyboard::setKeyboardMode(KeyboardMode mode)
{
if (mode == m_keyboardMode)
return;
m_keyboardMode = mode;
applyKeyboardMode(mode);
}
void QQnxAbstractVirtualKeyboard::setHeight(int height)
{
if (height == m_height)
return;
const int effectiveHeight = this->height();
m_height = height;
if (effectiveHeight != this->height())
emit heightChanged(this->height());
}
void QQnxAbstractVirtualKeyboard::setVisible(bool visible)
{
if (visible == m_visible)
return;
const int effectiveHeight = height();
m_visible = visible;
emit visibilityChanged(visible);
if (effectiveHeight != height())
emit heightChanged(height());
}
void QQnxAbstractVirtualKeyboard::setLocale(const QLocale &locale)
{
if (locale == m_locale)
return;
m_locale = locale;
emit localeChanged(locale);
}
QT_END_NAMESPACE

View File

@ -0,0 +1,100 @@
/***************************************************************************
**
** Copyright (C) 2011 - 2012 Research In Motion
** Contact: http://www.qt-project.org/
**
** This file is part of the plugins of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** GNU Lesser General Public License Usage
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this
** file. Please review the following information to ensure the GNU Lesser
** General Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU General
** Public License version 3.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of this
** file. Please review the following information to ensure the GNU General
** Public License version 3.0 requirements will be met:
** http://www.gnu.org/copyleft/gpl.html.
**
** Other Usage
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef QQNXABSTRACTVIRTUALKEYBOARD_H
#define QQNXABSTRACTVIRTUALKEYBOARD_H
#include <QLocale>
#include <QObject>
QT_BEGIN_NAMESPACE
class QQnxAbstractVirtualKeyboard : public QObject
{
Q_OBJECT
public:
// NOTE: Not all the following keyboard modes are currently used.
// Default - Regular Keyboard
// Url/Email - Enhanced keys for each types.
// Web - Regular keyboard with two blank keys, currently unused.
// NumPunc - Numbers & Punctionation, alternate to Symbol
// Symbol - All symbols, alternate to NumPunc, currently unused.
// Phone - Phone enhanced keyboard - currently unused as no alternate keyboard available to access a-zA-Z
// Pin - Keyboard for entering Pins (Hex values) currently unused.
//
// SPECIAL NOTE: Usage of NumPunc may have to be removed, ABC button is non-functional.
//
enum KeyboardMode { Default, Url, Email, Web, NumPunc, Symbol, Phone, Pin };
explicit QQnxAbstractVirtualKeyboard(QObject *parent = 0);
virtual bool showKeyboard() = 0;
virtual bool hideKeyboard() = 0;
int height() { return m_visible ? m_height : 0; }
bool isVisible() const { return m_visible; }
QLocale locale() const { return m_locale; }
void setKeyboardMode(KeyboardMode mode);
KeyboardMode keyboardMode() const { return m_keyboardMode; }
Q_SIGNALS:
void heightChanged(int height);
void visibilityChanged(bool visible);
void localeChanged(const QLocale &locale);
protected:
virtual void applyKeyboardMode(KeyboardMode mode) = 0;
void setHeight(int height);
void setVisible(bool visible);
void setLocale(const QLocale &locale);
private:
int m_height;
bool m_visible;
QLocale m_locale;
KeyboardMode m_keyboardMode;
};
QT_END_NAMESPACE
#endif // QQNXABSTRACTVIRTUALKEYBOARD_H

View File

@ -41,7 +41,7 @@
#include "qqnxinputcontext_imf.h"
#include "qqnxeventthread.h"
#include "qqnxvirtualkeyboard.h"
#include "qqnxabstractvirtualkeyboard.h"
#include <QtWidgets/QAbstractSpinBox>
#include <QtWidgets/QAction>
@ -676,7 +676,7 @@ static bool imfAvailable()
QT_BEGIN_NAMESPACE
QQnxInputContext::QQnxInputContext(QQnxVirtualKeyboard &keyboard):
QQnxInputContext::QQnxInputContext(QQnxAbstractVirtualKeyboard &keyboard):
QPlatformInputContext(),
m_lastCaretPos(0),
m_isComposing(false),
@ -1688,9 +1688,9 @@ void QQnxInputContext::inputItemChanged()
hideInputPanel();
} else {
if (qobject_cast<QAbstractSpinBox*>(inputItem))
m_virtualKeyboard.setKeyboardMode(QQnxVirtualKeyboard::Phone);
m_virtualKeyboard.setKeyboardMode(QQnxAbstractVirtualKeyboard::Phone);
else
m_virtualKeyboard.setKeyboardMode(QQnxVirtualKeyboard::Default);
m_virtualKeyboard.setKeyboardMode(QQnxAbstractVirtualKeyboard::Default);
if (!m_inputPanelVisible)
showInputPanel();

View File

@ -53,13 +53,13 @@
QT_BEGIN_NAMESPACE
class QQnxVirtualKeyboard;
class QQnxAbstractVirtualKeyboard;
class QQnxInputContext : public QPlatformInputContext
{
Q_OBJECT
public:
QQnxInputContext(QQnxVirtualKeyboard &keyboard);
explicit QQnxInputContext(QQnxAbstractVirtualKeyboard &keyboard);
~QQnxInputContext();
bool isValid() const;
@ -125,7 +125,7 @@ private:
QString m_composingText;
bool m_inputPanelVisible;
QLocale m_inputPanelLocale;
QQnxVirtualKeyboard &m_virtualKeyboad;
QQnxAbstractVirtualKeyboard &m_virtualKeyboad;
};
Q_DECLARE_METATYPE(extracted_text_t*)

View File

@ -40,7 +40,7 @@
****************************************************************************/
#include "qqnxinputcontext_noimf.h"
#include "qqnxvirtualkeyboard.h"
#include "qqnxabstractvirtualkeyboard.h"
#include <QtCore/QDebug>
#include <QtGui/QGuiApplication>
@ -48,7 +48,7 @@
QT_BEGIN_NAMESPACE
QQnxInputContext::QQnxInputContext(QQnxVirtualKeyboard &keyboard) :
QQnxInputContext::QQnxInputContext(QQnxAbstractVirtualKeyboard &keyboard) :
QPlatformInputContext(),
m_inputPanelVisible(false),
m_inputPanelLocale(QLocale::c()),
@ -179,9 +179,9 @@ void QQnxInputContext::inputItemChanged()
hideInputPanel();
} else {
if (qobject_cast<QAbstractSpinBox*>(inputItem))
m_virtualKeyboard.setKeyboardMode(QQnxVirtualKeyboard::Phone);
m_virtualKeyboard.setKeyboardMode(QQnxAbstractVirtualKeyboard::Phone);
else
m_virtualKeyboard.setKeyboardMode(QQnxVirtualKeyboard::Default);
m_virtualKeyboard.setKeyboardMode(QQnxAbstractVirtualKeyboard::Default);
if (!m_inputPanelVisible)
showInputPanel();

View File

@ -48,13 +48,13 @@
QT_BEGIN_NAMESPACE
class QQnxVirtualKeyboard;
class QQnxAbstractVirtualKeyboard;
class QQnxInputContext : public QPlatformInputContext
{
Q_OBJECT
public:
explicit QQnxInputContext(QQnxVirtualKeyboard &keyboard);
explicit QQnxInputContext(QQnxAbstractVirtualKeyboard &keyboard);
~QQnxInputContext();
bool isValid() const;
@ -79,7 +79,7 @@ private:
bool m_inputPanelVisible;
QLocale m_inputPanelLocale;
QQnxVirtualKeyboard &m_virtualKeyboard;
QQnxAbstractVirtualKeyboard &m_virtualKeyboard;
};
QT_END_NAMESPACE

View File

@ -53,7 +53,7 @@ QT_BEGIN_NAMESPACE
class QQnxEventThread;
class QQnxInputContext;
class QQnxNavigatorEventHandler;
class QQnxVirtualKeyboard;
class QQnxAbstractVirtualKeyboard;
class QQnxWindow;
class QQnxServices;
@ -104,7 +104,7 @@ private:
screen_context_t m_screenContext;
QQnxEventThread *m_eventThread;
QQnxNavigatorEventHandler *m_navigatorEventHandler;
QQnxVirtualKeyboard *m_virtualKeyboard;
QQnxAbstractVirtualKeyboard *m_virtualKeyboard;
QQnxInputContext *m_inputContext;
QPlatformFontDatabase *m_fontDatabase;
bool m_paintUsingOpenGL;

View File

@ -68,11 +68,7 @@ QQnxVirtualKeyboard::QQnxVirtualKeyboard()
: m_encoder(0),
m_decoder(0),
m_buffer(0),
m_height(0),
m_fd(-1),
m_keyboardMode(Default),
m_visible(false),
m_locale(QLatin1String("en_US")),
m_readNotifier(0)
{
}
@ -91,6 +87,11 @@ void QQnxVirtualKeyboard::start()
return;
}
void QQnxVirtualKeyboard::applyKeyboardMode(KeyboardMode mode)
{
applyKeyboardModeOptions(mode);
}
void QQnxVirtualKeyboard::close()
{
delete m_readNotifier;
@ -168,12 +169,6 @@ bool QQnxVirtualKeyboard::queryPPSInfo()
return true;
}
void QQnxVirtualKeyboard::notifyClientActiveStateChange(bool active)
{
if (!active)
hideKeyboard();
}
void QQnxVirtualKeyboard::ppsDataReady()
{
ssize_t nread = qt_safe_read(m_fd, m_buffer, ms_bufferSize - 1);
@ -208,17 +203,9 @@ void QQnxVirtualKeyboard::ppsDataReady()
if (pps_decoder_get_string(m_decoder, "msg", &value) == PPS_DECODER_OK) {
if (strcmp(value, "show") == 0) {
const bool oldVisible = m_visible;
m_visible = true;
handleKeyboardStateChangeMessage(true);
if (oldVisible != m_visible)
emit visibilityChanged(m_visible);
setVisible(true);
} else if (strcmp(value, "hide") == 0) {
const bool oldVisible = m_visible;
m_visible = false;
handleKeyboardStateChangeMessage(false);
if (oldVisible != m_visible)
emit visibilityChanged(m_visible);
setVisible(false);
} else if (strcmp(value, "info") == 0)
handleKeyboardInfoMessage();
else if (strcmp(value, "connect") == 0) { }
@ -264,38 +251,16 @@ void QQnxVirtualKeyboard::handleKeyboardInfoMessage()
// HUGE hack, should be removed ASAP.
newHeight -= KEYBOARD_SHADOW_HEIGHT; // We want to ignore the 8 pixel shadow above the keyboard. (PR 88400)
if (newHeight != m_height) {
m_height = newHeight;
if (m_visible)
emit heightChanged(m_height);
}
setHeight(newHeight);
const QLocale locale = QLocale(languageId + QLatin1Char('_') + countryId);
if (locale != m_locale) {
m_locale = locale;
emit localeChanged(locale);
}
setLocale(locale);
#ifdef QQNXVIRTUALKEYBOARD_DEBUG
qDebug() << "QQNX: handleKeyboardInfoMessage size=" << m_height << "locale=" << m_locale;
#endif
}
void QQnxVirtualKeyboard::handleKeyboardStateChangeMessage(bool visible)
{
#ifdef QQNXVIRTUALKEYBOARD_DEBUG
qDebug() << "QQNX: handleKeyboardStateChangeMessage " << visible;
#endif
if (visible != m_visible)
emit heightChanged(height());
if (visible)
showKeyboard();
else
hideKeyboard();
}
bool QQnxVirtualKeyboard::showKeyboard()
{
#ifdef QQNXVIRTUALKEYBOARD_DEBUG
@ -308,9 +273,9 @@ bool QQnxVirtualKeyboard::showKeyboard()
// NOTE: This must be done everytime the keyboard is shown even if there is no change because
// hiding the keyboard wipes the setting.
applyKeyboardModeOptions();
applyKeyboardModeOptions(keyboardMode());
if (m_visible)
if (isVisible())
return true;
pps_encoder_reset(m_encoder);
@ -362,17 +327,7 @@ bool QQnxVirtualKeyboard::hideKeyboard()
return true;
}
void QQnxVirtualKeyboard::setKeyboardMode(KeyboardMode mode)
{
if (m_keyboardMode == mode)
return;
m_keyboardMode = mode;
if (m_visible)
applyKeyboardModeOptions();
}
void QQnxVirtualKeyboard::applyKeyboardModeOptions()
void QQnxVirtualKeyboard::applyKeyboardModeOptions(KeyboardMode mode)
{
// Try to connect.
if (m_fd == -1 && !connect())
@ -382,7 +337,7 @@ void QQnxVirtualKeyboard::applyKeyboardModeOptions()
pps_encoder_add_string(m_encoder, "msg", "options");
pps_encoder_start_object(m_encoder, "dat");
switch (m_keyboardMode) {
switch (mode) {
case Url:
addUrlModeOptions();
break;

View File

@ -42,13 +42,8 @@
#ifndef VIRTUALKEYBOARD_H_
#define VIRTUALKEYBOARD_H_
#include <QtCore/QObject>
#include <QtCore/QLocale>
#include <QtGui/QPlatformScreen>
#include "qqnxabstractvirtualkeyboard.h"
#include <stddef.h>
#include <vector>
#include <string>
#include <sys/pps.h>
QT_BEGIN_NAMESPACE
@ -56,41 +51,21 @@ 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
class QQnxVirtualKeyboard : public QQnxAbstractVirtualKeyboard
{
Q_OBJECT
public:
// NOTE: Not all the following keyboard modes are currently used.
// Default - Regular Keyboard
// Url/Email - Enhanced keys for each types.
// Web - Regular keyboard with two blank keys, currently unused.
// NumPunc - Numbers & Punctionation, alternate to Symbol
// Symbol - All symbols, alternate to NumPunc, currently unused.
// Phone - Phone enhanced keyboard - currently unused as no alternate keyboard available to access a-zA-Z
// Pin - Keyboard for entering Pins (Hex values) currently unused.
//
// SPECIAL NOTE: Usage of NumPunc may have to be removed, ABC button is non-functional.
//
enum KeyboardMode { Default, Url, Email, Web, NumPunc, Symbol, Phone, Pin };
QQnxVirtualKeyboard();
~QQnxVirtualKeyboard();
bool showKeyboard();
bool hideKeyboard();
int height() { return m_visible ? m_height : 0; }
void setKeyboardMode(KeyboardMode);
void notifyClientActiveStateChange(bool);
bool isVisible() const { return m_visible; }
QLocale locale() const { return m_locale; }
public Q_SLOTS:
void start();
Q_SIGNALS:
void localeChanged(const QLocale &locale);
void visibilityChanged(bool visible);
void heightChanged(int height);
protected:
void applyKeyboardMode(KeyboardMode mode);
private Q_SLOTS:
void ppsDataReady();
@ -101,9 +76,8 @@ private:
void close();
bool queryPPSInfo();
void handleKeyboardInfoMessage();
void handleKeyboardStateChangeMessage(bool visible);
void applyKeyboardModeOptions();
void applyKeyboardModeOptions(KeyboardMode mode);
void addDefaultModeOptions();
void addUrlModeOptions();
void addEmailModeOptions();
@ -116,11 +90,7 @@ private:
pps_encoder_t *m_encoder;
pps_decoder_t *m_decoder;
char *m_buffer;
int m_height;
int m_fd;
KeyboardMode m_keyboardMode;
bool m_visible;
QLocale m_locale;
QSocketNotifier *m_readNotifier;
// Path to keyboardManager in PPS.