diff options
author | Benjamin Poulain <benjamin.poulain@nokia.com> | 2009-05-14 16:40:03 (GMT) |
---|---|---|
committer | Benjamin Poulain <benjamin.poulain@nokia.com> | 2009-05-14 16:40:03 (GMT) |
commit | ae3f20e9ce7f592c22c23e8dea6bb9feb52c8b90 (patch) | |
tree | 5beb13e5ab883f7511a13d97c1752d08fec65828 | |
parent | 85f98acaa3a38079071bea711e43c9a86edec1f6 (diff) | |
download | Qt-ae3f20e9ce7f592c22c23e8dea6bb9feb52c8b90.zip Qt-ae3f20e9ce7f592c22c23e8dea6bb9feb52c8b90.tar.gz Qt-ae3f20e9ce7f592c22c23e8dea6bb9feb52c8b90.tar.bz2 |
QColor::toCmyk() does not convert the color if it is already in CMYK
QColor::toCmyk() converted the color to RGB and then to CMYK. If the color
was already in CMYK, this conversion change it.
The color is now returned directly if it is in CMYK
Reviewed-by: Ariya
Task-number: 253625
-rw-r--r-- | src/gui/painting/qcolor.cpp | 4 | ||||
-rw-r--r-- | tests/auto/qcolor/tst_qcolor.cpp | 21 |
2 files changed, 23 insertions, 2 deletions
diff --git a/src/gui/painting/qcolor.cpp b/src/gui/painting/qcolor.cpp index 5d7d4ab..1723a19 100644 --- a/src/gui/painting/qcolor.cpp +++ b/src/gui/painting/qcolor.cpp @@ -1369,7 +1369,7 @@ QColor QColor::toRgb() const */ QColor QColor::toHsv() const { - if (!isValid()) + if (!isValid() || cspec == Hsv) return *this; if (cspec != Rgb) @@ -1421,7 +1421,7 @@ QColor QColor::toHsv() const */ QColor QColor::toCmyk() const { - if (!isValid()) + if (!isValid() || cspec == Cmyk) return *this; if (cspec != Rgb) return toRgb().toCmyk(); diff --git a/tests/auto/qcolor/tst_qcolor.cpp b/tests/auto/qcolor/tst_qcolor.cpp index 7608a15..684d5b5 100644 --- a/tests/auto/qcolor/tst_qcolor.cpp +++ b/tests/auto/qcolor/tst_qcolor.cpp @@ -111,12 +111,15 @@ private slots: void toRgb_data(); void toRgb(); + void toRgbNonDestructive(); void toHsv_data(); void toHsv(); + void toHsvNonDestructive(); void toCmyk_data(); void toCmyk(); + void toCmykNonDestructive(); void convertTo(); @@ -1124,6 +1127,12 @@ void tst_QColor::toHsv_data() << QColor::fromCmykF(0., 1., 1., 0.); } +void tst_QColor::toRgbNonDestructive() +{ + QColor aColor = QColor::fromRgbF(0.11, 0.22, 0.33, 0.44); + QCOMPARE(aColor, aColor.toRgb()); +} + void tst_QColor::toHsv() { // invalid should remain invalid @@ -1136,6 +1145,12 @@ void tst_QColor::toHsv() QCOMPARE(cmykColor.toHsv(), expectedColor); } +void tst_QColor::toHsvNonDestructive() +{ + QColor aColor = QColor::fromHsvF(0.11, 0.22, 0.33, 0.44); + QCOMPARE(aColor, aColor.toHsv()); +} + void tst_QColor::toCmyk_data() { QTest::addColumn<QColor>("expectedColor"); @@ -1165,6 +1180,12 @@ void tst_QColor::toCmyk() QCOMPARE(hsvColor.toCmyk(), expectedColor); } +void tst_QColor::toCmykNonDestructive() +{ + QColor aColor = QColor::fromCmykF(0.11, 0.22, 0.33, 0.44); + QCOMPARE(aColor, aColor.toCmyk()); +} + void tst_QColor::convertTo() { QColor color(Qt::black); |