diff options
author | Morten Johan Sorvig <morten.sorvig@digia.com> | 2012-10-17 14:23:32 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2012-11-19 08:30:05 +0100 |
commit | cfa0f3bd5673c54981383557cac863e44c8d40a7 (patch) | |
tree | 16c378fcf80aaf66ed0965a7364552ab826f3cb8 /src/plugins/platforms/cocoa/qcocoahelpers.mm | |
parent | a0af6c8e4ac3bc45992bebe5ffe5b2daf363d862 (diff) |
Compile with -no-widgets.
Remove QApplication usage in qcocoasystemtrayicon.mm
Move qt_mac_cg_context from qpaintengine_mac.mm to
qcocoahelpers.mm to make it available in no-widgets
builds.
(Move qt_mac_colorSpaceForDeviceType as well; color
space support needs to be cleaned up later on.)
Change-Id: I724fdb09538d65eae56c26165f3ba53b6814ea78
Reviewed-by: Liang Qi <liang.qi@digia.com>
Diffstat (limited to 'src/plugins/platforms/cocoa/qcocoahelpers.mm')
-rw-r--r-- | src/plugins/platforms/cocoa/qcocoahelpers.mm | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoahelpers.mm b/src/plugins/platforms/cocoa/qcocoahelpers.mm index bd89f26fca..0a8da0a956 100644 --- a/src/plugins/platforms/cocoa/qcocoahelpers.mm +++ b/src/plugins/platforms/cocoa/qcocoahelpers.mm @@ -48,6 +48,10 @@ #include <qpa/qplatformscreen.h> #include <private/qguiapplication_p.h> +#ifndef QT_NO_WIDGETS +#include <QtWidgets/QWidget> +#endif + QT_BEGIN_NAMESPACE // @@ -551,6 +555,17 @@ void qt_mac_cleanUpMacColorSpaces() m_displayColorSpaceHash.clear(); } +CGColorSpaceRef qt_mac_colorSpaceForDeviceType(const QPaintDevice *paintDevice) +{ +#ifdef QT_NO_WIDGETS + return qt_mac_displayColorSpace(0); +#else + bool isWidget = (paintDevice->devType() == QInternal::Widget); + return qt_mac_displayColorSpace(isWidget ? static_cast<const QWidget *>(paintDevice): 0); +#endif + +} + QString qt_mac_applicationName() { QString appName; @@ -696,4 +711,44 @@ QString qt_mac_removeAmpersandEscapes(QString s) return s.trimmed(); } +/*! \internal + + Returns the CoreGraphics CGContextRef of the paint device. 0 is + returned if it can't be obtained. It is the caller's responsibility to + CGContextRelease the context when finished using it. + + \warning This function is only available on Mac OS X. + \warning This function is duplicated in qmacstyle_mac.mm + */ +CGContextRef qt_mac_cg_context(const QPaintDevice *pdev) +{ + if (pdev->devType() == QInternal::Pixmap) { + const QPixmap *pm = static_cast<const QPixmap*>(pdev); + CGColorSpaceRef colorspace = qt_mac_colorSpaceForDeviceType(pdev); + uint flags = kCGImageAlphaPremultipliedFirst; + flags |= kCGBitmapByteOrder32Host; + CGContextRef ret = 0; + + QPlatformPixmap *data = const_cast<QPixmap *>(pm)->data_ptr().data(); + if (data && data->classId() == QPlatformPixmap::RasterClass) { + QImage *image = data->buffer(); + ret = CGBitmapContextCreate(image->bits(), image->width(), image->height(), + 8, image->bytesPerLine(), colorspace, flags); + } else { + qDebug() << "qt_mac_cg_context: Unsupported pixmap class"; + } + + CGContextTranslateCTM(ret, 0, pm->height()); + CGContextScaleCTM(ret, 1, -1); + return ret; + } else if (pdev->devType() == QInternal::Widget) { + //CGContextRef ret = static_cast<CGContextRef>(static_cast<const QWidget *>(pdev)->macCGHandle()); + ///CGContextRetain(ret); + //return ret; + qDebug() << "qt_mac_cg_context: not implemented: Widget class"; + return 0; + } + return 0; +} + QT_END_NAMESPACE |