diff options
author | Eike Ziller <eike.ziller@nokia.com> | 2011-08-05 06:43:24 (GMT) |
---|---|---|
committer | Eike Ziller <eike.ziller@nokia.com> | 2011-08-05 07:19:52 (GMT) |
commit | 2e0acaff8d152732986f628dd9e198ca4b304f64 (patch) | |
tree | 2dca97d88e2942ec751c2d505de000afdd4154e0 /src/plugins | |
parent | 920ce5ed71bc456e429b887801a8d8bea7a3db0d (diff) | |
download | Qt-2e0acaff8d152732986f628dd9e198ca4b304f64.zip Qt-2e0acaff8d152732986f628dd9e198ca4b304f64.tar.gz Qt-2e0acaff8d152732986f628dd9e198ca4b304f64.tar.bz2 |
Automatic closing of input panel on uikit when QML item looses focus.
I.e. we remember which item had focus when we got the request to open
the input panel, and close it when that looses focus, even if we don't
get an explicit close request.
Also set the "returnKey" to "Return" instead of "Done" if the focus item
is a TextEdit.
This adds a dependency of the platform plugin to declarative.
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/platforms/uikit/platform.pro | 2 | ||||
-rw-r--r-- | src/plugins/platforms/uikit/quikiteventloop.mm | 57 | ||||
-rw-r--r-- | src/plugins/platforms/uikit/quikitsoftwareinputhandler.h | 12 |
3 files changed, 65 insertions, 6 deletions
diff --git a/src/plugins/platforms/uikit/platform.pro b/src/plugins/platforms/uikit/platform.pro index 273c00d..726da06 100644 --- a/src/plugins/platforms/uikit/platform.pro +++ b/src/plugins/platforms/uikit/platform.pro @@ -2,7 +2,7 @@ TARGET = quikit include(../../qpluginbase.pri) QTDIR_build:DESTDIR = $$QT_BUILD_TREE/plugins/platforms -QT += opengl +QT += opengl declarative OBJECTIVE_SOURCES = main.mm \ quikitintegration.mm \ diff --git a/src/plugins/platforms/uikit/quikiteventloop.mm b/src/plugins/platforms/uikit/quikiteventloop.mm index 01ecf3f..7df7ec8 100644 --- a/src/plugins/platforms/uikit/quikiteventloop.mm +++ b/src/plugins/platforms/uikit/quikiteventloop.mm @@ -49,6 +49,8 @@ #include <QtGui/QApplication> #include <QtGui/QWidget> +#include <QtDeclarative/QDeclarativeView> +#include <QtDeclarative/QDeclarativeItem> #include <QtDebug> @interface QUIKitAppDelegate : NSObject <UIApplicationDelegate> { @@ -212,24 +214,69 @@ void QUIKitEventLoop::qtNeedsToProcessEvents() [mHelper performSelectorOnMainThread:@selector(processEvents) withObject:nil waitUntilDone:NO]; } +static UIReturnKeyType keyTypeForObject(QObject *obj) +{ + if (strcmp(obj->metaObject()->className(), "QDeclarativeTextEdit") == 0) + return UIReturnKeyDefault; + return UIReturnKeyDone; +} + bool QUIKitSoftwareInputHandler::eventFilter(QObject *obj, QEvent *event) { if (event->type() == QEvent::RequestSoftwareInputPanel) { + UIReturnKeyType returnKeyType = UIReturnKeyDone; + if (QDeclarativeView *declarativeView = qobject_cast<QDeclarativeView *>(obj)) { + // register on loosing the focus, so we can auto-remove the input panel again + QGraphicsScene *scene = declarativeView->scene(); + if (scene) { + if (mCurrentFocusObject) + disconnect(mCurrentFocusObject, 0, this, SLOT(activeFocusChanged(bool))); + QDeclarativeItem *focus = static_cast<QDeclarativeItem *>(scene->focusItem()); + mCurrentFocusObject = focus; + if (focus) { + connect(mCurrentFocusObject, SIGNAL(activeFocusChanged(bool)), this, SLOT(activeFocusChanged(bool))); + returnKeyType = keyTypeForObject(mCurrentFocusObject); + } + } + } QWidget *widget = qobject_cast<QWidget *>(obj); if (widget) { + mCurrentFocusWidget = widget; QUIKitWindow *platformWindow = static_cast<QUIKitWindow *>(widget->window()->platformWindow()); - if (platformWindow) [platformWindow->nativeView() becomeFirstResponder]; + if (platformWindow) { + platformWindow->nativeView().returnKeyType = returnKeyType; + [platformWindow->nativeView() becomeFirstResponder]; + } return true; } } else if (event->type() == QEvent::CloseSoftwareInputPanel) { QWidget *widget = qobject_cast<QWidget *>(obj); - if (widget) { - QUIKitWindow *platformWindow = static_cast<QUIKitWindow *>(widget->window()->platformWindow()); - if (platformWindow) [platformWindow->nativeView() resignFirstResponder]; - return true; + return closeSoftwareInputPanel(widget); + } + return false; +} + +bool QUIKitSoftwareInputHandler::closeSoftwareInputPanel(QWidget *widget) +{ + if (widget) { + QUIKitWindow *platformWindow = static_cast<QUIKitWindow *>(widget->window()->platformWindow()); + if (platformWindow) { + [platformWindow->nativeView() resignFirstResponder]; + mCurrentFocusWidget = 0; + if (mCurrentFocusObject) + disconnect(mCurrentFocusObject, 0, this, SLOT(activeFocusChanged(bool))); + mCurrentFocusObject = 0; } + return true; } return false; } +void QUIKitSoftwareInputHandler::activeFocusChanged(bool focus) +{ + if (!focus && mCurrentFocusWidget && mCurrentFocusObject) { + closeSoftwareInputPanel(mCurrentFocusWidget); + } +} + QT_END_NAMESPACE diff --git a/src/plugins/platforms/uikit/quikitsoftwareinputhandler.h b/src/plugins/platforms/uikit/quikitsoftwareinputhandler.h index 7e4f8e9..3f64bf5 100644 --- a/src/plugins/platforms/uikit/quikitsoftwareinputhandler.h +++ b/src/plugins/platforms/uikit/quikitsoftwareinputhandler.h @@ -45,6 +45,8 @@ #define QUIKITSOFTWAREINPUTHANDLER_H #include <QtCore/QObject> +#include <QtCore/QPointer> +#include <QtGui/QWidget> QT_BEGIN_NAMESPACE @@ -53,7 +55,17 @@ class QUIKitSoftwareInputHandler : public QObject Q_OBJECT public: + QUIKitSoftwareInputHandler() : mCurrentFocusWidget(0), mCurrentFocusObject(0) {} bool eventFilter(QObject *obj, QEvent *event); + +private slots: + void activeFocusChanged(bool focus); + +private: + bool closeSoftwareInputPanel(QWidget *widget); + + QPointer<QWidget> mCurrentFocusWidget; + QPointer<QObject> mCurrentFocusObject; }; QT_END_NAMESPACE |