📄 qcolor.cpp
字号:
\sa setHsv(), {QColor#The HSV Color Model}{The HSV Color Model}*/void QColor::getHsv(int *h, int *s, int *v, int *a) const{ if (!h || !s || !v) return; if (cspec != Invalid && cspec != Hsv) { toHsv().getHsv(h, s, v, a); return; } *h = ct.ahsv.hue == USHRT_MAX ? -1 : ct.ahsv.hue / 100; *s = ct.ahsv.saturation >> 8; *v = ct.ahsv.value >> 8; if (a) *a = ct.ahsv.alpha >> 8;}/*! Sets a HSV color value; \a h is the hue, \a s is the saturation, \a v is the value and \a a is the alpha component of the HSV color. All the values must be in the range 0.0-1.0. \sa getHsvF(), setHsv(), {QColor#The HSV Color Model}{The HSV Color Model}*/void QColor::setHsvF(qreal h, qreal s, qreal v, qreal a){ if (((h < 0.0 || h > 1.0) && h != -1.0) || (s < 0.0 || s > 1.0) || (v < 0.0 || v > 1.0) || (a < 0.0 || a > 1.0)) { qWarning("QColor::setHsv: HSV parameters out of range"); return; } cspec = Hsv; ct.ahsv.alpha = qRound(a * USHRT_MAX); ct.ahsv.hue = h == -1.0 ? USHRT_MAX : qRound(h * 36000); ct.ahsv.saturation = qRound(s * USHRT_MAX); ct.ahsv.value = qRound(v * USHRT_MAX); ct.ahsv.pad = 0;}/*! Sets a HSV color value; \a h is the hue, \a s is the saturation, \a v is the value and \a a is the alpha component of the HSV color. The saturation, value and alpha-channel values must be in the range 0-255, and the hue value must be greater than -1. \sa getHsv(), setHsvF(), {QColor#The HSV Color Model}{The HSV Color Model}*/void QColor::setHsv(int h, int s, int v, int a){ if (h < -1 || (uint)s > 255 || (uint)v > 255 || (uint)a > 255) { qWarning("QColor::setHsv: HSV parameters out of range"); invalidate(); return; } cspec = Hsv; ct.ahsv.alpha = a * 0x101; ct.ahsv.hue = h == -1 ? USHRT_MAX : (h % 360) * 100; ct.ahsv.saturation = s * 0x101; ct.ahsv.value = v * 0x101; ct.ahsv.pad = 0;}/*! Sets the contents pointed to by \a r, \a g, \a b, and \a a, to the red, green, blue, and alpha-channel (transparency) components of the color's RGB value. Note that the components can be retrieved individually using the redF(), greenF(), blueF() and alphaF() functions. \sa rgb(), setRgb()*/void QColor::getRgbF(qreal *r, qreal *g, qreal *b, qreal *a) const{ if (!r || !g || !b) return; if (cspec != Invalid && cspec != Rgb) { toRgb().getRgbF(r, g, b, a); return; } *r = ct.argb.red / qreal(USHRT_MAX); *g = ct.argb.green / qreal(USHRT_MAX); *b = ct.argb.blue / qreal(USHRT_MAX); if (a) *a = ct.argb.alpha / qreal(USHRT_MAX);}/*! Sets the contents pointed to by \a r, \a g, \a b, and \a a, to the red, green, blue, and alpha-channel (transparency) components of the color's RGB value. Note that the components can be retrieved individually using the red(), green(), blue() and alpha() functions. \sa rgb(), setRgb()*/void QColor::getRgb(int *r, int *g, int *b, int *a) const{ if (!r || !g || !b) return; if (cspec != Invalid && cspec != Rgb) { toRgb().getRgb(r, g, b, a); return; } *r = ct.argb.red >> 8; *g = ct.argb.green >> 8; *b = ct.argb.blue >> 8; if (a) *a = ct.argb.alpha >> 8;}/*! \obsolete \fn void QColor::getRgba(int *r, int *g, int *b, int *a) const Use getRgb() instead.*//*! \fn void QColor::setRgbF(qreal r, qreal g, qreal b, qreal a) Sets the color channels of this color to \a r (red), \a g (green), \a b (blue) and \a a (alpha, transparency). All values must be in the range 0.0-1.0. \sa rgb(), getRgbF(), setRgb()*/void QColor::setRgbF(qreal r, qreal g, qreal b, qreal a){ if (r < 0.0 || r > 1.0 || g < 0.0 || g > 1.0 || b < 0.0 || b > 1.0 || a < 0.0 || a > 1.0) { qWarning("QColor::setRgb: RGB parameter(s) out of range"); invalidate(); return; } cspec = Rgb; ct.argb.alpha = qRound(a * USHRT_MAX); ct.argb.red = qRound(r * USHRT_MAX); ct.argb.green = qRound(g * USHRT_MAX); ct.argb.blue = qRound(b * USHRT_MAX); ct.argb.pad = 0;}/*! Sets the RGB value to \a r, \a g, \a b and the alpha value to \a a. All the values must be in the range 0-255. \sa rgb(), getRgb(), setRgbF()*/void QColor::setRgb(int r, int g, int b, int a){ if ((uint)r > 255 || (uint)g > 255 || (uint)b > 255 || (uint)a > 255) { qWarning("QColor::setRgb: RGB parameter(s) out of range"); invalidate(); return; } cspec = Rgb; ct.argb.alpha = a * 0x101; ct.argb.red = r * 0x101; ct.argb.green = g * 0x101; ct.argb.blue = b * 0x101; ct.argb.pad = 0;}/*! \obsolete \fn void QColor::setRgba(int r, int g, int b, int a) Use setRgb() instead.*//*! \fn QRgb QColor::rgba() const Returns the RGB value of the color. Note that unlike rgb(), the alpha is not stripped. For an invalid color, the alpha value of the returned color is unspecified. \sa setRgba(), rgb()*/QRgb QColor::rgba() const{ if (cspec != Invalid && cspec != Rgb) return toRgb().rgba(); return qRgba(ct.argb.red >> 8, ct.argb.green >> 8, ct.argb.blue >> 8, ct.argb.alpha >> 8);}/*! Sets the RGBA value to \a rgba. Note that unlike setRgb(QRgb rgb), this function does not ignore the alpha. \sa rgba(), rgb()*/void QColor::setRgba(QRgb rgba){ cspec = Rgb; ct.argb.alpha = qAlpha(rgba) * 0x101; ct.argb.red = qRed(rgba) * 0x101; ct.argb.green = qGreen(rgba) * 0x101; ct.argb.blue = qBlue(rgba) * 0x101; ct.argb.pad = 0;}/*! \fn QRgb QColor::rgb() const Returns the RGB value of the color. The alpha is stripped for compatibility. \sa getRgb(), rgba()*/QRgb QColor::rgb() const{ if (cspec != Invalid && cspec != Rgb) return toRgb().rgb(); return qRgb(ct.argb.red >> 8, ct.argb.green >> 8, ct.argb.blue >> 8);}/*! \overload Sets the RGB value to \a rgb, ignoring the alpha.*/void QColor::setRgb(QRgb rgb){ cspec = Rgb; ct.argb.alpha = 0xffff; ct.argb.red = qRed(rgb) * 0x101; ct.argb.green = qGreen(rgb) * 0x101; ct.argb.blue = qBlue(rgb) * 0x101; ct.argb.pad = 0;}/*! Returns the alpha color component of this color. \sa setAlpha(), alphaF(), {QColor#Alpha-Blended Drawing}{Alpha-Blended Drawing}*/int QColor::alpha() const{ return ct.argb.alpha >> 8; }/*! Sets the alpha of this color to \a alpha. Integer alpha is specified in the range 0-255. \sa alpha(), alphaF(), {QColor#Alpha-Blended Drawing}{Alpha-Blended Drawing}*/void QColor::setAlpha(int alpha){ ct.argb.alpha = alpha * 0x101;}/*! Returns the alpha color component of this color. \sa setAlphaF(), alpha(), {QColor#Alpha-Blended Drawing}{Alpha-Blended Drawing}*/qreal QColor::alphaF() const{ return ct.argb.alpha / qreal(USHRT_MAX); }/*! Sets the alpha of this color to \a alpha. qreal alpha is specified in the range 0.0-1.0. \sa alphaF(), alpha(), {QColor#Alpha-Blended Drawing}{Alpha-Blended Drawing}*/void QColor::setAlphaF(qreal alpha){ qreal tmp = alpha * USHRT_MAX; ct.argb.alpha = qRound(tmp);}/*! Returns the red color component of this color. \sa setRed(), redF(), getRgb()*/int QColor::red() const{ if (cspec != Invalid && cspec != Rgb) return toRgb().red(); return ct.argb.red >> 8;}/*! Sets the red color component of this color to \a red. Int components are specified in the range 0-255. \sa red(), redF(), setRgb()*/void QColor::setRed(int red){ ct.argb.red = red * 0x101;}/*! Returns the green color component of this color. \sa setGreen(), greenF(), getRgb()*/int QColor::green() const{ if (cspec != Invalid && cspec != Rgb) return toRgb().green(); return ct.argb.green >> 8;}/*! Sets the green color component of this color to \a green. Int components are specified in the range 0-255. \sa green(), greenF(), setRgb()*/void QColor::setGreen(int green){ ct.argb.green = green * 0x101;}/*! Returns the blue color component of this color. \sa setBlue(), blueF(), getRgb()*/int QColor::blue() const{ if (cspec != Invalid && cspec != Rgb) return toRgb().blue(); return ct.argb.blue >> 8;}/*! Sets the blue color component of this color to \a blue. Int components are specified in the range 0-255. \sa blue(), blueF(), setRgb()*/void QColor::setBlue(int blue){ ct.argb.blue = blue * 0x101;}/*! Returns the red color component of this color. \sa setRedF(), red(), getRgbF()*/qreal QColor::redF() const{ if (cspec != Invalid && cspec != Rgb) return toRgb().redF(); return ct.argb.red / qreal(USHRT_MAX);}/*! Sets the red color component of this color to \a red. Float components are specified in the range 0.0-1.0. \sa redF(), red(), setRgbF()*/void QColor::setRedF(qreal red){ ct.argb.red = qRound(red * USHRT_MAX);}/*! Returns the green color component of this color. \sa setGreenF(), green(), getRgbF()*/qreal QColor::greenF() const{ if (cspec != Invalid && cspec != Rgb) return toRgb().greenF(); return ct.argb.green / qreal(USHRT_MAX);}/*! Sets the green color component of this color to \a green. Float components are specified in the range 0.0-1.0. \sa greenF(), green(), setRgbF()*/void QColor::setGreenF(qreal green){ ct.argb.green = qRound(green * USHRT_MAX);}/*! Returns the blue color component of this color. \sa setBlueF(), blue(), getRgbF()*/qreal QColor::blueF() const{ if (cspec != Invalid && cspec != Rgb) return toRgb().blueF(); return ct.argb.blue / qreal(USHRT_MAX);}/*! Sets the blue color component of this color to \a blue. Float components are specified in the range 0.0-1.0. \sa blueF(), blue(), setRgbF()*/void QColor::setBlueF(qreal blue){ ct.argb.blue = qRound(blue * USHRT_MAX);}/*! Returns the hue color component of this color. \sa hueF(), getHsv(), {QColor#The HSV Color Model}{The HSV Color Model}*/int QColor::hue() const{ if (cspec != Invalid && cspec != Hsv) return toHsv().hue(); return ct.ahsv.hue == USHRT_MAX ? -1 : ct.ahsv.hue / 100;}/*! Returns the saturation color component of this color. \sa saturationF(), getHsv(), {QColor#The HSV Color Model}{The HSV Color Model}*/int QColor::saturation() const{ if (cspec != Invalid && cspec != Hsv) return toHsv().saturation(); return ct.ahsv.saturation >> 8;}/*! Returns the value color component of this color. \sa valueF(), getHsv(), {QColor#The HSV Color Model}{The HSV Color Model}*/int QColor::value() const{ if (cspec != Invalid && cspec != Hsv) return toHsv().value(); return ct.ahsv.value >> 8;}/*! Returns the hue color component of this color. \sa hue(), getHsvF(), {QColor#The HSV Color Model}{The HSV Color Model}*/qreal QColor::hueF() const{ if (cspec != Invalid && cspec != Hsv) return toHsv().hueF(); return ct.ahsv.hue == USHRT_MAX ? -1.0 : ct.ahsv.hue / 36000.0;}/*! Returns the saturation color component of this color. \sa saturation() getHsvF(), {QColor#The HSV Color Model}{The HSV Color Model}*/qreal QColor::saturationF() const{ if (cspec != Invalid && cspec != Hsv) return toHsv().saturationF(); return ct.ahsv.saturation / qreal(USHRT_MAX);}/*! Returns the value color component of this color. \sa value() getHsvF(), {QColor#The HSV Color Model}{The HSV Color Model}*/qreal QColor::valueF() const
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -