aboutsummaryrefslogtreecommitdiffstats
path: root/src/imports/inputcontext
diff options
context:
space:
mode:
Diffstat (limited to 'src/imports/inputcontext')
-rw-r--r--src/imports/inputcontext/declarativeinputcontext.cpp199
-rw-r--r--src/imports/inputcontext/declarativeinputcontext.h104
-rwxr-xr-xsrc/imports/inputcontext/inputcontext.pro38
-rw-r--r--src/imports/inputcontext/inputcontextfilter.cpp352
-rw-r--r--src/imports/inputcontext/inputcontextfilter.h162
-rw-r--r--src/imports/inputcontext/inputcontextmodule.cpp413
-rw-r--r--src/imports/inputcontext/inputcontextmodule.h121
-rw-r--r--src/imports/inputcontext/plugin.cpp79
-rw-r--r--src/imports/inputcontext/qmldir1
9 files changed, 1469 insertions, 0 deletions
diff --git a/src/imports/inputcontext/declarativeinputcontext.cpp b/src/imports/inputcontext/declarativeinputcontext.cpp
new file mode 100644
index 0000000000..b52f6ecbba
--- /dev/null
+++ b/src/imports/inputcontext/declarativeinputcontext.cpp
@@ -0,0 +1,199 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "declarativeinputcontext.h"
+
+#include "inputcontextmodule.h"
+#include "inputcontextfilter.h"
+
+#include <QtCore/qdebug.h>
+
+QT_BEGIN_NAMESPACE
+
+DeclarativeInputContext::DeclarativeInputContext(QObject *parent)
+ : QInputContext(parent)
+ , m_module(0)
+{
+}
+
+DeclarativeInputContext::~DeclarativeInputContext()
+{
+}
+
+bool DeclarativeInputContext::isComposing() const
+{
+ return m_module && !m_module->preeditText().isEmpty();
+}
+
+QString DeclarativeInputContext::identifierName()
+{
+ return QLatin1String("Qt.labs.inputcontext/1.0");
+}
+
+QString DeclarativeInputContext::language()
+{
+ return QString();
+}
+
+void DeclarativeInputContext::setFocusWidget(QWidget *widget)
+{
+ QInputContext::setFocusWidget(widget);
+
+ if (m_module)
+ m_module->setFocusWidget(widget);
+}
+
+void DeclarativeInputContext::mouseHandler(int x, QMouseEvent *event)
+{
+ if (!m_mouseHandlers.isEmpty()) {
+ InputContextMouseEvent me(*event);
+ foreach (InputContextMouseHandler *handler, m_mouseHandlers) {
+ handler->processEvent(event->type(), x, &me);
+ if (me.isAccepted()) {
+ event->setAccepted(true);
+ return;
+ }
+ }
+ }
+}
+
+bool DeclarativeInputContext::filterMouseEvent(const QMouseEvent *event)
+{
+ if (!m_mouseFilters.isEmpty()) {
+ InputContextMouseEvent me(*event);
+ foreach (InputContextMouseFilter *filter, m_mouseFilters) {
+ filter->processEvent(event->type(), &me);
+ if (me.isAccepted())
+ return true;
+ }
+ }
+
+ return false;
+}
+
+bool DeclarativeInputContext::filterKeyEvent(const QKeyEvent *event)
+{
+ if (!m_keyFilters.isEmpty()) {
+ InputContextKeyEvent ke(*event);
+ foreach (InputContextKeyFilter *filter, m_keyFilters) {
+ filter->processEvent(event->type(), &ke);
+ if (ke.isAccepted())
+ return true;
+ }
+ }
+ return false;
+}
+
+bool DeclarativeInputContext::filterEvent(const QEvent *event)
+{
+ switch (event->type()) {
+ case QEvent::RequestSoftwareInputPanel:
+ if (m_module)
+ m_module->setVisible(true);
+ return true;
+ case QEvent::CloseSoftwareInputPanel:
+ if (m_module)
+ m_module->setVisible(false);
+ return true;
+ case QEvent::MouseButtonPress:
+ case QEvent::MouseButtonRelease:
+ case QEvent::MouseButtonDblClick:
+ case QEvent::MouseMove:
+ return filterMouseEvent(static_cast<const QMouseEvent *>(event));
+ case QEvent::KeyPress:
+ case QEvent::KeyRelease:
+ return filterKeyEvent(static_cast<const QKeyEvent *>(event));
+ default:
+ return false;
+ }
+}
+
+void DeclarativeInputContext::reset()
+{
+ if (m_module)
+ m_module->commit();
+}
+
+void DeclarativeInputContext::update()
+{
+ if (m_module)
+ m_module->update();
+}
+
+void DeclarativeInputContext::setModule(InputContextModule *module)
+{
+ m_module = module;
+}
+
+void DeclarativeInputContext::registerMouseHandler(InputContextMouseHandler *handler)
+{
+ connect(handler, SIGNAL(destroyed(QObject*)), this, SLOT(mouseHandlerDestroyed(QObject*)));
+ m_mouseHandlers.append(handler);
+}
+
+void DeclarativeInputContext::registerMouseFilter(InputContextMouseFilter *filter)
+{
+ connect(filter, SIGNAL(destroyed(QObject*)), this, SLOT(mouseFilterDestroyed(QObject*)));
+ m_mouseFilters.append(filter);
+}
+
+void DeclarativeInputContext::registerKeyFilter(InputContextKeyFilter *filter)
+{
+ connect(filter, SIGNAL(destroyed(QObject*)), this, SLOT(keyFilterDestroyed(QObject*)));
+ m_keyFilters.append(filter);
+}
+
+void DeclarativeInputContext::mouseHandlerDestroyed(QObject *handler)
+{
+ m_mouseHandlers.removeAll(static_cast<InputContextMouseHandler *>(handler));
+}
+
+void DeclarativeInputContext::mouseFilterDestroyed(QObject *filter)
+{
+ m_mouseFilters.removeAll(static_cast<InputContextMouseFilter *>(filter));
+}
+
+void DeclarativeInputContext::keyFilterDestroyed(QObject *filter)
+{
+ m_keyFilters.removeAll(static_cast<InputContextKeyFilter *>(filter));
+}
+
+QT_END_NAMESPACE
diff --git a/src/imports/inputcontext/declarativeinputcontext.h b/src/imports/inputcontext/declarativeinputcontext.h
new file mode 100644
index 0000000000..fff2931f2d
--- /dev/null
+++ b/src/imports/inputcontext/declarativeinputcontext.h
@@ -0,0 +1,104 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef DECLARATIVEINPUTCONTEXT_H
+#define DECLARATIVEINPUTCONTEXT_H
+
+#include <QtGui/qinputcontext.h>
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+QT_MODULE(Declarative)
+
+class InputContextKeyFilter;
+class InputContextModule;
+class InputContextMouseFilter;
+class InputContextMouseHandler;
+
+class DeclarativeInputContext : public QInputContext
+{
+ Q_OBJECT
+public:
+ explicit DeclarativeInputContext(QObject *parent = 0);
+ ~DeclarativeInputContext();
+
+ bool isComposing() const;
+
+ QString identifierName();
+ QString language();
+
+ void setFocusWidget(QWidget *widget);
+
+ void mouseHandler(int x, QMouseEvent *event);
+
+ bool filterMouseEvent(const QMouseEvent *event);
+ bool filterKeyEvent(const QKeyEvent *event);
+
+ bool filterEvent(const QEvent *event);
+
+ void reset();
+ void update();
+
+ void setModule(InputContextModule *module);
+
+ void registerMouseHandler(InputContextMouseHandler *handler);
+ void registerMouseFilter(InputContextMouseFilter *filter);
+ void registerKeyFilter(InputContextKeyFilter *filter);
+
+private slots:
+ void mouseHandlerDestroyed(QObject *handler);
+ void mouseFilterDestroyed(QObject *filter);
+ void keyFilterDestroyed(QObject *filter);
+
+private:
+ InputContextModule *m_module;
+ QList<InputContextMouseHandler *> m_mouseHandlers;
+ QList<InputContextMouseFilter *> m_mouseFilters;
+ QList<InputContextKeyFilter *> m_keyFilters;
+};
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
diff --git a/src/imports/inputcontext/inputcontext.pro b/src/imports/inputcontext/inputcontext.pro
new file mode 100755
index 0000000000..9c7ddf4e8b
--- /dev/null
+++ b/src/imports/inputcontext/inputcontext.pro
@@ -0,0 +1,38 @@
+TARGET = qmlinputcontextplugin
+TARGETPATH = Qt/labs/inputcontext
+include(../qimportbase.pri)
+
+QT += declarative script
+
+SOURCES += \
+ declarativeinputcontext.cpp \
+ inputcontextfilter.cpp \
+ inputcontextmodule.cpp \
+ plugin.cpp
+
+HEADERS += \
+ declarativeinputcontext.h \
+ inputcontextfilter.h \
+ inputcontextmodule.h
+
+OTHER_FILES = \
+ qmldir
+
+QTDIR_build:DESTDIR = $$QT_BUILD_TREE/imports/$$TARGETPATH
+target.path = $$[QT_INSTALL_IMPORTS]/$$TARGETPATH
+
+qmldir.files += $$PWD/qmldir
+qmldir.path += $$[QT_INSTALL_IMPORTS]/$$TARGETPATH
+
+symbian:{
+ TARGET.UID3 = 0x20031E91
+
+ isEmpty(DESTDIR):importFiles.files = qmlinputcontextplugin{QT_LIBINFIX}.dll qmldir
+ else:importFiles.files = $$DESTDIR/qmlinputcontextplugin$${QT_LIBINFIX}.dll qmldir
+ importFiles.path = $$QT_IMPORTS_BASE_DIR/$$TARGETPATH
+
+ DEPLOYMENT = importFiles
+}
+
+INSTALLS += target qmldir
+
diff --git a/src/imports/inputcontext/inputcontextfilter.cpp b/src/imports/inputcontext/inputcontextfilter.cpp
new file mode 100644
index 0000000000..c0c6c09ed9
--- /dev/null
+++ b/src/imports/inputcontext/inputcontextfilter.cpp
@@ -0,0 +1,352 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "inputcontextfilter.h"
+
+#include "declarativeinputcontext.h"
+
+#include <QtGui/qapplication.h>
+
+QT_BEGIN_NAMESPACE
+
+/*!
+ \qmlclass KeyEvent InputContextKeyEvent
+
+ \inqmlmodule Qt.labs.inputcontext
+
+ \brief The KeyEvent object provides information about a key event.
+*/
+
+/*!
+ \qmlproperty int KeyEvent::key
+
+ This property holds the key code of the key that was pressed or released.
+*/
+
+/*!
+ \qmlproperty string KeyEvent::text
+
+ This property holds the text that this key generated.
+*/
+
+/*!
+ \qmlproperty int KeyEvent::modifiers
+
+ This property holds the keyboard modifier flags that existed immediately
+ after this event was generated.
+*/
+
+/*!
+ \qmlproperty bool KeyEvent::autoRepeat
+
+ This property returns true if this event comes from an auto repeating key
+ press, on the initial key press this returns false.
+*/
+
+/*!
+ \qmlproperty int KeyEvent::count
+
+ This property holds the number of keys involved in this event. If the
+ \l text is non-empty this is the length of the string.
+*/
+
+/*!
+ \qmlproperty bool KeyEvent::accepted
+
+ This property holds whether the event was accepted.
+
+ This is false by default.
+*/
+
+/*!
+ \qmlclass MouseEvent InputContextMouseEvent
+
+ \inqmlmodule Qt.labs.inputcontext
+
+ \brief The MouseEvent object provides information about a mouse event.
+
+*/
+
+/*!
+ \qmlproperty int MouseEvent::x
+
+ This property holds the x position in scene coordinates of the mouse cursor
+ at the time of the event.
+*/
+
+/*!
+ \qmlproperty int MouseEvent::y
+
+ This property holds the y position in scene coordinates of the mouse cursor
+ at the time of the event.
+*/
+
+/*!
+ \qmlproperty enum MouseEvent::button
+
+ This property holds the button that caused the event.
+*/
+
+/*!
+ \qmlproperty int MouseEvent::buttons
+
+ This property holds the button state when the event was generated.
+*/
+
+/*!
+ \qmlproperty int MouseEvent::modifiers
+
+ This property holds the keyboard modifier flags that existed when the event
+ was generated.
+*/
+
+/*!
+ \qmlproperty bool MouseEvent::accepted
+
+ This property holds whether the event was accepted.
+
+ This is false by default.
+*/
+
+/*!
+ \qmlclass MouseHandler InputContextMouseHandler
+
+ \inqmlmodule Qt.labs.inputcontext
+
+ \brief The MouseHandler item provides mouse event handling for input methods.
+
+ The MouseHandler item can be used to handle mouse press, release, move and
+ double click events within or surrounding the pre-edit text.
+*/
+
+/*!
+ \qmlsignal MouseHandler::onPressed(int cursor, MouseEvent mouse)
+
+ This handler is called when there is a press. The \a cursor parameter is
+ the text cursor position of the press within the pre-edit text, and the
+ \a mouse parameter holds information about the press.
+*/
+
+/*!
+ \qmlsignal MouseHandler::onReleased(int cursor, MouseEvent mouse)
+
+ This handler is called when there is a release. The \a cursor parameter is
+ the text cursor position of the press within the pre-edit text, and the
+ \a mouse parameter holds information about the release.
+*/
+
+/*!
+ \qmlsignal MouseHandler::onPositionChanged(int cursor, MouseEvent mouse)
+
+ This handler is called when the mouse position changes.
+
+ The \a cursor parameter is the text cursor position of the press within
+ the pre-edit text, and the \a mouse parameter holds information about the
+ position change.
+*/
+
+/*!
+ \qmlsignal MouseHandler::onDoubleClicked(int cursor, MouseEvent mouse)
+
+ This handler is called when there is a double-click. The \a cursor
+ parameter is the text cursor position of the press within the pre-edit
+ text, and the \a mouse parameter holds information about the double-click.
+*/
+
+InputContextMouseHandler::InputContextMouseHandler(QObject *parent)
+ : QObject(parent)
+{
+ if (DeclarativeInputContext *context = qobject_cast<DeclarativeInputContext *>(
+ qApp->inputContext())) {
+ context->registerMouseHandler(this);
+ }
+}
+
+void InputContextMouseHandler::processEvent(QEvent::Type type, int cursor, InputContextMouseEvent *event)
+{
+ switch (type) {
+ case QEvent::MouseButtonPress:
+ emit pressed(cursor, event);
+ break;
+ case QEvent::MouseButtonRelease:
+ emit released(cursor, event);
+ break;
+ case QEvent::MouseButtonDblClick:
+ emit doubleClicked(cursor, event);
+ break;
+ case QEvent::MouseMove:
+ emit positionChanged(cursor, event);
+ break;
+ default:
+ break;
+ }
+}
+
+/*!
+ \qmlclass MouseFilter InputContextMouseFilter
+
+ \inqmlmodule Qt.labs.inputcontext
+
+ \brief The MouseFilter item provides mouse event filtering for input methods.
+
+ The MouseFilter item can be used to filter mouse press, release, move and
+ double click events received by the item with active focus.
+*/
+
+/*!
+ \qmlsignal MouseHandler::onPressed(MouseEvent mouse)
+
+ This handler is called when there is a press. The \a mouse parameter holds
+ information about the press.
+
+ If the event is accepted it will not be delivered to the item.
+*/
+
+/*!
+ \qmlsignal MouseHandler::onReleased(MouseEvent mouse)
+
+ This handler is called when there is a release. The \a mouse parameter
+ holds information about the release.
+
+ If the event is accepted it will not be delivered to the item.
+*/
+
+/*!
+ \qmlsignal MouseHandler::onPositionChanged(MouseEvent mouse)
+
+ This handler is called when the mouse position changes.
+
+ The \a mouse parameter holds information about the position change.
+
+ If the event is accepted it will not be delivered to the item.
+*/
+
+/*!
+ \qmlsignal MouseHandler::onDoubleClicked(MouseEvent mouse)
+
+ This handler is called when there is a double-click. The \a mouse
+ parameter holds information about the double-click.
+
+ If the event is accepted it will not be delivered to the item.
+*/
+
+InputContextMouseFilter::InputContextMouseFilter(QObject *parent)
+ : QObject(parent)
+{
+ if (DeclarativeInputContext *context = qobject_cast<DeclarativeInputContext *>(
+ qApp->inputContext())) {
+ context->registerMouseFilter(this);
+ }
+}
+
+void InputContextMouseFilter::processEvent(QEvent::Type type, InputContextMouseEvent *event)
+{
+ switch (type) {
+ case QEvent::MouseButtonPress:
+ emit pressed(event);
+ break;
+ case QEvent::MouseButtonRelease:
+ emit released(event);
+ break;
+ case QEvent::MouseButtonDblClick:
+ emit doubleClicked(event);
+ break;
+ case QEvent::MouseMove:
+ emit positionChanged(event);
+ break;
+ default:
+ break;
+ }
+}
+
+/*!
+ \qmlclass KeyFilter InputContextKeyFilter
+
+ \inqmlmodule Qt.labs.inputcontext
+
+ \brief The KeyFilter item provides key event filtering for input methods.
+
+ The KeyFilter item can be used to filter key press and releae events
+ received by the item with active focus.
+*/
+
+/*!
+ \qmlsignal KeyFilter::onPressed(KeyEvent event)
+
+ This handler is called when there is a key press. The \a event parameter
+ holds information about the press.
+
+ If the event is accepted it will not be delivered to the item.
+*/
+
+/*!
+ \qmlsignal KeyFilter::onReleased(KeyEvent event)
+
+ This handler is called when there is a key release. The \a event parameter
+ holds information about the release.
+
+ If the event is accepted it will not be delivered to the item.
+*/
+
+InputContextKeyFilter::InputContextKeyFilter(QObject *parent)
+ : QObject(parent)
+{
+ if (DeclarativeInputContext *context = qobject_cast<DeclarativeInputContext *>(
+ qApp->inputContext())) {
+ context->registerKeyFilter(this);
+ }
+}
+
+void InputContextKeyFilter::processEvent(QEvent::Type type, InputContextKeyEvent *event)
+{
+ switch (type) {
+ case QEvent::KeyPress:
+ emit pressed(event);
+ break;
+ case QEvent::KeyRelease:
+ emit released(event);
+ break;
+ default:
+ break;
+ }
+}
+
+QT_END_NAMESPACE
diff --git a/src/imports/inputcontext/inputcontextfilter.h b/src/imports/inputcontext/inputcontextfilter.h
new file mode 100644
index 0000000000..2dd7d5bd67
--- /dev/null
+++ b/src/imports/inputcontext/inputcontextfilter.h
@@ -0,0 +1,162 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef INPUTCONTEXTFILTER_H
+#define INPUTCONTEXTFILTER_H
+
+#include <QtDeclarative/qdeclarative.h>
+#include <QtGui/qevent.h>
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+QT_MODULE(Declarative)
+
+class InputContextKeyEvent : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(int key READ key)
+ Q_PROPERTY(QString text READ text)
+ Q_PROPERTY(int modifiers READ modifiers)
+ Q_PROPERTY(bool isAutoRepeat READ isAutoRepeat)
+ Q_PROPERTY(int count READ count)
+ Q_PROPERTY(bool accepted READ isAccepted WRITE setAccepted)
+
+public:
+ InputContextKeyEvent(const QKeyEvent &ke)
+ : event(ke) { event.setAccepted(false); }
+
+ int key() const { return event.key(); }
+ QString text() const { return event.text(); }
+ int modifiers() const { return event.modifiers(); }
+ bool isAutoRepeat() const { return event.isAutoRepeat(); }
+ int count() const { return event.count(); }
+
+ bool isAccepted() { return event.isAccepted(); }
+ void setAccepted(bool accepted) { event.setAccepted(accepted); }
+
+private:
+ QKeyEvent event;
+};
+
+class InputContextMouseEvent : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(int x READ x)
+ Q_PROPERTY(int y READ y)
+ Q_PROPERTY(int button READ button)
+ Q_PROPERTY(int buttons READ buttons)
+ Q_PROPERTY(int modifiers READ modifiers)
+ Q_PROPERTY(bool accepted READ isAccepted WRITE setAccepted)
+
+public:
+ InputContextMouseEvent(const QMouseEvent &me)
+ : event(me) { event.setAccepted(false);}
+
+ int x() const { return event.x(); }
+ int y() const { return event.y(); }
+ int button() const { return event.button(); }
+ int buttons() const { return event.buttons(); }
+ int modifiers() const { return event.modifiers(); }
+
+ bool isAccepted() { return event.isAccepted(); }
+ void setAccepted(bool accepted) { event.setAccepted(accepted); }
+
+private:
+ QMouseEvent event;
+};
+
+class InputContextMouseHandler : public QObject
+{
+ Q_OBJECT
+public:
+ InputContextMouseHandler(QObject *parent = 0);
+
+ void processEvent(QEvent::Type type, int cursor, InputContextMouseEvent *event);
+
+signals:
+ void pressed(int cursor, InputContextMouseEvent *mouse);
+ void released(int cursor, InputContextMouseEvent *mouse);
+ void doubleClicked(int cursor, InputContextMouseEvent *mouse);
+ void positionChanged(int cursor, InputContextMouseEvent *mouse);
+};
+
+class InputContextMouseFilter : public QObject
+{
+ Q_OBJECT
+public:
+ InputContextMouseFilter(QObject *parent = 0);
+
+ void processEvent(QEvent::Type type, InputContextMouseEvent *event);
+
+signals:
+ void pressed(InputContextMouseEvent *mouse);
+ void released(InputContextMouseEvent *mouse);
+ void doubleClicked(InputContextMouseEvent *mouse);
+ void positionChanged(InputContextMouseEvent *mouse);
+};
+
+class InputContextKeyFilter : public QObject
+{
+ Q_OBJECT
+public:
+ InputContextKeyFilter(QObject *parent = 0);
+
+ void processEvent(QEvent::Type type, InputContextKeyEvent *event);
+
+signals:
+ void pressed(InputContextKeyEvent *event);
+ void released(InputContextKeyEvent *event);
+};
+
+
+QT_END_NAMESPACE
+
+QML_DECLARE_TYPE(InputContextKeyEvent)
+QML_DECLARE_TYPE(InputContextMouseEvent)
+QML_DECLARE_TYPE(InputContextMouseHandler)
+QML_DECLARE_TYPE(InputContextMouseFilter)
+QML_DECLARE_TYPE(InputContextKeyFilter)
+
+QT_END_HEADER
+
+#endif
diff --git a/src/imports/inputcontext/inputcontextmodule.cpp b/src/imports/inputcontext/inputcontextmodule.cpp
new file mode 100644
index 0000000000..7dc124d083
--- /dev/null
+++ b/src/imports/inputcontext/inputcontextmodule.cpp
@@ -0,0 +1,413 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "inputcontextmodule.h"
+
+#include "declarativeinputcontext.h"
+
+#include <QtCore/qdebug.h>
+#include <QtGui/qapplication.h>
+#include <QtGui/qevent.h>
+#include <QtGui/qtextformat.h>
+
+QT_BEGIN_NAMESPACE
+
+/*!
+ \qmlmodule Qt.labs.inputcontext InputContextModule
+
+ \brief The Qt.labs.inputcontext module provides an API for implementing input methods is QML.
+*/
+
+InputContextModule::InputContextModule(QObject *parent)
+ : QObject(parent)
+ , m_inputContext(qobject_cast<DeclarativeInputContext *>(qApp->inputContext()))
+ , m_focusWidget(m_inputContext ? m_inputContext->focusWidget() : 0)
+ , m_visible(false)
+{
+ if (m_inputContext)
+ m_inputContext->setModule(this);
+}
+
+InputContextModule::~InputContextModule()
+{
+ if (m_inputContext)
+ m_inputContext->setModule(0);
+}
+
+/*!
+ \qmlproperty bool focus
+
+ \inqmlmodule Qt.labs.inputcontext
+
+ This property identifies whether an item that takes text input has active focus.
+*/
+
+bool InputContextModule::hasFocus() const
+{
+ return m_focusWidget != 0;
+}
+
+void InputContextModule::setFocusWidget(QWidget *widget)
+{
+ m_focusWidget = widget;
+
+ if (!m_focusWidget)
+ setVisible(false);
+
+ emit focusChanged();
+}
+
+/*!
+ \qmlproperty bool softwareInputPanelVisible
+
+ \inqmlmodule Qt.labs.inputcontext
+
+ This property identifies whether the item with focus has requested a
+ software input panel.
+*/
+
+bool InputContextModule::isVisible() const
+{
+ return m_visible;
+}
+
+void InputContextModule::setVisible(bool visible)
+{
+ if (m_visible != visible) {
+ m_visible = visible;
+
+ emit visibleChanged();
+ }
+}
+
+/*!
+ \qmlproperty string preeditText
+
+ \inqmlmodule Qt.labs.inputcontext
+
+ This property holds the uncommited text that is displayed in the item that
+ has focus.
+*/
+
+QString InputContextModule::preeditText() const
+{
+ return m_preeditText;
+}
+
+void InputContextModule::setPreeditText(const QString &text)
+{
+ if (text != m_preeditText)
+ sendPreedit(text);
+}
+
+/*!
+ \qmlproperty rectangle microFocus
+
+ \inqmlmodule Qt.labs.inputcontext
+
+ This property holds a rectangle in scene coordinates around the position
+ of the cursor.
+*/
+
+QRect InputContextModule::microFocus() const
+{
+ return m_focusWidget
+ ? m_focusWidget->inputMethodQuery(Qt::ImMicroFocus).toRect()
+ : QRect();
+}
+
+/*!
+ \qmlproperty font font
+
+ \inqmlmodule Qt.labs.inputcontext
+
+ This property holds the font of the text that currently has focus.
+*/
+
+QFont InputContextModule::font() const
+{
+ return m_focusWidget
+ ? m_focusWidget->inputMethodQuery(Qt::ImFont).value<QFont>()
+ : QFont();
+}
+
+/*!
+ \qmlproperty int cursorPosition
+
+ \inqmlmodule Qt.labs.inputcontext
+
+ This property holds the position of the text cursor in the
+ \l surroundingText.
+*/
+
+int InputContextModule::cursorPosition() const
+{
+ return m_focusWidget
+ ? m_focusWidget->inputMethodQuery(Qt::ImCursorPosition).toInt()
+ : 0;
+}
+
+/*!
+ \qmlproperty int anchorPosition
+
+ \inqmlmodule Qt.labs.inputcontext
+
+ This property holds the position of the selection anchor in the
+ \l surroundingText. If no text is selected this is the same as the
+ \l cursorPosition.
+*/
+
+int InputContextModule::anchorPosition() const
+{
+ return m_focusWidget
+ ? m_focusWidget->inputMethodQuery(Qt::ImAnchorPosition).toInt()
+ : 0;
+}
+
+/*!
+ \qmlproperty int maximumTextLength
+
+ \inqmlmodule Qt.labs.inputcontext
+
+ This property holds the maximum number of characters that the item with
+ focus can hold. If there is no limit -1 is returned.
+*/
+
+int InputContextModule::maximumTextLength() const
+{
+ QVariant length;
+ if (m_focusWidget)
+ length = m_focusWidget->inputMethodQuery(Qt::ImMaximumTextLength);
+ return length.isValid() ? length.toInt() : -1;
+}
+
+/*!
+ \qmlproperty string surroundingText
+
+ \inqmlmodule Qt.labs.inputcontext
+
+ This property holds the plain text around the input area. For example the
+ current paragraph.
+*/
+
+QString InputContextModule::surroundingText() const
+{
+ return m_focusWidget
+ ? m_focusWidget->inputMethodQuery(Qt::ImSurroundingText).toString()
+ : QString();
+}
+
+/*!
+ \qmlproperty string selectedText
+
+ \inqmlmodule Qt.labs.inputcontext
+
+ This property holds the currently selected text.
+*/
+
+QString InputContextModule::selectedText() const
+{
+ return m_focusWidget
+ ? m_focusWidget->inputMethodQuery(Qt::ImCurrentSelection).toString()
+ : QString();
+}
+
+/*!
+ \qmlmethod sendKeyPress(int key, string text, int modifiers, bool autoRepeat)
+
+ \inqmlmodule Qt.labs.inputcontext
+
+ This method sends a key press event to the item that currently has focus.
+
+ Int key is the code for the Qt::Key that the event loop should listen for.
+ If key is 0, the event is not a result of a known key; for example, it may
+ be the result of a compose sequence or keyboard macro. The modifiers holds
+ the keyboard modifiers, and the given text is the Unicode text that the key
+ generated. If autorep is true, isAutoRepeat() will be true. count is the
+ number of keys involved in the event.
+*/
+void InputContextModule::sendKeyPress(
+ int key, const QString &text, int modifiers, bool autoRepeat, int count)
+{
+ if (m_focusWidget) {
+ QKeyEvent event(
+ QEvent::KeyPress, key, Qt::KeyboardModifiers(modifiers), text, autoRepeat, count);
+ if (!m_inputContext || !m_inputContext->filterKeyEvent(&event))
+ QApplication::sendEvent(m_focusWidget, &event);
+ }
+}
+
+/*!
+ \qmlmethod sendKeyRelease(int key, string text, int modifiers)
+
+ \inqmlmodule Qt.labs.inputcontext
+
+ This method sends a key release event to the item that currently has focus.
+
+ Int key is the code for the Qt::Key that the event loop should listen for.
+ If key is 0, the event is not a result of a known key; for example, it may
+ be the result of a compose sequence or keyboard macro. The modifiers holds
+ the keyboard modifiers, and the given text is the Unicode text that the key
+ generated. count is the number of keys involved in the event.
+*/
+void InputContextModule::sendKeyRelease(int key, const QString &text, int modifiers, int count)
+{
+ if (m_focusWidget) {
+ QKeyEvent event(
+ QEvent::KeyRelease, key, Qt::KeyboardModifiers(modifiers), text, false, count);
+ if (!m_inputContext || !m_inputContext->filterKeyEvent(&event))
+ QApplication::sendEvent(m_focusWidget, &event);
+ }
+}
+
+/*!
+ \qmlmethod sendPreedit(string text, int cursor = -1)
+
+ \inqmlmodule Qt.labs.inputcontext
+
+ Sends a pre-edit event to the item with active focus.
+
+ This will set \l preeditText to \a text, and position the text \a cursor
+ within the pre-edit text. If the value of cursor is -1 the cursor will be
+ positioned at the end of the pre-edit text.
+*/
+void InputContextModule::sendPreedit(const QString &text, int cursor)
+{
+ const QString preedit = m_preeditText;
+ m_preeditText = text;
+
+ if (m_inputContext) {
+ QList<QInputMethodEvent::Attribute> attributes;
+
+ if (cursor >= 0 && cursor <= text.length()) {
+ attributes.append(QInputMethodEvent::Attribute(
+ QInputMethodEvent::Cursor, cursor, text.length(), QVariant()));
+ } else {
+ cursor = text.length();
+ }
+
+ if (cursor > 0) {
+ attributes.append(QInputMethodEvent::Attribute(
+ QInputMethodEvent::TextFormat,
+ 0,
+ cursor,
+ m_inputContext->standardFormat(QInputContext::PreeditFormat)));
+ }
+ if (cursor < text.length()) {
+ attributes.append(QInputMethodEvent::Attribute(
+ QInputMethodEvent::TextFormat,
+ cursor,
+ text.length(),
+ m_inputContext->standardFormat(QInputContext::SelectionFormat)));
+ }
+
+ m_inputContext->sendEvent(QInputMethodEvent(text, attributes));
+ }
+
+ if (m_preeditText != preedit)
+ emit preeditTextChanged();
+}
+
+
+/*!
+ \qmlmethod commit()
+
+ \inqmlmodule Qt.labs.inputcontext
+
+ Commits \l preeditText to the item with active focus.
+*/
+void InputContextModule::commit()
+{
+ // Create an explicit copy of m_preeditText as the reference value is cleared before sending
+ // the event.
+ commit(QString(m_preeditText));
+}
+
+/*!
+ \qmlmethod commit(string)
+
+ \inqmlmodule Qt.labs.inputcontext
+
+ Commits \a text to the item with active focus and clears the current
+ \l preeditText. The text will be inserted into the \l surroundingText at a
+ position \a replacementStart relative to the \l cursorPosition and will
+ replace \a replacementLength characters.
+*/
+void InputContextModule::commit(const QString &text, int replacementStart, int replacementLength)
+{
+ const QString preedit = m_preeditText;
+ m_preeditText.clear();
+
+ if (m_inputContext) {
+ QInputMethodEvent inputEvent;
+ inputEvent.setCommitString(text, replacementStart, replacementLength);
+ m_inputContext->sendEvent(inputEvent);
+ }
+
+ if (m_preeditText != preedit)
+ emit preeditTextChanged();
+}
+
+/*!
+ \qmlmethod clear()
+
+ \inqmlmodule Qt.labs.inputcontext
+
+ Clears the current \l preeditText.
+*/
+void InputContextModule::clear()
+{
+ const QString preedit = m_preeditText;
+ m_preeditText.clear();
+
+ if (m_inputContext)
+ m_inputContext->sendEvent(QInputMethodEvent());
+
+ if (m_preeditText != preedit)
+ emit preeditTextChanged();
+}
+
+void InputContextModule::update()
+{
+ emit contextUpdated();
+}
+
+QT_END_NAMESPACE
diff --git a/src/imports/inputcontext/inputcontextmodule.h b/src/imports/inputcontext/inputcontextmodule.h
new file mode 100644
index 0000000000..470701e34e
--- /dev/null
+++ b/src/imports/inputcontext/inputcontextmodule.h
@@ -0,0 +1,121 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef INPUTCONTEXTMODULE_H
+#define INPUTCONTEXTMODULE_H
+
+#include <QtCore/qobject.h>
+#include <QtCore/qrect.h>
+#include <QtGui/qfont.h>
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+QT_MODULE(Declarative)
+
+class DeclarativeInputContext;
+
+class InputContextModule : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(bool softwareInputPanelVisible READ isVisible WRITE setVisible NOTIFY visibleChanged)
+ Q_PROPERTY(bool focus READ hasFocus NOTIFY focusChanged)
+ Q_PROPERTY(QString preeditText READ preeditText WRITE setPreeditText NOTIFY preeditTextChanged)
+ Q_PROPERTY(QRect microFocus READ microFocus NOTIFY contextUpdated)
+ Q_PROPERTY(QFont font READ font NOTIFY contextUpdated)
+ Q_PROPERTY(int cursorPosition READ cursorPosition NOTIFY contextUpdated)
+ Q_PROPERTY(int anchorPosition READ anchorPosition NOTIFY contextUpdated)
+ Q_PROPERTY(int maximumTextLength READ maximumTextLength NOTIFY contextUpdated)
+ Q_PROPERTY(QString surroundingText READ surroundingText NOTIFY contextUpdated)
+ Q_PROPERTY(QString selectedText READ selectedText NOTIFY contextUpdated)
+public:
+ explicit InputContextModule(QObject *parent = 0);
+ ~InputContextModule();
+
+ bool hasFocus() const;
+ void setFocusWidget(QWidget *widget);
+
+ bool isVisible() const;
+ void setVisible(bool visible);
+
+ QString preeditText() const;
+ void setPreeditText(const QString &text);
+
+ QRect microFocus() const;
+ QFont font() const;
+ int cursorPosition() const;
+ int anchorPosition() const;
+ int maximumTextLength() const;
+ QString surroundingText() const;
+ QString selectedText() const;
+
+ Q_INVOKABLE void sendKeyPress(
+ int key, const QString &text, int modifiers = 0, bool autoRepeat = false, int count = 1);
+ Q_INVOKABLE void sendKeyRelease(int key, const QString &text, int modifiers = 0, int count = 1);
+
+ Q_INVOKABLE void sendPreedit(const QString &text, int cursor = -1);
+
+ Q_INVOKABLE void commit();
+ Q_INVOKABLE void commit(const QString &text, int replacementStart = 0, int replacementEnd = 0);
+
+ Q_INVOKABLE void clear();
+
+ void update();
+
+signals:
+ void preeditTextChanged();
+ void visibleChanged();
+ void contextUpdated();
+ void focusChanged();
+
+private:
+ QString m_preeditText;
+ DeclarativeInputContext *m_inputContext;
+ QWidget *m_focusWidget;
+ bool m_visible;
+};
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
diff --git a/src/imports/inputcontext/plugin.cpp b/src/imports/inputcontext/plugin.cpp
new file mode 100644
index 0000000000..1f4bcde673
--- /dev/null
+++ b/src/imports/inputcontext/plugin.cpp
@@ -0,0 +1,79 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "declarativeinputcontext.h"
+#include "inputcontextfilter.h"
+#include "inputcontextmodule.h"
+
+#include <QtDeclarative/qdeclarativeextensionplugin.h>
+#include <QtGui/qapplication.h>
+
+QT_BEGIN_NAMESPACE
+
+static QObject *createContext(QDeclarativeEngine *, QScriptEngine *)
+{
+ return new InputContextModule;
+}
+
+class InputContextQmlPlugin : public QDeclarativeExtensionPlugin
+{
+ Q_OBJECT
+public:
+ virtual void registerTypes(const char *uri)
+ {
+ Q_ASSERT(QLatin1String(uri) == QLatin1String("Qt.labs.inputcontext"));
+
+ qApp->setInputContext(new DeclarativeInputContext);
+
+ qmlRegisterModuleApi(uri, 1, 0, createContext);
+ qmlRegisterType<InputContextMouseHandler>(uri, 1, 0, "MouseHandler");
+ qmlRegisterType<InputContextMouseFilter>(uri, 1, 0, "MouseFilter");
+ qmlRegisterType<InputContextKeyFilter>(uri, 1, 0, "KeyFilter");
+ qmlRegisterType<InputContextMouseEvent>();
+ qmlRegisterType<InputContextKeyEvent>();
+ }
+};
+
+QT_END_NAMESPACE
+
+Q_EXPORT_PLUGIN2(InputContext, QT_PREPEND_NAMESPACE(InputContextQmlPlugin));
+
+#include "plugin.moc"
diff --git a/src/imports/inputcontext/qmldir b/src/imports/inputcontext/qmldir
new file mode 100644
index 0000000000..3fb65a6e0e
--- /dev/null
+++ b/src/imports/inputcontext/qmldir
@@ -0,0 +1 @@
+plugin qmlinputcontextplugin