iOS: report changes to keyboard rect back to Qt

QInputContext expects us to report whenever the
input panel changes geometry. This patch implements
this.

Change-Id: I9162f0d48da6925274a7489c9bcb6adab9afae82
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@digia.com>
bb10
Richard Moe Gustavsen 2012-12-18 09:50:28 +01:00 committed by Tor Arne Vestbø
parent b960424195
commit 31796ca8ab
5 changed files with 25 additions and 5 deletions

View File

@ -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

View File

@ -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

View File

@ -56,6 +56,7 @@ public:
QIOSInputContext();
~QIOSInputContext();
QRectF keyboardRect() const;
void showInputPanel();
void hideInputPanel();
bool isInputPanelVisible() const;

View File

@ -39,6 +39,7 @@
**
****************************************************************************/
#include "qiosglobal.h"
#include "qiosinputcontext.h"
#include "qioswindow.h"
#include <QGuiApplication>
@ -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())

View File

@ -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);