diff options
Diffstat (limited to 'src/plugins/platforms/ios/qiosscreen.mm')
-rw-r--r-- | src/plugins/platforms/ios/qiosscreen.mm | 57 |
1 files changed, 53 insertions, 4 deletions
diff --git a/src/plugins/platforms/ios/qiosscreen.mm b/src/plugins/platforms/ios/qiosscreen.mm index d53f0df846..013061a6d2 100644 --- a/src/plugins/platforms/ios/qiosscreen.mm +++ b/src/plugins/platforms/ios/qiosscreen.mm @@ -47,6 +47,7 @@ #include "quiview.h" #include <QtGui/private/qwindow_p.h> +#include <private/qcoregraphics_p.h> #include <sys/sysctl.h> @@ -143,21 +144,25 @@ static QIOSScreen* qtPlatformScreenFor(UIScreen *uiScreen) self = [super init]; if (self) { m_screen = screen; +#ifndef Q_OS_TVOS [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:@"UIDeviceOrientationDidChangeNotification" object:nil]; +#endif } return self; } - (void)dealloc { +#ifndef Q_OS_TVOS [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications]; [[NSNotificationCenter defaultCenter] removeObserver:self name:@"UIDeviceOrientationDidChangeNotification" object:nil]; +#endif [super dealloc]; } @@ -171,6 +176,8 @@ static QIOSScreen* qtPlatformScreenFor(UIScreen *uiScreen) // ------------------------------------------------------------------------- +QT_BEGIN_NAMESPACE + /*! Returns the model identifier of the device. @@ -256,9 +263,14 @@ void QIOSScreen::updateProperties() QRect previousGeometry = m_geometry; QRect previousAvailableGeometry = m_availableGeometry; - m_geometry = fromCGRect(m_uiScreen.bounds).toRect(); - m_availableGeometry = fromCGRect(m_uiScreen.applicationFrame).toRect(); + m_geometry = QRectF::fromCGRect(m_uiScreen.bounds).toRect(); +#ifdef Q_OS_TVOS + m_availableGeometry = m_geometry; +#else + m_availableGeometry = QRectF::fromCGRect(m_uiScreen.applicationFrame).toRect(); +#endif +#ifndef Q_OS_TVOS if (m_uiScreen == [UIScreen mainScreen]) { Qt::ScreenOrientation statusBarOrientation = toQtScreenOrientation(UIDeviceOrientation([UIApplication sharedApplication].statusBarOrientation)); @@ -286,6 +298,7 @@ void QIOSScreen::updateProperties() m_availableGeometry = transform.mapRect(m_availableGeometry); } } +#endif if (m_geometry != previousGeometry) { QRectF physicalGeometry; @@ -298,7 +311,7 @@ void QIOSScreen::updateProperties() // before being output on the physical display. We have to take this into account when // computing the physical size. Note that unlike the native bounds, the physical size // follows the primary orientation of the screen. - physicalGeometry = mapBetween(nativeOrientation(), primaryOrientation, fromCGRect(m_uiScreen.nativeBounds).toRect()); + physicalGeometry = mapBetween(nativeOrientation(), primaryOrientation, QRectF::fromCGRect(m_uiScreen.nativeBounds).toRect()); } else { physicalGeometry = QRectF(0, 0, m_geometry.width() * devicePixelRatio(), m_geometry.height() * devicePixelRatio()); } @@ -393,7 +406,7 @@ qreal QIOSScreen::devicePixelRatio() const Qt::ScreenOrientation QIOSScreen::nativeOrientation() const { CGRect nativeBounds = -#if QT_IOS_PLATFORM_SDK_EQUAL_OR_ABOVE(__IPHONE_8_0) +#if !defined(Q_OS_TVOS) && QT_IOS_PLATFORM_SDK_EQUAL_OR_ABOVE(__IPHONE_8_0) QSysInfo::MacintoshVersion >= QSysInfo::MV_IOS_8_0 ? m_uiScreen.nativeBounds : #endif m_uiScreen.bounds; @@ -406,6 +419,9 @@ Qt::ScreenOrientation QIOSScreen::nativeOrientation() const Qt::ScreenOrientation QIOSScreen::orientation() const { +#ifdef Q_OS_TVOS + return Qt::PrimaryOrientation; +#else // Auxiliary screens are always the same orientation as their primary orientation if (m_uiScreen != [UIScreen mainScreen]) return Qt::PrimaryOrientation; @@ -430,6 +446,7 @@ Qt::ScreenOrientation QIOSScreen::orientation() const } return toQtScreenOrientation(deviceOrientation); +#endif } void QIOSScreen::setOrientationUpdateMask(Qt::ScreenOrientations mask) @@ -443,6 +460,38 @@ void QIOSScreen::setOrientationUpdateMask(Qt::ScreenOrientations mask) } } +QPixmap QIOSScreen::grabWindow(WId window, int x, int y, int width, int height) const +{ + if (window && ![reinterpret_cast<id>(window) isKindOfClass:[UIView class]]) + return QPixmap(); + + UIView *view = window ? reinterpret_cast<UIView *>(window) : m_uiWindow; + + if (width < 0) + width = qMax(view.bounds.size.width - x, CGFloat(0)); + if (height < 0) + height = qMax(view.bounds.size.height - y, CGFloat(0)); + + CGRect captureRect = [m_uiWindow convertRect:CGRectMake(x, y, width, height) fromView:view]; + captureRect = CGRectIntersection(captureRect, m_uiWindow.bounds); + + UIGraphicsBeginImageContextWithOptions(captureRect.size, NO, 0.0); + CGContextRef context = UIGraphicsGetCurrentContext(); + CGContextTranslateCTM(context, -captureRect.origin.x, -captureRect.origin.y); + + // Draws the complete view hierarchy of m_uiWindow into the given rect, which + // needs to be the same aspect ratio as the m_uiWindow's size. Since we've + // translated the graphics context, and are potentially drawing into a smaller + // context than the full window, the resulting image will be a subsection of the + // full screen. + [m_uiWindow drawViewHierarchyInRect:m_uiWindow.bounds afterScreenUpdates:NO]; + + UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext(); + UIGraphicsEndImageContext(); + + return QPixmap::fromImage(qt_mac_toQImage(screenshot.CGImage)); +} + UIScreen *QIOSScreen::uiScreen() const { return m_uiScreen; |