summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/cocoa/qcocoatheme.mm
diff options
context:
space:
mode:
authorJake Petroules <jake.petroules@theqtcompany.com>2015-12-09 21:04:48 -0800
committerJake Petroules <jake.petroules@theqtcompany.com>2015-12-11 11:06:52 +0000
commit0ba7df26038e3cea431ee70995332d7e9f027213 (patch)
treeedb9ed98629be3cf32e542e688fa834795c035b2 /src/plugins/platforms/cocoa/qcocoatheme.mm
parent95a6dc1cb910ca92bdb8651bc6091d0dd1c579b8 (diff)
React to changes in the system color palette.
Task-number: QTBUG-49734 Change-Id: Ic7926b53b6ee417c6c6206f7a9d5bb08bfd0c051 Reviewed-by: Morten Johan Sørvig <morten.sorvig@theqtcompany.com>
Diffstat (limited to 'src/plugins/platforms/cocoa/qcocoatheme.mm')
-rw-r--r--src/plugins/platforms/cocoa/qcocoatheme.mm42
1 files changed, 40 insertions, 2 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoatheme.mm b/src/plugins/platforms/cocoa/qcocoatheme.mm
index bf2e726be1..1fd40c49f1 100644
--- a/src/plugins/platforms/cocoa/qcocoatheme.mm
+++ b/src/plugins/platforms/cocoa/qcocoatheme.mm
@@ -57,6 +57,31 @@
#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";
@@ -64,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