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

📄 qcolor.cpp

📁 qt-x11-opensource-src-4.1.4.tar.gz源码
💻 CPP
📖 第 1 页 / 共 4 页
字号:
{    if (cspec != Invalid && cspec != Hsv)        return toHsv().valueF();    return ct.ahsv.value / qreal(USHRT_MAX);}/*!    Returns the cyan color component of this color.    \sa cyanF(), getCmyk(), {QColor#The CMYK Color Model}{The CMYK    Color Model}*/int QColor::cyan() const{    if (cspec != Invalid && cspec != Cmyk)        return toCmyk().cyan();    return ct.acmyk.cyan >> 8;}/*!    Returns the magenta color component of this color.    \sa magentaF(), getCmyk(), {QColor#The CMYK Color Model}{The CMYK    Color Model}*/int QColor::magenta() const{    if (cspec != Invalid && cspec != Cmyk)        return toCmyk().magenta();    return ct.acmyk.magenta >> 8;}/*!    Returns the yellow color component of this color.    \sa yellowF(), getCmyk(), {QColor#The CMYK Color Model}{The CMYK    Color Model}*/int QColor::yellow() const{    if (cspec != Invalid && cspec != Cmyk)        return toCmyk().yellow();    return ct.acmyk.yellow >> 8;}/*!    Returns the black color component of this color.    \sa blackF(), getCmyk(), {QColor#The CMYK Color Model}{The CMYK    Color Model}*/int QColor::black() const{    if (cspec != Invalid && cspec != Cmyk)        return toCmyk().black();    return ct.acmyk.black >> 8;}/*!    Returns the cyan color component of this color.    \sa cyan(), getCmykF(), {QColor#The CMYK Color Model}{The CMYK    Color Model}*/qreal QColor::cyanF() const{    if (cspec != Invalid && cspec != Cmyk)        return toCmyk().cyanF();    return ct.acmyk.cyan / qreal(USHRT_MAX);}/*!    Returns the magenta color component of this color.    \sa magenta(), getCmykF(), {QColor#The CMYK Color Model}{The CMYK    Color Model}*/qreal QColor::magentaF() const{    if (cspec != Invalid && cspec != Cmyk)        return toCmyk().magentaF();    return ct.acmyk.magenta / qreal(USHRT_MAX);}/*!    Returns the yellow color component of this color.     \sa yellow(), getCmykF(), {QColor#The CMYK Color Model}{The CMYK    Color Model}*/qreal QColor::yellowF() const{    if (cspec != Invalid && cspec != Cmyk)        return toCmyk().yellowF();    return ct.acmyk.yellow / qreal(USHRT_MAX);}/*!    Returns the black color component of this color.    \sa black(), getCmykF(), {QColor#The CMYK Color Model}{The CMYK    Color Model}*/qreal QColor::blackF() const{    if (cspec != Invalid && cspec != Cmyk)        return toCmyk().blackF();    return ct.acmyk.black / qreal(USHRT_MAX);}/*!    Create and returns an RGB QColor based on this color.    \sa fromRgb(), convertTo(), isValid()*/QColor QColor::toRgb() const{    if (!isValid() || cspec == Rgb)        return *this;    QColor color;    color.cspec = Rgb;    color.ct.argb.alpha = ct.argb.alpha;    color.ct.argb.pad = 0;    switch (cspec) {    case 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;            }            // chromatic case            const qreal h = ct.ahsv.hue / 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 * (1.0 - s);            if (i & 1) {                const qreal q = v * (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:                    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:                    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 * (1.0 - (s * (1.0 - f)));                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:                    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:                    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;        }    case Cmyk:        {            const qreal c = ct.acmyk.cyan / qreal(USHRT_MAX);            const qreal m = ct.acmyk.magenta / qreal(USHRT_MAX);            const qreal y = ct.acmyk.yellow / qreal(USHRT_MAX);            const qreal k = ct.acmyk.black / qreal(USHRT_MAX);            color.ct.argb.red   = qRound((1.0 - (c * (1.0 - k) + k)) * USHRT_MAX);            color.ct.argb.green = qRound((1.0 - (m * (1.0 - k) + k)) * USHRT_MAX);            color.ct.argb.blue  = qRound((1.0 - (y * (1.0 - k) + k)) * USHRT_MAX);            break;        }    default:        break;    }    return color;}#define Q_MAX_3(a, b, c) ( ( a > b && a > c) ? a : (b > c ? b : c) )#define Q_MIN_3(a, b, c) ( ( a < b && a < c) ? a : (b < c ? b : c) )/*!    Creates and returns an HSV QColor based on this color.    \sa fromHsv(), convertTo(), isValid(), {QColor#The HSV Color    Model}{The HSV Color Model}*/QColor QColor::toHsv() const{    if (!isValid())        return *this;    if (cspec != Rgb)        return toRgb().toHsv();    QColor color;    color.cspec = Hsv;    color.ct.ahsv.alpha = ct.argb.alpha;    color.ct.ahsv.pad = 0;    const qreal r = ct.argb.red   / qreal(USHRT_MAX);    const qreal g = ct.argb.green / qreal(USHRT_MAX);    const qreal b = ct.argb.blue  / qreal(USHRT_MAX);    const qreal max = Q_MAX_3(r, g, b);    const qreal min = Q_MIN_3(r, g, b);    const qreal delta = max - min;    color.ct.ahsv.value = qRound(max * USHRT_MAX);    if (delta == 0.0) {        // achromatic case, hue is undefined        color.ct.ahsv.hue = USHRT_MAX;        color.ct.ahsv.saturation = 0;    } else {        // chromatic case        qreal hue = 0;        color.ct.ahsv.saturation = qRound((delta / max) * USHRT_MAX);        if (r == max) {            hue = ((g - b) /delta);        } else if (g == max) {            hue = (2.0 + (b - r) / delta);        } else if (b == max) {            hue = (4.0 + (r - g) / delta);        } else {            Q_ASSERT_X(false, "QColor::toHsv", "internal error");        }        hue *= 60.0;        if (hue < 0.0)            hue += 360.0;        color.ct.ahsv.hue = qRound(hue * 100);    }    return color;}/*!    Creates and returns a CMYK QColor based on this color.    \sa fromCmyk(), convertTo(), isValid(), {QColor#The CMYK Color    Model}{The CMYK Color Model}*/QColor QColor::toCmyk() const{    if (!isValid())        return *this;    if (cspec != Rgb)        return toRgb().toCmyk();    QColor color;    color.cspec = Cmyk;    color.ct.acmyk.alpha = ct.argb.alpha;    // rgb -> cmy    const qreal r = ct.argb.red   / qreal(USHRT_MAX);    const qreal g = ct.argb.green / qreal(USHRT_MAX);    const qreal b = ct.argb.blue  / qreal(USHRT_MAX);    qreal c = 1.0 - r;    qreal m = 1.0 - g;    qreal y = 1.0 - b;    // cmy -> cmyk    const qreal k = qMin(c, qMin(m, y));    if (!qFuzzyCompare(k,1)) {        c = (c - k) / (1.0 - k);        m = (m - k) / (1.0 - k);        y = (y - k) / (1.0 - k);    }    color.ct.acmyk.cyan    = qRound(c * USHRT_MAX);    color.ct.acmyk.magenta = qRound(m * USHRT_MAX);    color.ct.acmyk.yellow  = qRound(y * USHRT_MAX);    color.ct.acmyk.black   = qRound(k * USHRT_MAX);    return color;}QColor QColor::convertTo(QColor::Spec colorSpec) const{    if (colorSpec == cspec)        return *this;    switch (colorSpec) {    case Rgb:        return toRgb();    case Hsv:        return toHsv();    case Cmyk:        return toCmyk();    case Invalid:        break;    }    return QColor(); // must be invalid}/*!    Static convenience function that returns a QColor constructed from    the given QRgb value \a rgb.    Note that the alpha component of \a rgb is ignored (i.e. it is    automatically set to 255), use the fromRgba() function to include the    alpha-channel specified by the given QRgb value.    \sa fromRgba(), fromRgbF(), toRgb(), isValid()*/QColor QColor::fromRgb(QRgb rgb){    return fromRgb(qRed(rgb), qGreen(rgb), qBlue(rgb));}/*!    Static convenience function that returns a QColor constructed from    the given QRgb value \a rgba.    Note that unlike the fromRgb() function, the alpha-channel    specified by the given QRgb value is included.    \sa fromRgb(), isValid()*/QColor QColor::fromRgba(QRgb rgba){    return fromRgb(qRed(rgba), qGreen(rgba), qBlue(rgba), qAlpha(rgba));}/*!    Static convenience function that returns a QColor constructed from    the RGB color values, \a r (red), \a g (green), \a b (blue),    and \a a (alpha-channel, i.e. transparency).    All the values must be in the range 0-255.    \sa toRgb(), fromRgbF(), isValid()*/QColor QColor::fromRgb(int r, int g, int b, int a){    if (r < 0 || r > 255        || g < 0 || g > 255        || b < 0 || b > 255        || a < 0 || a > 255) {        qWarning("QColor::fromRgb: RGB paramaters out of range");        return QColor();    }    QColor color;    color.cspec = Rgb;    color.ct.argb.alpha = a * 0x101;    color.ct.argb.red   = r * 0x101;    color.ct.argb.green = g * 0x101;    color.ct.argb.blue  = b * 0x101;    color.ct.argb.pad   = 0;    return color;}/*!    Static convenience function that returns a QColor constructed from    the RGB color values, \a r (red), \a g (green), \a b (blue), and    \a a (alpha-channel, i.e. transparency).    All the values must be in the range 0.0-1.0.    \sa fromRgb(), toRgb(), isValid()*/QColor QColor::fromRgbF(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::fromRgb: RGB paramaters out of range");        return QColor();    }    QColor color;    color.cspec = Rgb;    color.ct.argb.alpha = qRound(a * USHRT_MAX);    color.ct.argb.red   = qRound(r * USHRT_MAX);    color.ct.argb.green = qRound(g * USHRT_MAX);    color.ct.argb.blue  = qRound(b * USHRT_MAX);    color.ct.argb.pad   = 0;    return color;}/*!    Static convenience function that returns a QColor constructed from    the HSV color values, \a h (hue), \a s (saturation), \a v (value),    and \a a (alpha-channel, i.e. transparency).    The value of \a s, \a v, and \a a must all be in the range    0-255; the value of \a h must be in the range 0-359.    \sa toHsv(), fromHsvF(), isValid(), {QColor#The HSV Color    Model}{The HSV Color Model}*/QColor QColor::fromHsv(int h, int s, int v, int a){    if (((h < 0 || h >= 360) && h != -1)        || s < 0 || s > 255        || v < 0 || v > 255        || a < 0 || a > 255) {        qWarning("QColor::fromHsv: HSV parameters out of range");        return QColor();    }    QColor color;    color.cspec = Hsv;    color.ct.ahsv.alpha      = a * 0x101;    color.ct.ahsv.hue        = h == -1 ? USHRT_MAX : (h % 360) * 100;    color.ct.ahsv.saturation = s * 0x101;    color.ct.ahsv.value      = v * 0x101;    color.ct.ahsv.pad        = 0;    return color;}/*!    \overload    Static convenience function that returns a QColor constructed from    the HSV color values, \a h (hue), \a s (saturation), \a v (value),    and \a a (alpha-channel, i.e. transparency).    All the values must be in the range 0.0-1.0.    \sa toHsv(), fromHsv(), isValid(), {QColor#The HSV Color    Model}{The HSV Color Model}*/QColor QColor::fromHsvF(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::fromHsv: HSV parameters out of range");        return QColor();    }    QColor color;    color.cspec = Hsv;    color.ct.ahsv.alpha      = qRound(a * USHRT_MAX);    color.ct.ahsv.hue        = h == -1.0 ? USHRT_MAX : qRound(h * 36000);    color.ct.ahsv.saturation = qRound(s * USHRT_MAX);    color.ct.ahsv.value      = qRound(v * USHRT_MAX);    color.ct.ahsv.pad        = 0;    return color;}/*!    Sets the contents pointed to by \a c, \a m, \a y, \a k, and \a a,    to the cyan, magenta, yellow, black, and alpha-channel    (transparency) components of the color's CMYK value.    Note that the components can be retrieved individually using the    cyan(), magenta(), yellow(), black() and alpha() functions.    \sa setCmyk(), {QColor#The CMYK Color Model}{The CMYK Color Model}*/void QColor::getCmyk(int *c, int *m, int *y, int *k, int *a){    if (!c || !m || !y || !k)        return;    if (cspec != Invalid && cspec != Cmyk) {        toCmyk().getCmyk(c, m, y, k, a);        return;    }    *c = ct.acmyk.cyan >> 8;    *m = ct.acmyk.magenta >> 8;    *y = ct.acmyk.yellow >> 8;    *k = ct.acmyk.black >> 8;    if (a)        *a = ct.acmyk.alpha >> 8;}/*!    Sets the contents pointed to by \a c, \a m, \a y, \a k, and \a a,    to the cyan, magenta, yellow, black, and alpha-channel    (transparency) components of the color's CMYK value.    Note that the components can be retrieved individually using the    cyanF(), magentaF(), yellowF(), blackF() and alphaF() functions.    \sa setCmykF(), {QColor#The CMYK Color Model}{The CMYK Color Model}*/void QColor::getCmykF(qreal *c, qreal *m, qreal *y, qreal *k, qreal *a){    if (!c || !m || !y || !k)        return;    if (cspec != Invalid && cspec != Cmyk) {        toCmyk().getCmykF(c, m, y, k, a);        return;    }

⌨️ 快捷键说明

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