From 71726ccf676ef0921ef557c7162d2d87563066fb Mon Sep 17 00:00:00 2001 From: Pekka Vuorela Date: Tue, 24 Jan 2012 17:44:38 +0200 Subject: Renamed QInputPanel as QInputMethod QInputMethod better describes what the class is about, input methods in general, be they panels or just composing input from key events. Compatability headers added for old name. Not bulletproof but should be enough to get transition done. Change-Id: Iefde6e7ccb1ec4a3b226cef3469089e751c60fc1 Reviewed-by: Joona Petrell --- src/gui/kernel/kernel.pri | 4 +- src/gui/kernel/qguiapplication.cpp | 17 +- src/gui/kernel/qguiapplication.h | 5 +- src/gui/kernel/qguiapplication_p.h | 2 +- src/gui/kernel/qinputmethod.cpp | 376 +++++++++++++++++++++++++++ src/gui/kernel/qinputmethod.h | 134 ++++++++++ src/gui/kernel/qinputmethod_p.h | 83 ++++++ src/gui/kernel/qinputpanel.cpp | 376 --------------------------- src/gui/kernel/qinputpanel.h | 83 +----- src/gui/kernel/qinputpanel_p.h | 33 +-- src/gui/kernel/qplatforminputcontext_qpa.cpp | 28 +- 11 files changed, 635 insertions(+), 506 deletions(-) create mode 100644 src/gui/kernel/qinputmethod.cpp create mode 100644 src/gui/kernel/qinputmethod.h create mode 100644 src/gui/kernel/qinputmethod_p.h delete mode 100644 src/gui/kernel/qinputpanel.cpp (limited to 'src/gui/kernel') diff --git a/src/gui/kernel/kernel.pri b/src/gui/kernel/kernel.pri index bc0cb4e974..7b01ba14cd 100644 --- a/src/gui/kernel/kernel.pri +++ b/src/gui/kernel/kernel.pri @@ -38,6 +38,8 @@ HEADERS += \ kernel/qdnd_p.h \ kernel/qevent.h \ kernel/qevent_p.h \ + kernel/qinputmethod.h \ + kernel/qinputmethod_p.h \ kernel/qinputpanel.h \ kernel/qinputpanel_p.h \ kernel/qkeysequence.h \ @@ -84,7 +86,7 @@ SOURCES += \ kernel/qdrag.cpp \ kernel/qdnd.cpp \ kernel/qevent.cpp \ - kernel/qinputpanel.cpp \ + kernel/qinputmethod.cpp \ kernel/qkeysequence.cpp \ kernel/qkeymapper.cpp \ kernel/qkeymapper_qpa.cpp \ diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index a97647f504..4096628d93 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -183,7 +183,7 @@ QGuiApplication::~QGuiApplication() QGuiApplicationPrivate::QGuiApplicationPrivate(int &argc, char **argv, int flags) : QCoreApplicationPrivate(argc, argv, flags), styleHints(0), - inputPanel(0) + inputMethod(0) { self = this; application_type = QCoreApplication::GuiClient; @@ -522,7 +522,7 @@ QGuiApplicationPrivate::~QGuiApplicationPrivate() cleanupThreadData(); delete styleHints; - delete inputPanel; + delete inputMethod; delete platform_integration; platform_integration = 0; @@ -1572,12 +1572,17 @@ QStyleHints *QGuiApplication::styleHints() const \sa QInputPanel */ -QInputPanel *QGuiApplication::inputPanel() const +QInputMethod *QGuiApplication::inputMethod() const { Q_D(const QGuiApplication); - if (!d->inputPanel) - const_cast(d)->inputPanel = new QInputPanel(); - return d->inputPanel; + if (!d->inputMethod) + const_cast(d)->inputMethod = new QInputMethod(); + return d->inputMethod; +} + +QInputPanel *QGuiApplication::inputPanel() const +{ + return inputMethod(); } diff --git a/src/gui/kernel/qguiapplication.h b/src/gui/kernel/qguiapplication.h index 9bf6a69c45..75046d8767 100644 --- a/src/gui/kernel/qguiapplication.h +++ b/src/gui/kernel/qguiapplication.h @@ -44,6 +44,7 @@ #include #include +#include #include #include #include @@ -58,7 +59,6 @@ class QPlatformNativeInterface; class QPalette; class QScreen; class QStyleHints; -class QInputPanel; #if defined(qApp) #undef qApp @@ -121,7 +121,8 @@ public: static inline bool isLeftToRight() { return layoutDirection() == Qt::LeftToRight; } QStyleHints *styleHints() const; - QInputPanel *inputPanel() const; + QT_DEPRECATED QInputPanel *inputPanel() const; + QInputMethod *inputMethod() const; static QPlatformNativeInterface *platformNativeInterface(); diff --git a/src/gui/kernel/qguiapplication_p.h b/src/gui/kernel/qguiapplication_p.h index 2f1cfa509d..d9444ebe95 100644 --- a/src/gui/kernel/qguiapplication_p.h +++ b/src/gui/kernel/qguiapplication_p.h @@ -181,7 +181,7 @@ public: static QFont *app_font; QStyleHints *styleHints; - QInputPanel *inputPanel; + QInputMethod *inputMethod; static QList generic_plugin_list; #ifndef QT_NO_SHORTCUT diff --git a/src/gui/kernel/qinputmethod.cpp b/src/gui/kernel/qinputmethod.cpp new file mode 100644 index 0000000000..de00396e40 --- /dev/null +++ b/src/gui/kernel/qinputmethod.cpp @@ -0,0 +1,376 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtGui module 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 +#include +#include +#include + +QT_BEGIN_NAMESPACE + +/*! + \internal +*/ +QInputMethod::QInputMethod() + : QObject(*new QInputMethodPrivate) +{ + // might be instantiated before QGuiApplication is fully done, need to connect later + QTimer::singleShot(0, this, SLOT(q_connectFocusObject())); +} + +/*! + \internal +*/ +QInputMethod::~QInputMethod() +{ +} + +/*! + \class QInputMethod + \brief The QInputMethod class provides access to the active text input method. + + QInputMethod is used by the text editors for integrating to the platform text input + methods and more commonly by application views for querying various text input method-related + information like virtual keyboard visibility and keyboard dimensions. + + Qt Quick also provides access to QInputMethod in QML through \l{QmlGlobalQtObject}{Qt global object} + as \c Qt.application.inputPanel property. +*/ + +/*! + \property QInputMethod::inputItem + \brief Focused item that accepts text input + \obsolete + + Input item is set and unset by the focused window. In QML Scene Graph this is done by + QQuickCanvas and the input item is either TextInput or TextEdit element. Any QObject can + behave as an input item as long as it responds to QInputMethodQueryEvent and QInputMethodEvent + events sent by the input methods. + + \sa inputItemTransform, inputWindow, QInputMethodQueryEvent, QInputMethodEvent +*/ +QObject *QInputMethod::inputItem() const +{ + Q_D(const QInputMethod); + return d->inputItem.data(); +} + +void QInputMethod::setInputItem(QObject *inputItem) +{ + Q_D(QInputMethod); + + if (d->inputItem.data() == inputItem) + return; + + d->inputItem = inputItem; + emit inputItemChanged(); +} + +/*! + Returns the currently focused window containing the input item. + + \obsolete +*/ +QWindow *QInputMethod::inputWindow() const +{ + return qApp->activeWindow(); +} + +/*! + Returns the transformation from input item coordinates to the window coordinates. +*/ +QTransform QInputMethod::inputItemTransform() const +{ + Q_D(const QInputMethod); + return d->inputItemTransform; +} + +/*! + Sets the transformation from input item coordinates to the window coordinates. + Item transform needs to be updated by the focused window like QQuickCanvas whenever + item is moved inside the scene. +*/ +void QInputMethod::setInputItemTransform(const QTransform &transform) +{ + Q_D(QInputMethod); + if (d->inputItemTransform == transform) + return; + + d->inputItemTransform = transform; + emit cursorRectangleChanged(); +} + +/*! + \property QInputMethod::cursorRectangle + \brief Input item's cursor rectangle in window coordinates. + + Cursor rectangle is often used by various text editing controls + like text prediction popups for following the text being typed. +*/ +QRectF QInputMethod::cursorRectangle() const +{ + Q_D(const QInputMethod); + + if (!d->inputItem) + return QRectF(); + + QInputMethodQueryEvent query(Qt::ImCursorRectangle); + QGuiApplication::sendEvent(d->inputItem.data(), &query); + QRect r = query.value(Qt::ImCursorRectangle).toRect(); + if (!r.isValid()) + return QRect(); + + return d->inputItemTransform.mapRect(r); +} + +/*! + \property QInputMethod::keyboardRectangle + \brief Virtual keyboard's geometry in window coordinates. +*/ +QRectF QInputMethod::keyboardRectangle() const +{ + Q_D(const QInputMethod); + QPlatformInputContext *ic = d->platformInputContext(); + if (ic) + return ic->keyboardRect(); + return QRectF(); +} + +/*! + Requests virtual keyboard to open. If the platform + doesn't provide virtual keyboard the visibility + remains false. + + Normally applications should not need to call this + function, keyboard should automatically open when + the text editor gains focus. +*/ +void QInputMethod::show() +{ + Q_D(QInputMethod); + QPlatformInputContext *ic = d->platformInputContext(); + if (ic) + ic->showInputPanel(); +} + +/*! + Requests virtual keyboard to close. + + Normally applications should not need to call this function, + keyboard should automatically close when the text editor loses + focus, for example when the parent view is closed. +*/ +void QInputMethod::hide() +{ + Q_D(QInputMethod); + QPlatformInputContext *ic = d->platformInputContext(); + if (ic) + ic->hideInputPanel(); +} + +/*! + \property QInputMethod::visible + \brief Virtual keyboard's visibility on the screen + + Input method visibility remains false for devices + with no virtual keyboards. + + \sa show(), hide() +*/ +bool QInputMethod::visible() const +{ + Q_D(const QInputMethod); + QPlatformInputContext *ic = d->platformInputContext(); + if (ic) + return ic->isInputPanelVisible(); + return false; +} + +/*! + Controls the keyboard visibility. Equivalent + to calling show() and hide() functions. + + \sa show(), hide() +*/ +void QInputMethod::setVisible(bool visible) +{ + visible ? show() : hide(); +} + +/*! + \property QInputMethod::animating + \brief True when the virtual keyboard is being opened or closed. + + Animating is false when keyboard is fully open or closed. + When \c animating is \c true and \c visibility is \c true keyboard + is being opened. When \c animating is \c true and \c visibility is + false keyboard is being closed. +*/ + +bool QInputMethod::isAnimating() const +{ + Q_D(const QInputMethod); + QPlatformInputContext *ic = d->platformInputContext(); + if (ic) + return ic->isAnimating(); + return false; +} + +/*! + \property QInputMethod::locale + \brief Current input locale. +*/ +QLocale QInputMethod::locale() const +{ + Q_D(const QInputMethod); + QPlatformInputContext *ic = d->platformInputContext(); + if (ic) + return ic->locale(); + return QLocale::c(); +} + +/*! + \property QInputMethod::inputDirection + \brief Current input direction. +*/ +Qt::LayoutDirection QInputMethod::inputDirection() const +{ + Q_D(const QInputMethod); + QPlatformInputContext *ic = d->platformInputContext(); + if (ic) + return ic->inputDirection(); + return Qt::LeftToRight; +} + +/*! + Called by the input item to inform the platform input methods when there has been + state changes in editor's input method query attributes. When calling the function + \a queries parameter has to be used to tell what has changes, which input method + can use to make queries for attributes it's interested with QInputMethodQueryEvent. + + In particular calling update whenever the cursor position changes is important as + that often causes other query attributes like surrounding text and text selection + to change as well. The attributes that often change together with cursor position + have been grouped in Qt::ImQueryInput value for convenience. +*/ +void QInputMethod::update(Qt::InputMethodQueries queries) +{ + Q_D(QInputMethod); + + if (queries & Qt::ImEnabled) + d->q_checkFocusObject(qApp->focusObject()); + + QPlatformInputContext *ic = d->platformInputContext(); + if (ic) + ic->update(queries); + + if (queries & Qt::ImCursorRectangle) + emit cursorRectangleChanged(); +} + +/*! + Resets the input method state. For example, a text editor normally calls + this method before inserting a text to make widget ready to accept a text. + + Input method resets automatically when the focused editor changes. +*/ +void QInputMethod::reset() +{ + Q_D(QInputMethod); + QPlatformInputContext *ic = d->platformInputContext(); + if (ic) + ic->reset(); +} + +/*! + Commits the word user is currently composing to the editor. The function is + mostly needed by the input methods with text prediction features and by the + methods where the script used for typing characters is different from the + script that actually gets appended to the editor. Any kind of action that + interrupts the text composing needs to flush the composing state by calling the + commit() function, for example when the cursor is moved elsewhere. +*/ +void QInputMethod::commit() +{ + Q_D(QInputMethod); + QPlatformInputContext *ic = d->platformInputContext(); + if (ic) + ic->commit(); +} + +/*! + Called by the input item when the word currently being composed is tapped by + the user. Input methods often use this information to offer more word + suggestions to the user. +*/ +void QInputMethod::invokeAction(Action a, int cursorPosition) +{ + Q_D(QInputMethod); + QPlatformInputContext *ic = d->platformInputContext(); + if (ic) + ic->invokeAction(a, cursorPosition); +} + +// temporary handlers for updating focus item based on application focus +void QInputMethodPrivate::q_connectFocusObject() +{ + Q_Q(QInputMethod); + QObject::connect(qApp, SIGNAL(focusObjectChanged(QObject*)), + q, SLOT(q_checkFocusObject(QObject*))); + q_checkFocusObject(qApp->focusObject()); +} + +void QInputMethodPrivate::q_checkFocusObject(QObject *object) +{ + Q_Q(QInputMethod); + + bool enabled = false; + if (object) { + QInputMethodQueryEvent query(Qt::ImEnabled); + QGuiApplication::sendEvent(object, &query); + enabled = query.value(Qt::ImEnabled).toBool(); + } + q->setInputItem(enabled ? object : 0); +} + +QT_END_NAMESPACE + +#include "moc_qinputmethod.cpp" diff --git a/src/gui/kernel/qinputmethod.h b/src/gui/kernel/qinputmethod.h new file mode 100644 index 0000000000..535ed1608d --- /dev/null +++ b/src/gui/kernel/qinputmethod.h @@ -0,0 +1,134 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtGui module 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 QINPUTMETHOD_H +#define QINPUTMETHOD_H + +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Gui) + +class QInputMethodPrivate; +class QWindow; +class QRectF; +class QTransform; + +class Q_GUI_EXPORT QInputMethod : public QObject +{ + Q_OBJECT + Q_DECLARE_PRIVATE(QInputMethod) + Q_PROPERTY(QObject *inputItem READ inputItem WRITE setInputItem NOTIFY inputItemChanged) + Q_PROPERTY(QRectF cursorRectangle READ cursorRectangle NOTIFY cursorRectangleChanged) + Q_PROPERTY(QRectF keyboardRectangle READ keyboardRectangle NOTIFY keyboardRectangleChanged) + Q_PROPERTY(bool visible READ visible NOTIFY visibleChanged) + Q_PROPERTY(bool animating READ isAnimating NOTIFY animatingChanged) + Q_PROPERTY(QLocale locale READ locale NOTIFY localeChanged) + Q_PROPERTY(Qt::LayoutDirection inputDirection READ inputDirection NOTIFY inputDirectionChanged) + + Q_ENUMS(Action) +public: + QT_DEPRECATED QObject *inputItem() const; + QT_DEPRECATED void setInputItem(QObject *inputItemChanged); + + // the window containing the editor + QT_DEPRECATED QWindow *inputWindow() const; + + QTransform inputItemTransform() const; + void setInputItemTransform(const QTransform &transform); + + // in window coordinates + QRectF cursorRectangle() const; // ### what if we have rotations for the item? + + // keyboard geometry in window coords + QRectF keyboardRectangle() const; + + enum Action { + Click, + ContextMenu + }; + + bool visible() const; + void setVisible(bool visible); + + bool isAnimating() const; + + QLocale locale() const; + Qt::LayoutDirection inputDirection() const; + +public Q_SLOTS: + void show(); + void hide(); + + void update(Qt::InputMethodQueries queries); + void reset(); + void commit(); + + void invokeAction(Action a, int cursorPosition); + +Q_SIGNALS: + void inputItemChanged(); + void cursorRectangleChanged(); + void keyboardRectangleChanged(); + void visibleChanged(); + void animatingChanged(); + void localeChanged(); + void inputDirectionChanged(Qt::LayoutDirection newDirection); + +private: + friend class QGuiApplication; + friend class QGuiApplicationPrivate; + friend class QPlatformInputContext; + QInputMethod(); + ~QInputMethod(); + + Q_PRIVATE_SLOT(d_func(), void q_connectFocusObject()); + Q_PRIVATE_SLOT(d_func(), void q_checkFocusObject(QObject* object)); +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif diff --git a/src/gui/kernel/qinputmethod_p.h b/src/gui/kernel/qinputmethod_p.h new file mode 100644 index 0000000000..862764d1bc --- /dev/null +++ b/src/gui/kernel/qinputmethod_p.h @@ -0,0 +1,83 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtGui module 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 QINPUTMETHOD_P_H +#define QINPUTMETHOD_P_H + +#include +#include +#include +#include +#include +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +class QInputMethodPrivate : public QObjectPrivate +{ + Q_DECLARE_PUBLIC(QInputMethod) + +public: + inline QInputMethodPrivate() : testContext(0) + {} + QPlatformInputContext *platformInputContext() const + { + return testContext ? testContext : QGuiApplicationPrivate::platformIntegration()->inputContext(); + } + static inline QInputMethodPrivate *get(QInputMethod *inputMethod) + { + return inputMethod->d_func(); + } + void q_connectFocusObject(); + void q_checkFocusObject(QObject *object); + + QTransform inputItemTransform; + QWeakPointer inputItem; + QPlatformInputContext *testContext; +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif diff --git a/src/gui/kernel/qinputpanel.cpp b/src/gui/kernel/qinputpanel.cpp deleted file mode 100644 index 8b28c680bf..0000000000 --- a/src/gui/kernel/qinputpanel.cpp +++ /dev/null @@ -1,376 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the QtGui module 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 -#include -#include -#include - -QT_BEGIN_NAMESPACE - -/*! - \internal -*/ -QInputPanel::QInputPanel() - : QObject(*new QInputPanelPrivate) -{ - // might be instantiated before QGuiApplication is fully done, need to connect later - QTimer::singleShot(0, this, SLOT(q_connectFocusObject())); -} - -/*! - \internal -*/ -QInputPanel::~QInputPanel() -{ -} - -/*! - \class QInputPanel - \brief The QInputPanel class provides access to the active text input method. - - QInputPanel is used by the text editors for integrating to the platform text input - methods and more commonly by application views for querying various text input method-related - information like virtual keyboard visibility and keyboard dimensions. - - Qt Quick also provides access to QInputPanel in QML through \l{QmlGlobalQtObject}{Qt global object} - as \c Qt.application.inputPanel property. -*/ - -/*! - \property QInputPanel::inputItem - \brief Focused item that accepts text input - \obsolete - - Input item is set and unset by the focused window. In QML Scene Graph this is done by - QQuickCanvas and the input item is either TextInput or TextEdit element. Any QObject can - behave as an input item as long as it responds to QInputMethodQueryEvent and QInputMethodEvent - events sent by the input methods. - - \sa inputItemTransform, inputWindow, QInputMethodQueryEvent, QInputMethodEvent -*/ -QObject *QInputPanel::inputItem() const -{ - Q_D(const QInputPanel); - return d->inputItem.data(); -} - -void QInputPanel::setInputItem(QObject *inputItem) -{ - Q_D(QInputPanel); - - if (d->inputItem.data() == inputItem) - return; - - d->inputItem = inputItem; - emit inputItemChanged(); -} - -/*! - Returns the currently focused window containing the input item. - - \obsolete -*/ -QWindow *QInputPanel::inputWindow() const -{ - return qApp->activeWindow(); -} - -/*! - Returns the transformation from input item coordinates to the window coordinates. -*/ -QTransform QInputPanel::inputItemTransform() const -{ - Q_D(const QInputPanel); - return d->inputItemTransform; -} - -/*! - Sets the transformation from input item coordinates to the window coordinates. - Item transform needs to be updated by the focused window like QQuickCanvas whenever - item is moved inside the scene. -*/ -void QInputPanel::setInputItemTransform(const QTransform &transform) -{ - Q_D(QInputPanel); - if (d->inputItemTransform == transform) - return; - - d->inputItemTransform = transform; - emit cursorRectangleChanged(); -} - -/*! - \property QInputPanel::cursorRectangle - \brief Input item's cursor rectangle in window coordinates. - - Cursor rectangle is often used by various text editing controls - like text prediction popups for following the text being typed. -*/ -QRectF QInputPanel::cursorRectangle() const -{ - Q_D(const QInputPanel); - - if (!d->inputItem) - return QRectF(); - - QInputMethodQueryEvent query(Qt::ImCursorRectangle); - QGuiApplication::sendEvent(d->inputItem.data(), &query); - QRect r = query.value(Qt::ImCursorRectangle).toRect(); - if (!r.isValid()) - return QRect(); - - return d->inputItemTransform.mapRect(r); -} - -/*! - \property QInputPanel::keyboardRectangle - \brief Virtual keyboard's geometry in window coordinates. -*/ -QRectF QInputPanel::keyboardRectangle() const -{ - Q_D(const QInputPanel); - QPlatformInputContext *ic = d->platformInputContext(); - if (ic) - return ic->keyboardRect(); - return QRectF(); -} - -/*! - Requests virtual keyboard to open. If the platform - doesn't provide virtual keyboard the visibility - remains false. - - Normally applications should not need to call this - function, keyboard should automatically open when - the text editor gains focus. -*/ -void QInputPanel::show() -{ - Q_D(QInputPanel); - QPlatformInputContext *ic = d->platformInputContext(); - if (ic) - ic->showInputPanel(); -} - -/*! - Requests virtual keyboard to close. - - Normally applications should not need to call this function, - keyboard should automatically close when the text editor loses - focus, for example when the parent view is closed. -*/ -void QInputPanel::hide() -{ - Q_D(QInputPanel); - QPlatformInputContext *ic = d->platformInputContext(); - if (ic) - ic->hideInputPanel(); -} - -/*! - \property QInputPanel::visible - \brief Virtual keyboard's visibility on the screen - - Input panel visibility remains false for devices - with no virtual keyboards. - - \sa show(), hide() -*/ -bool QInputPanel::visible() const -{ - Q_D(const QInputPanel); - QPlatformInputContext *ic = d->platformInputContext(); - if (ic) - return ic->isInputPanelVisible(); - return false; -} - -/*! - Controls the keyboard visibility. Equivalent - to calling show() and hide() functions. - - \sa show(), hide() -*/ -void QInputPanel::setVisible(bool visible) -{ - visible ? show() : hide(); -} - -/*! - \property QInputPanel::animating - \brief True when the virtual keyboard is being opened or closed. - - Animating is false when keyboard is fully open or closed. - When \c animating is \c true and \c visibility is \c true keyboard - is being opened. When \c animating is \c true and \c visibility is - false keyboard is being closed. -*/ - -bool QInputPanel::isAnimating() const -{ - Q_D(const QInputPanel); - QPlatformInputContext *ic = d->platformInputContext(); - if (ic) - return ic->isAnimating(); - return false; -} - -/*! - \property QInputPanel::locale - \brief Current input locale. -*/ -QLocale QInputPanel::locale() const -{ - Q_D(const QInputPanel); - QPlatformInputContext *ic = d->platformInputContext(); - if (ic) - return ic->locale(); - return QLocale::c(); -} - -/*! - \property QInputPanel::inputDirection - \brief Current input direction. -*/ -Qt::LayoutDirection QInputPanel::inputDirection() const -{ - Q_D(const QInputPanel); - QPlatformInputContext *ic = d->platformInputContext(); - if (ic) - return ic->inputDirection(); - return Qt::LeftToRight; -} - -/*! - Called by the input item to inform the platform input methods when there has been - state changes in editor's input method query attributes. When calling the function - \a queries parameter has to be used to tell what has changes, which input method - can use to make queries for attributes it's interested with QInputMethodQueryEvent. - - In particular calling update whenever the cursor position changes is important as - that often causes other query attributes like surrounding text and text selection - to change as well. The attributes that often change together with cursor position - have been grouped in Qt::ImQueryInput value for convenience. -*/ -void QInputPanel::update(Qt::InputMethodQueries queries) -{ - Q_D(QInputPanel); - - if (queries & Qt::ImEnabled) - d->q_checkFocusObject(qApp->focusObject()); - - QPlatformInputContext *ic = d->platformInputContext(); - if (ic) - ic->update(queries); - - if (queries & Qt::ImCursorRectangle) - emit cursorRectangleChanged(); -} - -/*! - Resets the input method state. For example, a text editor normally calls - this method before inserting a text to make widget ready to accept a text. - - Input method resets automatically when the focused editor changes. -*/ -void QInputPanel::reset() -{ - Q_D(QInputPanel); - QPlatformInputContext *ic = d->platformInputContext(); - if (ic) - ic->reset(); -} - -/*! - Commits the word user is currently composing to the editor. The function is - mostly needed by the input methods with text prediction features and by the - methods where the script used for typing characters is different from the - script that actually gets appended to the editor. Any kind of action that - interrupts the text composing needs to flush the composing state by calling the - commit() function, for example when the cursor is moved elsewhere. -*/ -void QInputPanel::commit() -{ - Q_D(QInputPanel); - QPlatformInputContext *ic = d->platformInputContext(); - if (ic) - ic->commit(); -} - -/*! - Called by the input item when the word currently being composed is tapped by - the user. Input methods often use this information to offer more word - suggestions to the user. -*/ -void QInputPanel::invokeAction(Action a, int cursorPosition) -{ - Q_D(QInputPanel); - QPlatformInputContext *ic = d->platformInputContext(); - if (ic) - ic->invokeAction(a, cursorPosition); -} - -// temporary handlers for updating focus item based on application focus -void QInputPanelPrivate::q_connectFocusObject() -{ - Q_Q(QInputPanel); - QObject::connect(qApp, SIGNAL(focusObjectChanged(QObject*)), - q, SLOT(q_checkFocusObject(QObject*))); - q_checkFocusObject(qApp->focusObject()); -} - -void QInputPanelPrivate::q_checkFocusObject(QObject *object) -{ - Q_Q(QInputPanel); - - bool enabled = false; - if (object) { - QInputMethodQueryEvent query(Qt::ImEnabled); - QGuiApplication::sendEvent(object, &query); - enabled = query.value(Qt::ImEnabled).toBool(); - } - q->setInputItem(enabled ? object : 0); -} - -QT_END_NAMESPACE - -#include "moc_qinputpanel.cpp" diff --git a/src/gui/kernel/qinputpanel.h b/src/gui/kernel/qinputpanel.h index 7b16709e42..95be71d7b5 100644 --- a/src/gui/kernel/qinputpanel.h +++ b/src/gui/kernel/qinputpanel.h @@ -42,89 +42,16 @@ #ifndef QINPUTPANEL_H #define QINPUTPANEL_H -#include +#include QT_BEGIN_HEADER QT_BEGIN_NAMESPACE - -class QInputPanelPrivate; -class QWindow; -class QRectF; -class QTransform; - -class Q_GUI_EXPORT QInputPanel : public QObject -{ - Q_OBJECT - Q_DECLARE_PRIVATE(QInputPanel) - Q_PROPERTY(QObject *inputItem READ inputItem WRITE setInputItem NOTIFY inputItemChanged) - Q_PROPERTY(QRectF cursorRectangle READ cursorRectangle NOTIFY cursorRectangleChanged) - Q_PROPERTY(QRectF keyboardRectangle READ keyboardRectangle NOTIFY keyboardRectangleChanged) - Q_PROPERTY(bool visible READ visible NOTIFY visibleChanged) - Q_PROPERTY(bool animating READ isAnimating NOTIFY animatingChanged) - Q_PROPERTY(QLocale locale READ locale NOTIFY localeChanged) - Q_PROPERTY(Qt::LayoutDirection inputDirection READ inputDirection NOTIFY inputDirectionChanged) - - Q_ENUMS(Action) -public: - QT_DEPRECATED QObject *inputItem() const; - QT_DEPRECATED void setInputItem(QObject *inputItemChanged); - - // the window containing the editor - QT_DEPRECATED QWindow *inputWindow() const; - - QTransform inputItemTransform() const; - void setInputItemTransform(const QTransform &transform); - - // in window coordinates - QRectF cursorRectangle() const; // ### what if we have rotations for the item? - - // keyboard geometry in window coords - QRectF keyboardRectangle() const; - - enum Action { - Click, - ContextMenu - }; - - bool visible() const; - void setVisible(bool visible); - - bool isAnimating() const; - - QLocale locale() const; - Qt::LayoutDirection inputDirection() const; - -public Q_SLOTS: - void show(); - void hide(); - - void update(Qt::InputMethodQueries queries); - void reset(); - void commit(); - - void invokeAction(Action a, int cursorPosition); - -Q_SIGNALS: - void inputItemChanged(); - void cursorRectangleChanged(); - void keyboardRectangleChanged(); - void visibleChanged(); - void animatingChanged(); - void localeChanged(); - void inputDirectionChanged(Qt::LayoutDirection newDirection); - -private: - friend class QGuiApplication; - friend class QGuiApplicationPrivate; - friend class QPlatformInputContext; - QInputPanel(); - ~QInputPanel(); - - Q_PRIVATE_SLOT(d_func(), void q_connectFocusObject()); - Q_PRIVATE_SLOT(d_func(), void q_checkFocusObject(QObject* object)); -}; +#if 0 +#pragma qt_class(QInputPanel) +#endif +#define QInputPanel QInputMethod QT_END_NAMESPACE diff --git a/src/gui/kernel/qinputpanel_p.h b/src/gui/kernel/qinputpanel_p.h index 88916f80a4..a4f24505c6 100644 --- a/src/gui/kernel/qinputpanel_p.h +++ b/src/gui/kernel/qinputpanel_p.h @@ -42,39 +42,16 @@ #ifndef QINPUTPANEL_P_H #define QINPUTPANEL_P_H -#include -#include -#include -#include -#include -#include +#include QT_BEGIN_HEADER QT_BEGIN_NAMESPACE -class QInputPanelPrivate : public QObjectPrivate -{ - Q_DECLARE_PUBLIC(QInputPanel) - -public: - inline QInputPanelPrivate() : testContext(0) - {} - QPlatformInputContext *platformInputContext() const - { - return testContext ? testContext : QGuiApplicationPrivate::platformIntegration()->inputContext(); - } - static inline QInputPanelPrivate *get(QInputPanel *inputPanel) - { - return inputPanel->d_func(); - } - void q_connectFocusObject(); - void q_checkFocusObject(QObject *object); - - QTransform inputItemTransform; - QWeakPointer inputItem; - QPlatformInputContext *testContext; -}; +#if 0 +#pragma qt_class(QInputPanelPrivate) +#endif +#define QInputPanelPrivate QInputMethodPrivate QT_END_NAMESPACE diff --git a/src/gui/kernel/qplatforminputcontext_qpa.cpp b/src/gui/kernel/qplatforminputcontext_qpa.cpp index f36a4a1af5..ee18f3ebd1 100644 --- a/src/gui/kernel/qplatforminputcontext_qpa.cpp +++ b/src/gui/kernel/qplatforminputcontext_qpa.cpp @@ -68,7 +68,7 @@ QT_BEGIN_NAMESPACE QPlatformInputContext provides an interface the actual input methods can derive from by reimplementing methods. - \sa QInputPanel + \sa QInputMethod */ /*! @@ -94,7 +94,7 @@ bool QPlatformInputContext::isValid() const } /*! - Method to be called when input method needs to be reset. Called by QInputPanel::reset(). + Method to be called when input method needs to be reset. Called by QInputMethod::reset(). No further QInputMethodEvents should be sent as response. */ void QPlatformInputContext::reset() @@ -106,7 +106,7 @@ void QPlatformInputContext::commit() } /*! - Notification on editor updates. Called by QInputPanel::update(). + Notification on editor updates. Called by QInputMethod::update(). */ void QPlatformInputContext::update(Qt::InputMethodQueries) { @@ -117,12 +117,12 @@ void QPlatformInputContext::update(Qt::InputMethodQueries) the user. Input methods often use this information to offer more word suggestions to the user. */ -void QPlatformInputContext::invokeAction(QInputPanel::Action action, int cursorPosition) +void QPlatformInputContext::invokeAction(QInputMethod::Action action, int cursorPosition) { Q_UNUSED(cursorPosition) // Default behavior for simple ephemeral input contexts. Some // complex input contexts should not be reset here. - if (action == QInputPanel::Click) + if (action == QInputMethod::Click) reset(); } @@ -148,17 +148,17 @@ QRectF QPlatformInputContext::keyboardRect() const } /*! - Active QPlatformInputContext is responsible for providing keyboardRectangle property to QInputPanel. + Active QPlatformInputContext is responsible for providing keyboardRectangle property to QInputMethod. In addition of providing the value in keyboardRect function, it also needs to call this emit function whenever the property changes. */ void QPlatformInputContext::emitKeyboardRectChanged() { - emit qApp->inputPanel()->keyboardRectangleChanged(); + emit qApp->inputMethod()->keyboardRectangleChanged(); } /*! - This function can be reimplemented to return true whenever input panel is animating + This function can be reimplemented to return true whenever input method is animating shown or hidden. Default implementation returns false. */ bool QPlatformInputContext::isAnimating() const @@ -167,13 +167,13 @@ bool QPlatformInputContext::isAnimating() const } /*! - Active QPlatformInputContext is responsible for providing animating property to QInputPanel. + Active QPlatformInputContext is responsible for providing animating property to QInputMethod. In addition of providing the value in isAnimation function, it also needs to call this emit function whenever the property changes. */ void QPlatformInputContext::emitAnimatingChanged() { - emit qApp->inputPanel()->animatingChanged(); + emit qApp->inputMethod()->animatingChanged(); } /*! @@ -199,13 +199,13 @@ bool QPlatformInputContext::isInputPanelVisible() const } /*! - Active QPlatformInputContext is responsible for providing visible property to QInputPanel. + Active QPlatformInputContext is responsible for providing visible property to QInputMethod. In addition of providing the value in isInputPanelVisible function, it also needs to call this emit function whenever the property changes. */ void QPlatformInputContext::emitInputPanelVisibleChanged() { - emit qApp->inputPanel()->visibleChanged(); + emit qApp->inputMethod()->visibleChanged(); } QLocale QPlatformInputContext::locale() const @@ -215,7 +215,7 @@ QLocale QPlatformInputContext::locale() const void QPlatformInputContext::emitLocaleChanged() { - emit qApp->inputPanel()->localeChanged(); + emit qApp->inputMethod()->localeChanged(); } Qt::LayoutDirection QPlatformInputContext::inputDirection() const @@ -225,7 +225,7 @@ Qt::LayoutDirection QPlatformInputContext::inputDirection() const void QPlatformInputContext::emitInputDirectionChanged(Qt::LayoutDirection newDirection) { - emit qApp->inputPanel()->inputDirectionChanged(newDirection); + emit qApp->inputMethod()->inputDirectionChanged(newDirection); } -- cgit v1.2.3