summaryrefslogtreecommitdiffstats
path: root/src/plugins/styles
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2019-05-27 15:34:10 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2019-05-27 15:34:10 +0200
commit518cf3312c101ea1c5ae5199611ebda46a74dadd (patch)
treefe580d423d8938caad9d6705c7ef9da13d2d8e14 /src/plugins/styles
parent59937de098dd86472e73146bd0c84e980022e24d (diff)
parent65cfac73bd1c09eafadf57a3b7161f52b186c37d (diff)
Merge remote-tracking branch 'origin/5.13' into dev
Diffstat (limited to 'src/plugins/styles')
-rw-r--r--src/plugins/styles/mac/qmacstyle_mac.mm44
1 files changed, 41 insertions, 3 deletions
diff --git a/src/plugins/styles/mac/qmacstyle_mac.mm b/src/plugins/styles/mac/qmacstyle_mac.mm
index 3474e82c13..392368a40b 100644
--- a/src/plugins/styles/mac/qmacstyle_mac.mm
+++ b/src/plugins/styles/mac/qmacstyle_mac.mm
@@ -150,6 +150,16 @@ static QWindow *qt_getWindow(const QWidget *widget)
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
{
@@ -162,6 +172,23 @@ QT_NAMESPACE_ALIAS_OBJC_CLASS(NotificationReceiver);
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
@@ -2068,11 +2095,17 @@ QMacStyle::QMacStyle()
Q_D(QMacStyle);
QMacAutoReleasePool pool;
- d->receiver = [[NotificationReceiver alloc] init];
+ d->receiver = [[NotificationReceiver alloc] initWithPrivateStyle:d];
[[NSNotificationCenter defaultCenter] addObserver:d->receiver
selector:@selector(scrollBarStyleDidChange:)
name:NSPreferredScrollerStyleDidChangeNotification
object:nil];
+#if QT_MACOS_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_14)
+ if (QOperatingSystemVersion::current() >= QOperatingSystemVersion::MacOSMojave) {
+ [NSApplication.sharedApplication addObserver:d->receiver forKeyPath:@"effectiveAppearance"
+ options:NSKeyValueObservingOptionNew context:nullptr];
+ }
+#endif
}
QMacStyle::~QMacStyle()
@@ -2081,6 +2114,10 @@ QMacStyle::~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];
}
@@ -6129,8 +6166,9 @@ QSize QMacStyle::sizeFromContents(ContentsType ct, const QStyleOption *opt,
switch (ct) {
#if QT_CONFIG(spinbox)
case CT_SpinBox:
- if (qstyleoption_cast<const QStyleOptionSpinBox *>(opt)) {
- const int buttonWidth = 20; // FIXME Use subControlRect()
+ if (const QStyleOptionSpinBox *vopt = qstyleoption_cast<const QStyleOptionSpinBox *>(opt)) {
+ const bool hasButtons = (vopt->buttonSymbols != QAbstractSpinBox::NoButtons);
+ const int buttonWidth = hasButtons ? proxy()->subControlRect(CC_SpinBox, vopt, SC_SpinBoxUp, widget).width() : 0;
sz += QSize(buttonWidth, 0);
}
break;