From 31796ca8abb8878165c7099145b08abfdf8bf1e3 Mon Sep 17 00:00:00 2001 From: Richard Moe Gustavsen Date: Tue, 18 Dec 2012 09:50:28 +0100 Subject: iOS: report changes to keyboard rect back to Qt MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit QInputContext expects us to report whenever the input panel changes geometry. This patch implements this. Change-Id: I9162f0d48da6925274a7489c9bcb6adab9afae82 Reviewed-by: Tor Arne Vestbø --- src/plugins/platforms/ios/qiosglobal.h | 1 + src/plugins/platforms/ios/qiosglobal.mm | 9 +++++++++ src/plugins/platforms/ios/qiosinputcontext.h | 1 + src/plugins/platforms/ios/qiosinputcontext.mm | 15 +++++++++++++-- src/plugins/platforms/ios/qiosscreen.mm | 4 +--- 5 files changed, 25 insertions(+), 5 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/platforms/ios/qiosglobal.h b/src/plugins/platforms/ios/qiosglobal.h index 7a23a2a485..849d9bce37 100644 --- a/src/plugins/platforms/ios/qiosglobal.h +++ b/src/plugins/platforms/ios/qiosglobal.h @@ -54,6 +54,7 @@ CGRect toCGRect(const QRect &rect); QRect fromCGRect(const CGRect &rect); Qt::ScreenOrientation toQtScreenOrientation(UIDeviceOrientation uiDeviceOrientation); UIDeviceOrientation fromQtScreenOrientation(Qt::ScreenOrientation qtOrientation); +QRect fromPortraitToPrimary(const QRect &rect); QT_END_NAMESPACE diff --git a/src/plugins/platforms/ios/qiosglobal.mm b/src/plugins/platforms/ios/qiosglobal.mm index a8a89a1637..f9b4b14a19 100644 --- a/src/plugins/platforms/ios/qiosglobal.mm +++ b/src/plugins/platforms/ios/qiosglobal.mm @@ -113,5 +113,14 @@ UIDeviceOrientation fromQtScreenOrientation(Qt::ScreenOrientation qtOrientation) return uiOrientation; } +QRect fromPortraitToPrimary(const QRect &rect) +{ + // UIScreen is always in portrait. Use this function to convert CGRects + // aligned with UIScreen into whatever is the current orientation of QScreen. + QScreen *screen = QGuiApplication::primaryScreen(); + return screen->isPortrait(screen->primaryOrientation()) ? rect + : QRect(rect.y(), screen->geometry().width() - rect.width() - rect.x(), rect.height(), rect.width()); +} + QT_END_NAMESPACE diff --git a/src/plugins/platforms/ios/qiosinputcontext.h b/src/plugins/platforms/ios/qiosinputcontext.h index 22782d183c..ceed5ffaf2 100644 --- a/src/plugins/platforms/ios/qiosinputcontext.h +++ b/src/plugins/platforms/ios/qiosinputcontext.h @@ -56,6 +56,7 @@ public: QIOSInputContext(); ~QIOSInputContext(); + QRectF keyboardRect() const; void showInputPanel(); void hideInputPanel(); bool isInputPanelVisible() const; diff --git a/src/plugins/platforms/ios/qiosinputcontext.mm b/src/plugins/platforms/ios/qiosinputcontext.mm index 7937337e4a..89d210cb54 100644 --- a/src/plugins/platforms/ios/qiosinputcontext.mm +++ b/src/plugins/platforms/ios/qiosinputcontext.mm @@ -39,6 +39,7 @@ ** ****************************************************************************/ +#include "qiosglobal.h" #include "qiosinputcontext.h" #include "qioswindow.h" #include @@ -47,6 +48,7 @@ @public QIOSInputContext *m_context; BOOL m_keyboardVisible; + QRectF m_keyboardRect; } @end @@ -80,6 +82,10 @@ { CGRect frame; [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] getValue:&frame]; + + m_keyboardRect = fromPortraitToPrimary(fromCGRect(frame)); + m_context->emitKeyboardRectChanged(); + BOOL visible = CGRectIntersectsRect(frame, [UIScreen mainScreen].bounds); if (m_keyboardVisible != visible) { m_keyboardVisible = visible; @@ -90,8 +96,8 @@ @end QIOSInputContext::QIOSInputContext() - : QPlatformInputContext(), - m_keyboardListener([[QIOSKeyboardListener alloc] initWithQIOSInputContext:this]) + : QPlatformInputContext() + , m_keyboardListener([[QIOSKeyboardListener alloc] initWithQIOSInputContext:this]) { } @@ -100,6 +106,11 @@ QIOSInputContext::~QIOSInputContext() [m_keyboardListener release]; } +QRectF QIOSInputContext::keyboardRect() const +{ + return m_keyboardListener->m_keyboardRect; +} + void QIOSInputContext::showInputPanel() { if (isInputPanelVisible()) diff --git a/src/plugins/platforms/ios/qiosscreen.mm b/src/plugins/platforms/ios/qiosscreen.mm index fdf2f31ea1..a0403a0d69 100644 --- a/src/plugins/platforms/ios/qiosscreen.mm +++ b/src/plugins/platforms/ios/qiosscreen.mm @@ -212,11 +212,9 @@ void QIOSScreen::setPrimaryOrientation(Qt::ScreenOrientation orientation) return; // Switching portrait/landscape means swapping width/height (and adjusting x/y): - CGRect frame = m_uiScreen.applicationFrame; - m_availableGeometry = portrait ? QRect(frame.origin.x, frame.origin.y, frame.size.width, frame.size.height) - : QRect(frame.origin.y, m_geometry.width() - frame.size.width - frame.origin.x, frame.size.height, frame.size.width); m_geometry = QRect(0, 0, m_geometry.height(), m_geometry.width()); m_physicalSize = QSizeF(m_physicalSize.height(), m_physicalSize.width()); + m_availableGeometry = fromPortraitToPrimary(fromCGRect(m_uiScreen.applicationFrame)); QWindowSystemInterface::handleScreenGeometryChange(screen(), m_geometry); QWindowSystemInterface::handleScreenAvailableGeometryChange(screen(), m_availableGeometry); -- cgit v1.2.3