#include "qbrush.h"
#include "qpixmap.h"
#include "qbitmap.h"
#include "qpixmapcache.h"
#include "qdatastream.h"
#include "qvariant.h"
#include "qline.h"
#include "qdebug.h"
Include dependency graph for qbrush.cpp:

Go to the source code of this file.
Classes | |
| struct | QTexturedBrushData |
| struct | QGradientBrushData |
| class | QBrushStatic |
Functions | |
| const uchar * | qt_patternForBrush (int brushStyle, bool invert) |
| QPixmap | qt_pixmapForBrush (int brushStyle, bool invert) |
| QImage | qt_imageForBrush (int brushStyle, bool invert) |
| static QBrushData * | nullBrushInstance () |
| static bool | qbrush_check_type (Qt::BrushStyle style) |
| QDebug | operator<< (QDebug dbg, const QBrush &b) |
| QDataStream & | operator<< (QDataStream &s, const QBrush &b) |
| QDataStream & | operator>> (QDataStream &s, QBrush &b) |
| static QPointF | qt_radial_gradient_adapt_focal_point (const QPointF ¢er, qreal radius, const QPointF &focalPoint) |
| static QBrushData* nullBrushInstance | ( | ) | [static] |
Definition at line 253 of file qbrush.cpp.
References Qt::black, QBrushStatic::destroyed, QBrushStatic::pointer, q_atomic_test_and_set_ptr(), and x.
Referenced by QBrush::init(), and QBrush::QBrush().
00254 { 00255 static QBrushStatic defaultBrush; 00256 if (!defaultBrush.pointer && !defaultBrush.destroyed) { 00257 QBrushData *x = new QBrushData; 00258 x->ref = 1; x->style = Qt::BrushStyle(0); x->color = Qt::black; 00259 if (!q_atomic_test_and_set_ptr(&defaultBrush.pointer, 0, x)) 00260 delete x; 00261 } 00262 return defaultBrush.pointer; 00263 }
Here is the call graph for this function:

| QDataStream& operator<< | ( | QDataStream & | s, | |
| const QBrush & | b | |||
| ) | [related] |
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 }
Definition at line 859 of file qbrush.cpp.
00860 { 00861 #ifndef Q_BROKEN_DEBUG_STREAM 00862 dbg.nospace() << "QBrush(" << b.color() << ',' << b.style() << ')'; 00863 return dbg.space(); 00864 #else 00865 qWarning("This compiler doesn't support streaming QBrush to QDebug"); 00866 return dbg; 00867 Q_UNUSED(b); 00868 #endif 00869 }
| QDataStream& operator>> | ( | QDataStream & | s, | |
| QBrush & | b | |||
| ) | [related] |
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 }
| static bool qbrush_check_type | ( | Qt::BrushStyle | style | ) | [static] |
Definition at line 265 of file qbrush.cpp.
References Qt::ConicalGradientPattern, Qt::LinearGradientPattern, qWarning(), Qt::RadialGradientPattern, and Qt::TexturePattern.
Referenced by QBrush::QBrush(), and QBrush::setStyle().
00265 { 00266 switch (style) { 00267 case Qt::TexturePattern: 00268 qWarning("QBrush: Incorrect use of TexturePattern"); 00269 break; 00270 case Qt::LinearGradientPattern: 00271 case Qt::RadialGradientPattern: 00272 case Qt::ConicalGradientPattern: 00273 qWarning("QBrush: Wrong use of a gradient pattern"); 00274 break; 00275 default: 00276 return true; 00277 } 00278 return false; 00279 }
Here is the call graph for this function:

| QImage qt_imageForBrush | ( | int | brushStyle, | |
| bool | invert | |||
| ) |
Definition at line 90 of file qbrush.cpp.
References QImage::Format_MonoLSB, image, qt_patternForBrush(), and y.
Referenced by QSpanData::setup().
00091 { 00092 QImage image(8, 8, QImage::Format_MonoLSB); 00093 const uchar *pattern = qt_patternForBrush(brushStyle, invert); 00094 00095 for (int y=0; y<8; ++y) 00096 *image.scanLine(y) = pattern[y]; 00097 00098 return image; 00099 }
Here is the call graph for this function:

| const uchar* qt_patternForBrush | ( | int | brushStyle, | |
| bool | invert | |||
| ) |
Definition at line 33 of file qbrush.cpp.
References Qt::Dense1Pattern, Qt::LinearGradientPattern, and Qt::SolidPattern.
Referenced by qt_imageForBrush(), and qt_pixmapForBrush().
00034 { 00035 Q_ASSERT(brushStyle > Qt::SolidPattern && brushStyle < Qt::LinearGradientPattern); 00036 if(invert) { 00037 static const uchar dense1_pat[] = { 0xff, 0xbb, 0xff, 0xff, 0xff, 0xbb, 0xff, 0xff }; 00038 static const uchar dense2_pat[] = { 0x77, 0xff, 0xdd, 0xff, 0x77, 0xff, 0xdd, 0xff }; 00039 static const uchar dense3_pat[] = { 0x55, 0xbb, 0x55, 0xee, 0x55, 0xbb, 0x55, 0xee }; 00040 static const uchar dense4_pat[] = { 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55 }; 00041 static const uchar dense5_pat[] = { 0xaa, 0x44, 0xaa, 0x11, 0xaa, 0x44, 0xaa, 0x11 }; 00042 static const uchar dense6_pat[] = { 0x88, 0x00, 0x22, 0x00, 0x88, 0x00, 0x22, 0x00 }; 00043 static const uchar dense7_pat[] = { 0x00, 0x44, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00 }; 00044 static const uchar hor_pat[] = { 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00 }; 00045 static const uchar ver_pat[] = { 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10 }; 00046 static const uchar cross_pat[] = { 0x10, 0x10, 0x10, 0xff, 0x10, 0x10, 0x10, 0x10 }; 00047 static const uchar bdiag_pat[] = { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 }; 00048 static const uchar fdiag_pat[] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 }; 00049 static const uchar dcross_pat[] = { 0x81, 0x42, 0x24, 0x18, 0x18, 0x24, 0x42, 0x81 }; 00050 static const uchar *const pat_tbl[] = { 00051 dense1_pat, dense2_pat, dense3_pat, dense4_pat, dense5_pat, 00052 dense6_pat, dense7_pat, 00053 hor_pat, ver_pat, cross_pat, bdiag_pat, fdiag_pat, dcross_pat }; 00054 return pat_tbl[brushStyle - Qt::Dense1Pattern]; 00055 } 00056 static const uchar dense1_pat[] = { 0x00, 0x44, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00 }; 00057 static const uchar dense2_pat[] = { 0x88, 0x00, 0x22, 0x00, 0x88, 0x00, 0x22, 0x00 }; 00058 static const uchar dense3_pat[] = { 0xaa, 0x44, 0xaa, 0x11, 0xaa, 0x44, 0xaa, 0x11 }; 00059 static const uchar dense4_pat[] = { 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa }; 00060 static const uchar dense5_pat[] = { 0x55, 0xbb, 0x55, 0xee, 0x55, 0xbb, 0x55, 0xee }; 00061 static const uchar dense6_pat[] = { 0x77, 0xff, 0xdd, 0xff, 0x77, 0xff, 0xdd, 0xff }; 00062 static const uchar dense7_pat[] = { 0xff, 0xbb, 0xff, 0xff, 0xff, 0xbb, 0xff, 0xff }; 00063 static const uchar hor_pat[] = { 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0xff }; 00064 static const uchar ver_pat[] = { 0xef, 0xef, 0xef, 0xef, 0xef, 0xef, 0xef, 0xef }; 00065 static const uchar cross_pat[] = { 0xef, 0xef, 0xef, 0x00, 0xef, 0xef, 0xef, 0xef }; 00066 static const uchar bdiag_pat[] = { 0x7f, 0xbf, 0xdf, 0xef, 0xf7, 0xfb, 0xfd, 0xfe }; 00067 static const uchar fdiag_pat[] = { 0xfe, 0xfd, 0xfb, 0xf7, 0xef, 0xdf, 0xbf, 0x7f }; 00068 static const uchar dcross_pat[] = { 0x7e, 0xbd, 0xdb, 0xe7, 0xe7, 0xdb, 0xbd, 0x7e }; 00069 static const uchar *const pat_tbl[] = { 00070 dense1_pat, dense2_pat, dense3_pat, dense4_pat, dense5_pat, 00071 dense6_pat, dense7_pat, 00072 hor_pat, ver_pat, cross_pat, bdiag_pat, fdiag_pat, dcross_pat }; 00073 return pat_tbl[brushStyle - Qt::Dense1Pattern]; 00074 }
| QPixmap qt_pixmapForBrush | ( | int | brushStyle, | |
| bool | invert | |||
| ) |
Definition at line 76 of file qbrush.cpp.
References QPixmapCache::find(), QImage::Format_MonoLSB, QBitmap::fromData(), QPixmapCache::insert(), key, QString::number(), and qt_patternForBrush().
Referenced by getPatternFill(), and QX11PaintEngine::updateBrush().
00077 { 00078 QPixmap pm; 00079 QString key = QLatin1String("$qt-brush$") + QString::number(brushStyle) 00080 + QString::number((int)invert); 00081 if (!QPixmapCache::find(key, pm)) { 00082 pm = QBitmap::fromData(QSize(8, 8), qt_patternForBrush(brushStyle, invert), 00083 QImage::Format_MonoLSB); 00084 QPixmapCache::insert(key, pm); 00085 } 00086 00087 return pm; 00088 }
Here is the call graph for this function:

| static QPointF qt_radial_gradient_adapt_focal_point | ( | const QPointF & | center, | |
| qreal | radius, | |||
| const QPointF & | focalPoint | |||
| ) | [static] |
Definition at line 1533 of file qbrush.cpp.
References QTextStream::center(), QLineF::length(), QLineF::p2(), and QLineF::setLength().
Referenced by QRadialGradient::QRadialGradient().
01536 { 01537 // We have a one pixel buffer zone to avoid numerical instability on the 01538 // circle border 01539 //### this is hacky because technically we should adjust based on current matrix 01540 const qreal compensated_radius = radius - 0.0000000001; 01541 QLineF line(center, focalPoint); 01542 if (line.length() > (compensated_radius)) 01543 line.setLength(compensated_radius); 01544 return line.p2(); 01545 }
Here is the call graph for this function:

1.5.1