⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qcolor.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    The color is left invalid if the \a name cannot be parsed.    \sa setNamedColor(), name(), isValid()*//*!    \fn QColor::QColor(const char *name)    Constructs a named color in the same way as setNamedColor() using    the given \a name.    The color is left invalid if the \a name cannot be parsed.    \sa setNamedColor(), name(), isValid()*//*!    \fn QColor::QColor(const QColor &color)    Constructs a color that is a copy of \a color.    \sa isValid()*//*!    \fn bool QColor::isValid() const    Returns true if the color is valid; otherwise returns false.*//*!    Returns the name of the color in the format "#RRGGBB"; i.e. a "#"    character followed by three two-digit hexadecimal numbers.    \sa setNamedColor()*/QString QColor::name() const{    QString s;    s.sprintf("#%02x%02x%02x", red(), green(), blue());    return s;}/*!    Sets the RGB value of this QColor to \a name, which may be in one    of these formats:    \list    \i #RGB (each of R, G, and B is a single hex digit)    \i #RRGGBB    \i #RRRGGGBBB    \i #RRRRGGGGBBBB    \i A name from the list of colors defined in the list of \l{SVG color keyword names}       provided by the World Wide Web Consortium; for example, "steelblue" or "gainsboro".       These color names work on all platforms.    \i \c transparent - representing the absence of a color.    \i \e{X11 only}: If allowX11ColorNames() returns true, any valid X11 color name. See       the documentation for \c XParseColor() for information about valid X11 color names.    \endlist    The color is invalid if \a name cannot be parsed.    \sa QColor(), name(), isValid(), allowX11ColorNames()*/void QColor::setNamedColor(const QString &name){    if (name.isEmpty()) {        invalidate();        return;    }    if (name.startsWith(QLatin1Char('#'))) {        QRgb rgb;        if (qt_get_hex_rgb(name.constData(), name.length(), &rgb)) {            setRgb(rgb);        } else {            qWarning("QColor::setNamedColor: Could not parse color '%s'", name.toLatin1().constData());            invalidate();        }        return;    }#ifndef QT_NO_COLORNAMES    QRgb rgb;    if (qt_get_named_rgb(name.constData(), name.length(), &rgb)) {        setRgb(rgb);    } else#endif    {#ifdef Q_WS_X11        XColor result;        if (allowX11ColorNames()            && QApplication::instance()            && QX11Info::display()            && XParseColor(QX11Info::display(), QX11Info::appColormap(), name.toLatin1().constData(), &result)) {            setRgb(result.red >> 8, result.green >> 8, result.blue >> 8);        } else#endif        {            qWarning("QColor::setNamedColor: Unknown color name '%s'", name.toLatin1().constData());            invalidate();        }    }}/*!    Returns a QStringList containing the color names Qt knows about.    \sa {QColor#Predefined Colors}{Predefined Colors}*/QStringList QColor::colorNames(){#ifndef QT_NO_COLORNAMES    return qt_get_colornames();#else    return QStringList();#endif}/*!    Sets the contents pointed to by \a h, \a s, \a v, and \a a, to the    hue, saturation, value, and alpha-channel (transparency)    components of the color's HSV value.    Note that the components can be retrieved individually using the    hueF(), saturationF(), valueF() and alphaF() functions.    \sa setHsv() {QColor#The HSV Color Model}{The HSV Color Model}*/void QColor::getHsvF(qreal *h, qreal *s, qreal *v, qreal *a) const{        if (!h || !s || !v)        return;    if (cspec != Invalid && cspec != Hsv) {        toHsv().getHsvF(h, s, v, a);        return;    }    *h = ct.ahsv.hue == USHRT_MAX ? -1.0 : ct.ahsv.hue / 36000.0;    *s = ct.ahsv.saturation / qreal(USHRT_MAX);    *v = ct.ahsv.value / qreal(USHRT_MAX);    if (a)        *a = ct.ahsv.alpha / qreal(USHRT_MAX);}/*!    Sets the contents pointed to by \a h, \a s, \a v, and \a a, to the    hue, saturation, value, and alpha-channel (transparency)    components of the color's HSV value.    Note that the components can be retrieved individually using the    hue(), saturation(), value() and alpha() functions.    \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::setHsvF: 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::setRgbF: RGB parameters 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 parameters 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){    QCOLOR_INT_RANGE_CHECK("QColor::setAlpha", alpha);    ct.argb.alpha = alpha * 0x101;}/*!    Returns the alpha color component of this color.    \sa setAlphaF(), alpha(),  {QColor#Alpha-Blended    Drawing}{Alpha-Blended Drawing}*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -