diff options
author | Tor Arne Vestbø <tor.arne.vestbo@digia.com> | 2014-09-18 12:48:29 +0200 |
---|---|---|
committer | Tor Arne Vestbø <tor.arne.vestbo@digia.com> | 2014-09-20 11:53:43 +0200 |
commit | e98b5cddeb09e24373371af190dfcd92c9292aaf (patch) | |
tree | d55ec2d4f22eb467613444bfe40e2679bdc6422c /src | |
parent | 6910b8a552de6f0cd98fdfa50620825d59d63363 (diff) |
iOS: Allow settings custom input and accessory views through ImPlatformData
Change-Id: Ib802c73f9c9e27853fa0dd25c304d77df570309e
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@digia.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/platforms/ios/qiosinputcontext.h | 3 | ||||
-rw-r--r-- | src/plugins/platforms/ios/qiosinputcontext.mm | 4 | ||||
-rw-r--r-- | src/plugins/platforms/ios/qiostextresponder.h | 3 | ||||
-rw-r--r-- | src/plugins/platforms/ios/qiostextresponder.mm | 57 |
4 files changed, 65 insertions, 2 deletions
diff --git a/src/plugins/platforms/ios/qiosinputcontext.h b/src/plugins/platforms/ios/qiosinputcontext.h index 7f94a9836a..8d7f45d2bd 100644 --- a/src/plugins/platforms/ios/qiosinputcontext.h +++ b/src/plugins/platforms/ios/qiosinputcontext.h @@ -48,6 +48,9 @@ #include <QtGui/qtransform.h> #include <qpa/qplatforminputcontext.h> +const char kImePlatformDataInputView[] = "inputView"; +const char kImePlatformDataInputAccessoryView[] = "inputAccessoryView"; + QT_BEGIN_NAMESPACE @class QIOSKeyboardListener; diff --git a/src/plugins/platforms/ios/qiosinputcontext.mm b/src/plugins/platforms/ios/qiosinputcontext.mm index cbf3fb4ff2..aeef24b0b3 100644 --- a/src/plugins/platforms/ios/qiosinputcontext.mm +++ b/src/plugins/platforms/ios/qiosinputcontext.mm @@ -420,10 +420,10 @@ void QIOSInputContext::focusWindowChanged(QWindow *focusWindow) void QIOSInputContext::update(Qt::InputMethodQueries updatedProperties) { // Mask for properties that we are interested in and see if any of them changed - updatedProperties &= (Qt::ImEnabled | Qt::ImHints | Qt::ImQueryInput); + updatedProperties &= (Qt::ImEnabled | Qt::ImHints | Qt::ImQueryInput | Qt::ImPlatformData); Qt::InputMethodQueries changedProperties = m_imeState.update(updatedProperties); - if (changedProperties & (Qt::ImEnabled | Qt::ImHints)) { + if (changedProperties & (Qt::ImEnabled | Qt::ImHints | Qt::ImPlatformData)) { // Changes to enablement or hints require virtual keyboard reconfigure [m_textResponder release]; m_textResponder = [[QIOSTextInputResponder alloc] initWithInputContext:this]; diff --git a/src/plugins/platforms/ios/qiostextresponder.h b/src/plugins/platforms/ios/qiostextresponder.h index 7290d9e454..2923feba3b 100644 --- a/src/plugins/platforms/ios/qiostextresponder.h +++ b/src/plugins/platforms/ios/qiostextresponder.h @@ -58,6 +58,9 @@ class QIOSInputContext; - (id)initWithInputContext:(QIOSInputContext *)context; - (void)notifyInputDelegate:(Qt::InputMethodQueries)updatedProperties; +@property(readwrite, retain) UIView *inputView; +@property(readwrite, retain) UIView *inputAccessoryView; + // UITextInputTraits @property(nonatomic) UITextAutocapitalizationType autocapitalizationType; @property(nonatomic) UITextAutocorrectionType autocorrectionType; diff --git a/src/plugins/platforms/ios/qiostextresponder.mm b/src/plugins/platforms/ios/qiostextresponder.mm index ea6b5ffb94..54362cde7a 100644 --- a/src/plugins/platforms/ios/qiostextresponder.mm +++ b/src/plugins/platforms/ios/qiostextresponder.mm @@ -114,6 +114,55 @@ // ------------------------------------------------------------------------- +@interface WrapperView : UIView +@end + +@implementation WrapperView + +-(id)initWithView:(UIView *)view +{ + if (self = [self init]) { + [self addSubview:view]; + + self.autoresizingMask = view.autoresizingMask; + + [self sizeToFit]; + } + + return self; +} + +- (void)layoutSubviews +{ + UIView* view = [self.subviews firstObject]; + view.frame = self.bounds; + + // FIXME: During orientation changes the size and position + // of the view is not respected by the host view, even if + // we call sizeToFit or setNeedsLayout on the superview. +} + +- (CGSize)sizeThatFits:(CGSize)size +{ + return [[self.subviews firstObject] sizeThatFits:size]; +} + +// By keeping the responder (QIOSTextInputResponder in this case) +// retained, we ensure that all messages sent to the view during +// its lifetime in a window hierarcy will be able to traverse the +// responder chain. +-(void)willMoveToWindow:(UIWindow *)window +{ + if (window) + [[self nextResponder] retain]; + else + [[self nextResponder] autorelease]; +} + +@end + +// ------------------------------------------------------------------------- + @implementation QIOSTextInputResponder - (id)initWithInputContext:(QIOSInputContext *)inputContext @@ -153,11 +202,19 @@ else self.keyboardType = UIKeyboardTypeDefault; + QVariantMap platformData = [self imValue:Qt::ImPlatformData].toMap(); + if (UIView *inputView = static_cast<UIView *>(platformData.value(kImePlatformDataInputView).value<void *>())) + self.inputView = [[[WrapperView alloc] initWithView:inputView] autorelease]; + if (UIView *accessoryView = static_cast<UIView *>(platformData.value(kImePlatformDataInputAccessoryView).value<void *>())) + self.inputAccessoryView = [[[WrapperView alloc] initWithView:accessoryView] autorelease]; + return self; } - (void)dealloc { + self.inputView = 0; + self.inputAccessoryView = 0; [super dealloc]; } |