iOS: add global function 'isQtApplication'

Several places in the code we need to check if the plugin is
running as a cross-platform Qt application or inside a
native app. So we refactor this function to qiosglobal so
we can access it from everywhere.

Change-Id: I78db0dcde71b7d281868ce304867c8f876caef2a
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@digia.com>
This commit is contained in:
Richard Moe Gustavsen 2012-12-18 12:50:50 +01:00 committed by Tor Arne Vestbø
parent 5abe9aa435
commit b960424195
4 changed files with 16 additions and 2 deletions

View File

@ -49,6 +49,7 @@
QT_BEGIN_NAMESPACE
bool isQtApplication();
CGRect toCGRect(const QRect &rect);
QRect fromCGRect(const CGRect &rect);
Qt::ScreenOrientation toQtScreenOrientation(UIDeviceOrientation uiDeviceOrientation);

View File

@ -40,10 +40,23 @@
****************************************************************************/
#include "qiosglobal.h"
#include "qiosapplicationdelegate.h"
#include <QtGui/qscreen.h>
QT_BEGIN_NAMESPACE
bool isQtApplication()
{
// Returns true if the plugin is in full control of the whole application. This means
// that we control the application delegate and the top view controller, and can take
// actions that impacts all parts of the application. The opposite means that we are
// embedded inside a native iOS application, and should be more focused on playing along
// with native UIControls, and less inclined to change structures that lies outside the
// scope of our QWindows/UIViews.
static bool isQt = ([[UIApplication sharedApplication].delegate isKindOfClass:[QIOSApplicationDelegate class]]);
return isQt;
}
CGRect toCGRect(const QRect &rect)
{
return CGRectMake(rect.x(), rect.y(), rect.width(), rect.height());

View File

@ -139,7 +139,7 @@ QIOSScreen::QIOSScreen(unsigned int screenIndex)
const qreal millimetersPerInch = 25.4;
m_physicalSize = QSizeF(m_geometry.size()) / unscaledDpi * millimetersPerInch;
if ([[UIApplication sharedApplication].delegate isKindOfClass:[QIOSApplicationDelegate class]]) {
if (isQtApplication()) {
// When in a non-mixed environment, let QScreen follow the current interface orientation:
UIViewController *controller = [UIApplication sharedApplication].delegate.window.rootViewController;
setPrimaryOrientation(toQtScreenOrientation(controller.interfaceOrientation));

View File

@ -196,7 +196,7 @@ QIOSWindow::QIOSWindow(QWindow *window)
, m_glData()
, m_devicePixelRatio(1.0)
{
if ([[UIApplication sharedApplication].delegate isKindOfClass:[QIOSApplicationDelegate class]])
if (isQtApplication())
[[UIApplication sharedApplication].delegate.window.rootViewController.view addSubview:m_view];
setWindowState(window->windowState());