Compile with -no-widgets.
authorMorten Johan Sorvig <morten.sorvig@digia.com>
Wed, 17 Oct 2012 12:23:32 +0000 (14:23 +0200)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Mon, 19 Nov 2012 07:30:05 +0000 (08:30 +0100)
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>
src/plugins/platforms/cocoa/qcocoahelpers.h
src/plugins/platforms/cocoa/qcocoahelpers.mm
src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm
src/plugins/platforms/cocoa/qpaintengine_mac.mm

index 2de955c..de98d52 100644 (file)
@@ -99,6 +99,7 @@ void qt_mac_transformProccessToForegroundApplication();
 QString qt_mac_removeMnemonics(const QString &original);
 CGColorSpaceRef qt_mac_genericColorSpace();
 CGColorSpaceRef qt_mac_displayColorSpace(const QWidget *widget);
+CGColorSpaceRef qt_mac_colorSpaceForDeviceType(const QPaintDevice *paintDevice);
 QString qt_mac_applicationName();
 
 inline int qt_mac_flipYCoordinate(int y)
@@ -157,6 +158,8 @@ public:
     }
 };
 
+CGContextRef qt_mac_cg_context(const QPaintDevice *pdev);
+
 QT_END_NAMESPACE
 
 #endif //QCOCOAHELPERS_H
index bd89f26..0a8da0a 100644 (file)
 #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
index 2cb15b1..8a08924 100755 (executable)
@@ -79,7 +79,6 @@
 #include "qcocoasystemtrayicon.h"
 #include <qtemporaryfile.h>
 #include <qimagewriter.h>
-#include <qapplication.h>
 #include <qdebug.h>
 
 #include "qcocoamenu.h"
@@ -238,7 +237,7 @@ void QCocoaSystemTrayIcon::showMessage(const QString &title, const QString &mess
         return;
     QPixmap notificationIconPixmap = icon.pixmap(32, 32);
     QTemporaryFile notificationIconFile;
-    QString notificationType(QLatin1String("Notification")), notificationIcon, notificationApp(QApplication::applicationName());
+    QString notificationType(QLatin1String("Notification")), notificationIcon, notificationApp(qt_mac_applicationName());
     if (notificationApp.isEmpty())
         notificationApp = QLatin1String("Application");
     if (!notificationIconPixmap.isNull() && notificationIconFile.open()) {
index 404c03d..5b83477 100644 (file)
@@ -116,13 +116,6 @@ void qt_mac_clip_cg(CGContextRef hd, const QRegion &rgn, CGAffineTransform *orig
     }
 }
 
-CGColorSpaceRef qt_mac_colorSpaceForDeviceType(const QPaintDevice *paintDevice)
-{
-    bool isWidget = (paintDevice->devType() == QInternal::Widget);
-    return QCoreGraphicsPaintEngine::macDisplayColorSpace(isWidget ? static_cast<const QWidget *>(paintDevice)
-                                                                   : 0);
-}
-
 // Implemented for qt_mac_p.h
 QMacCGContext::QMacCGContext(QPainter *p)
 {
@@ -206,46 +199,6 @@ CGAffineTransform qt_mac_convert_transform_to_cg(const QTransform &t) {
     return CGAffineTransformMake(t.m11(), t.m12(), t.m21(), t.m22(), t.dx(),  t.dy());
 }
 
-/*! \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;
-}
-
 inline static QCFType<CGColorRef> cgColorForQColor(const QColor &col, QPaintDevice *pdev)
 {
     CGFloat components[] = {