diff options
Diffstat (limited to 'src/plugins/platforms/uikit')
-rw-r--r-- | src/plugins/platforms/uikit/quikiteventloop.h | 4 | ||||
-rw-r--r-- | src/plugins/platforms/uikit/quikiteventloop.mm | 23 | ||||
-rw-r--r-- | src/plugins/platforms/uikit/quikitsoftwareinputhandler.h | 18 | ||||
-rw-r--r-- | src/plugins/platforms/uikit/quikitwindow.h | 24 | ||||
-rw-r--r-- | src/plugins/platforms/uikit/quikitwindow.mm | 69 | ||||
-rw-r--r-- | src/plugins/platforms/uikit/uikit.pro | 2 |
6 files changed, 136 insertions, 4 deletions
diff --git a/src/plugins/platforms/uikit/quikiteventloop.h b/src/plugins/platforms/uikit/quikiteventloop.h index cf5c682..b81e0fd 100644 --- a/src/plugins/platforms/uikit/quikiteventloop.h +++ b/src/plugins/platforms/uikit/quikiteventloop.h @@ -42,6 +42,9 @@ #ifndef QUIKITEVENTLOOP_H #define QUIKITEVENTLOOP_H +#include "quikitsoftwareinputhandler.h" + +#include <QtCore/QEvent> #include <QtGui/QPlatformEventLoopIntegration> @class EventLoopHelper; @@ -61,6 +64,7 @@ public: EventLoopHelper *mHelper; NSTimer *mTimer; + QUIKitSoftwareInputHandler *mInputHandler; }; QT_END_NAMESPACE diff --git a/src/plugins/platforms/uikit/quikiteventloop.mm b/src/plugins/platforms/uikit/quikiteventloop.mm index d3afd86..8d2603c 100644 --- a/src/plugins/platforms/uikit/quikiteventloop.mm +++ b/src/plugins/platforms/uikit/quikiteventloop.mm @@ -124,6 +124,7 @@ QT_BEGIN_NAMESPACE QUIKitEventLoop::QUIKitEventLoop() { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; + mInputHandler = new QUIKitSoftwareInputHandler; mHelper = [[EventLoopHelper alloc] initWithEventLoopIntegration:this]; mTimer = [[NSTimer timerWithTimeInterval:0.030 target:mHelper selector:@selector(processEventsAndSchedule) userInfo:nil repeats:YES] retain]; [pool release]; @@ -133,10 +134,12 @@ QUIKitEventLoop::~QUIKitEventLoop() { [mTimer release]; [mHelper release]; + delete mInputHandler; } void QUIKitEventLoop::startEventLoop() { + qApp->installEventFilter(mInputHandler); NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; [[NSRunLoop currentRunLoop] addTimer:[mTimer autorelease] forMode:NSDefaultRunLoopMode]; UIApplicationMain(qApp->argc(), qApp->argv(), nil, @"QUIKitAppDelegate"); @@ -153,4 +156,24 @@ void QUIKitEventLoop::qtNeedsToProcessEvents() [mHelper performSelectorOnMainThread:@selector(processEvents) withObject:nil waitUntilDone:NO]; } +bool QUIKitSoftwareInputHandler::eventFilter(QObject *obj, QEvent *event) +{ + if (event->type() == QEvent::RequestSoftwareInputPanel) { + QWidget *widget = qobject_cast<QWidget *>(obj); + if (widget) { + QUIKitWindow *platformWindow = static_cast<QUIKitWindow *>(widget->platformWindow()); + [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->platformWindow()); + [platformWindow->nativeView() resignFirstResponder]; + return true; + } + } + return false; +} + QT_END_NAMESPACE diff --git a/src/plugins/platforms/uikit/quikitsoftwareinputhandler.h b/src/plugins/platforms/uikit/quikitsoftwareinputhandler.h new file mode 100644 index 0000000..c0a5c25 --- /dev/null +++ b/src/plugins/platforms/uikit/quikitsoftwareinputhandler.h @@ -0,0 +1,18 @@ +#ifndef QUIKITSOFTWAREINPUTHANDLER_H +#define QUIKITSOFTWAREINPUTHANDLER_H + +#include <QtCore/QObject> + +QT_BEGIN_NAMESPACE + +class QUIKitSoftwareInputHandler : public QObject +{ + Q_OBJECT + +public: + bool eventFilter(QObject *obj, QEvent *event); +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/plugins/platforms/uikit/quikitwindow.h b/src/plugins/platforms/uikit/quikitwindow.h index f6d2c27..9e73754 100644 --- a/src/plugins/platforms/uikit/quikitwindow.h +++ b/src/plugins/platforms/uikit/quikitwindow.h @@ -49,7 +49,7 @@ #import <OpenGLES/ES1/glext.h> #import <OpenGLES/EAGL.h> -@interface EAGLView : UIView +@interface EAGLView : UIView <UIKeyInput> { QPlatformWindow *mWindow; EAGLContext *mContext; @@ -58,6 +58,15 @@ GLint mFramebufferHeight; GLuint mFramebuffer, mColorRenderbuffer, mDepthRenderbuffer; + + // ------- Text Input ---------- + UITextAutocapitalizationType autocapitalizationType; + UITextAutocorrectionType autocorrectionType; + BOOL enablesReturnKeyAutomatically; + UIKeyboardAppearance keyboardAppearance; + UIKeyboardType keyboardType; + UIReturnKeyType returnKeyType; + BOOL secureTextEntry; } - (void)setContext:(EAGLContext *)newContext; @@ -67,6 +76,18 @@ - (void)makeCurrent; - (void)setWindow:(QPlatformWindow *)window; - (void)sendMouseEventForTouches:(NSSet *)touches withEvent:(UIEvent *)event fakeButtons:(Qt::MouseButtons)buttons; + + +// ------- Text Input ---------- + +@property(nonatomic) UITextAutocapitalizationType autocapitalizationType; +@property(nonatomic) UITextAutocorrectionType autocorrectionType; +@property(nonatomic) BOOL enablesReturnKeyAutomatically; +@property(nonatomic) UIKeyboardAppearance keyboardAppearance; +@property(nonatomic) UIKeyboardType keyboardType; +@property(nonatomic) UIReturnKeyType returnKeyType; +@property(nonatomic, getter=isSecureTextEntry) BOOL secureTextEntry; + @end class EAGLPlatformContext; @@ -82,6 +103,7 @@ public: ~QUIKitWindow(); UIWindow *nativeWindow() const { return mWindow; } + UIView *nativeView() const { return mView; } void setGeometry(const QRect &rect); UIWindow *ensureNativeWindow(); diff --git a/src/plugins/platforms/uikit/quikitwindow.mm b/src/plugins/platforms/uikit/quikitwindow.mm index aafbfa1..ff60de7 100644 --- a/src/plugins/platforms/uikit/quikitwindow.mm +++ b/src/plugins/platforms/uikit/quikitwindow.mm @@ -46,6 +46,8 @@ #include "quikitscreen.h" #include <QtDebug> +#include <QtGui/QApplication> +#include <QtGui/QKeyEvent> #include <QtGui/QPlatformGLContext> #include <QtGui/QWindowSystemInterface> @@ -120,15 +122,22 @@ private: return [CAEAGLLayer class]; } -- (id)init +- (id)initWithFrame:(CGRect)frame { - if ((self = [super init])) { + if ((self = [super initWithFrame:frame])) { CAEAGLLayer *eaglLayer = (CAEAGLLayer *)self.layer; eaglLayer.opaque = TRUE; eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithBool:NO], kEAGLDrawablePropertyRetainedBacking, kEAGLColorFormatRGBA8, kEAGLDrawablePropertyColorFormat, nil]; + autocapitalizationType = UITextAutocapitalizationTypeNone; + autocorrectionType = UITextAutocorrectionTypeNo; + enablesReturnKeyAutomatically = NO; + keyboardAppearance = UIKeyboardAppearanceDefault; + keyboardType = UIKeyboardTypeDefault; + returnKeyType = UIReturnKeyDone; + secureTextEntry = NO; } return self; } @@ -246,6 +255,61 @@ private: [self sendMouseEventForTouches:touches withEvent:event fakeButtons:Qt::NoButton]; } +// ------- Text Input ---------- + +@synthesize autocapitalizationType; +@synthesize autocorrectionType; +@synthesize enablesReturnKeyAutomatically; +@synthesize keyboardAppearance; +@synthesize keyboardType; +@synthesize returnKeyType; +@synthesize secureTextEntry; + +- (BOOL)canBecomeFirstResponder +{ + return YES; +} + +- (BOOL)hasText +{ + return YES; +} + +- (void)insertText:(NSString *)text +{ + QKeyEvent *ev; + int key = 0; + if ([text isEqualToString:@"\n"]) + key = (int)Qt::Key_Return; + ev = new QKeyEvent(QEvent::KeyPress, + key, + Qt::NoModifier, + QString::fromUtf8([text UTF8String]) + ); + qApp->postEvent(qApp->focusWidget(), ev); + ev = new QKeyEvent(QEvent::KeyRelease, + key, + Qt::NoModifier, + QString::fromUtf8([text UTF8String]) + ); + qApp->postEvent(qApp->focusWidget(), ev); +} + +- (void)deleteBackward +{ + QKeyEvent *ev; + ev = new QKeyEvent(QEvent::KeyPress, + (int)Qt::Key_Backspace, + Qt::NoModifier + ); + qApp->postEvent(qApp->focusWidget(), ev); + ev = new QKeyEvent(QEvent::KeyRelease, + (int)Qt::Key_Backspace, + Qt::NoModifier + ); + qApp->postEvent(qApp->focusWidget(), ev); +} + @end QT_BEGIN_NAMESPACE @@ -284,7 +348,6 @@ UIWindow *QUIKitWindow::ensureNativeWindow() { if (!mWindow) { // window - CGRect screenBounds = [mScreen->uiScreen() bounds]; QRect geom = geometry(); CGRect frame = CGRectMake(geom.x(), geom.y(), geom.width(), geom.height()); mWindow = [[UIWindow alloc] initWithFrame:frame]; diff --git a/src/plugins/platforms/uikit/uikit.pro b/src/plugins/platforms/uikit/uikit.pro index 1589ee9..6f5947f 100644 --- a/src/plugins/platforms/uikit/uikit.pro +++ b/src/plugins/platforms/uikit/uikit.pro @@ -17,6 +17,8 @@ OBJECTIVE_HEADERS = quikitintegration.h \ quikiteventloop.h \ quikitwindowsurface.h +HEADERS = quikitsoftwareinputhandler.h + #add libz for freetype. LIBS += -lz |