From 88c1670a658d55257d50181d741afe562e44344b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20R=C3=B8dal?= Date: Wed, 26 Jan 2011 13:37:45 +0100 Subject: Fixed hslHue / hslHueF returning the wrong value for achromatic QColors. Made toHsl() work the same way as toHsv(), ensuring the hue gets set to USHRT_MAX and not 0. Task-number: QTBUG-16530 Reviewed-by: Eskil Abrahamsen Blomfeldt --- src/gui/painting/qcolor.cpp | 2 +- tests/auto/qcolor/tst_qcolor.cpp | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/gui/painting/qcolor.cpp b/src/gui/painting/qcolor.cpp index dea3a72..173fb71 100644 --- a/src/gui/painting/qcolor.cpp +++ b/src/gui/painting/qcolor.cpp @@ -1781,7 +1781,7 @@ QColor QColor::toHsl() const color.ct.ahsl.lightness = qRound(lightness * USHRT_MAX); if (qFuzzyIsNull(delta)) { // achromatic case, hue is undefined - color.ct.ahsl.hue = 0; + color.ct.ahsl.hue = USHRT_MAX; color.ct.ahsl.saturation = 0; } else { // chromatic case diff --git a/tests/auto/qcolor/tst_qcolor.cpp b/tests/auto/qcolor/tst_qcolor.cpp index fcd608b..d42c26c 100644 --- a/tests/auto/qcolor/tst_qcolor.cpp +++ b/tests/auto/qcolor/tst_qcolor.cpp @@ -148,6 +148,8 @@ private slots: void specConstructor_data(); void specConstructor(); + void achromaticHslHue(); + #ifdef Q_WS_X11 void allowX11ColorNames(); void setallowX11ColorNames(); @@ -1459,6 +1461,14 @@ void tst_QColor::specConstructor() QCOMPARE(color.spec(), spec); } +void tst_QColor::achromaticHslHue() +{ + QColor color = Qt::black; + + QColor hsl = color.toHsl(); + QCOMPARE(hsl.hslHue(), -1); +} + #ifdef Q_WS_X11 void tst_QColor::allowX11ColorNames() { -- cgit v0.12