QBrush Class Reference

#include <qbrush.h>

Collaboration diagram for QBrush:

Collaboration graph
[legend]
List of all members.

Detailed Description

The QBrush class defines the fill pattern of shapes drawn by QPainter.

A brush has a style, a color, a gradient and a texture.

The brush style() defines the fill pattern using the Qt::BrushStyle enum. The default brush style is Qt::NoBrush (depending on how you construct a brush). This style tells the painter to not fill shapes. The standard style for filling is Qt::SolidPattern. The style can be set when the brush is created using the appropriate constructor, and in addition the setStyle() function provides means for altering the style once the brush is constructed.

Brush Styles

The brush color() defines the color of the fill pattern. The color can either be one of Qt's predefined colors, Qt::GlobalColor, or any other custom QColor. The currently set color can be retrieved and altered using the color() and setColor() functions, respectively.

The gradient() defines the gradient fill used when the current style is either Qt::LinearGradientPattern, Qt::RadialGradientPattern or Qt::ConicalGradientPattern. The gradient can only be set when constructing the brush, while the texture() can be set using the appropriate constructor or by using the setTexture() function. The texture() defines the pixmap used when the current style is Qt::TexturePattern.

Note that applying setTexture() makes style() == Qt::TexturePattern, regardless of previous style settings. Also, 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.

The isOpaque() function returns true if the brush is fully opaque otherwise false. A brush is considered opaque if:

The alpha component of the color() is 255. Its texture() does not have an alpha channel and is not a QBitmap. The colors in the gradient() all have an alpha component that is 255.

100% brush-outline.png Outlines

To specify the style and color of lines and outlines, use the QPainter's {QPen}{pen} combined with Qt::PenStyle and Qt::GlobalColor:

        QPainter painter(this);

        painter.setBrush(Qt::cyan);
        painter.setPen(Qt::darkCyan);
        painter.drawRect(0, 0, 100,100);

        painter.setBrush(Qt::NoBrush);
        painter.setPen(Qt::darkGreen);
        painter.drawRect(40, 40, 100, 100);

Note that, by default, QPainter renders the outline (using the currently set pen) when drawing shapes. Use {Qt::NoPen}{painter.setPen(Qt::NoPen)} to disable this behavior.

For more information about painting in general, see {The Paint System} documentation.

See also:
Qt::BrushStyle, QPainter, QColor

Definition at line 44 of file qbrush.h.

Public Member Functions

 QBrush ()
 QBrush (Qt::BrushStyle bs)
 QBrush (const QColor &color, Qt::BrushStyle bs=Qt::SolidPattern)
 QBrush (Qt::GlobalColor color, Qt::BrushStyle bs=Qt::SolidPattern)
 QBrush (const QColor &color, const QPixmap &pixmap)
 QBrush (Qt::GlobalColor color, const QPixmap &pixmap)
 QBrush (const QPixmap &pixmap)
 QBrush (const QImage &image)
 QBrush (const QBrush &brush)
 QBrush (const QGradient &gradient)
 ~QBrush ()
QBrushoperator= (const QBrush &brush)
 operator QVariant () const
Qt::BrushStyle style () const
void setStyle (Qt::BrushStyle)
const QMatrixmatrix () const
void setMatrix (const QMatrix &mat)
QPixmap texture () const
void setTexture (const QPixmap &pixmap)
QImage textureImage () const
void setTextureImage (const QImage &image)
const QColorcolor () const
void setColor (const QColor &color)
void setColor (Qt::GlobalColor color)
const QGradientgradient () const
bool isOpaque () const
bool operator== (const QBrush &b) const
bool operator!= (const QBrush &b) const

Private Member Functions

void detach (Qt::BrushStyle newStyle)
void init (const QColor &color, Qt::BrushStyle bs)
void cleanUp (QBrushData *x)

Private Attributes

QBrushDatad

Friends

class QPainter

Related Functions

(Note that these are not member functions.)

QDataStreamoperator<< (QDataStream &stream, const QBrush &brush)
QDataStreamoperator>> (QDataStream &stream, QBrush &brush)


Constructor & Destructor Documentation

QBrush::QBrush (  ) 

Constructs a default black brush with the style Qt::NoBrush (i.e. this brush will not fill shapes).

Definition at line 316 of file qbrush.cpp.

References d, nullBrushInstance(), QBrushData::ref, and QBasicAtomic::ref().

00317 {
00318     d = nullBrushInstance();
00319     Q_ASSERT(d);
00320     d->ref.ref();
00321 }

Here is the call graph for this function:

QBrush::QBrush ( Qt::BrushStyle  style  ) 

Constructs a black brush with the given style.

See also:
setStyle()

Definition at line 356 of file qbrush.cpp.

References Qt::black, d, init(), nullBrushInstance(), qbrush_check_type(), QBrushData::ref, and QBasicAtomic::ref().

00357 {
00358     if (qbrush_check_type(style))
00359         init(Qt::black, style);
00360     else {
00361         d = nullBrushInstance();
00362         d->ref.ref();
00363     }
00364 }

Here is the call graph for this function:

QBrush::QBrush ( const QColor color,
Qt::BrushStyle  style = Qt::SolidPattern 
)

Constructs a brush with the given color and style.

See also:
setColor(), setStyle()

Definition at line 372 of file qbrush.cpp.

References color(), d, init(), nullBrushInstance(), qbrush_check_type(), QBrushData::ref, and QBasicAtomic::ref().

00373 {
00374     if (qbrush_check_type(style))
00375         init(color, style);
00376     else {
00377         d = nullBrushInstance();
00378         d->ref.ref();
00379     }
00380 }

Here is the call graph for this function:

QBrush::QBrush ( Qt::GlobalColor  color,
Qt::BrushStyle  style = Qt::SolidPattern 
)

Constructs a brush with the given color and style.

See also:
setColor(), setStyle()

Definition at line 389 of file qbrush.cpp.

References d, init(), nullBrushInstance(), qbrush_check_type(), QBrushData::ref, and QBasicAtomic::ref().

00390 {
00391     if (qbrush_check_type(style))
00392         init(color, style);
00393     else {
00394         d = nullBrushInstance();
00395         d->ref.ref();
00396     }
00397 }

Here is the call graph for this function:

QBrush::QBrush ( const QColor color,
const QPixmap pixmap 
)

Constructs a brush with the given color and the custom pattern stored in pixmap.

The style is set to Qt::TexturePattern. The color will only have an effect for QBitmaps.

See also:
setColor(), setPixmap()

Definition at line 409 of file qbrush.cpp.

References color(), init(), setTexture(), and Qt::TexturePattern.

00410 {
00411     init(color, Qt::TexturePattern);
00412     setTexture(pixmap);
00413 }

Here is the call graph for this function:

QBrush::QBrush ( Qt::GlobalColor  color,
const QPixmap pixmap 
)

Constructs a brush with the given color and the custom pattern stored in pixmap.

The style is set to Qt::TexturePattern. The color will only have an effect for QBitmaps.

See also:
setColor(), setPixmap()

Definition at line 425 of file qbrush.cpp.

References init(), setTexture(), and Qt::TexturePattern.

00426 {
00427     init(color, Qt::TexturePattern);
00428     setTexture(pixmap);
00429 }

Here is the call graph for this function:

QBrush::QBrush ( const QPixmap pixmap  ) 

Constructs a brush with a black color and a texture set to the given pixmap. The style is set to Qt::TexturePattern.

See also:
setTexture()

Definition at line 330 of file qbrush.cpp.

References Qt::black, init(), setTexture(), and Qt::TexturePattern.

00331 {
00332     init(Qt::black, Qt::TexturePattern);
00333     setTexture(pixmap);
00334 }

Here is the call graph for this function:

QBrush::QBrush ( const QImage image  ) 

Constructs a brush with a black color and a texture set to the given image. The style is set to Qt::TexturePattern.

See also:
setTextureImage()

Definition at line 344 of file qbrush.cpp.

References Qt::black, image, init(), setTextureImage(), and Qt::TexturePattern.

00345 {
00346     init(Qt::black, Qt::TexturePattern);
00347     setTextureImage(image);
00348 }

Here is the call graph for this function:

QBrush::QBrush ( const QBrush other  ) 

Constructs a copy of other.

Definition at line 435 of file qbrush.cpp.

References d, QBrushData::ref, and QBasicAtomic::ref().

00436 {
00437     d = other.d;
00438     d->ref.ref();
00439 }

Here is the call graph for this function:

QBrush::QBrush ( const QGradient gradient  ) 

Constructs a brush based on the given gradient.

The brush style is set to the corresponding gradient style (either Qt::LinearGradientPattern, Qt::RadialGradientPattern or Qt::ConicalGradientPattern).

Definition at line 448 of file qbrush.cpp.

References Qt::ConicalGradientPattern, d, gradient(), init(), Qt::LinearGradientPattern, QGradient::NoGradient, Qt::RadialGradientPattern, and QGradient::type().

00449 {
00450     Q_ASSERT_X(gradient.type() != QGradient::NoGradient, "QBrush::QBrush",
00451                "QGradient should not be used directly, use the linear, radial\n"
00452                "or conical gradients instead");
00453 
00454     const Qt::BrushStyle enum_table[] = {
00455         Qt::LinearGradientPattern,
00456         Qt::RadialGradientPattern,
00457         Qt::ConicalGradientPattern
00458     };
00459 
00460     init(QColor(), enum_table[gradient.type()]);
00461     QGradientBrushData *grad = static_cast<QGradientBrushData *>(d);
00462     grad->gradient = gradient;
00463 }

Here is the call graph for this function:

QBrush::~QBrush (  ) 

Destroys the brush.

Definition at line 469 of file qbrush.cpp.

References cleanUp(), d, QBasicAtomic::deref(), and QBrushData::ref.

00470 {
00471     if (!d->ref.deref())
00472         cleanUp(d);
00473 }

Here is the call graph for this function:


Member Function Documentation

QBrush & QBrush::operator= ( const QBrush brush  ) 

Assigns the given brush to this brush and returns a reference to this brush.

Definition at line 535 of file qbrush.cpp.

References b, cleanUp(), d, qAtomicSetPtr(), and x.

00536 {
00537     QBrushData *x = b.d;
00538     x->ref.ref();
00539     x = qAtomicSetPtr(&d, x);
00540     if (!x->ref.deref())
00541         cleanUp(x);
00542     return *this;
00543 }

Here is the call graph for this function:

QBrush::operator QVariant (  )  const

Returns the brush as a QVariant

Definition at line 548 of file qbrush.cpp.

References QVariant::Brush.

00549 {
00550     return QVariant(QVariant::Brush, this);
00551 }

Qt::BrushStyle QBrush::style (  )  const [inline]

Returns the brush style.

See also:
setStyle()

Definition at line 131 of file qbrush.h.

References d, and QBrushData::style.

Referenced by QPdfEnginePrivate::addBrushPattern(), QTextHtmlParserNode::applyCssDeclarations(), Q3SVGPaintEnginePrivate::applyStyle(), QTextHtmlParserNode::charFormat(), check_gradient(), QTextLayout::draw(), QTextLine::draw(), QRenderRule::drawBackground(), QPainterPrivate::drawOpaqueBackground(), QPainterPrivate::drawStretchToDevice(), QWidgetPrivate::drawWidget(), fillBackground(), QX11PaintEnginePrivate::fillPolygon_dev(), QWidgetPrivate::hasBackground(), is_brush_transparent(), QWidgetPrivate::isBackgroundInherited(), QWidgetPrivate::isOpaque(), QPen::isSolid(), QStyleSheetBackgroundData::isTransparent(), qdesigner_internal::ColorDelegate::paint(), qdesigner_internal::QtBrushButton::paintEvent(), qdesigner_internal::QtBrushWidget::paintEvent(), parseDefaultTextStyle(), Q3SVGPaintEnginePrivate::play(), QAbstractFormBuilder::saveBrush(), QTextHtmlImporter::scanTable(), QWorkspace::setBackground(), QPainter::setBackground(), QPainter::setBrush(), qdesigner_internal::QtBrushPatternEditor::setBrush(), qdesigner_internal::QtBrushEditor::setBrush(), QPainter::setPen(), setPenAndDrawBackground(), QSpanData::setup(), qdesigner_internal::QtBrushEditorPrivate::slotChooserClicked(), qdesigner_internal::QtBrushButtonPrivate::slotEditBrush(), qdesigner_internal::QtBrushEditorPrivate::slotPatternChooserClicked(), qdesigner_internal::QtBrushEditorPrivate::slotTextureChooserClicked(), QPicturePaintEngine::updateBackground(), QPicturePaintEngine::updateBrush(), and QWidgetPrivate::updateSystemBackground().

00131 { return d->style; }

void QBrush::setStyle ( Qt::BrushStyle  style  ) 

Sets the brush style to style.

See also:
style()

Definition at line 567 of file qbrush.cpp.

References d, detach(), qbrush_check_type(), and QBrushData::style.

Referenced by parseQBrush(), QGraphicsSimpleTextItemPrivate::QGraphicsSimpleTextItemPrivate(), QAbstractFormBuilder::setupBrush(), and qdesigner_internal::QtBrushPatternEditorPrivate::slotPatternChanged().

00568 {
00569     if (d->style == style)
00570         return;
00571 
00572     if (qbrush_check_type(style)) {
00573         detach(style);
00574         d->style = style;
00575     }
00576 }

Here is the call graph for this function:

const QMatrix & QBrush::matrix (  )  const [inline]

Since:
4.2
Returns the current transformation matrix for the brush.

See also:
setMatrix()

Definition at line 133 of file qbrush.h.

References d, and QBrushData::transform.

Referenced by setMatrix().

00133 { return d->transform; }

void QBrush::setMatrix ( const QMatrix matrix  ) 

Since:
4.2
Sets matrix as an explicit transformation matrix on the current brush. The brush transformation matrix is merged with QPainter transformation matrix to produce the final result.

See also:
matrix()

Definition at line 781 of file qbrush.cpp.

References d, detach(), matrix(), QBrushData::style, and QBrushData::transform.

Referenced by QSvgGradientStyle::apply(), QRenderRule::drawBackground(), and fillBackground().

00782 {
00783     detach(d->style);
00784     d->transform = matrix;
00785 }

Here is the call graph for this function:

QPixmap QBrush::texture (  )  const

Returns the custom brush pattern, or a null pixmap if no custom brush pattern has been set.

See also:
setTexture()

Definition at line 650 of file qbrush.cpp.

References d, QBrushData::style, and Qt::TexturePattern.

Referenced by QPdfEnginePrivate::addBrushPattern(), QPlastiqueStyle::drawComplexControl(), QPlastiqueStyle::drawControl(), QPlastiqueStyle::drawPrimitive(), QWidgetPrivate::drawWidget(), QX11PaintEnginePrivate::fillPolygon_dev(), is_brush_transparent(), isOpaque(), qBrushDark(), qBrushLight(), qBrushSetAlphaF(), QAbstractFormBuilder::saveBrush(), QSpanData::setup(), qdesigner_internal::QtBrushButtonPrivate::slotEditBrush(), qdesigner_internal::BrushEditor::textureChooserActivated(), and QWidgetPrivate::updateSystemBackground().

00651 {
00652     return d->style == Qt::TexturePattern
00653                      ? ((QTexturedBrushData*) d)->pixmap()
00654                      : QPixmap();
00655 }

void QBrush::setTexture ( const QPixmap pixmap  ) 

Sets the brush pixmap to 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 ( {QBitmap}{QBitmaps}).

See also:
texture()

Definition at line 667 of file qbrush.cpp.

References d, data, detach(), QPixmap::isNull(), Qt::NoBrush, and Qt::TexturePattern.

Referenced by QAbstractTextDocumentLayout::drawInlineObject(), QBrush(), qBrushDark(), qBrushLight(), qBrushSetAlphaF(), and QAbstractFormBuilder::setupBrush().

00668 {
00669     if (!pixmap.isNull()) {
00670         detach(Qt::TexturePattern);
00671         QTexturedBrushData *data = static_cast<QTexturedBrushData *>(d);
00672         data->setPixmap(pixmap);
00673     } else {
00674         detach(Qt::NoBrush);
00675     }
00676 }

Here is the call graph for this function:

QImage QBrush::textureImage (  )  const

Since:
4.2
Returns the custom brush pattern, or a null image if no custom brush pattern has been set.

If the texture was set as a QPixmap it will be converted to a QImage.

See also:
setTextureImage()

Definition at line 691 of file qbrush.cpp.

References d, QBrushData::style, and Qt::TexturePattern.

00692 {
00693     return d->style == Qt::TexturePattern
00694                      ? ((QTexturedBrushData *) d)->image()
00695                      : QImage();
00696 }

void QBrush::setTextureImage ( const QImage image  ) 

Since:
4.2
Sets the brush image to image. The style is set to Qt::TexturePattern.

The current brush color will only have an effect for monochrome images, i.e. for QImage::depth() == 1.

See also:
textureImage()

Definition at line 711 of file qbrush.cpp.

References d, data, detach(), image, Qt::NoBrush, and Qt::TexturePattern.

Referenced by QBrush().

00712 {
00713     if (!image.isNull()) {
00714         detach(Qt::TexturePattern);
00715         QTexturedBrushData *data = static_cast<QTexturedBrushData *>(d);
00716         data->setImage(image);
00717     } else {
00718         detach(Qt::NoBrush);
00719     }
00720 }

Here is the call graph for this function:

const QColor & QBrush::color (  )  const [inline]

Returns the brush color.

See also:
setColor()

Definition at line 132 of file qbrush.h.

References QBrushData::color, and d.

Referenced by QTextEditPrivate::_q_currentCharFormatChanged(), QPdfEnginePrivate::addBrushPattern(), PanelShape::animate(), Q3SVGPaintEnginePrivate::applyStyle(), QGLDrawable::backgroundColor(), QPen::color(), QCalendarModel::data(), Q3TextHorizontalLine::draw(), Q3TextTable::draw(), QTextLine::draw(), Q3TextDocument::draw(), QCommonStyle::drawComplexControl(), QWindowsStyle::drawComplexControl(), QCleanlooksStyle::drawComplexControl(), QPlastiqueStyle::drawComplexControl(), QPlastiqueStyle::drawControl(), QCleanlooksStyle::drawControl(), QMotifStyle::drawControl(), QWindowsStyle::drawControl(), QWindowsXPStyle::drawControl(), QCommonStyle::drawControl(), QFrame::drawFrame(), QStyle::drawItemText(), QPainterPrivate::drawOpaqueBackground(), QCommonStyle::drawPrimitive(), QCleanlooksStyle::drawPrimitive(), QCDEStyle::drawPrimitive(), QPlastiqueStyle::drawPrimitive(), NorwegianWoodStyle::drawPrimitive(), QWindowsStyle::drawPrimitive(), QLCDNumberPrivate::drawSegment(), Q3TextParagraph::drawString(), QTextHtmlExporter::emitBlockAttributes(), QTextHtmlExporter::emitTable(), Q3IconView::eventFilter(), QX11PaintEnginePrivate::fillPolygon_dev(), init(), Q3TextEdit::inputMethodEvent(), qdesigner_internal::StyledButton::onEditor(), Q3DateTimeEditorPrivate::paint(), Q3CheckTableItem::paint(), Q3ListBox::paintCell(), Q3Table::paintCell(), QLineEdit::paintEvent(), qdesigner_internal::StyledButton::paintEvent(), QLabel::paintEvent(), Q3ListViewItem::paintFocus(), Q3Table::paintFocus(), paintGrid(), Q3SVGPaintEnginePrivate::play(), QPlastiqueStyle::polish(), NorwegianWoodStyle::polish(), QCleanlooksStyle::polish(), QWindowsXPStyle::polish(), QWindowsStyle::polish(), QBrush(), qBrushDark(), qBrushLight(), qBrushSetAlphaF(), qDrawShadeLine(), qDrawShadePanel(), qDrawShadeRect(), qDrawWinButton(), qDrawWinPanel(), qt_cleanlooks_draw_mdibutton(), qt_plastique_draw_handle(), qt_plastique_drawFrame(), qt_plastique_drawShadedPanel(), QAbstractFormBuilder::saveBrush(), QPainter::setBackground(), QPainter::setBrush(), qdesigner_internal::QtBrushPatternEditor::setBrush(), qdesigner_internal::BrushEditor::setBrush(), QPalette::setColorGroup(), Q3SVGPaintEnginePrivate::setStyleProperty(), QSpanData::setup(), QInputContext::standardFormat(), QCleanlooksStyle::styleHint(), QTextHtmlExporter::toHtml(), QPicturePaintEngine::updateBackground(), QX11PaintEngine::updateBrush(), SpreadSheet::updateColor(), QWidgetPrivate::updateSystemBackground(), and Q3ListBox::viewportPaintEvent().

00132 { return d->color; }

void QBrush::setColor ( const QColor color  ) 

Sets the brush color to the given 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.

See also:
color()

Definition at line 599 of file qbrush.cpp.

References c, QBrushData::color, d, detach(), and QBrushData::style.

Referenced by PanelShape::animate(), qdesigner_internal::StyledButton::onEditor(), parseQBrush(), NorwegianWoodStyle::polish(), qBrushDark(), qBrushLight(), qBrushSetAlphaF(), qdesigner_internal::StyledButton::setBrush(), setColor(), QAbstractFormBuilder::setupBrush(), qdesigner_internal::QtBrushPatternEditorPrivate::slotChangeAlpha(), qdesigner_internal::QtBrushPatternEditorPrivate::slotChangeColor(), qdesigner_internal::QtBrushPatternEditorPrivate::slotChangeHue(), qdesigner_internal::QtBrushPatternEditorPrivate::slotChangeSaturation(), and qdesigner_internal::QtBrushPatternEditorPrivate::slotChangeValue().

00600 {
00601     detach(d->style);
00602     d->color = c;
00603 }

Here is the call graph for this function:

void QBrush::setColor ( Qt::GlobalColor  color  )  [inline]

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Sets the brush color to the given color.

Definition at line 105 of file qbrush.h.

References setColor().

00106 { setColor(QColor(acolor)); }

Here is the call graph for this function:

const QGradient * QBrush::gradient (  )  const

Returns the gradient describing this brush.

Definition at line 726 of file qbrush.cpp.

References Qt::ConicalGradientPattern, d, Qt::LinearGradientPattern, Qt::RadialGradientPattern, and QBrushData::style.

Referenced by check_gradient(), detach(), QPlastiqueStyle::drawComplexControl(), QPlastiqueStyle::drawControl(), QPlastiqueStyle::drawPrimitive(), isOpaque(), qdesigner_internal::ColorDelegate::paint(), QBrush(), qBrushDark(), qBrushLight(), qBrushSetAlphaF(), qMapBrushToRect(), QAbstractFormBuilder::saveBrush(), and QSpanData::setup().

00727 {
00728     if (d->style == Qt::LinearGradientPattern
00729         || d->style == Qt::RadialGradientPattern
00730         || d->style == Qt::ConicalGradientPattern) {
00731         return &static_cast<const QGradientBrushData *>(d)->gradient;
00732     }
00733     return 0;
00734 }

bool QBrush::isOpaque (  )  const

Returns true if the brush is fully opaque otherwise false. A brush is considered opaque if:

The alpha component of the color() is 255. Its texture() does not have an alpha channel and is not a QBitmap. The colors in the gradient() all have an alpha component that is 255.

Definition at line 748 of file qbrush.cpp.

References QColor::alpha, QVector< T >::at(), QBrushData::color, Qt::ConicalGradientPattern, d, gradient(), QPixmap::hasAlpha(), i, Qt::LinearGradientPattern, Qt::RadialGradientPattern, QVector< T >::size(), Qt::SolidPattern, QGradient::stops(), QBrushData::style, texture(), and Qt::TexturePattern.

Referenced by QPdfEnginePrivate::addBrushPattern(), QWidgetPrivate::isBackgroundInherited(), QWidgetPrivate::isOpaque(), QStyleSheetBackgroundData::isTransparent(), QWidgetPrivate::paintBackground(), QSpanData::setup(), QX11PaintEngine::updateBrush(), QPdfBaseEngine::updateState(), and QWidgetPrivate::updateSystemBackground().

00749 {
00750     bool opaqueColor = d->color.alpha() == 255;
00751 
00752     // Test awfully simple case first
00753     if (d->style == Qt::SolidPattern)
00754         return opaqueColor;
00755 
00756     if (d->style == Qt::LinearGradientPattern
00757         || d->style == Qt::RadialGradientPattern
00758         || d->style == Qt::ConicalGradientPattern) {
00759         QGradientStops stops = gradient()->stops();
00760         for (int i=0; i<stops.size(); ++i)
00761             if (stops.at(i).second.alpha() != 255)
00762                 return false;
00763         return true;
00764     } else if (d->style == Qt::TexturePattern) {
00765         return !texture().hasAlpha();
00766     }
00767 
00768     return false;
00769 }

Here is the call graph for this function:

bool QBrush::operator== ( const QBrush brush  )  const

Returns true if the brush is equal to the given brush; otherwise returns false.

Two brushes are equal if they have equal styles, colors and pixmaps.

See also:
operator!=()

Definition at line 821 of file qbrush.cpp.

References b, QBrushData::color, Qt::ConicalGradientPattern, d, QGradientBrushData::gradient, QPixmap::isNull(), Qt::LinearGradientPattern, Qt::RadialGradientPattern, QPixmap::serialNumber(), QBrushData::style, and Qt::TexturePattern.

00822 {
00823     if (b.d == d)
00824         return true;
00825     if (b.d->style == d->style && b.d->color == d->color) {
00826         switch (d->style) {
00827         case Qt::TexturePattern: {
00828             QPixmap &us = ((QTexturedBrushData *) d)->pixmap();
00829             QPixmap &them = ((QTexturedBrushData *) b.d)->pixmap();
00830             return ((us.isNull() && them.isNull()) || us.serialNumber() == them.serialNumber());
00831         }
00832         case Qt::LinearGradientPattern:
00833         case Qt::RadialGradientPattern:
00834         case Qt::ConicalGradientPattern:
00835             {
00836                 QGradientBrushData *d1 = static_cast<QGradientBrushData *>(d);
00837                 QGradientBrushData *d2 = static_cast<QGradientBrushData *>(b.d);
00838                 return d1->gradient == d2->gradient;
00839             }
00840         default:
00841             return true;
00842         }
00843     }
00844     return false;
00845 }

Here is the call graph for this function:

bool QBrush::operator!= ( const QBrush brush  )  const [inline]

Returns true if the brush is different from the given brush; otherwise returns false.

Two brushes are different if they have different styles, colors or pixmaps.

See also:
operator==()

Definition at line 86 of file qbrush.h.

References b, and QVariant::operator==().

00086 { return !(operator==(b)); }

Here is the call graph for this function:

void QBrush::detach ( Qt::BrushStyle  newStyle  )  [private]

Definition at line 492 of file qbrush.cpp.

References cleanUp(), QBrushData::color, Qt::ConicalGradientPattern, d, gradient(), Qt::LinearGradientPattern, qAtomicSetPtr(), Qt::RadialGradientPattern, QBrushData::ref, QTexturedBrushData::setPixmap(), QBrushData::style, Qt::TexturePattern, QBrushData::transform, and x.

Referenced by setColor(), setMatrix(), setStyle(), setTexture(), and setTextureImage().

00493 {
00494     if (newStyle == d->style && d->ref == 1)
00495         return;
00496 
00497     QBrushData *x;
00498     switch(newStyle) {
00499     case Qt::TexturePattern: {
00500         QTexturedBrushData *tbd = new QTexturedBrushData;
00501         tbd->setPixmap(d->style == Qt::TexturePattern
00502                        ? static_cast<QTexturedBrushData *>(d)->pixmap()
00503                        : QPixmap());
00504         x = tbd;
00505         break;
00506         }
00507     case Qt::LinearGradientPattern:
00508     case Qt::RadialGradientPattern:
00509     case Qt::ConicalGradientPattern:
00510         x = new QGradientBrushData;
00511         static_cast<QGradientBrushData *>(x)->gradient =
00512             static_cast<QGradientBrushData *>(d)->gradient;
00513         break;
00514     default:
00515         x = new QBrushData;
00516         break;
00517     }
00518     x->ref = 1;
00519     x->style = newStyle;
00520     x->color = d->color;
00521     x->transform = d->transform;
00522     x = qAtomicSetPtr(&d, x);
00523     if (!x->ref.deref())
00524         cleanUp(x);
00525 }

Here is the call graph for this function:

void QBrush::init ( const QColor color,
Qt::BrushStyle  bs 
) [private]

Definition at line 286 of file qbrush.cpp.

References color(), QBrushData::color, Qt::ConicalGradientPattern, d, Qt::LinearGradientPattern, Qt::NoBrush, nullBrushInstance(), Qt::RadialGradientPattern, QBrushData::ref, QBasicAtomic::ref(), QBrushData::style, and Qt::TexturePattern.

Referenced by QBrush().

00287 {
00288     switch(style) {
00289     case Qt::NoBrush:
00290         d = nullBrushInstance();
00291         d->ref.ref();
00292         return;
00293     case Qt::TexturePattern:
00294         d = new QTexturedBrushData;
00295         static_cast<QTexturedBrushData *>(d)->setPixmap(QPixmap());
00296         break;
00297     case Qt::LinearGradientPattern:
00298     case Qt::RadialGradientPattern:
00299     case Qt::ConicalGradientPattern:
00300         d = new QGradientBrushData;
00301         break;
00302     default:
00303         d = new QBrushData;
00304         break;
00305     }
00306     d->ref = 1;
00307     d->style = style;
00308     d->color = color;
00309 }

Here is the call graph for this function:

void QBrush::cleanUp ( QBrushData x  )  [private]

Definition at line 475 of file qbrush.cpp.

References Qt::ConicalGradientPattern, Qt::LinearGradientPattern, Qt::RadialGradientPattern, Qt::TexturePattern, and x.

Referenced by detach(), operator=(), and ~QBrush().

00476 {
00477     switch (x->style) {
00478     case Qt::TexturePattern:
00479         delete static_cast<QTexturedBrushData*>(x);
00480         break;
00481     case Qt::LinearGradientPattern:
00482     case Qt::RadialGradientPattern:
00483     case Qt::ConicalGradientPattern:
00484         delete static_cast<QGradientBrushData*>(x);
00485         break;
00486     default:
00487         delete x;
00488     }
00489 }


Friends And Related Function Documentation

friend class QPainter [friend]

Definition at line 98 of file qbrush.h.

QDataStream & operator<< ( QDataStream stream,
const QBrush brush 
) [related]

Writes the given brush to the given stream and returns a reference to the stream.

See also:
{Format of the QDataStream Operators}

Definition at line 886 of file qbrush.cpp.

00887 {
00888     s << (quint8)b.style() << b.color();
00889     if (b.style() == Qt::TexturePattern) {
00890         s << b.texture();
00891     } else if (b.style() == Qt::LinearGradientPattern
00892                || b.style() == Qt::RadialGradientPattern
00893                || b.style() == Qt::ConicalGradientPattern) {
00894         const QGradient *gradient = b.gradient();
00895         int type_as_int = int(gradient->type());
00896         s << type_as_int;
00897 
00898         if (sizeof(qreal) == sizeof(double)) {
00899             s << gradient->stops();
00900         } else {
00901             // ensure that we write doubles here instead of streaming the stops
00902             // directly; otherwise, platforms that redefine qreal might generate
00903             // data that cannot be read on other platforms.
00904             QVector<QGradientStop> stops = gradient->stops();
00905             s << quint32(stops.size());
00906             for (int i = 0; i < stops.size(); ++i) {
00907                 const QGradientStop &stop = stops.at(i);
00908                 s << QPair<double, QColor>(double(stop.first), stop.second);
00909             }
00910         }
00911 
00912         if (gradient->type() == QGradient::LinearGradient) {
00913             s << static_cast<const QLinearGradient *>(gradient)->start();
00914             s << static_cast<const QLinearGradient *>(gradient)->finalStop();
00915         } else if (gradient->type() == QGradient::RadialGradient) {
00916             s << static_cast<const QRadialGradient *>(gradient)->center();
00917             s << static_cast<const QRadialGradient *>(gradient)->focalPoint();
00918             s << (double) static_cast<const QRadialGradient *>(gradient)->radius();
00919         } else { // type == Conical
00920             s << static_cast<const QConicalGradient *>(gradient)->center();
00921             s << (double) static_cast<const QConicalGradient *>(gradient)->angle();
00922         }
00923     }
00924     return s;
00925 }

QDataStream & operator>> ( QDataStream stream,
QBrush brush 
) [related]

Reads the given brush from the given stream and returns a reference to the stream.

See also:
{Format of the QDataStream Operators}

Definition at line 937 of file qbrush.cpp.

00938 {
00939     quint8 style;
00940     QColor color;
00941     s >> style;
00942     s >> color;
00943     if (style == Qt::TexturePattern) {
00944         QPixmap pm;
00945         s >> pm;
00946         b = QBrush(color, pm);
00947     } else if (style == Qt::LinearGradientPattern
00948                || style == Qt::RadialGradientPattern
00949                || style == Qt::ConicalGradientPattern) {
00950 
00951         int type_as_int;
00952         QGradient::Type type;
00953         QGradientStops stops;
00954 
00955         s >> type_as_int;
00956         type = QGradient::Type(type_as_int);
00957 
00958         if (sizeof(qreal) == sizeof(double)) {
00959             s >> stops;
00960         } else {
00961             quint32 numStops;
00962             double n;
00963             QColor c;
00964 
00965             s >> numStops;
00966             for (quint32 i = 0; i < numStops; ++i) {
00967                 s >> n >> c;
00968                 stops << QPair<qreal, QColor>(n, c);
00969             }
00970         }
00971 
00972         if (type == QGradient::LinearGradient) {
00973             QPointF p1, p2;
00974             s >> p1;
00975             s >> p2;
00976             QLinearGradient lg(p1, p2);
00977             lg.setStops(stops);
00978             b = QBrush(lg);
00979         } else if (type == QGradient::RadialGradient) {
00980             QPointF center, focal;
00981             double radius;
00982             s >> center;
00983             s >> focal;
00984             s >> radius;
00985             QRadialGradient rg(center, radius, focal);
00986             rg.setStops(stops);
00987             b = QBrush(rg);
00988         } else { // type == QGradient::ConicalGradient
00989             QPointF center;
00990             double angle;
00991             s >> center;
00992             s >> angle;
00993             QConicalGradient cg(center, angle);
00994             cg.setStops(stops);
00995             b = QBrush(cg);
00996         }
00997 
00998     } else {
00999         b = QBrush(color, (Qt::BrushStyle)style);
01000     }
01001     return s;
01002 }


Member Data Documentation

QBrushData* QBrush::d [private]

Definition at line 101 of file qbrush.h.

Referenced by color(), detach(), gradient(), init(), isOpaque(), matrix(), operator=(), operator==(), QBrush(), setColor(), setMatrix(), setStyle(), setTexture(), setTextureImage(), style(), texture(), textureImage(), and ~QBrush().


The documentation for this class was generated from the following files:
Generated on Thu Mar 15 16:53:28 2007 for Qt 4.2 User's Guide by  doxygen 1.5.1