diff options
author | Tasuku Suzuki <tasuku.suzuki@nokia.com> | 2012-07-01 17:27:30 +0900 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-07-06 13:57:55 +0200 |
commit | 89d7a55db453d8cb6d582e209dea88de66995c8f (patch) | |
tree | af608e4b2823e066937f7431331350e3c8bae08e /src/plugins/platforms/cocoa/qcocoaintegration.mm | |
parent | 2b1a501ac5d3aa36ac44d1dda5f4f9a1794dfeca (diff) |
QPlatformScreen::grabWindow() support on Mac
Added QCocoaScreen::grabWindow() and copied Qt 4 implimentation.
examples/desktop/screenshot works but WId window is not handled yet.
Change-Id: If228bb59d98a5166788ab38293d7e6a6300d1f85
Reviewed-by: Morten Johan Sørvig <morten.sorvig@nokia.com>
Diffstat (limited to 'src/plugins/platforms/cocoa/qcocoaintegration.mm')
-rw-r--r-- | src/plugins/platforms/cocoa/qcocoaintegration.mm | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoaintegration.mm b/src/plugins/platforms/cocoa/qcocoaintegration.mm index 29c5ec7e3c..ccb1121276 100644 --- a/src/plugins/platforms/cocoa/qcocoaintegration.mm +++ b/src/plugins/platforms/cocoa/qcocoaintegration.mm @@ -88,6 +88,67 @@ QCocoaScreen::~QCocoaScreen() delete m_cursor; } +extern CGContextRef qt_mac_cg_context(const QPaintDevice *pdev); + +QPixmap QCocoaScreen::grabWindow(WId window, int x, int y, int width, int height) const +{ + // TODO window should be handled + Q_UNUSED(window) + + const int maxDisplays = 128; // 128 displays should be enough for everyone. + CGDirectDisplayID displays[maxDisplays]; + CGDisplayCount displayCount; + CGRect cgRect; + + if (width < 0 || height < 0) { + // get all displays + cgRect = CGRectInfinite; + } else { + cgRect = CGRectMake(x, y, width, height); + } + const CGDisplayErr err = CGGetDisplaysWithRect(cgRect, maxDisplays, displays, &displayCount); + + if (err && displayCount == 0) + return QPixmap(); + + // calculate pixmap size + QSize windowSize(width, height); + if (width < 0 || height < 0) { + QRect windowRect; + for (uint i = 0; i < displayCount; ++i) { + const CGRect cgRect = CGDisplayBounds(displays[i]); + QRect qRect(cgRect.origin.x, cgRect.origin.y, cgRect.size.width, cgRect.size.height); + windowRect = windowRect.united(qRect); + } + if (width < 0) + windowSize.setWidth(windowRect.width()); + if (height < 0) + windowSize.setHeight(windowRect.height()); + } + + QPixmap windowPixmap(windowSize); + windowPixmap.fill(Qt::transparent); + + for (uint i = 0; i < displayCount; ++i) { + const CGRect bounds = CGDisplayBounds(displays[i]); + int w = (width < 0 ? bounds.size.width : width); + int h = (height < 0 ? bounds.size.height : height); + QRect displayRect = QRect(x, y, w, h); + QCFType<CGImageRef> image = CGDisplayCreateImageForRect(displays[i], + CGRectMake(displayRect.x(), displayRect.y(), displayRect.width(), displayRect.height())); + QPixmap pix(w, h); + pix.fill(Qt::transparent); + CGRect rect = CGRectMake(0, 0, w, h); + CGContextRef ctx = qt_mac_cg_context(&pix); + qt_mac_drawCGImage(ctx, &rect, image); + CGContextRelease(ctx); + + QPainter painter(&windowPixmap); + painter.drawPixmap(bounds.origin.x, bounds.origin.y, pix); + } + return windowPixmap; +} + QCocoaIntegration::QCocoaIntegration() : mFontDb(new QCoreTextFontDatabase()) , mEventDispatcher(new QCocoaEventDispatcher()) |