*/
void QColor::getHsv(int *h, int *s, int *v, int *a) const
{
- if (!h || !s || !v)
+ if (!h || !s || !v) {
return;
+ }
if (cspec != QColor::Invalid && cspec != QColor::Hsv) {
toHsv().getHsv(h, s, v, a);
*/
void QColor::getRgbF(qreal *r, qreal *g, qreal *b, qreal *a) const
{
- if (!r || !g || !b)
+ if (!r || !g || !b) {
return;
+ }
if (cspec != QColor::Invalid && cspec != QColor::Rgb) {
toRgb().getRgbF(r, g, b, a);
*/
void QColor::getRgb(int *r, int *g, int *b, int *a) const
{
- if (!r || !g || !b)
+ if (!r || !g || !b) {
return;
+ }
if (cspec != QColor::Invalid && cspec != QColor::Rgb) {
toRgb().getRgb(r, g, b, a);
QRgb QColor::rgba() const
{
- if (cspec != QColor::Invalid && cspec != QColor::Rgb)
+ if (cspec != QColor::Invalid && cspec != QColor::Rgb) {
return toRgb().rgba();
+ }
return qRgba(ct.argb.red >> 8, ct.argb.green >> 8, ct.argb.blue >> 8, ct.argb.alpha >> 8);
}
*/
QRgb QColor::rgb() const
{
- if (cspec != QColor::Invalid && cspec != QColor::Rgb)
+ if (cspec != QColor::Invalid && cspec != QColor::Rgb) {
return toRgb().rgb();
+ }
return qRgb(ct.argb.red >> 8, ct.argb.green >> 8, ct.argb.blue >> 8);
}
Drawing}{Alpha-Blended Drawing}
*/
int QColor::alpha() const
-{ return ct.argb.alpha >> 8; }
+{
+ return ct.argb.alpha >> 8;
+}
/*!
*/
int QColor::red() const
{
- if (cspec != QColor::Invalid && cspec != QColor::Rgb)
+ if (cspec != QColor::Invalid && cspec != QColor::Rgb) {
return toRgb().red();
+ }
return ct.argb.red >> 8;
}
*/
int QColor::green() const
{
- if (cspec != QColor::Invalid && cspec != QColor::Rgb)
+ if (cspec != QColor::Invalid && cspec != QColor::Rgb) {
return toRgb().green();
+ }
return ct.argb.green >> 8;
}
*/
int QColor::blue() const
{
- if (cspec != QColor::Invalid && cspec != QColor::Rgb)
+ if (cspec != QColor::Invalid && cspec != QColor::Rgb) {
return toRgb().blue();
+ }
return ct.argb.blue >> 8;
}
*/
qreal QColor::redF() const
{
- if (cspec != QColor::Invalid && cspec != QColor::Rgb)
+ if (cspec != QColor::Invalid && cspec != QColor::Rgb) {
return toRgb().redF();
+ }
return ct.argb.red / qreal(USHRT_MAX);
}
*/
qreal QColor::greenF() const
{
- if (cspec != QColor::Invalid && cspec != QColor::Rgb)
+ if (cspec != QColor::Invalid && cspec != QColor::Rgb) {
return toRgb().greenF();
+ }
return ct.argb.green / qreal(USHRT_MAX);
}
*/
qreal QColor::blueF() const
{
- if (cspec != QColor::Invalid && cspec != QColor::Rgb)
+ if (cspec != QColor::Invalid && cspec != QColor::Rgb) {
return toRgb().blueF();
+ }
return ct.argb.blue / qreal(USHRT_MAX);
}
*/
int QColor::hsvHue() const
{
- if (cspec != QColor::Invalid && cspec != QColor::Hsv)
+ if (cspec != QColor::Invalid && cspec != QColor::Hsv) {
return toHsv().hue();
+ }
return ct.ahsv.hue == USHRT_MAX ? -1 : ct.ahsv.hue / 100;
}
*/
int QColor::hsvSaturation() const
{
- if (cspec != QColor::Invalid && cspec != QColor::Hsv)
+ if (cspec != QColor::Invalid && cspec != QColor::Hsv) {
return toHsv().saturation();
+ }
return ct.ahsv.saturation >> 8;
}
*/
int QColor::value() const
{
- if (cspec != QColor::Invalid && cspec != QColor::Hsv)
+ if (cspec != QColor::Invalid && cspec != QColor::Hsv) {
return toHsv().value();
+ }
return ct.ahsv.value >> 8;
}
*/
qreal QColor::hsvHueF() const
{
- if (cspec != QColor::Invalid && cspec != QColor::Hsv)
+ if (cspec != QColor::Invalid && cspec != QColor::Hsv) {
return toHsv().hueF();
+ }
return ct.ahsv.hue == USHRT_MAX ? qreal(-1.0) : ct.ahsv.hue / qreal(36000.0);
}
*/
qreal QColor::hsvSaturationF() const
{
- if (cspec != QColor::Invalid && cspec != QColor::Hsv)
+ if (cspec != QColor::Invalid && cspec != QColor::Hsv) {
return toHsv().saturationF();
+ }
return ct.ahsv.saturation / qreal(USHRT_MAX);
}
*/
qreal QColor::valueF() const
{
- if (cspec != QColor::Invalid && cspec != QColor::Hsv)
+ if (cspec != QColor::Invalid && cspec != QColor::Hsv) {
return toHsv().valueF();
+ }
return ct.ahsv.value / qreal(USHRT_MAX);
}
return *this;
}
+ Q_ASSERT(cspec == QColor::Hsv);
+
QColor color;
color.cspec = QColor::Rgb;
color.ct.argb.alpha = ct.argb.alpha;
- switch (cspec) {
- case QColor::Hsv: {
- if (ct.ahsv.saturation == 0 || ct.ahsv.hue == USHRT_MAX) {
- // achromatic case
- color.ct.argb.red = color.ct.argb.green = color.ct.argb.blue = ct.ahsv.value;
- break;
- }
+ if (ct.ahsv.saturation == 0 || ct.ahsv.hue == USHRT_MAX) {
+ // achromatic case
+ color.ct.argb.red = color.ct.argb.green = color.ct.argb.blue = ct.ahsv.value;
+ return color;
+ }
- // chromatic case
- const qreal h = ct.ahsv.hue == 36000 ? 0 : ct.ahsv.hue / qreal(6000.);
- const qreal s = ct.ahsv.saturation / qreal(USHRT_MAX);
- const qreal v = ct.ahsv.value / qreal(USHRT_MAX);
- const int i = int(h);
- const qreal f = h - i;
- const qreal p = v * (qreal(1.0) - s);
-
- if (i & 1) {
- const qreal q = v * (qreal(1.0) - (s * f));
-
- switch (i) {
- case 1:
+ // chromatic case
+ const qreal h = ct.ahsv.hue == 36000 ? 0 : ct.ahsv.hue / qreal(6000.);
+ const qreal s = ct.ahsv.saturation / qreal(USHRT_MAX);
+ const qreal v = ct.ahsv.value / qreal(USHRT_MAX);
+ const int i = int(h);
+ const qreal f = h - i;
+ const qreal p = v * (qreal(1.0) - s);
+
+ if (i & 1) {
+ const qreal q = v * (qreal(1.0) - (s * f));
+
+ switch (i) {
+ case 1: {
color.ct.argb.red = qRound(q * USHRT_MAX);
color.ct.argb.green = qRound(v * USHRT_MAX);
color.ct.argb.blue = qRound(p * USHRT_MAX);
break;
- case 3:
+ }
+ case 3: {
color.ct.argb.red = qRound(p * USHRT_MAX);
color.ct.argb.green = qRound(q * USHRT_MAX);
color.ct.argb.blue = qRound(v * USHRT_MAX);
break;
- case 5:
+ }
+ case 5: {
color.ct.argb.red = qRound(v * USHRT_MAX);
color.ct.argb.green = qRound(p * USHRT_MAX);
color.ct.argb.blue = qRound(q * USHRT_MAX);
break;
}
- } else {
- const qreal t = v * (qreal(1.0) - (s * (qreal(1.0) - f)));
+ }
+ } else {
+ const qreal t = v * (qreal(1.0) - (s * (qreal(1.0) - f)));
- switch (i) {
- case 0:
+ switch (i) {
+ case 0: {
color.ct.argb.red = qRound(v * USHRT_MAX);
color.ct.argb.green = qRound(t * USHRT_MAX);
color.ct.argb.blue = qRound(p * USHRT_MAX);
break;
- case 2:
+ }
+ case 2: {
color.ct.argb.red = qRound(p * USHRT_MAX);
color.ct.argb.green = qRound(v * USHRT_MAX);
color.ct.argb.blue = qRound(t * USHRT_MAX);
break;
- case 4:
+ }
+ case 4: {
color.ct.argb.red = qRound(t * USHRT_MAX);
color.ct.argb.green = qRound(p * USHRT_MAX);
color.ct.argb.blue = qRound(v * USHRT_MAX);
break;
}
}
- break;
- }
- default:
- break;
}
return color;
if (!isValid() || cspec == QColor::Hsv)
return *this;
- if (cspec != QColor::Rgb)
- return toRgb().toHsv();
+ Q_ASSERT(cspec == QColor::Rgb);
QColor color;
color.cspec = QColor::Hsv;