summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms
diff options
context:
space:
mode:
authorGabriel de Dietrich <gabriel.dedietrich@digia.com>2013-06-28 17:32:08 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-07-01 14:00:30 +0200
commit93e79d865c127aad0de0a44007253845cb291b4a (patch)
tree29e85f839acf9c717cd46fe84a53897ec7e81fab /src/plugins/platforms
parent0aa067504006a177191f6a6644069b7109b980e3 (diff)
Cocoa: Let Cocoa pick the right pixmap for menu item icons
Task-number: QTBUG-31477 Change-Id: Iac2d13b68d36c691b60685b69cd390958c35fae3 Reviewed-by: James Turner <james.turner@kdab.com> Reviewed-by: Jake Petroules <jake.petroules@petroules.com> Reviewed-by: Shawn Rutledge <shawn.rutledge@digia.com>
Diffstat (limited to 'src/plugins/platforms')
-rw-r--r--src/plugins/platforms/cocoa/qcocoahelpers.h1
-rw-r--r--src/plugins/platforms/cocoa/qcocoahelpers.mm18
-rw-r--r--src/plugins/platforms/cocoa/qcocoamenuitem.mm3
3 files changed, 21 insertions, 1 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoahelpers.h b/src/plugins/platforms/cocoa/qcocoahelpers.h
index c801d9d926..3e402673f3 100644
--- a/src/plugins/platforms/cocoa/qcocoahelpers.h
+++ b/src/plugins/platforms/cocoa/qcocoahelpers.h
@@ -71,6 +71,7 @@ inline NSMutableArray *qt_mac_QStringListToNSMutableArray(const QStringList &qst
CGImageRef qt_mac_image_to_cgimage(const QImage &image);
NSImage *qt_mac_cgimage_to_nsimage(CGImageRef iamge);
NSImage *qt_mac_create_nsimage(const QPixmap &pm);
+NSImage *qt_mac_create_nsimage(const QIcon &icon);
NSSize qt_mac_toNSSize(const QSize &qtSize);
NSRect qt_mac_toNSRect(const QRect &rect);
diff --git a/src/plugins/platforms/cocoa/qcocoahelpers.mm b/src/plugins/platforms/cocoa/qcocoahelpers.mm
index 1b3db9f63a..09d1a96789 100644
--- a/src/plugins/platforms/cocoa/qcocoahelpers.mm
+++ b/src/plugins/platforms/cocoa/qcocoahelpers.mm
@@ -139,6 +139,24 @@ NSImage *qt_mac_create_nsimage(const QPixmap &pm)
return nsImage;
}
+NSImage *qt_mac_create_nsimage(const QIcon &icon)
+{
+ if (icon.isNull())
+ return nil;
+
+ NSImage *nsImage = [[NSImage alloc] init];
+ foreach (QSize size, icon.availableSizes()) {
+ QPixmap pm = icon.pixmap(size);
+ QImage image = pm.toImage();
+ CGImageRef cgImage = qt_mac_image_to_cgimage(image);
+ NSBitmapImageRep *imageRep = [[NSBitmapImageRep alloc] initWithCGImage:cgImage];
+ [nsImage addRepresentation:imageRep];
+ [imageRep release];
+ CGImageRelease(cgImage);
+ }
+ return nsImage;
+}
+
HIMutableShapeRef qt_mac_QRegionToHIMutableShape(const QRegion &region)
{
HIMutableShapeRef shape = HIShapeCreateMutable();
diff --git a/src/plugins/platforms/cocoa/qcocoamenuitem.mm b/src/plugins/platforms/cocoa/qcocoamenuitem.mm
index 1e2b593a08..6d8174c667 100644
--- a/src/plugins/platforms/cocoa/qcocoamenuitem.mm
+++ b/src/plugins/platforms/cocoa/qcocoamenuitem.mm
@@ -310,7 +310,8 @@ NSMenuItem *QCocoaMenuItem::sync()
}
if (!m_icon.isNull()) {
- NSImage *img = static_cast<NSImage *>(qt_mac_create_nsimage(m_icon.pixmap(16, QIcon::Normal)));
+ NSImage *img = qt_mac_create_nsimage(m_icon);
+ [img setSize:NSMakeSize(16, 16)];
[m_native setImage: img];
[img release];
}