9#include <qpa/qplatformpixmap.h>
14#include <QtCore/qjsondocument.h>
15#include <QtCore/qjsonarray.h>
16#include <QtCore/qcoreapplication.h>
17#include "private/qhexstring_p.h"
18#include <QtCore/qnumeric.h>
19#include <QtCore/qfile.h>
20#include <QtCore/qmutex.h>
21#include <QtCore/private/qoffsetstringarray_p.h>
27#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
35 static const uchar pat_tbl[][2][8] = {
37 { 0x00, 0x44, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00 },
38 { 0xff, 0xbb, 0xff, 0xff, 0xff, 0xbb, 0xff, 0xff },
40 { 0x88, 0x00, 0x22, 0x00, 0x88, 0x00, 0x22, 0x00 },
41 { 0x77, 0xff, 0xdd, 0xff, 0x77, 0xff, 0xdd, 0xff },
43 { 0xaa, 0x44, 0xaa, 0x11, 0xaa, 0x44, 0xaa, 0x11 },
44 { 0x55, 0xbb, 0x55, 0xee, 0x55, 0xbb, 0x55, 0xee },
46 { 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa },
47 { 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55 },
49 { 0x55, 0xbb, 0x55, 0xee, 0x55, 0xbb, 0x55, 0xee },
50 { 0xaa, 0x44, 0xaa, 0x11, 0xaa, 0x44, 0xaa, 0x11 },
52 { 0x77, 0xff, 0xdd, 0xff, 0x77, 0xff, 0xdd, 0xff },
53 { 0x88, 0x00, 0x22, 0x00, 0x88, 0x00, 0x22, 0x00 },
55 { 0xff, 0xbb, 0xff, 0xff, 0xff, 0xbb, 0xff, 0xff },
56 { 0x00, 0x44, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00 },
58 { 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0xff },
59 { 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00 },
61 { 0xef, 0xef, 0xef, 0xef, 0xef, 0xef, 0xef, 0xef },
62 { 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10 },
64 { 0xef, 0xef, 0xef, 0x00, 0xef, 0xef, 0xef, 0xef },
65 { 0x10, 0x10, 0x10, 0xff, 0x10, 0x10, 0x10, 0x10 },
67 { 0x7f, 0xbf, 0xdf, 0xef, 0xf7, 0xfb, 0xfd, 0xfe },
68 { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 },
70 { 0xfe, 0xfd, 0xfb, 0xf7, 0xef, 0xdf, 0xbf, 0x7f },
71 { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 },
73 { 0x7e, 0xbd, 0xdb, 0xe7, 0xe7, 0xdb, 0xbd, 0x7e },
74 { 0x81, 0x42, 0x24, 0x18, 0x18, 0x24, 0x42, 0x81 },
101 : m_initialized(
false)
114 m_initialized =
true;
131 m_initialized =
false;
143 qt_brushPatternImageCache()->cleanup();
148 return qt_brushPatternImageCache()->getImage(brushStyle,
invert);
233 if (
d && !
d->ref.deref())
324 brush->ref.storeRelaxed(1);
330 if (!
brush->ref.deref())
339 return nullBrushInstance_holder()->brush;
345 qWarning(
"QBrush: Incorrect use of TexturePattern");
350 qWarning(
"QBrush: Wrong use of a gradient pattern");
383 d->ref.storeRelaxed(1);
563 if (
data->m_has_pixmap_texture)
592 x->ref.storeRelaxed(1);
595 x->transform = d->transform;
657 if (d->style ==
style)
778 if (!
image.isNull()) {
811 if (delta.
x() * delta.
x() + delta.
y() * delta.
y() > rg->
radius() * rg->
radius())
832 bool opaqueColor = d->color.alphaF() >= 1.0f;
845 for (
int i=0;
i<stops.
size(); ++
i)
846 if (stops.
at(
i).second.alphaF() < 1.0f)
902 if (
b.d->style != d->style ||
b.d->color != d->color ||
b.d->transform != d->transform)
911 const QPixmap *us =
nullptr, *them =
nullptr;
912 qint64 cacheKey1, cacheKey2;
921 cacheKey2 = them->cacheKey();
925 if (cacheKey1 != cacheKey2)
942 return d1->gradient ==
d2->gradient;
949#ifndef QT_NO_DEBUG_STREAM
971 "LinearGradientPattern",
972 "RadialGradientPattern",
973 "ConicalGradientPattern",
974 "",
"",
"",
"",
"",
"",
979 dbg.nospace() <<
"QBrush(" <<
b.color() <<
',' << BRUSH_STYLES[
b.style()] <<
')';
987#ifndef QT_NO_DATASTREAM
1001 bool gradient_style =
false;
1005 gradient_style =
true;
1010 s << style <<
b.color();
1013 s <<
b.textureImage();
1018 int type_as_int = int(gradient->
type());
1031 if (
sizeof(
qreal) ==
sizeof(
double)) {
1039 for (
int i = 0;
i < stops.
size(); ++
i) {
1041 s << QPair<double, QColor>(
double(stop.first), stop.second);
1046 s << static_cast<const QLinearGradient *>(gradient)->start();
1047 s << static_cast<const QLinearGradient *>(gradient)->finalStop();
1049 s << static_cast<const QRadialGradient *>(gradient)->center();
1050 s << static_cast<const QRadialGradient *>(gradient)->focalPoint();
1051 s << (double) static_cast<const QRadialGradient *>(gradient)->radius();
1053 s << (double) static_cast<const QRadialGradient *>(gradient)->focalRadius();
1055 s << static_cast<const QConicalGradient *>(gradient)->center();
1056 s << (double) static_cast<const QConicalGradient *>(gradient)->angle();
1085 b.setTextureImage(std::move(
img));
1089 b.setTexture(std::move(pm));
1116 if (
sizeof(
qreal) ==
sizeof(
double)) {
1127 stops << QPair<qreal, QColor>(
n,
c);
1144 double focalRadius = 0;
1284 : m_type(NoGradient)
1478 : m_type(LinearGradient)
1481 , m_coordinateMode(ObjectMode)
1566 qWarning(
"QGradient::setColorAt: Color position must be specified in the range 0 to 1");
1582 return stop.first >= 0 && stop.first <= 1;
1591 const bool sorted = stop.first > lastPos;
1594 lastPos = stop.first;
1674 return m_coordinateMode;
1685 m_coordinateMode =
mode;
1708 return m_interpolationMode;
1720 m_interpolationMode =
mode;
1741 if (gradient.m_type != m_type
1742 || gradient.m_spread != m_spread
1743 || gradient.m_coordinateMode != m_coordinateMode
1744 || gradient.m_interpolationMode != m_interpolationMode)
return false;
2006 const qreal compensated_radius = radius - radius *
qreal(0.001);
2009 line.setLength(compensated_radius);
2032 m_data.radial.fradius = 0;
2035 m_data.radial.fx = adapted_focal.
x();
2036 m_data.radial.fy = adapted_focal.
y();
2052 m_data.radial.fradius = 0;
2097 m_data.radial.cradius = 1;
2098 m_data.radial.fradius = 0;
2116 m_data.radial.fradius = 0;
2137 m_data.radial.fradius = 0;
2202 return m_data.radial.cradius;
2231 return m_data.radial.cradius;
2257 return m_data.radial.fradius;
2403 m_data.conical.angle = 0;
2456 return m_data.conical.angle;
2516#include "moc_qbrush.cpp"
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.
QBrushPatternImageCache()
QImage getImage(int brushStyle, bool invert) const
void setColor(const QColor &color)
Sets the brush color to the given color.
void setStyle(Qt::BrushStyle)
Sets the brush style to style.
void setTransform(const QTransform &)
QBrush & operator=(const QBrush &brush)
Assigns the given brush to this brush and returns a reference to this brush.
void setTextureImage(const QImage &image)
bool operator==(const QBrush &b) const
Returns true if the brush is equal to the given brush; otherwise returns false.
friend bool Q_GUI_EXPORT qHasPixmapTexture(const QBrush &brush)
bool isOpaque() const
Returns true if the brush is fully opaque otherwise false.
const QGradient * gradient() const
Returns the gradient describing this brush.
QBrush()
Constructs a default black brush with the style Qt::NoBrush (i.e.
void setTexture(const QPixmap &pixmap)
Sets the brush pixmap to pixmap.
~QBrush()
Destroys the brush.
QImage textureImage() const
QPixmap texture() const
Returns the custom brush pattern, or a null pixmap if no custom brush pattern has been set.
const QColor & color() const
Returns the brush color.
std::unique_ptr< QBrushData, QBrushDataPointerDeleter > DataPtr
Qt::BrushStyle style() const
Returns the brush style.
The QColor class provides colors based on RGB, HSV or CMYK values.
void setCenter(const QPointF ¢er)
Sets the center of this conical gradient in logical coordinates to center.
qreal angle() const
Returns the start angle of the conical gradient in logical coordinates.
QConicalGradient()
Constructs a conical with center at (0, 0) starting the interpolation at angle 0.
void setAngle(qreal angle)
QPointF center() const
Returns the center of the conical gradient in logical coordinates.
\inmodule QtCore\reentrant
QGradientStop
Typedef for QPair<\l qreal, QColor>.
void setSpread(Spread spread)
Specifies the spread method that should be used for this gradient.
void setCoordinateMode(CoordinateMode mode)
Spread spread() const
Returns the spread method use by this gradient.
CoordinateMode coordinateMode() const
void setStops(const QGradientStops &stops)
Replaces the current set of stop points with the given stopPoints.
void setColorAt(qreal pos, const QColor &color)
Creates a stop point at the given position with the given color.
InterpolationMode interpolationMode() const
Spread
Specifies how the area outside the gradient area should be filled.
Type type() const
Returns the type of gradient.
void setInterpolationMode(InterpolationMode mode)
QGradientStops stops() const
Returns the stop points for this gradient.
bool operator==(const QGradient &gradient) const
Returns true if the gradient is the same as the other gradient specified; otherwise returns false.
Type
Specifies the type of gradient.
bool hasAlphaChannel() const
Returns true if the image has a format that respects the alpha channel, otherwise returns false.
bool isNull() const
Returns true if it is a null image, otherwise returns false.
QPointF start() const
Returns the start point of this linear gradient in logical coordinates.
QPointF finalStop() const
Returns the final stop point of this linear gradient in logical coordinates.
QLinearGradient()
Constructs a default linear gradient with interpolation area between (0, 0) and (1,...
void setFinalStop(const QPointF &stop)
void setStart(const QPointF &start)
qsizetype size() const noexcept
bool isEmpty() const noexcept
iterator insert(qsizetype i, parameter_type t)
static QList< QGradientStop > fromReadOnlyData(const QGradientStop(&t)[N]) noexcept
const_reference at(qsizetype i) const noexcept
void reserve(qsizetype size)
static bool find(const QString &key, QPixmap *pixmap)
Looks for a cached pixmap associated with the given key in the cache.
static bool insert(const QString &key, const QPixmap &pixmap)
Inserts a copy of the pixmap pixmap associated with the key into the cache.
Returns a copy of the pixmap that is transformed using the given transformation transform and transfo...
QImage toImage() const
Converts the pixmap to a QImage.
bool isNull() const
Returns true if this is a null pixmap; otherwise returns false.
QPlatformPixmap * handle() const
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.
qint64 cacheKey() const
Returns a number that identifies this QPixmap.
bool hasAlphaChannel() const
bool isQBitmap() const
Returns true if this is a QBitmap; otherwise returns false.
\inmodule QtCore\reentrant
constexpr qreal x() const noexcept
Returns the x coordinate of this point.
constexpr qreal y() const noexcept
Returns the y coordinate of this point.
void setCenter(const QPointF ¢er)
QPointF center() const
Returns the center of this radial gradient in logical coordinates.
qreal focalRadius() const
void setFocalPoint(const QPointF &focalPoint)
QRadialGradient()
Constructs a simple radial gradient with the center and focal point at (0, 0) with a radius of 1.
void setCenterRadius(qreal radius)
QPointF focalPoint() const
Returns the focal point of this radial gradient in logical coordinates.
qreal centerRadius() const
void setFocalRadius(qreal radius)
qreal radius() const
Returns the radius of this radial gradient in logical coordinates.
void setRadius(qreal radius)
\macro QT_RESTRICTED_CAST_FROM_ASCII
qsizetype length() const
Returns the number of characters in this string.
static auto fromValue(T &&value) noexcept(std::is_nothrow_copy_constructible_v< T > &&Private::CanUseInternalSpace< T >) -> std::enable_if_t< std::conjunction_v< std::is_copy_constructible< T >, std::is_destructible< T > >, QVariant >
Combined button and popup list for selecting options.
Q_GUI_EXPORT QImage qt_imageForBrush(int brushStyle, bool invert)
static bool qbrush_check_type(Qt::BrushStyle style)
Q_GUI_EXPORT QPixmap qt_pixmapForBrush(int brushStyle, bool invert)
static constexpr bool use_same_brushdata(Qt::BrushStyle lhs, Qt::BrushStyle rhs)
QDebug operator<<(QDebug dbg, const QBrush &b)
bool Q_GUI_EXPORT qHasPixmapTexture(const QBrush &brush)
static void qt_cleanup_brush_pattern_image_cache()
static QPointF qt_radial_gradient_adapt_focal_point(const QPointF ¢er, qreal radius, const QPointF &focalPoint)
static void deleteData(QBrushData *d)
static QBrushData * nullBrushInstance()
const uchar * qt_patternForBrush(int brushStyle, bool invert)
QDataStream & operator>>(QDataStream &s, QBrush &b)
Q_GUI_EXPORT bool qt_isExtendedRadialGradient(const QBrush &brush)
QPair< qreal, QColor > QGradientStop
void qAddPostRoutine(QtCleanUpFunction p)
static QDBusError::ErrorType get(const char *name)
bool qFuzzyIsNull(qfloat16 f) noexcept
bool qIsNaN(qfloat16 f) noexcept
#define Q_GLOBAL_STATIC(TYPE, NAME,...)
constexpr auto qOffsetStringArray(const char(&...strings)[Nx]) noexcept
GLboolean GLboolean GLboolean b
GLint GLint GLint GLint GLint x
[0]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLuint GLenum GLenum transform
void operator()(QBrushData *d) const noexcept
\inmodule QtCore \reentrant
void setImage(const QImage &image)
void setPixmap(const QPixmap &pm)
bool m_has_pixmap_texture
struct QGradient::QGradientData::@231 radial
struct QGradient::QGradientData::@230 linear
struct QGradient::QGradientData::@232 conical
static QList< QGradientStop > qt_preset_gradient_stops(QGradient::Preset preset)
static constexpr QGradient::QGradientData qt_preset_gradient_data[]