diff options
Diffstat (limited to 'src/gui/kernel')
-rw-r--r-- | src/gui/kernel/kernel.pri | 3 | ||||
-rw-r--r-- | src/gui/kernel/qguiapplication.cpp | 24 | ||||
-rw-r--r-- | src/gui/kernel/qguiapplication.h | 3 | ||||
-rw-r--r-- | src/gui/kernel/qguiapplication_p.h | 1 | ||||
-rw-r--r-- | src/gui/kernel/qinputpanel.cpp | 172 | ||||
-rw-r--r-- | src/gui/kernel/qinputpanel.h | 121 | ||||
-rw-r--r-- | src/gui/kernel/qinputpanel_p.h | 68 | ||||
-rw-r--r-- | src/gui/kernel/qplatforminputcontext_qpa.cpp | 28 | ||||
-rw-r--r-- | src/gui/kernel/qplatforminputcontext_qpa.h | 17 |
9 files changed, 417 insertions, 20 deletions
diff --git a/src/gui/kernel/kernel.pri b/src/gui/kernel/kernel.pri index 2167510c4d..5195b2e3f5 100644 --- a/src/gui/kernel/kernel.pri +++ b/src/gui/kernel/kernel.pri @@ -13,6 +13,8 @@ HEADERS += \ kernel/qdnd_p.h \ kernel/qevent.h \ kernel/qevent_p.h \ + kernel/qinputpanel.h \ + kernel/qinputpanel_p.h \ kernel/qkeysequence.h \ kernel/qkeysequence_p.h \ kernel/qkeymapper_p.h \ @@ -29,6 +31,7 @@ SOURCES += \ kernel/qdrag.cpp \ kernel/qdnd.cpp \ kernel/qevent.cpp \ + kernel/qinputpanel.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 6cddf3ab73..e9edeb9247 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -60,6 +60,7 @@ #include <QtGui/QPlatformIntegration> #include <QtGui/QGenericPluginFactory> #include <QtGui/qstylehints.h> +#include <QtGui/qinputpanel.h> #include <QWindowSystemInterface> #include "private/qwindowsysteminterface_qpa_p.h" @@ -174,7 +175,8 @@ QGuiApplication::~QGuiApplication() QGuiApplicationPrivate::QGuiApplicationPrivate(int &argc, char **argv, int flags) : QCoreApplicationPrivate(argc, argv, flags), - styleHints(0) + styleHints(0), + inputPanel(0) { self = this; } @@ -403,6 +405,7 @@ QGuiApplicationPrivate::~QGuiApplicationPrivate() cleanupThreadData(); delete styleHints; + delete inputPanel; delete platform_integration; platform_integration = 0; @@ -1186,6 +1189,25 @@ QStyleHints *QGuiApplication::styleHints() const } +/*! + \since 5.0 + + returns the input panel. + + The input panel returns properties about the state and position of + the virtual keyboard. It also provides information about the position of the + current focused input element. + + \sa QInputPanel + */ +QInputPanel *QGuiApplication::inputPanel() const +{ + Q_D(const QGuiApplication); + if (!d->inputPanel) + const_cast<QGuiApplicationPrivate *>(d)->inputPanel = new QInputPanel(); + return d->inputPanel; +} + // Returns the current platform used by keyBindings uint QGuiApplicationPrivate::currentKeyPlatform() diff --git a/src/gui/kernel/qguiapplication.h b/src/gui/kernel/qguiapplication.h index c402b9b9dc..0649b5de31 100644 --- a/src/gui/kernel/qguiapplication.h +++ b/src/gui/kernel/qguiapplication.h @@ -59,6 +59,7 @@ class QPlatformNativeInterface; class QPalette; class QScreen; class QStyleHints; +class QInputPanel; #if defined(qApp) #undef qApp @@ -113,10 +114,12 @@ public: static inline bool isRightToLeft() { return layoutDirection() == Qt::RightToLeft; } static inline bool isLeftToRight() { return layoutDirection() == Qt::LeftToRight; } + // ### move to QInputPanel static QLocale keyboardInputLocale(); static Qt::LayoutDirection keyboardInputDirection(); QStyleHints *styleHints() const; + QInputPanel *inputPanel() const; static QPlatformNativeInterface *platformNativeInterface(); diff --git a/src/gui/kernel/qguiapplication_p.h b/src/gui/kernel/qguiapplication_p.h index bdf79d4394..9f64911399 100644 --- a/src/gui/kernel/qguiapplication_p.h +++ b/src/gui/kernel/qguiapplication_p.h @@ -173,6 +173,7 @@ public: static QFont *app_font; QStyleHints *styleHints; + QInputPanel *inputPanel; static bool quitOnLastWindowClosed; diff --git a/src/gui/kernel/qinputpanel.cpp b/src/gui/kernel/qinputpanel.cpp new file mode 100644 index 0000000000..36104f3816 --- /dev/null +++ b/src/gui/kernel/qinputpanel.cpp @@ -0,0 +1,172 @@ +/**************************************************************************** +** +** 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 QtGui module 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 <qinputpanel.h> +#include <private/qinputpanel_p.h> +#include <qplatforminputcontext_qpa.h> +#include <private/qguiapplication_p.h> + +QInputPanel::QInputPanel() + : QObject(*new QInputPanelPrivate) +{ +} + +QInputPanel::~QInputPanel() +{ +} + + +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(); +} + +QWindow *QInputPanel::inputWindow() const +{ + return qApp->activeWindow(); +} + +QTransform QInputPanel::inputItemTransform() const +{ + Q_D(const QInputPanel); + return d->inputItemTransform; +} + +void QInputPanel::setInputItemTranform(const QTransform &transform) +{ + Q_D(QInputPanel); + d->inputItemTransform = transform; + emit cursorRectChanged(); +} + +QRectF QInputPanel::cursorRect() const +{ + QInputMethodQueryEvent query(Qt::ImMicroFocus); + QGuiApplication::sendEvent(inputItem(), &query); + QRect r = query.value().toRect(); + if (!r.isValid()) + return QRect(); + + Q_D(const QInputPanel); + return d->inputItemTransform.mapRect(r); +} + +QRectF QInputPanel::keyboardRect() +{ + QPlatformInputContext *ic = QGuiApplicationPrivate::platformIntegration()->inputContext(); + if (ic) + return ic->keyboardRect(); + return QRectF(); +} + +void QInputPanel::open() +{ + setOpen(true); +} + +void QInputPanel::close() +{ + setOpen(false); +} + +bool QInputPanel::isOpen() const +{ + Q_D(const QInputPanel); + + return d->open; +} + +void QInputPanel::setOpen(bool open) +{ + Q_D(QInputPanel); + if (d->open == open) + return; + + d->open = open; + emit openChanged(); +} + +bool QInputPanel::isAnimating() const +{ + QPlatformInputContext *ic = QGuiApplicationPrivate::platformIntegration()->inputContext(); + if (ic) + return ic->isAnimating(); + return false; +} + + +void QInputPanel::update(Qt::InputMethodQueries queries) +{ + QPlatformInputContext *ic = QGuiApplicationPrivate::platformIntegration()->inputContext(); + if (ic) + ic->update(queries); + + if (queries & Qt::ImMicroFocus) + emit cursorRectChanged(); +} + +void QInputPanel::reset() +{ + QPlatformInputContext *ic = QGuiApplicationPrivate::platformIntegration()->inputContext(); + if (ic) + ic->reset(); +} + +void QInputPanel::invokeAction(Action a, int cursorPosition) +{ + QPlatformInputContext *ic = QGuiApplicationPrivate::platformIntegration()->inputContext(); + if (ic) + ic->invokeAction(a, cursorPosition); +} + +#include "moc_qinputpanel.cpp" diff --git a/src/gui/kernel/qinputpanel.h b/src/gui/kernel/qinputpanel.h new file mode 100644 index 0000000000..2348fbd62f --- /dev/null +++ b/src/gui/kernel/qinputpanel.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 QtGui module 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 QINPUTPANEL_H +#define QINPUTPANEL_H + +#include <QtCore/qobject.h> + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Gui) + +class QInputPanelPrivate; +class QWindow; +class QRectF; + +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 cursorRect READ cursorRect NOTIFY cursorRectChanged) + Q_PROPERTY(QRectF keyboardRect READ keyboardRect NOTIFY keyboardRectChanged) + Q_PROPERTY(bool open READ isOpen WRITE setOpen NOTIFY openChanged) + Q_PROPERTY(bool animating READ isAnimating NOTIFY animatingChanged) + +public: + QObject *inputItem() const; + void setInputItem(QObject *inputItemChanged); + + // the window containing the editor + QWindow *inputWindow() const; + + QTransform inputItemTransform() const; + void setInputItemTranform(const QTransform &transform); + + // in window coordinates + QRectF cursorRect() const; // ### what if we have rotations for the item? + + // keyboard geometry in window coords + QRectF keyboardRect(); + + enum Action { + Click, + ContextMenu + }; + + bool isOpen() const; + void setOpen(bool open); + + bool isAnimating() const; + +public Q_SLOTS: + void open(); + void close(); + + void update(Qt::InputMethodQueries queries); + void reset(); + + void invokeAction(Action a, int cursorPosition); + +Q_SIGNALS: + void inputItemChanged(); + void cursorRectChanged(); + void keyboardRectChanged(); + void openChanged(); + void animatingChanged(); + +private: + friend class QGuiApplication; + friend class QGuiApplicationPrivate; + friend class QPlatformInputContext; + QInputPanel(); + ~QInputPanel(); +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif diff --git a/src/gui/kernel/qinputpanel_p.h b/src/gui/kernel/qinputpanel_p.h new file mode 100644 index 0000000000..567459c79e --- /dev/null +++ b/src/gui/kernel/qinputpanel_p.h @@ -0,0 +1,68 @@ +/**************************************************************************** +** +** 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 QtGui module 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 QINPUTPANEL_P_H +#define QINPUTPANEL_P_H + +#include <qinputpanel.h> +#include <private/qobject_p.h> +#include <QtCore/QWeakPointer> + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +class QInputPanelPrivate : public QObjectPrivate +{ +public: + inline QInputPanelPrivate() + : open(false) + {} + QTransform inputItemTransform; + QWeakPointer<QObject> inputItem; + bool open; +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif diff --git a/src/gui/kernel/qplatforminputcontext_qpa.cpp b/src/gui/kernel/qplatforminputcontext_qpa.cpp index 4ef25ddbe5..8c08c13180 100644 --- a/src/gui/kernel/qplatforminputcontext_qpa.cpp +++ b/src/gui/kernel/qplatforminputcontext_qpa.cpp @@ -40,8 +40,7 @@ ****************************************************************************/ #include <qplatforminputcontext_qpa.h> - -#include <QtGui/QMouseEvent> +#include <qguiapplication.h> QT_BEGIN_NAMESPACE @@ -57,26 +56,37 @@ void QPlatformInputContext::reset() { } -void QPlatformInputContext::update() +void QPlatformInputContext::update(Qt::InputMethodQueries) { } -void QPlatformInputContext::mouseHandler(int, QMouseEvent *event) +void QPlatformInputContext::invokeAction(QInputPanel::Action action, int cursorPosition) { // Default behavior for simple ephemeral input contexts. Some // complex input contexts should not be reset here. - if (event->type() == QEvent::MouseButtonPress || event->type() == QEvent::MouseButtonDblClick) + if (action == QInputPanel::Click) reset(); } -QObject *QPlatformInputContext::focusObject() const +QRectF QPlatformInputContext::keyboardRect() const +{ + return QRectF(); +} + +void QPlatformInputContext::emitKeyboardRectChanged() const { - return m_focusObject.data(); + emit qApp->inputPanel()->keyboardRectChanged(); } -void QPlatformInputContext::setFocusObject(QObject *object) +bool QPlatformInputContext::isAnimating() { - m_focusObject = object; + return false; } +void QPlatformInputContext::emitAnimatingChanged() +{ + emit qApp->inputPanel()->animatingChanged(); +} + + QT_END_NAMESPACE diff --git a/src/gui/kernel/qplatforminputcontext_qpa.h b/src/gui/kernel/qplatforminputcontext_qpa.h index 57694fe9d9..3bdce73019 100644 --- a/src/gui/kernel/qplatforminputcontext_qpa.h +++ b/src/gui/kernel/qplatforminputcontext_qpa.h @@ -42,7 +42,7 @@ #ifndef QPLATFORMINPUTCONTEXT_H #define QPLATFORMINPUTCONTEXT_H -#include <QtCore/QWeakPointer> +#include <qinputpanel.h> QT_BEGIN_HEADER @@ -60,17 +60,14 @@ public: virtual ~QPlatformInputContext(); virtual void reset(); - virtual void update(); + virtual void update(Qt::InputMethodQueries); + virtual void invokeAction(QInputPanel::Action, int cursorPosition); - virtual void mouseHandler(int x, QMouseEvent *event); + virtual QRectF keyboardRect() const; + void emitKeyboardRectChanged() const; - QObject *focusObject() const; - virtual void setFocusObject(QObject *object); - -// virtual QList<QAction *> actions(); -private: - QWeakPointer<QObject> m_focusObject; - QWeakPointer<QWindow> m_focusWindow; + virtual bool isAnimating(); + void emitAnimatingChanged(); }; QT_END_NAMESPACE |