summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/ios/qiosscreen.mm
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2016-09-21 08:50:26 +0200
committerLiang Qi <liang.qi@qt.io>2016-09-21 09:11:02 +0200
commiteaec2b664aa2c3cbca13b425901888468a4652a1 (patch)
tree93dbd19f3b538baa81dec6c04e5258161f7d8cfb /src/plugins/platforms/ios/qiosscreen.mm
parent278e557ceacbe7de728987a4a5365f78e56d76b1 (diff)
parent31c251765db45a068f1268027e5dd600151af1e5 (diff)
Merge remote-tracking branch 'origin/5.8' into dev
Conflicts: src/gui/painting/qcoregraphics.mm src/network/access/qnetworkrequest.h src/plugins/platforms/cocoa/qcocoahelpers.mm Change-Id: I81266414c06ea2edf63cbc7e93a86bd5d66a31a5
Diffstat (limited to 'src/plugins/platforms/ios/qiosscreen.mm')
-rw-r--r--src/plugins/platforms/ios/qiosscreen.mm35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/plugins/platforms/ios/qiosscreen.mm b/src/plugins/platforms/ios/qiosscreen.mm
index 7dd2ce7f6e..86bce0d70b 100644
--- a/src/plugins/platforms/ios/qiosscreen.mm
+++ b/src/plugins/platforms/ios/qiosscreen.mm
@@ -48,6 +48,7 @@
#include <QtCore/qoperatingsystemversion.h>
#include <QtGui/private/qwindow_p.h>
+#include <private/qcoregraphics_p.h>
#include <sys/sysctl.h>
@@ -176,6 +177,8 @@ static QIOSScreen* qtPlatformScreenFor(UIScreen *uiScreen)
// -------------------------------------------------------------------------
+QT_BEGIN_NAMESPACE
+
/*!
Returns the model identifier of the device.
@@ -458,6 +461,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;