summaryrefslogtreecommitdiffstats
path: root/src/gui/kernel/qt_cocoa_helpers_mac.mm
diff options
context:
space:
mode:
authorNorwegian Rock Cat <qt-info@nokia.com>2009-07-17 11:32:21 (GMT)
committerNorwegian Rock Cat <qt-info@nokia.com>2009-07-17 11:53:49 (GMT)
commit68c0e6a8ba1e92bf0152adcaa86eebb83dcfd1d8 (patch)
tree4647f3283723ffc421a3462cff8c2ceb74d9bcfe /src/gui/kernel/qt_cocoa_helpers_mac.mm
parentc0dfc3f7cedb889e8d68161080262e715165e771 (diff)
downloadQt-68c0e6a8ba1e92bf0152adcaa86eebb83dcfd1d8.zip
Qt-68c0e6a8ba1e92bf0152adcaa86eebb83dcfd1d8.tar.gz
Qt-68c0e6a8ba1e92bf0152adcaa86eebb83dcfd1d8.tar.bz2
Move QMacStyle icon handling down to the common style.
This is more follow the cue of what is done on X11, mainly, if you are creating things like messageboxes or file views, you want them to follow the desktop (yes, you do). If you disable desktop settings aware, you get the old look. This also meant shifting around some functions into qt_cocoa_helpers_mac to make them more readily available instead of living in differnt files. People who use standard pixmap get the old values, but I think that's fine. If you haven't moved onto standardIcon (introduced in 4.1), you don't get the latest bling. Review-by: Jens Bache-Wiig
Diffstat (limited to 'src/gui/kernel/qt_cocoa_helpers_mac.mm')
-rw-r--r--src/gui/kernel/qt_cocoa_helpers_mac.mm46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/gui/kernel/qt_cocoa_helpers_mac.mm b/src/gui/kernel/qt_cocoa_helpers_mac.mm
index a98a7f8..223e36b 100644
--- a/src/gui/kernel/qt_cocoa_helpers_mac.mm
+++ b/src/gui/kernel/qt_cocoa_helpers_mac.mm
@@ -77,6 +77,7 @@
#include <qwidget.h>
#include <qdesktopwidget.h>
#include <qevent.h>
+#include <qpixmapcache.h>
#include <private/qevent_p.h>
#include <private/qt_cocoa_helpers_mac_p.h>
#include <private/qt_mac_p.h>
@@ -1147,4 +1148,49 @@ QString qt_mac_get_pasteboardString()
}
}
+QPixmap qt_mac_convert_iconref(const IconRef icon, int width, int height)
+{
+ QPixmap ret(width, height);
+ ret.fill(QColor(0, 0, 0, 0));
+
+ CGRect rect = CGRectMake(0, 0, width, height);
+
+ CGContextRef ctx = qt_mac_cg_context(&ret);
+ CGAffineTransform old_xform = CGContextGetCTM(ctx);
+ CGContextConcatCTM(ctx, CGAffineTransformInvert(old_xform));
+ CGContextConcatCTM(ctx, CGAffineTransformIdentity);
+
+ ::RGBColor b;
+ b.blue = b.green = b.red = 255*255;
+ PlotIconRefInContext(ctx, &rect, kAlignNone, kTransformNone, &b, kPlotIconRefNormalFlags, icon);
+ CGContextRelease(ctx);
+ return ret;
+}
+
+void qt_mac_constructQIconFromIconRef(const IconRef icon, const IconRef overlayIcon, QIcon *retIcon, QStyle::StandardPixmap standardIcon)
+{
+ int size = 16;
+ while (size <= 128) {
+
+ const QString cacheKey = QLatin1String("qt_mac_constructQIconFromIconRef") + QString::number(standardIcon) + QString::number(size);
+ QPixmap mainIcon;
+ if (standardIcon >= QStyle::SP_CustomBase) {
+ mainIcon = qt_mac_convert_iconref(icon, size, size);
+ } else if (QPixmapCache::find(cacheKey, mainIcon) == false) {
+ mainIcon = qt_mac_convert_iconref(icon, size, size);
+ QPixmapCache::insert(cacheKey, mainIcon);
+ }
+
+ if (overlayIcon) {
+ int littleSize = size / 2;
+ QPixmap overlayPix = qt_mac_convert_iconref(overlayIcon, littleSize, littleSize);
+ QPainter painter(&mainIcon);
+ painter.drawPixmap(size - littleSize, size - littleSize, overlayPix);
+ }
+
+ retIcon->addPixmap(mainIcon);
+ size += size; // 16 -> 32 -> 64 -> 128
+ }
+}
+
QT_END_NAMESPACE