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

📄 qbrush.cpp

📁 qt-x11-opensource-src-4.1.4.tar.gz源码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
}/*!    \fn const QColor &QBrush::color() const    Returns the brush color.    \sa setColor()*//*!    \fn void QBrush::setColor(const QColor &color)    Sets the brush color to the given \a color.    Note that calling setColor() will not make a difference if the    style is a gradient. The same is the case if the style is    Qt::TexturePattern style unless the current texture is a QBitmap.    \sa color()*/void QBrush::setColor(const QColor &c){    detach(d->style);    d->color = c;}/*!    \fn void QBrush::setColor(Qt::GlobalColor color)    \overload    Sets the brush color to the given \a color.*/#ifdef QT3_SUPPORT/*!    \fn void QBrush::setPixmap(const QPixmap &pixmap)    \compat    Sets a custom pattern for this brush.    Use setTexture() instead.*//*!    \fn QPixmap *QBrush::pixmap() const    Returns a pointer to the custom brush pattern.    Use texture() instead.*/QPixmap *QBrush::pixmap() const{    if (d->style != Qt::TexturePattern)        return 0;    QTexturedBrushData *data  = static_cast<QTexturedBrushData*>(d);    return data->pixmap.isNull() ? 0 : &data->pixmap;}#endif/*!    \fn QPixmap QBrush::texture() const    Returns the custom brush pattern, or a null pixmap if no custom brush pattern    has been set.    \sa setTexture()*/QPixmap QBrush::texture() const{    return d->style == Qt::TexturePattern                     ? static_cast<const QTexturedBrushData*>(d)->pixmap : QPixmap();}/*!    Sets the brush pixmap to \a pixmap. The style is set to    Qt::TexturePattern.    The current brush color will only have an effect for monochrome    pixmaps, i.e. for QPixmap::depth() == 1 (\l {QBitmap}{QBitmaps}).    \sa texture()*/void QBrush::setTexture(const QPixmap &pixmap){    if (!pixmap.isNull()) {        detach(Qt::TexturePattern);        QTexturedBrushData *data = static_cast<QTexturedBrushData *>(d);        data->pixmap = pixmap;    } else {        detach(Qt::NoBrush);    }}/*!    Returns the gradient describing this brush.*/const QGradient *QBrush::gradient() const{    if (d->style == Qt::LinearGradientPattern        || d->style == Qt::RadialGradientPattern        || d->style == Qt::ConicalGradientPattern) {        return &static_cast<const QGradientBrushData *>(d)->gradient;    }    return 0;}/*!    Returns true if the brush is fully opaque otherwise false. A brush    is considered opaque if:    \list    \i The alpha component of the color() is 255.    \i Its texture() does not an alpha channel and is not a QBitmap.    \i The colors in the gradient() all have an alpha component that is 255.    \endlist*/bool QBrush::isOpaque() const{    bool opaqueColor = d->color.alpha() == 255;    // Test awfully simple case first    if (d->style == Qt::SolidPattern)        return opaqueColor;    if (d->style == Qt::LinearGradientPattern        || d->style == Qt::RadialGradientPattern        || d->style == Qt::ConicalGradientPattern) {        QGradientStops stops = gradient()->stops();        for (int i=0; i<stops.size(); ++i)            if (stops.at(i).second.alpha() != 255)                return false;        return true;    } else if (d->style == Qt::TexturePattern) {        return !texture().hasAlpha();    }    return opaqueColor;}/*!    \fn bool QBrush::operator!=(const QBrush &brush) const    Returns true if the brush is different from the given \a brush;    otherwise returns false.    Two brushes are different if they have different styles, colors or    pixmaps.    \sa operator==()*//*!    \fn bool QBrush::operator==(const QBrush &brush) const    Returns true if the brush is equal to the given \a brush;    otherwise returns false.    Two brushes are equal if they have equal styles, colors and    pixmaps.    \sa operator!=()*/bool QBrush::operator==(const QBrush &b) const{    if (b.d == d)        return true;    if (b.d->style == d->style && b.d->color == d->color) {        switch (d->style) {        case Qt::TexturePattern: {            QPixmap us = static_cast<QTexturedBrushData *>(d)->pixmap;            QPixmap them = static_cast<QTexturedBrushData *>(b.d)->pixmap;            return ((us.isNull() && them.isNull()) || us.serialNumber() == them.serialNumber());        }        case Qt::LinearGradientPattern:        case Qt::RadialGradientPattern:        case Qt::ConicalGradientPattern:            {                QGradientBrushData *d1 = static_cast<QGradientBrushData *>(d);                QGradientBrushData *d2 = static_cast<QGradientBrushData *>(b.d);                return d1->gradient == d2->gradient;            }        default:            return true;        }    }    return false;}/*!    \fn QBrush::operator const QColor&() const    Returns the brush's color.    Use color() instead.*/#ifndef QT_NO_DEBUG_STREAM/*!  \internal*/QDebug operator<<(QDebug dbg, const QBrush &b){#ifndef Q_BROKEN_DEBUG_STREAM    dbg.nospace() << "QBrush(" << b.color() << ',' << b.style() << ')';    return dbg.space();#else    qWarning("This compiler doesn't support streaming QBrush to QDebug");    return dbg;    Q_UNUSED(b);#endif}#endif/*****************************************************************************  QBrush stream functions *****************************************************************************/#ifndef QT_NO_DATASTREAM/*!    \fn QDataStream &operator<<(QDataStream &stream, const QBrush &brush)    \relates QBrush    Writes the given \a brush to the given \a stream and returns a    reference to the \a stream.    \sa {Format of the QDataStream Operators}*/QDataStream &operator<<(QDataStream &s, const QBrush &b){    s << (quint8)b.style() << b.color();    if (b.style() == Qt::TexturePattern) {        s << b.texture();    } else if (b.style() == Qt::LinearGradientPattern               || b.style() == Qt::RadialGradientPattern               || b.style() == Qt::ConicalGradientPattern) {        const QGradient *gradient = b.gradient();        s << gradient->type();        s << gradient->stops();        if (gradient->type() == QGradient::LinearGradient) {            s << static_cast<const QLinearGradient *>(gradient)->start();            s << static_cast<const QLinearGradient *>(gradient)->finalStop();        } else if (gradient->type() == QGradient::RadialGradient) {            s << static_cast<const QRadialGradient *>(gradient)->center();            s << static_cast<const QRadialGradient *>(gradient)->focalPoint();            s << static_cast<const QRadialGradient *>(gradient)->radius();        } else { // type == Conical            s << static_cast<const QConicalGradient *>(gradient)->center();            s << static_cast<const QConicalGradient *>(gradient)->angle();        }    }    return s;}/*!    \fn QDataStream &operator>>(QDataStream &stream, QBrush &brush)    \relates QBrush    Reads the given \a brush from the given \a stream and returns a    reference to the \a stream.    \sa {Format of the QDataStream Operators}*/QDataStream &operator>>(QDataStream &s, QBrush &b){    quint8 style;    QColor color;    s >> style;    s >> color;    if (style == Qt::TexturePattern) {        QPixmap pm;        s >> pm;        b = QBrush(color, pm);    } else if (style == Qt::LinearGradientPattern               || style == Qt::RadialGradientPattern               || style == Qt::ConicalGradientPattern) {        int type_as_int;        QGradient::Type type;        QGradientStops stops;        s >> type_as_int;        type = QGradient::Type(type_as_int);        s >> stops;        if (type == QGradient::LinearGradient) {            QPointF p1, p2;            s >> p1;            s >> p2;            QLinearGradient lg(p1, p2);            lg.setStops(stops);            b = QBrush(lg);        } else if (type == QGradient::RadialGradient) {            QPointF center, focal;            double radius;            s >> center;            s >> focal;            s >> radius;            QRadialGradient rg(center, radius, focal);            rg.setStops(stops);            b = QBrush(rg);        } else { // type == QGradient::ConicalGradient            QPointF center;            double angle;            s >> center;            s >> angle;            QConicalGradient cg(center, angle);            cg.setStops(stops);            b = QBrush(cg);        }    } else {        b = QBrush(color, (Qt::BrushStyle)style);    }    return s;}#endif // QT_NO_DATASTREAM/******************************************************************************* * QGradient implementations *//*!    \class QGradient    \ingroup multimedia    \brief The QGradient class is used in combination with QBrush to    specify gradient fills.    Qt currently supports three types of gradient fills:    \list    \o \e Linear gradients interpolate colors between start and end points.    \o \e Radial gradients interpolate colors between a focal point and end        points on a circle surrounding it.    \o \e Conical gradients interpolate colors around a center point.    \endlist    A gradient's type can be retrieved using the type() function.    Each of the types is represented by a subclass of QGradient:    \table    \row    \o \inlineimage qgradient-linear.png    \o \inlineimage qgradient-radial.png    \o \inlineimage qgradient-conical.png    \header    \o QLinearGradient    \o QRadialGradient    \o QConicalGradient    \endtable    The colors in a gradient is defined using stop points of the    QGradientStop type, i.e. a position and a color.  Use the    setColorAt() function to define a single stop    point. Alternatively, use the setStops() function to define    several stop points in one go. Note that the latter function \e    replaces the current set of stop points.    It is the gradient's complete set of stop points (accessible    through the stops() function) that describes how the gradient area    should be filled. If no stop points have been specified, a    gradient of black at 0 to white at 1 is used.    A diagonal linear gradient from black at (100, 100) to white at    (200, 200) could be specified like this:    \quotefromfile snippets/brush/brush.cpp    \skipto LINEAR    \skipto QLinearGradient    \printuntil Qt::white    A gradient can have an arbitrary number of stop points. The    following would create a radial gradient starting with    red in the center, blue and then green on the edges:    \quotefromfile snippets/brush/brush.cpp    \skipto RADIAL    \skipto QRadialGradient    \printuntil Qt::green    It is possible to repeat or reflect the gradient outside its area    by specifiying the \l {QGradient::Spread}{spread method} using the    setSpread() function. The default is to pad the outside area with    the color at the closest stop point. The currently set \l    {QGradient::Spread}{spread method} can be retrieved using the    spread() function. The QGradient::Spread enum defines three    different methods:    \table    \row    \o \inlineimage qradialgradient-pad.png    \o \inlineimage qradialgradient-repeat.png    \o \inlineimage qradialgradient-reflect.png    \row    \o \l {QGradient::PadSpread}{PadSpread}    \o \l {QGradient::RepeatSpread}{RepeatSpread}    \o \l {QGradient::ReflectSpread}{ReflectSpread}    \endtable    Note that the setSpread() function only has effect for linear and    radial gradients. The reason is that the conical gradient is    closed by definition, i.e. the \e conical gradient fills the    entire circle from 0 - 360 degrees, while the boundary of a radial    or a linear gradient can be specified through its radius or final    stop points, respectively.    \sa {demos/gradients}{The Gradients Demo}, QBrush*//*!    \internal*/QGradient::QGradient(){}/*!    \enum QGradient::Type    Specifies the type of gradient.    \value LinearGradient  Interpolates colors between start and end points    (QLinearGradient).    \value RadialGradient Interpolate colors between a focal point and end    points on a circle surrounding it (QRadialGradient).    \value ConicalGradient Interpolate colors around a center point (QConicalGradient).    \value NoGradient No gradient is used.    \sa type()*//*!    \enum QGradient::Spread    Specifies how the area outside the gradient area should be    filled.    \value PadSpread The area is filled with the closest stop    color. This is the default.    \value RepeatSpread The gradient  is repeated outside the gradient    area.    \value ReflectSpread The gradient is reflected outside the    gradient area.    \sa spread(), setSpread()*//*!    \fn void QGradient::setSpread(Spread method)    Specifies the spread \a method that should be used for this    gradient.    Note that this function only has effect for linear and radial    gradients.

⌨️ 快捷键说明

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