Qt 4.8
quikitscreen.mm
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the plugins of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "quikitscreen.h"
43 #include "quikitwindow.h"
44 
45 #include <QtGui/QApplication>
46 
47 #include <QtDebug>
48 
50 
52  : QPlatformScreen(),
53  m_index(screenIndex)
54 {
55  NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
56  CGRect bounds = [uiScreen() bounds];
57  CGFloat scale = [uiScreen() scale];
59 
61 
62  m_depth = 24;
63 
64  const qreal inch = 25.4;
65  qreal unscaledDpi = 160.;
66  int dragDistance = 12 * scale;
67  if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
68  unscaledDpi = 132.;
69  dragDistance = 10 * scale;
70  }
71  m_physicalSize = QSize(qRound(bounds.size.width * inch / unscaledDpi), qRound(bounds.size.height * inch / unscaledDpi));
72  qApp->setStartDragDistance(dragDistance);
73 
74  QFont font; // system font is helvetica, so that is fine already
75  font.setPixelSize([UIFont systemFontSize] * scale);
76  qApp->setFont(font);
77 
78  [pool release];
79 }
80 
82 {
83 }
84 
85 UIScreen *QUIKitScreen::uiScreen() const
86 {
87  return [[UIScreen screens] objectAtIndex:m_index];
88 }
89 
91 {
92  CGRect bounds = [uiScreen() bounds];
93  CGFloat scale = [uiScreen() scale];
94  switch ([[UIApplication sharedApplication] statusBarOrientation]) {
95  case UIInterfaceOrientationPortrait:
96  case UIInterfaceOrientationPortraitUpsideDown:
97  m_geometry = QRect(bounds.origin.x * scale, bounds.origin.y * scale,
98  bounds.size.width * scale, bounds.size.height * scale);;
99  break;
100  case UIInterfaceOrientationLandscapeLeft:
101  case UIInterfaceOrientationLandscapeRight:
102  m_geometry = QRect(bounds.origin.x * scale, bounds.origin.y * scale,
103  bounds.size.height * scale, bounds.size.width * scale);
104  break;
105  }
106  foreach (QWidget *widget, qApp->topLevelWidgets()) {
107  QUIKitWindow *platformWindow = static_cast<QUIKitWindow *>(widget->platformWindow());
108  if (platformWindow && platformWindow->platformScreen() == this) {
109  platformWindow->updateGeometryAndOrientation();
110  }
111  }
112 }
113 
double qreal
Definition: qglobal.h:1193
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
QPointer< QWidget > widget
The QPlatformScreen class provides an abstraction for visual displays.
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
QImage::Format m_format
Definition: quikitscreen.h:68
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
QUIKitScreen * platformScreen() const
Definition: quikitwindow.h:123
#define qApp
static bool init
QUIKitScreen(int screenIndex)
Definition: quikitscreen.mm:51
void updateGeometryAndOrientation()
QSize m_physicalSize
Definition: quikitscreen.h:69
void updateInterfaceOrientation()
Definition: quikitscreen.mm:90
struct CGRect CGRect
The QFont class specifies a font used for drawing text.
Definition: qfont.h:64
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
UIScreen * uiScreen() const
Definition: quikitscreen.mm:85
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
QRect m_geometry
Definition: quikitscreen.h:66
void setPixelSize(int)
Sets the font size to pixelSize pixels.
Definition: qfont.cpp:1156
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203
float CGFloat