50 #include <QtCore/qcoreapplication.h> 51 #include "private/qstylehelper_p.h" 52 #include <QtCore/qnumeric.h> 60 static const uchar dense1_pat[] = { 0xff, 0xbb, 0xff, 0xff, 0xff, 0xbb, 0xff, 0xff };
61 static const uchar dense2_pat[] = { 0x77, 0xff, 0xdd, 0xff, 0x77, 0xff, 0xdd, 0xff };
62 static const uchar dense3_pat[] = { 0x55, 0xbb, 0x55, 0xee, 0x55, 0xbb, 0x55, 0xee };
63 static const uchar dense4_pat[] = { 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55 };
64 static const uchar dense5_pat[] = { 0xaa, 0x44, 0xaa, 0x11, 0xaa, 0x44, 0xaa, 0x11 };
65 static const uchar dense6_pat[] = { 0x88, 0x00, 0x22, 0x00, 0x88, 0x00, 0x22, 0x00 };
66 static const uchar dense7_pat[] = { 0x00, 0x44, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00 };
67 static const uchar hor_pat[] = { 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00 };
68 static const uchar ver_pat[] = { 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10 };
69 static const uchar cross_pat[] = { 0x10, 0x10, 0x10, 0xff, 0x10, 0x10, 0x10, 0x10 };
70 static const uchar bdiag_pat[] = { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 };
71 static const uchar fdiag_pat[] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 };
72 static const uchar dcross_pat[] = { 0x81, 0x42, 0x24, 0x18, 0x18, 0x24, 0x42, 0x81 };
73 static const uchar *
const pat_tbl[] = {
74 dense1_pat, dense2_pat, dense3_pat, dense4_pat, dense5_pat,
75 dense6_pat, dense7_pat,
76 hor_pat, ver_pat, cross_pat, bdiag_pat, fdiag_pat, dcross_pat };
79 static const uchar dense1_pat[] = { 0x00, 0x44, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00 };
80 static const uchar dense2_pat[] = { 0x88, 0x00, 0x22, 0x00, 0x88, 0x00, 0x22, 0x00 };
81 static const uchar dense3_pat[] = { 0xaa, 0x44, 0xaa, 0x11, 0xaa, 0x44, 0xaa, 0x11 };
82 static const uchar dense4_pat[] = { 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa };
83 static const uchar dense5_pat[] = { 0x55, 0xbb, 0x55, 0xee, 0x55, 0xbb, 0x55, 0xee };
84 static const uchar dense6_pat[] = { 0x77, 0xff, 0xdd, 0xff, 0x77, 0xff, 0xdd, 0xff };
85 static const uchar dense7_pat[] = { 0xff, 0xbb, 0xff, 0xff, 0xff, 0xbb, 0xff, 0xff };
86 static const uchar hor_pat[] = { 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0xff };
87 static const uchar ver_pat[] = { 0xef, 0xef, 0xef, 0xef, 0xef, 0xef, 0xef, 0xef };
88 static const uchar cross_pat[] = { 0xef, 0xef, 0xef, 0x00, 0xef, 0xef, 0xef, 0xef };
89 static const uchar bdiag_pat[] = { 0x7f, 0xbf, 0xdf, 0xef, 0xf7, 0xfb, 0xfd, 0xfe };
90 static const uchar fdiag_pat[] = { 0xfe, 0xfd, 0xfb, 0xf7, 0xef, 0xdf, 0xbf, 0x7f };
91 static const uchar dcross_pat[] = { 0x7e, 0xbd, 0xdb, 0xe7, 0xe7, 0xdb, 0xbd, 0x7e };
92 static const uchar *
const pat_tbl[] = {
93 dense1_pat, dense2_pat, dense3_pat, dense4_pat, dense5_pat,
94 dense6_pat, dense7_pat,
95 hor_pat, ver_pat, cross_pat, bdiag_pat, fdiag_pat, dcross_pat };
164 qt_brushPatternImageCache()->cleanup();
169 return qt_brushPatternImageCache()->getImage(brushStyle, invert);
175 m_has_pixmap_texture =
false;
187 m_has_pixmap_texture =
false;
190 m_has_pixmap_texture =
true;
200 m_has_pixmap_texture =
false;
211 if (m_image.isNull() && m_pixmap)
212 m_image = m_pixmap->toImage();
352 : globalStatic(_globalStatic)
375 qWarning(
"QBrush: Incorrect use of TexturePattern");
380 qWarning(
"QBrush: Wrong use of a gradient pattern");
400 d.reset(nullBrushInstance());
402 if (
d->color != color) setColor(color);
427 :
d(nullBrushInstance())
468 if (qbrush_check_type(style))
471 d.
reset(nullBrushInstance());
484 if (qbrush_check_type(style))
487 d.
reset(nullBrushInstance());
504 if (qbrush_check_type(style))
507 d.
reset(nullBrushInstance());
564 "QGradient should not be used directly, use the linear, radial\n" 565 "or conical gradients instead");
692 if (qbrush_check_type(style)) {
764 QPixmap *QBrush::pixmap()
const 770 return pixmap.
isNull() ? 0 : &pixmap;
891 if (delta.
x() * delta.
x() + delta.
y() * delta.
y() > rg->
radius() * rg->
radius())
925 for (
int i=0; i<stops.
size(); ++i)
926 if (stops.
at(i).
second.alpha() != 255)
1054 #ifndef QT_NO_DEBUG_STREAM 1060 #ifndef Q_BROKEN_DEBUG_STREAM 1061 static const char *BRUSH_STYLES[] = {
1077 "LinearGradientPattern",
1078 "RadialGradientPattern",
1079 "ConicalGradientPattern",
1084 dbg.
nospace() <<
"QBrush(" << b.
color() <<
',' << BRUSH_STYLES[b.
style()] <<
')';
1087 qWarning(
"This compiler doesn't support streaming QBrush to QDebug");
1097 #ifndef QT_NO_DATASTREAM 1114 bool gradient_style =
false;
1118 gradient_style =
true;
1123 s << style << b.
color();
1128 int type_as_int = int(gradient->
type());
1131 s << int(gradient->
spread());
1138 if (
sizeof(
qreal) ==
sizeof(double)) {
1139 s << gradient->
stops();
1146 for (
int i = 0; i < stops.
size(); ++i) {
1148 s << QPair<double, QColor>(double(stop.
first), stop.
second);
1153 s << static_cast<const QLinearGradient *>(
gradient)->start();
1154 s << static_cast<const QLinearGradient *>(
gradient)->finalStop();
1157 s << static_cast<const QRadialGradient *>(
gradient)->focalPoint();
1158 s << (double) static_cast<const QRadialGradient *>(
gradient)->radius();
1161 s << (double) static_cast<const QConicalGradient *>(
gradient)->
angle();
1217 if (
sizeof(
qreal) ==
sizeof(
double)) {
1225 for (
quint32 i = 0; i < numStops; ++i) {
1227 stops << QPair<qreal, QColor>(n,
c);
1275 #endif // QT_NO_DATASTREAM 1381 : m_type(NoGradient), dummy(0)
1477 if ((pos > 1 || pos < 0) && !
qIsNaN(pos)) {
1478 qWarning(
"QGradient::setColorAt: Color position must be specified in the range 0 to 1");
1487 m_stops[index].second = color;
1507 for (
int i=0; i<stops.
size(); ++i)
1530 #define Q_DUMMY_ACCESSOR union {void *p; uint i;}; p = dummy; 1627 i |= (
uint(mode) << 2);
1684 return const_cast<const QGradient *
>(
this)->
operator==(gradient);
1762 m_data.linear.x2 = finalStop.
x();
1763 m_data.linear.y2 = finalStop.
y();
1783 m_data.linear.x1 = xStart;
1784 m_data.linear.y1 = yStart;
1785 m_data.linear.x2 = xFinalStop;
1786 m_data.linear.y2 = yFinalStop;
1940 const qreal compensated_radius = radius - radius *
qreal(0.001);
1941 QLineF line(center, focalPoint);
1942 if (line.
length() > (compensated_radius))
1963 m_data.radial.cx = center.
x();
1964 m_data.radial.cy = center.
y();
1965 m_data.radial.cradius = radius;
1968 m_data.radial.fx = adapted_focal.
x();
1969 m_data.radial.fy = adapted_focal.
y();
1982 m_data.radial.cx = center.
x();
1983 m_data.radial.cy = center.
y();
1984 m_data.radial.cradius = radius;
1985 m_data.radial.fx = center.
x();
1986 m_data.radial.fy = center.
y();
2008 m_data.radial.cradius = radius;
2014 m_data.radial.fx = adapted_focal.
x();
2015 m_data.radial.fy = adapted_focal.
y();
2030 m_data.radial.cradius = radius;
2046 m_data.radial.cradius = 1;
2064 m_data.radial.cx = center.
x();
2065 m_data.radial.cy = center.
y();
2066 m_data.radial.cradius = centerRadius;
2068 m_data.radial.fx = focalPoint.
x();
2069 m_data.radial.fy = focalPoint.
y();
2070 setFocalRadius(focalRadius);
2089 m_data.radial.cradius = centerRadius;
2093 setFocalRadius(focalRadius);
2137 m_data.radial.cx = center.
x();
2138 m_data.radial.cy = center.
y();
2153 return m_data.radial.cradius;
2168 m_data.radial.cradius = radius;
2185 return m_data.radial.cradius;
2197 m_data.radial.cradius = radius;
2238 u.f = float(radius);
2240 i |= (
u.i + 0x04) & ~0x07;
2286 m_data.radial.fx = focalPoint.
x();
2287 m_data.radial.fy = focalPoint.
y();
2343 m_data.conical.cx = center.
x();
2344 m_data.conical.cy = center.
y();
2380 m_data.conical.angle = 0;
2422 m_data.conical.cx = center.
x();
2423 m_data.conical.cy = center.
y();
2436 return m_data.conical.angle;
2506 #undef Q_DUMMY_ACCESSOR struct QGradient::@216::@218 radial
The QVariant class acts like a union for the most common Qt data types.
struct QGradient::@216::@217 linear
qreal focalRadius() const
Returns the focal radius of this radial gradient in logical coordinates.
void setFinalStop(const QPointF &stop)
Sets the final stop point of this linear gradient in logical coordinates to stop. ...
The QDebug class provides an output stream for debugging information.
void setCenterRadius(qreal radius)
The QColor class provides colors based on RGB, HSV or CMYK values.
QLinearGradient()
Constructs a default linear gradient with interpolation area between (0, 0) and (1, 1).
QPointF focalPoint() const
Returns the focal point of this radial gradient in logical coordinates.
QGlobalStaticDeleter(QGlobalStatic< QBrushData > &_globalStatic)
static QPixmap fromImage(const QImage &image, Qt::ImageConversionFlags flags=Qt::AutoColor)
Converts the given image to a pixmap using the specified flags to control the conversion.
QGlobalStatic< QBrushData > & globalStatic
The QLatin1Literal class provides a thin wrapper around string literals used in source code...
void setColorAt(qreal pos, const QColor &color)
Creates a stop point at the given position with the given color.
#define QT_END_NAMESPACE
This macro expands to.
const QColor & color() const
Returns the brush color.
Q_GUI_EXPORT QImage qt_imageForBrush(int brushStyle, bool invert)
QBrush & operator=(const QBrush &brush)
Assigns the given brush to this brush and returns a reference to this brush.
qreal length() const
Returns the length of the line.
QImage getImage(int brushStyle, bool invert) const
T * data() const
Returns the value of the pointer referenced by this object.
const QGradient * gradient() const
Returns the gradient describing this brush.
The QMatrix class specifies 2D transformations of a coordinate system.
void qAddPostRoutine(QtCleanUpFunction p)
void cleanUp(QBrushData *x)
void setTransform(const QTransform &)
Sets matrix as an explicit transformation matrix on the current brush.
QDebug & nospace()
Clears the stream's internal flag that records whether the last character was a space and returns a r...
CoordinateMode coordinateMode() const
Returns the coordinate mode of this gradient.
void setAngle(qreal angle)
Sets angle to be the start angle for this conical gradient in logical coordinates.
bool isNull() const
Returns true if it is a null image, otherwise returns false.
QScopedPointer< QBrushData, QBrushDataPointerDeleter > d
void detach(Qt::BrushStyle newStyle)
The QConicalGradient class is used in combination with QBrush to specify a conical gradient brush...
static QBitmap fromData(const QSize &size, const uchar *bits, QImage::Format monoFormat=QImage::Format_MonoLSB)
Constructs a bitmap with the given size, and sets the contents to the bits supplied.
const uchar * qt_patternForBrush(int brushStyle, bool invert)
QRadialGradient()
Constructs a simple radial gradient with the center and focal point at (0, 0) with a radius of 1...
T * take()
Returns the value of the pointer referenced by this object.
The QPointF class defines a point in the plane using floating point precision.
bool operator==(const QBrush &b) const
Returns true if the brush is equal to the given brush; otherwise returns false.
bool hasAlphaChannel() const
Returns true if the image has a format that respects the alpha channel, otherwise returns false...
CoordinateMode
This enum specifies how gradient coordinates map to the paint device on which the gradient is used...
bool ref()
Atomically increments the value of this QAtomicInt.
The QRadialGradient class is used in combination with QBrush to specify a radial gradient brush...
QBrushPatternImageCache()
The QString class provides a Unicode character string.
static void qt_cleanup_brush_pattern_image_cache()
QTransform transform() const
Returns the current transformation matrix for the brush.
void setPixmap(const QPixmap &pm)
qreal angle() const
Returns the start angle of the conical gradient in logical coordinates.
bool operator==(const QGradient &gradient) const
Returns true if the gradient is the same as the other gradient specified; otherwise returns false...
InterpolationMode interpolationMode() const
Returns the interpolation mode of this gradient.
static QPixmap * find(const QString &key)
qreal x() const
Returns the x-coordinate of this point.
The QScopedPointer class stores a pointer to a dynamically allocated object, and deletes it upon dest...
QPointF center() const
Returns the center of the conical gradient in logical coordinates.
friend bool Q_GUI_EXPORT qHasPixmapTexture(const QBrush &brush)
The QLineF class provides a two-dimensional vector using floating point precision.
QGradientStops stops() const
Returns the stop points for this gradient.
static QPointF qt_radial_gradient_adapt_focal_point(const QPointF ¢er, qreal radius, const QPointF &focalPoint)
void setSpread(Spread spread)
Specifies the spread method that should be used for this gradient.
void setCenter(const QPointF ¢er)
Sets the center of this conical gradient in logical coordinates to center.
#define QT_BEGIN_NAMESPACE
This macro expands to.
QGradientStop
Typedef for QPair<qreal , QColor>.
QConicalGradient()
Constructs a conical with center at (0, 0) starting the interpolation at angle 0. ...
bool Q_GUI_EXPORT qHasPixmapTexture(const QBrush &brush)
void setInterpolationMode(InterpolationMode mode)
Sets the interpolation mode of this gradient to mode.
void clear()
Removes all the elements from the vector and releases the memory used by the vector.
void setStyle(Qt::BrushStyle)
Sets the brush style to style.
bool deref()
Atomically decrements the value of this QAtomicInt.
QDataStream & operator<<(QDataStream &stream, const QBrush &brush)
Writes the given brush to the given stream and returns a reference to the stream. ...
QBasicAtomicPointer< T > pointer
Q_CORE_EXPORT void qWarning(const char *,...)
The QImage class provides a hardware-independent image representation that allows direct access to th...
Q_GLOBAL_STATIC_WITH_INITIALIZER(QBrushPatternImageCache, qt_brushPatternImageCache, { qAddPostRoutine(qt_cleanup_brush_pattern_image_cache);}) static void qt_cleanup_brush_pattern_image_cache()
static const char * data(const QByteArray &arr)
bool isQBitmap() const
Returns true if this is a QBitmap; otherwise returns false.
void setLength(qreal len)
Sets the length of the line to the given length.
static void cleanup(QBrushData *d)
Type
Specifies the type of gradient.
Qt::BrushStyle style() const
Returns the brush style.
QPixmap texture() const
Returns the custom brush pattern, or a null pixmap if no custom brush pattern has been set...
QDataStream & operator>>(QDataStream &stream, QBrush &brush)
Reads the given brush from the given stream and returns a reference to the stream.
bool isOpaque() const
Returns true if the brush is fully opaque otherwise false.
QPointF start() const
Returns the start point of this linear gradient in logical coordinates.
union QGradient::@216 m_data
Q_CORE_EXPORT bool qIsNaN(double d)
Returns true if the double {d} is not a number (NaN).
const QMatrix & matrix() const
Returns the current transformation matrix for the brush.
void reset(T *other=0)
Deletes the existing object it is pointing to if any, and sets its pointer to other.
const T & at(int i) const
Returns the item at index position i in the vector.
Spread
Specifies how the area outside the gradient area should be filled.
Q_CORE_EXPORT QTextStream & center(QTextStream &s)
int version() const
Returns the version number of the data serialization format.
void setImage(const QImage &image)
void setColor(const QColor &color)
Sets the brush color to the given color.
The QBrush class defines the fill pattern of shapes drawn by QPainter.
void insert(int i, const T &t)
Inserts value at index position i in the vector.
void setTexture(const QPixmap &pixmap)
Sets the brush pixmap to pixmap.
#define Q_ASSERT_X(cond, where, what)
qreal angle(const QPointF &p1, const QPointF &p2)
Type type() const
Returns the type of gradient.
ushort alpha
Returns the alpha color component of this color.
The QLinearGradient class is used in combination with QBrush to specify a linear gradient brush...
The QGradient class is used in combination with QBrush to specify gradient fills. ...
static void deleteData(QBrushData *d)
void setCoordinateMode(CoordinateMode mode)
Sets the coordinate mode of this gradient to mode.
void setRadius(qreal radius)
void setMatrix(const QMatrix &mat)
Sets matrix as an explicit transformation matrix on the current brush.
void setTextureImage(const QImage &image)
Sets the brush image to image.
static bool insert(const QString &key, const QPixmap &pixmap)
Inserts a copy of the pixmap pixmap associated with the key into the cache.
void setFocalRadius(qreal radius)
Q_GUI_EXPORT bool qt_isExtendedRadialGradient(const QBrush &brush)
void setStops(const QGradientStops &stops)
Replaces the current set of stop points with the given stopPoints.
QPointF p2() const
Returns the line's end point.
void setCenter(const QPointF ¢er)
Sets the center of this radial gradient in logical coordinates to center.
qreal radius() const
Returns the radius of this radial gradient in logical coordinates.
Spread spread() const
Returns the spread method use by this gradient.
qint64 cacheKey() const
Returns a number that identifies this QPixmap.
qreal y() const
Returns the y-coordinate of this point.
QPointF center() const
Returns the center of this radial gradient in logical coordinates.
The QPixmap class is an off-screen image representation that can be used as a paint device...
struct QGradient::@216::@219 conical
static Q_DECL_CONSTEXPR bool qFuzzyIsNull(double d)
The QSize class defines the size of a two-dimensional object using integer point precision.
bool isEmpty() const
Returns true if the vector has size 0; otherwise returns false.
The QDataStream class provides serialization of binary data to a QIODevice.
QImage m_images[Qt::DiagCrossPattern - Qt::Dense1Pattern+1][2]
~QBrush()
Destroys the brush.
bool m_has_pixmap_texture
bool isNull() const
Returns true if this is a null pixmap; otherwise returns false.
qreal centerRadius() const
Returns the center radius of this radial gradient in logical coordinates.
void setStart(const QPointF &start)
Sets the start point of this linear gradient in logical coordinates to start.
bool hasAlphaChannel() const
Returns true if the pixmap has a format that respects the alpha channel, otherwise returns false...
QDebug & space()
Writes a space character to the debug stream and returns a reference to the stream.
QImage textureImage() const
Returns the custom brush pattern, or a null image if no custom brush pattern has been set...
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
void init(const QColor &color, Qt::BrushStyle bs)
Initializes the brush.
int size() const
Returns the number of items in the vector.
QPixmap qt_pixmapForBrush(int brushStyle, bool invert)
QBrush()
Constructs a default black brush with the style Qt::NoBrush (i.e.
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
void setFocalPoint(const QPointF &focalPoint)
Sets the focal point of this radial gradient in logical coordinates to focalPoint.
QPointF finalStop() const
Returns the final stop point of this linear gradient in logical coordinates.