diff options
Diffstat (limited to 'src/plugins/platforms/cocoa/qcocoatheme.mm')
-rw-r--r-- | src/plugins/platforms/cocoa/qcocoatheme.mm | 59 |
1 files changed, 44 insertions, 15 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoatheme.mm b/src/plugins/platforms/cocoa/qcocoatheme.mm index 4b73d0af08..1fd40c49f1 100644 --- a/src/plugins/platforms/cocoa/qcocoatheme.mm +++ b/src/plugins/platforms/cocoa/qcocoatheme.mm @@ -31,7 +31,7 @@ ** ****************************************************************************/ -#import <Cocoa/Cocoa.h> +#import <AppKit/AppKit.h> #include "qcocoatheme.h" #include "messages.h" @@ -55,6 +55,33 @@ #include <qpa/qplatformintegration.h> #include <qpa/qplatformnativeinterface.h> +#include <Carbon/Carbon.h> + +@interface QT_MANGLE_NAMESPACE(QCocoaThemeNotificationReceiver) : NSObject { +QCocoaTheme *mPrivate; +} +- (id)initWithPrivate:(QCocoaTheme *)priv; +- (void)systemColorsDidChange:(NSNotification *)notification; +@end + +QT_NAMESPACE_ALIAS_OBJC_CLASS(QCocoaThemeNotificationReceiver); + +@implementation QCocoaThemeNotificationReceiver +- (id)initWithPrivate:(QCocoaTheme *)priv +{ + self = [super init]; + mPrivate = priv; + return self; +} + +- (void)systemColorsDidChange:(NSNotification *)notification +{ + Q_UNUSED(notification); + mPrivate->reset(); + QWindowSystemInterface::handleThemeChange(Q_NULLPTR); +} +@end + QT_BEGIN_NAMESPACE const char *QCocoaTheme::name = "cocoa"; @@ -62,14 +89,27 @@ const char *QCocoaTheme::name = "cocoa"; QCocoaTheme::QCocoaTheme() :m_systemPalette(0) { - + m_notificationReceiver = [[QT_MANGLE_NAMESPACE(QCocoaThemeNotificationReceiver) alloc] initWithPrivate:this]; + [[NSNotificationCenter defaultCenter] addObserver:m_notificationReceiver + selector:@selector(systemColorsDidChange:) + name:NSSystemColorsDidChangeNotification + object:nil]; } QCocoaTheme::~QCocoaTheme() { + [[NSNotificationCenter defaultCenter] removeObserver:m_notificationReceiver]; + [m_notificationReceiver release]; + reset(); + qDeleteAll(m_fonts); +} + +void QCocoaTheme::reset() +{ delete m_systemPalette; + m_systemPalette = Q_NULLPTR; qDeleteAll(m_palettes); - qDeleteAll(m_fonts); + m_palettes.clear(); } bool QCocoaTheme::usePlatformNativeDialog(DialogType dialogType) const @@ -257,18 +297,7 @@ QPixmap QCocoaTheme::fileIconPixmap(const QFileInfo &fileInfo, const QSizeF &siz NSImage *iconImage = [[NSWorkspace sharedWorkspace] iconForFile:QCFString::toNSString(fileInfo.canonicalFilePath())]; if (!iconImage) return QPixmap(); - NSSize pixmapSize = NSMakeSize(size.width(), size.height()); - QPixmap pixmap(pixmapSize.width, pixmapSize.height); - pixmap.fill(Qt::transparent); - [iconImage setSize:pixmapSize]; - NSRect iconRect = NSMakeRect(0, 0, pixmapSize.width, pixmapSize.height); - CGContextRef ctx = qt_mac_cg_context(&pixmap); - NSGraphicsContext *gc = [NSGraphicsContext graphicsContextWithGraphicsPort:ctx flipped:YES]; - [NSGraphicsContext saveGraphicsState]; - [NSGraphicsContext setCurrentContext:gc]; - [iconImage drawInRect:iconRect fromRect:iconRect operation:NSCompositeSourceOver fraction:1.0 respectFlipped:YES hints:nil]; - [NSGraphicsContext restoreGraphicsState]; - return pixmap; + return qt_mac_toQPixmap(iconImage, size); } QVariant QCocoaTheme::themeHint(ThemeHint hint) const |