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

📄 qcolor.cpp

📁 qt-x11-opensource-src-4.1.4.tar.gz源码
💻 CPP
📖 第 1 页 / 共 4 页
字号:
    *c = ct.acmyk.cyan    / qreal(USHRT_MAX);    *m = ct.acmyk.magenta / qreal(USHRT_MAX);    *y = ct.acmyk.yellow  / qreal(USHRT_MAX);    *k = ct.acmyk.black   / qreal(USHRT_MAX);    if (a)        *a = ct.acmyk.alpha / qreal(USHRT_MAX);}/*!    Sets the color to CMYK values, \a c (cyan), \a m (magenta), \a y (yellow),    \a k (black), and \a a (alpha-channel, i.e. transparency).    All the values must be in the range 0-255.    \sa getCmyk(), setCmykF(), {QColor#The CMYK Color Model}{The    CMYK Color Model}*/void QColor::setCmyk(int c, int m, int y, int k, int a){    if (c < 0 || c > 255        || m < 0 || m > 255        || y < 0 || y > 255        || k < 0 || k > 255        || a < 0 || a > 255) {        qWarning("QColor::setCmyk: CMYK paramaters out of range");        return;    }    cspec = Cmyk;    ct.acmyk.alpha   = a * 0x101;    ct.acmyk.cyan    = c * 0x101;    ct.acmyk.magenta = m * 0x101;    ct.acmyk.yellow  = y * 0x101;    ct.acmyk.black   = k * 0x101;}/*!    \overload    Sets the color to CMYK values, \a c (cyan), \a m (magenta), \a y (yellow),    \a k (black), and \a a (alpha-channel, i.e. transparency).    All the values must be in the range 0.0-1.0.    \sa getCmykF() setCmyk(), {QColor#The CMYK Color Model}{The CMYK    Color Model}*/void QColor::setCmykF(qreal c, qreal m, qreal y, qreal k, qreal a){    if (c < 0.0 || c > 1.0        || m < 0.0 || m > 1.0        || y < 0.0 || y > 1.0        || k < 0.0 || k > 1.0        || a < 0.0 || a > 1.0) {        qWarning("QColor::setCmyk: CMYK paramaters out of range");        return;    }    cspec = Cmyk;    ct.acmyk.alpha   = qRound(a * USHRT_MAX);    ct.acmyk.cyan    = qRound(c * USHRT_MAX);    ct.acmyk.magenta = qRound(m * USHRT_MAX);    ct.acmyk.yellow  = qRound(y * USHRT_MAX);    ct.acmyk.black   = qRound(k * USHRT_MAX);}/*!    Static convenience function that returns a QColor constructed from    the given CMYK color values: \a c (cyan), \a m (magenta), \a y    (yellow), \a k (black), and \a a (alpha-channel,    i.e. transparency).    All the values must be in the range 0-255.    \sa toCmyk(), fromCmykF(), isValid(), {QColor#The CMYK Color Model}{The CMYK    Color Model}*/QColor QColor::fromCmyk(int c, int m, int y, int k, int a){    if (c < 0 || c > 255        || m < 0 || m > 255        || y < 0 || y > 255        || k < 0 || k > 255        || a < 0 || a > 255) {        qWarning("QColor::fromCmyk: CMYK paramaters out of range");        return QColor();    }    QColor color;    color.cspec = Cmyk;    color.ct.acmyk.alpha   = a * 0x101;    color.ct.acmyk.cyan    = c * 0x101;    color.ct.acmyk.magenta = m * 0x101;    color.ct.acmyk.yellow  = y * 0x101;    color.ct.acmyk.black   = k * 0x101;    return color;}/*!    \overload    Static convenience function that returns a QColor constructed from    the given CMYK color values: \a c (cyan), \a m (magenta), \a y    (yellow), \a k (black), and \a a (alpha-channel,    i.e. transparency).    All the values must be in the range 0.0-1.0.    \sa toCmyk(), fromCmyk(), isValid(), {QColor#The CMYK Color    Model}{The CMYK Color Model}*/QColor QColor::fromCmykF(qreal c, qreal m, qreal y, qreal k, qreal a){    if (c < 0.0 || c > 1.0        || m < 0.0 || m > 1.0        || y < 0.0 || y > 1.0        || k < 0.0 || k > 1.0        || a < 0.0 || a > 1.0) {        qWarning("QColor::fromCmyk: CMYK paramaters out of range");        return QColor();    }    QColor color;    color.cspec = Cmyk;    color.ct.acmyk.alpha   = qRound(a * USHRT_MAX);    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;}/*!    Returns a lighter (or darker) color, but does not change this    object.    If the \a factor is greater than 100, this functions returns a    lighter color. Setting \a factor to 150 returns a color that is    50% brighter. If the \a factor is less than 100, the return color    is darker, but we recommend using the dark() function for this    purpose. If the \a factor is 0 or negative, the return value is    unspecified.    The function converts the current RGB color to HSV, multiplies the    value (V) component by \a factor and converts the color back to    RGB.    \sa dark(), isValid()*/QColor QColor::light(int factor) const{    if (factor <= 0)                                // invalid lightness factor        return *this;    else if (factor < 100)                        // makes color darker        return dark(10000/factor);    QColor hsv = toHsv();    int s = hsv.ct.ahsv.saturation;    int v = hsv.ct.ahsv.value;    v = (factor*v)/100;    if (v > USHRT_MAX) {        // overflow... adjust saturation        s -= v - USHRT_MAX;        if (s < 0)            s = 0;        v = USHRT_MAX;    }    hsv.ct.ahsv.saturation = s;    hsv.ct.ahsv.value = v;    // convert back to same color spec as original color    return hsv.convertTo(cspec);}/*!    Returns a darker (or lighter) color, but does not change this    object.    If the \a factor is greater than 100, this functions returns a    darker color. Setting \a factor to 300 returns a color that has    one-third the brightness. If the \a factor is less than 100, the    return color is lighter, but we recommend using the light()    function for this purpose. If the \a factor is 0 or negative, the    return value is unspecified.    The function converts the current RGB color to HSV, divides the    value (V) component by \a factor and converts the color back to    RGB.    \sa light(), isValid()*/QColor QColor::dark(int factor) const{    if (factor <= 0)                                // invalid darkness factor        return *this;    else if (factor < 100)                        // makes color lighter        return light(10000/factor);    QColor hsv = toHsv();    hsv.ct.ahsv.value = (hsv.ct.ahsv.value * 100) / factor;    // convert back to same color spec as original color    return hsv.convertTo(cspec);}/*!    Assigns a copy of the color \a color to this color, and returns a    reference to it.*/QColor &QColor::operator=(const QColor &color){    cspec = color.cspec;    ct.argb = color.ct.argb;    return *this;}/*! \overload    Assigns a copy of the \a color and returns a reference to this color. */QColor &QColor::operator=(Qt::GlobalColor color){    return operator=(QColor(color));}/*!    Returns true if this color has the same RGB value as the color \a    color; otherwise returns false.*/bool QColor::operator==(const QColor &color) const{    return (cspec == color.cspec            && ct.argb.alpha == color.ct.argb.alpha            && ct.argb.red   == color.ct.argb.red            && ct.argb.green == color.ct.argb.green            && ct.argb.blue  == color.ct.argb.blue            && ct.argb.pad   == color.ct.argb.pad);}/*!    Returns true if this color has a different RGB value from the    color \a color; otherwise returns false.*/bool QColor::operator!=(const QColor &color) const{ return !operator==(color); }/*!   Returns the color as a QVariant*/QColor::operator QVariant() const{    return QVariant(QVariant::Color, this);}/*! \internal    Marks the color as invalid and sets all components to zero (alpha    is set to fully opaque for compatibility with Qt 3).*/void QColor::invalidate(){    cspec = Invalid;    ct.argb.alpha = USHRT_MAX;    ct.argb.red = 0;    ct.argb.green = 0;    ct.argb.blue = 0;    ct.argb.pad = 0;}#ifdef QT3_SUPPORT/*!    Returns the pixel value used by the underlying window system to    refer to a color.    Use QColormap::pixel() instead.    \oldcode        QColor myColor;        uint pixel = myColor.pixel(screen);    \newcode        QColormap cmap = QColormap::instance(screen);        uint pixel  = cmap.pixel(*this);    \endcode*/uint QColor::pixel(int screen) const{    QColormap cmap = QColormap::instance(screen);    return cmap.pixel(*this);}#endif // QT3_SUPPORT/*****************************************************************************  QColor stream functions *****************************************************************************/#ifndef QT_NO_DEBUG_STREAMQDebug operator<<(QDebug dbg, const QColor &c){#ifndef Q_BROKEN_DEBUG_STREAM    if (!c.isValid())        dbg.nospace() << "QColor(Invalid)";    else if (c.spec() == QColor::Rgb)        dbg.nospace() << "QColor(ARGB " << c.alphaF() << ", " << c.redF() << ", " << c.greenF() << ", " << c.blueF() << ")";    else if (c.spec() == QColor::Hsv)        dbg.nospace() << "QColor(AHSV " << c.alphaF() << ", " << c.hueF() << ", " << c.saturationF() << ", " << c.valueF() << ")";    else if (c.spec() == QColor::Cmyk)        dbg.nospace() << "QColor(ACMYK " << c.alphaF() << ", " << c.cyanF() << ", " << c.magentaF() << ", " << c.yellowF() << ", "                      << c.blackF()<< ")";    return dbg.space();#else    qWarning("This compiler doesn't support streaming QColor to QDebug");    return dbg;    Q_UNUSED(c);#endif}#endif#ifndef QT_NO_DATASTREAM/*!    \fn QDataStream &operator<<(QDataStream &stream, const QColor &color)    \relates QColor    Writes the \a color to the \a stream.    \sa {Format of the QDataStream Operators}*/QDataStream &operator<<(QDataStream &stream, const QColor &color){    if (stream.version() < 7) {        quint32 p = (quint32)color.rgb();        if (stream.version() == 1) // Swap red and blue            p = ((p << 16) & 0xff0000) | ((p >> 16) & 0xff) | (p & 0xff00ff00);        return stream << p;    }    qint8   s = color.cspec;    quint16 a = color.ct.argb.alpha;    quint16 r = color.ct.argb.red;    quint16 g = color.ct.argb.green;    quint16 b = color.ct.argb.blue;    quint16 p = color.ct.argb.pad;    stream << s;    stream << a;    stream << r;    stream << g;    stream << b;    stream << p;    return stream;}/*!    \fn QDataStream &operator>>(QDataStream &stream, QColor &color)    \relates QColor    Reads the \a color from the \a stream.    \sa { Format of the QDataStream Operators}*/QDataStream &operator>>(QDataStream &stream, QColor &color){    if (stream.version() < 7) {        quint32 p;        stream >> p;        if (stream.version() == 1) // Swap red and blue            p = ((p << 16) & 0xff0000) | ((p >> 16) & 0xff) | (p & 0xff00ff00);        color.setRgb(p);        return stream;    }    qint8 s;    quint16 a, r, g, b, p;    stream >> s;    stream >> a;    stream >> r;    stream >> g;    stream >> b;    stream >> p;    color.cspec = QColor::Spec(s);    color.ct.argb.alpha = a;    color.ct.argb.red   = r;    color.ct.argb.green = g;    color.ct.argb.blue  = b;    color.ct.argb.pad   = p;    return stream;}#endif/*****************************************************************************  QColor global functions (documentation only) *****************************************************************************//*!    \fn int qRed(QRgb rgb)    \relates QColor    Returns the red component of the ARGB quadruplet \a rgb.    \sa qRgb(), QColor::red()*//*!    \fn int qGreen(QRgb rgb)    \relates QColor    Returns the green component of the ARGB quadruplet \a rgb.    \sa qRgb(), QColor::green()*//*!    \fn int qBlue(QRgb rgb)    \relates QColor    Returns the blue component of the ARGB quadruplet \a rgb.    \sa qRgb(), QColor::blue()*//*!    \fn int qAlpha(QRgb rgba)    \relates QColor    Returns the alpha component of the ARGB quadruplet \a rgba.    \sa qRgb(), QColor::alpha()*//*!    \fn QRgb qRgb(int r, int g, int b)    \relates QColor    Returns the ARGB quadruplet (255, \a{r}, \a{g}, \a{b}).    \sa qRgba(), qRed(), qGreen(), qBlue()*//*!    \fn QRgb qRgba(int r, int g, int b, int a)    \relates QColor    Returns the ARGB quadruplet (\a{a}, \a{r}, \a{g}, \a{b}).    \sa qRgb(), qRed(), qGreen(), qBlue()*//*!    \fn int qGray(int r, int g, int b)    \relates QColor    Returns a gray value (0 to 255) from the (\a r, \a g, \a b)    triplet.    The gray value is calculated using the formula (\a r * 11 + \a g *    16 + \a b * 5)/32.*//*!    \fn int qGray(QRgb rgb)    \overload    \relates QColor    Returns a gray value (0 to 255) from the given ARGB quadruplet \a    rgb.    The gray value is calculated using the formula (R * 11 + G *    16 + B * 5)/32.  Note that the alpha-channel is ignored.*//*!    \fn QColor::QColor(int x, int y, int z, Spec colorSpec)    Use one of the other QColor constructors, or one of the static    convenience functions, instead.*//*!    \fn QColor::rgb(int *r, int *g, int *b) const    Use getRgb() instead.*//*!    \fn QColor::hsv(int *h, int *s, int *v) const    Use getHsv() instead.*//*!    \fn QColor QColor::convertTo(Spec colorSpec) const    Creates a copy of \e this color in the format specified by \a    colorSpec.    \sa spec(), toCmyk(), toHsv(), toRgb(), isValid()*//*!    \typedef QRgb    \relates QColor    An ARGB quadruplet on the format #AARRGGBB, equivalent to an    unsigned int.    Note that the type also holds a value for the alpha-channel. The    default alpha channel is \c ff, i.e opaque. For more information,    see the \l {QColor#Alpha-Blended Drawing}{Alpha-Blended Drawing}    section.    \sa QColor::rgb(), QColor::rgba()*/

⌨️ 快捷键说明

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