summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/platforms')
-rw-r--r--src/plugins/platforms/cocoa/qcocoatheme.h5
-rw-r--r--src/plugins/platforms/cocoa/qcocoatheme.mm42
2 files changed, 45 insertions, 2 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoatheme.h b/src/plugins/platforms/cocoa/qcocoatheme.h
index 0cd7b7d4c8..5ec0b30786 100644
--- a/src/plugins/platforms/cocoa/qcocoatheme.h
+++ b/src/plugins/platforms/cocoa/qcocoatheme.h
@@ -37,6 +37,8 @@
#include <QtCore/QHash>
#include <qpa/qplatformtheme.h>
+Q_FORWARD_DECLARE_OBJC_CLASS(QT_MANGLE_NAMESPACE(QCocoaThemeNotificationReceiver));
+
QT_BEGIN_NAMESPACE
class QPalette;
@@ -46,6 +48,8 @@ public:
QCocoaTheme();
~QCocoaTheme();
+ void reset();
+
QPlatformMenuItem* createPlatformMenuItem() const Q_DECL_OVERRIDE;
QPlatformMenu* createPlatformMenu() const Q_DECL_OVERRIDE;
QPlatformMenuBar* createPlatformMenuBar() const Q_DECL_OVERRIDE;
@@ -73,6 +77,7 @@ private:
mutable QPalette *m_systemPalette;
mutable QHash<QPlatformTheme::Palette, QPalette*> m_palettes;
mutable QHash<QPlatformTheme::Font, QFont*> m_fonts;
+ mutable QCocoaThemeNotificationReceiver *m_notificationReceiver;
};
QT_END_NAMESPACE
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