diff options
author | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2020-03-23 14:09:03 +0100 |
---|---|---|
committer | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2020-03-23 17:36:52 +0100 |
commit | c14f3deca91eb6e7ab23f5f73004f4f824b97d95 (patch) | |
tree | 1770fd7d40346694ab36466859477ee4efbfe55c /src/gui/painting/qcoregraphics.mm | |
parent | 9ff75d4ea11c78ad4acaf5f51e119b5039595837 (diff) |
Fix deprecation warnings from NSColor(Space) with macOS 10.14 SDK
The support for handling color spaces by names is deprecated in
recent AppKit versions, and should be replaced by using
NSColor.type, and operations on the type-specific properties of
the color.
Merge the two implementations from qcoregraphics.mm and
qcocoacolordialoghelper.mm, which also fixes the inconsistent
interpretation of color components as device dependent (in
qcoregraphics) or generic (in qcocoacolordialoghelper). We now
always populate the QColor with device independent components.
Change-Id: Id79c609736ff1962bebe4bd7158781a6d1b4475e
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'src/gui/painting/qcoregraphics.mm')
-rw-r--r-- | src/gui/painting/qcoregraphics.mm | 43 |
1 files changed, 29 insertions, 14 deletions
diff --git a/src/gui/painting/qcoregraphics.mm b/src/gui/painting/qcoregraphics.mm index 94ba004c93..1125a9183c 100644 --- a/src/gui/painting/qcoregraphics.mm +++ b/src/gui/painting/qcoregraphics.mm @@ -240,18 +240,33 @@ QColor qt_mac_toQColor(CGColorRef color) QColor qt_mac_toQColor(const NSColor *color) { QColor qtColor; - NSString *colorSpace = [color colorSpaceName]; - if (colorSpace == NSDeviceCMYKColorSpace) { - CGFloat cyan, magenta, yellow, black, alpha; - [color getCyan:&cyan magenta:&magenta yellow:&yellow black:&black alpha:&alpha]; - qtColor.setCmykF(cyan, magenta, yellow, black, alpha); - } else { - NSColor *tmpColor; - tmpColor = [color colorUsingColorSpaceName:NSDeviceRGBColorSpace]; - CGFloat red, green, blue, alpha; + switch (color.type) { + case NSColorTypeComponentBased: { + const NSColorSpace *colorSpace = [color colorSpace]; + if (colorSpace == NSColorSpace.genericRGBColorSpace + && color.numberOfComponents == 4) { // rbga + CGFloat components[4]; + [color getComponents:components]; + qtColor.setRgbF(components[0], components[1], components[2], components[3]); + break; + } else if (colorSpace == NSColorSpace.genericCMYKColorSpace + && color.numberOfComponents == 5) { // cmyk + alpha + CGFloat components[5]; + [color getComponents:components]; + qtColor.setCmykF(components[0], components[1], components[2], components[3], components[4]); + break; + } + } + Q_FALLTHROUGH(); + default: { + const NSColor *tmpColor = [color colorUsingColorSpace:NSColorSpace.genericRGBColorSpace]; + CGFloat red = 0, green = 0, blue = 0, alpha = 0; [tmpColor getRed:&red green:&green blue:&blue alpha:&alpha]; qtColor.setRgbF(red, green, blue, alpha); + break; + } } + return qtColor; } #endif @@ -277,9 +292,9 @@ static bool qt_mac_isSystemColorOrInstance(const NSColor *color, NSString *color // We specifically do not want isKindOfClass: here if ([color.className isEqualToString:className]) // NSPatternColorSpace return true; - if ([color.catalogNameComponent isEqualToString:@"System"] && - [color.colorNameComponent isEqualToString:colorNameComponent] && - [color.colorSpaceName isEqualToString:NSNamedColorSpace]) + if (color.type == NSColorTypeCatalog && + [color.catalogNameComponent isEqualToString:@"System"] && + [color.colorNameComponent isEqualToString:colorNameComponent]) return true; return false; } @@ -335,8 +350,8 @@ QBrush qt_mac_toQBrush(const NSColor *color, QPalette::ColorGroup colorGroup) return qtBrush; } - if (NSColor *patternColor = [color colorUsingColorSpaceName:NSPatternColorSpace]) { - NSImage *patternImage = patternColor.patternImage; + if (color.type == NSColorTypePattern) { + NSImage *patternImage = color.patternImage; const QSizeF sz(patternImage.size.width, patternImage.size.height); // FIXME: QBrush is not resolution independent (QTBUG-49774) qtBrush.setTexture(qt_mac_toQPixmap(patternImage, sz)); |