summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/cocoa
diff options
context:
space:
mode:
authorMorten Johan Sørvig <morten.sorvig@qt.io>2020-06-22 16:07:59 +0200
committerMorten Johan Sørvig <morten.sorvig@qt.io>2020-08-06 08:34:12 +0000
commitb7a1bd306443e4f932a96020c1d48418916237ea (patch)
tree52eed105e256841250ad44468047c51c1a7092d6 /src/plugins/platforms/cocoa
parent6d6ed64d6ca27c1b5fec305e6ed9b923b5bb1037 (diff)
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 <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/plugins/platforms/cocoa')
-rw-r--r--src/plugins/platforms/cocoa/qcocoacolordialoghelper.mm30
1 files changed, 28 insertions, 2 deletions
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);
}