From b7a1bd306443e4f932a96020c1d48418916237ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Mon, 22 Jun 2020 16:07:59 +0200 Subject: macOS: Make getColor() return generic RGB components Discard the color space and return the selected RGB/CMYK color components, without any color space conversion. This enables predictable color handling as long as you stay on a single display. All color triplets are display RGB: drawing the QColor returned by getColor() will reproduce the selected color on-screen. (Predictable color across multiple displays require color management, which is out of scope here). Fixes: QTBUG-84124 Pick-to: 5.15 Change-Id: I43d8dc15d07635fabdd0662c84f7c0b5ac40b7ab Reviewed-by: Volker Hilsheimer --- .../platforms/cocoa/qcocoacolordialoghelper.mm | 30 ++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'src/plugins/platforms/cocoa') diff --git a/src/plugins/platforms/cocoa/qcocoacolordialoghelper.mm b/src/plugins/platforms/cocoa/qcocoacolordialoghelper.mm index 49812423eb..8d256ae09e 100644 --- a/src/plugins/platforms/cocoa/qcocoacolordialoghelper.mm +++ b/src/plugins/platforms/cocoa/qcocoacolordialoghelper.mm @@ -181,8 +181,34 @@ QT_NAMESPACE_ALIAS_OBJC_CLASS(QNSColorPanelDelegate); - (void)updateQtColor { - NSColor *color = [mColorPanel color]; - mQtColor = qt_mac_toQColor(color); + // Discard the color space and pass the color components to QColor. This + // is a good option as long as QColor is color-unmanaged: we preserve the + // exact RGB value from the color picker, which is predictable. Further, + // painting with the color will reproduce the same color on-screen, as + // long as the the same screen is used for selecting the color. + NSColor *componentColor = [[mColorPanel color] colorUsingType:NSColorTypeComponentBased]; + switch (componentColor.colorSpace.colorSpaceModel) + { + case NSColorSpaceModelGray: { + CGFloat white = 0, alpha = 0; + [componentColor getWhite:&white alpha:&alpha]; + mQtColor.setRgbF(white, white, white, alpha); + } break; + case NSColorSpaceModelRGB: { + CGFloat red = 0, green = 0, blue = 0, alpha = 0; + [componentColor getRed:&red green:&green blue:&blue alpha:&alpha]; + mQtColor.setRgbF(red, green, blue, alpha); + } break; + case NSColorSpaceModelCMYK: { + CGFloat cyan = 0, magenta = 0, yellow = 0, black = 0, alpha = 0; + [componentColor getCyan:&cyan magenta:&magenta yellow:&yellow black:&black alpha:&alpha]; + mQtColor.setCmykF(cyan, magenta, yellow, black, alpha); + } break; + default: + qWarning("QNSColorPanelDelegate: Unsupported color space model"); + break; + } + if (mHelper) emit mHelper->currentColorChanged(mQtColor); } -- cgit v1.2.3