summaryrefslogtreecommitdiffstats
path: root/src/plugins/styles
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2019-06-14 11:56:56 +0200
committerLiang Qi <liang.qi@qt.io>2019-06-14 13:45:18 +0200
commitb1a216649ec064412160638dd00195cd47c567aa (patch)
treea4134415a3849cfb857942e698514be9da18924f /src/plugins/styles
parent2e20ae3c1b57169497f6f3904623be4f5e617e12 (diff)
parent1632786f00875d23c7d111cbb29dedaa35c1c8c2 (diff)
Merge remote-tracking branch 'origin/5.13' into dev
Conflicts: qmake/generators/makefile.cpp qmake/generators/unix/unixmake2.cpp src/corelib/thread/qthread_unix.cpp tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp Change-Id: I1df0d4ba20685de7f9300bf07458c13376493408
Diffstat (limited to 'src/plugins/styles')
-rw-r--r--src/plugins/styles/mac/qmacstyle_mac.mm85
-rw-r--r--src/plugins/styles/mac/qmacstyle_mac_p_p.h4
2 files changed, 22 insertions, 67 deletions
diff --git a/src/plugins/styles/mac/qmacstyle_mac.mm b/src/plugins/styles/mac/qmacstyle_mac.mm
index 743713c86a..05c397a6f1 100644
--- a/src/plugins/styles/mac/qmacstyle_mac.mm
+++ b/src/plugins/styles/mac/qmacstyle_mac.mm
@@ -82,53 +82,6 @@ static QWindow *qt_getWindow(const QWidget *widget)
return widget ? widget->window()->windowHandle() : 0;
}
-@interface QT_MANGLE_NAMESPACE(NotificationReceiver) : NSObject
-@end
-
-QT_NAMESPACE_ALIAS_OBJC_CLASS(NotificationReceiver);
-
-@implementation NotificationReceiver
-{
- QMacStylePrivate *privateStyle;
-}
-
-- (instancetype)initWithPrivateStyle:(QMacStylePrivate *)style
-{
- if (self = [super init])
- privateStyle = style;
- return self;
-}
-
-- (void)scrollBarStyleDidChange:(NSNotification *)notification
-{
- Q_UNUSED(notification);
-
- // purge destroyed scroll bars:
- QMacStylePrivate::scrollBars.removeAll(QPointer<QObject>());
-
- QEvent event(QEvent::StyleChange);
- for (const auto &o : QMacStylePrivate::scrollBars)
- QCoreApplication::sendEvent(o, &event);
-}
-
-- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object
- change:(NSDictionary<NSKeyValueChangeKey, id> *)change context:(void *)context
-{
- Q_UNUSED(keyPath);
- Q_UNUSED(object);
- Q_UNUSED(change);
- Q_UNUSED(context);
-
- Q_ASSERT([keyPath isEqualToString:@"effectiveAppearance"]);
- Q_ASSERT(object == NSApp);
-
- for (NSView *b : privateStyle->cocoaControls)
- [b release];
- privateStyle->cocoaControls.clear();
-}
-
-@end
-
@interface QT_MANGLE_NAMESPACE(QIndeterminateProgressIndicator) : NSProgressIndicator
@property (readonly, nonatomic) NSInteger animators;
@@ -2032,33 +1985,33 @@ void QMacStylePrivate::resolveCurrentNSView(QWindow *window) const
QMacStyle::QMacStyle()
: QCommonStyle(*new QMacStylePrivate)
{
- Q_D(QMacStyle);
QMacAutoReleasePool pool;
- d->receiver = [[NotificationReceiver alloc] initWithPrivateStyle:d];
- [[NSNotificationCenter defaultCenter] addObserver:d->receiver
- selector:@selector(scrollBarStyleDidChange:)
- name:NSPreferredScrollerStyleDidChangeNotification
- object:nil];
+ static QMacNotificationObserver scrollbarStyleObserver(nil,
+ NSPreferredScrollerStyleDidChangeNotification, []() {
+ // Purge destroyed scroll bars
+ QMacStylePrivate::scrollBars.removeAll(QPointer<QObject>());
+
+ QEvent event(QEvent::StyleChange);
+ for (const auto &o : QMacStylePrivate::scrollBars)
+ QCoreApplication::sendEvent(o, &event);
+ });
+
#if QT_MACOS_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_14)
+ Q_D(QMacStyle);
+ // FIXME: Tie this logic into theme change, or even polish/unpolish
if (QOperatingSystemVersion::current() >= QOperatingSystemVersion::MacOSMojave) {
- [NSApplication.sharedApplication addObserver:d->receiver forKeyPath:@"effectiveAppearance"
- options:NSKeyValueObservingOptionNew context:nullptr];
+ d->appearanceObserver = QMacKeyValueObserver(NSApp, @"effectiveAppearance", [&d] {
+ for (NSView *b : d->cocoaControls)
+ [b release];
+ d->cocoaControls.clear();
+ });
}
#endif
}
QMacStyle::~QMacStyle()
{
- Q_D(QMacStyle);
- QMacAutoReleasePool pool;
-
- [[NSNotificationCenter defaultCenter] removeObserver:d->receiver];
-#if QT_MACOS_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_14)
- if (QOperatingSystemVersion::current() >= QOperatingSystemVersion::MacOSMojave)
- [NSApplication.sharedApplication removeObserver:d->receiver forKeyPath:@"effectiveAppearance"];
-#endif
- [d->receiver release];
}
void QMacStyle::polish(QPalette &)
@@ -3094,7 +3047,9 @@ void QMacStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPai
theStroker.setCapStyle(Qt::FlatCap);
theStroker.setDashPattern(QVector<qreal>() << 1 << 2);
path = theStroker.createStroke(path);
- p->fillPath(path, QColor(0, 0, 0, 119));
+ const auto dark = qt_mac_applicationIsInDarkMode() ? opt->palette.dark().color().darker()
+ : QColor(0, 0, 0, 119);
+ p->fillPath(path, dark);
}
break;
case PE_FrameWindow:
diff --git a/src/plugins/styles/mac/qmacstyle_mac_p_p.h b/src/plugins/styles/mac/qmacstyle_mac_p_p.h
index 6e7004485c..d6af18f01f 100644
--- a/src/plugins/styles/mac/qmacstyle_mac_p_p.h
+++ b/src/plugins/styles/mac/qmacstyle_mac_p_p.h
@@ -156,7 +156,6 @@ Q_FORWARD_DECLARE_MUTABLE_CG_TYPE(CGContext);
Q_FORWARD_DECLARE_OBJC_CLASS(NSView);
Q_FORWARD_DECLARE_OBJC_CLASS(NSCell);
-Q_FORWARD_DECLARE_OBJC_CLASS(QT_MANGLE_NAMESPACE(NotificationReceiver));
QT_BEGIN_NAMESPACE
@@ -295,13 +294,14 @@ public:
static QVector<QPointer<QObject> > scrollBars;
mutable QPointer<QFocusFrame> focusWidget;
- QT_MANGLE_NAMESPACE(NotificationReceiver) *receiver;
mutable NSView *backingStoreNSView;
mutable QHash<CocoaControl, NSView *> cocoaControls;
mutable QHash<CocoaControl, NSCell *> cocoaCells;
QFont smallSystemFont;
QFont miniSystemFont;
+
+ QMacKeyValueObserver appearanceObserver;
};
QT_END_NAMESPACE