Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qbrush.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QBRUSH_H
5#define QBRUSH_H
6
7#include <QtGui/qtguiglobal.h>
8#include <QtCore/qlist.h>
9#include <QtCore/qpair.h>
10#include <QtCore/qpoint.h>
11#include <QtCore/qscopedpointer.h>
12#include <QtGui/qcolor.h>
13#include <QtGui/qimage.h>
14#include <QtGui/qpixmap.h>
15#include <QtGui/qtransform.h>
16
18
19
20struct QBrushData;
21class QPixmap;
22class QGradient;
23class QVariant;
25{
26 void operator()(QBrushData *d) const noexcept;
27};
28
29class Q_GUI_EXPORT QBrush
30{
31public:
32 QBrush();
36
37 QBrush(const QColor &color, const QPixmap &pixmap);
39 QBrush(const QPixmap &pixmap);
40 QBrush(const QImage &image);
41
42 QBrush(const QBrush &brush);
43
44 QBrush(const QGradient &gradient);
45
46 ~QBrush();
47 QBrush &operator=(const QBrush &brush);
48 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QBrush)
49 inline void swap(QBrush &other) noexcept
50 { d.swap(other.d); }
51
52 operator QVariant() const;
53
54 inline Qt::BrushStyle style() const;
56
57 inline QTransform transform() const;
58 void setTransform(const QTransform &);
59
60 QPixmap texture() const;
61 void setTexture(const QPixmap &pixmap);
62
63 QImage textureImage() const;
64 void setTextureImage(const QImage &image);
65
66 inline const QColor &color() const;
67 void setColor(const QColor &color);
68 inline void setColor(Qt::GlobalColor color);
69
70 const QGradient *gradient() const;
71
72 bool isOpaque() const;
73
74 bool operator==(const QBrush &b) const;
75 inline bool operator!=(const QBrush &b) const { return !(operator==(b)); }
76
77 using DataPtr = std::unique_ptr<QBrushData, QBrushDataPointerDeleter>;
78
79private:
80 friend class QRasterPaintEngine;
82 friend struct QSpanData;
83 friend class QPainter;
84 friend bool Q_GUI_EXPORT qHasPixmapTexture(const QBrush& brush);
85 void detach(Qt::BrushStyle newStyle);
86 void init(const QColor &color, Qt::BrushStyle bs);
87 DataPtr d;
88
89public:
90 inline bool isDetached() const;
91 inline DataPtr &data_ptr() { return d; }
92};
93
95{ setColor(QColor(acolor)); }
96
97Q_DECLARE_SHARED(QBrush)
98
99/*****************************************************************************
100 QBrush stream functions
101 *****************************************************************************/
102
103#ifndef QT_NO_DATASTREAM
104Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QBrush &);
105Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QBrush &);
106#endif
107
108#ifndef QT_NO_DEBUG_STREAM
109Q_GUI_EXPORT QDebug operator<<(QDebug, const QBrush &);
110#endif
111
119
120inline Qt::BrushStyle QBrush::style() const { return d->style; }
121inline const QColor &QBrush::color() const { return d->color; }
122inline QTransform QBrush::transform() const { return d->transform; }
123inline bool QBrush::isDetached() const { return d->ref.loadRelaxed() == 1; }
124
125
126/*******************************************************************************
127 * QGradients
128 */
129class QGradientPrivate;
130
131typedef QPair<qreal, QColor> QGradientStop;
132typedef QList<QGradientStop> QGradientStops;
133
134class Q_GUI_EXPORT QGradient
135{
137public:
144 Q_ENUM(Type)
145
146 enum Spread {
149 RepeatSpread
150 };
151 Q_ENUM(Spread)
152
159 Q_ENUM(CoordinateMode)
160
163 ComponentInterpolation
164 };
165
166 enum Preset {
167 WarmFlame = 1,
168 NightFade = 2,
169 SpringWarmth = 3,
170 JuicyPeach = 4,
171 YoungPassion = 5,
172 LadyLips = 6,
173 SunnyMorning = 7,
174 RainyAshville = 8,
175 FrozenDreams = 9,
176 WinterNeva = 10,
177 DustyGrass = 11,
178 TemptingAzure = 12,
179 HeavyRain = 13,
180 AmyCrisp = 14,
181 MeanFruit = 15,
182 DeepBlue = 16,
183 RipeMalinka = 17,
184 CloudyKnoxville = 18,
185 MalibuBeach = 19,
186 NewLife = 20,
187 TrueSunset = 21,
188 MorpheusDen = 22,
189 RareWind = 23,
190 NearMoon = 24,
191 WildApple = 25,
192 SaintPetersburg = 26,
193 PlumPlate = 28,
194 EverlastingSky = 29,
195 HappyFisher = 30,
196 Blessing = 31,
197 SharpeyeEagle = 32,
198 LadogaBottom = 33,
199 LemonGate = 34,
200 ItmeoBranding = 35,
201 ZeusMiracle = 36,
202 OldHat = 37,
203 StarWine = 38,
204 HappyAcid = 41,
205 AwesomePine = 42,
206 NewYork = 43,
207 ShyRainbow = 44,
208 MixedHopes = 46,
209 FlyHigh = 47,
210 StrongBliss = 48,
211 FreshMilk = 49,
212 SnowAgain = 50,
213 FebruaryInk = 51,
214 KindSteel = 52,
215 SoftGrass = 53,
216 GrownEarly = 54,
217 SharpBlues = 55,
218 ShadyWater = 56,
219 DirtyBeauty = 57,
220 GreatWhale = 58,
221 TeenNotebook = 59,
222 PoliteRumors = 60,
223 SweetPeriod = 61,
224 WideMatrix = 62,
225 SoftCherish = 63,
226 RedSalvation = 64,
227 BurningSpring = 65,
228 NightParty = 66,
229 SkyGlider = 67,
230 HeavenPeach = 68,
231 PurpleDivision = 69,
232 AquaSplash = 70,
233 SpikyNaga = 72,
234 LoveKiss = 73,
235 CleanMirror = 75,
236 PremiumDark = 76,
237 ColdEvening = 77,
238 CochitiLake = 78,
239 SummerGames = 79,
240 PassionateBed = 80,
241 MountainRock = 81,
242 DesertHump = 82,
243 JungleDay = 83,
244 PhoenixStart = 84,
245 OctoberSilence = 85,
246 FarawayRiver = 86,
247 AlchemistLab = 87,
248 OverSun = 88,
249 PremiumWhite = 89,
250 MarsParty = 90,
251 EternalConstance = 91,
252 JapanBlush = 92,
253 SmilingRain = 93,
254 CloudyApple = 94,
255 BigMango = 95,
256 HealthyWater = 96,
257 AmourAmour = 97,
258 RiskyConcrete = 98,
259 StrongStick = 99,
260 ViciousStance = 100,
261 PaloAlto = 101,
262 HappyMemories = 102,
263 MidnightBloom = 103,
264 Crystalline = 104,
265 PartyBliss = 106,
266 ConfidentCloud = 107,
267 LeCocktail = 108,
268 RiverCity = 109,
269 FrozenBerry = 110,
270 ChildCare = 112,
271 FlyingLemon = 113,
272 NewRetrowave = 114,
273 HiddenJaguar = 115,
274 AboveTheSky = 116,
275 Nega = 117,
276 DenseWater = 118,
277 Seashore = 120,
278 MarbleWall = 121,
279 CheerfulCaramel = 122,
280 NightSky = 123,
281 MagicLake = 124,
282 YoungGrass = 125,
283 ColorfulPeach = 126,
284 GentleCare = 127,
285 PlumBath = 128,
286 HappyUnicorn = 129,
287 AfricanField = 131,
288 SolidStone = 132,
289 OrangeJuice = 133,
290 GlassWater = 134,
291 NorthMiracle = 136,
292 FruitBlend = 137,
293 MillenniumPine = 138,
294 HighFlight = 139,
295 MoleHall = 140,
296 SpaceShift = 142,
297 ForestInei = 143,
298 RoyalGarden = 144,
299 RichMetal = 145,
300 JuicyCake = 146,
301 SmartIndigo = 147,
302 SandStrike = 148,
303 NorseBeauty = 149,
304 AquaGuidance = 150,
305 SunVeggie = 151,
306 SeaLord = 152,
307 BlackSea = 153,
308 GrassShampoo = 154,
309 LandingAircraft = 155,
310 WitchDance = 156,
311 SleeplessNight = 157,
312 AngelCare = 158,
313 CrystalRiver = 159,
314 SoftLipstick = 160,
315 SaltMountain = 161,
316 PerfectWhite = 162,
317 FreshOasis = 163,
318 StrictNovember = 164,
319 MorningSalad = 165,
320 DeepRelief = 166,
321 SeaStrike = 167,
322 NightCall = 168,
323 SupremeSky = 169,
324 LightBlue = 170,
325 MindCrawl = 171,
326 LilyMeadow = 172,
327 SugarLollipop = 173,
328 SweetDessert = 174,
329 MagicRay = 175,
330 TeenParty = 176,
331 FrozenHeat = 177,
332 GagarinView = 178,
333 FabledSunset = 179,
334 PerfectBlue = 180,
335
336 NumPresets
337 };
338 Q_ENUM(Preset)
339
340 QGradient();
341 QGradient(Preset);
342 ~QGradient();
343
344 Type type() const { return m_type; }
345
346 inline void setSpread(Spread spread);
347 Spread spread() const { return m_spread; }
348
349 void setColorAt(qreal pos, const QColor &color);
350
351 void setStops(const QGradientStops &stops);
352 QGradientStops stops() const;
353
354 CoordinateMode coordinateMode() const;
355 void setCoordinateMode(CoordinateMode mode);
356
357 InterpolationMode interpolationMode() const;
358 void setInterpolationMode(InterpolationMode mode);
359
360 bool operator==(const QGradient &gradient) const;
361 inline bool operator!=(const QGradient &other) const
362 { return !operator==(other); }
363
365 struct {
367 } linear;
368 struct {
369 qreal cx, cy, fx, fy, cradius, fradius;
370 } radial;
371 struct {
372 qreal cx, cy, angle;
373 } conical;
374 };
375
376private:
377 friend class QLinearGradient;
378 friend class QRadialGradient;
379 friend class QConicalGradient;
380 friend class QBrush;
381
382 Type m_type = NoGradient;
383 Spread m_spread = PadSpread;
384 QGradientStops m_stops;
386 CoordinateMode m_coordinateMode = LogicalMode;
387 InterpolationMode m_interpolationMode = ColorInterpolation;
388};
389
390inline void QGradient::setSpread(Spread aspread)
391{ m_spread = aspread; }
392
393class Q_GUI_EXPORT QLinearGradient : public QGradient
394{
395public:
397 QLinearGradient(const QPointF &start, const QPointF &finalStop);
398 QLinearGradient(qreal xStart, qreal yStart, qreal xFinalStop, qreal yFinalStop);
400
401 QPointF start() const;
402 void setStart(const QPointF &start);
403 inline void setStart(qreal x, qreal y) { setStart(QPointF(x, y)); }
404
405 QPointF finalStop() const;
406 void setFinalStop(const QPointF &stop);
408};
409
410
411class Q_GUI_EXPORT QRadialGradient : public QGradient
412{
413public:
415 QRadialGradient(const QPointF &center, qreal radius, const QPointF &focalPoint);
416 QRadialGradient(qreal cx, qreal cy, qreal radius, qreal fx, qreal fy);
417
418 QRadialGradient(const QPointF &center, qreal radius);
419 QRadialGradient(qreal cx, qreal cy, qreal radius);
420
421 QRadialGradient(const QPointF &center, qreal centerRadius, const QPointF &focalPoint, qreal focalRadius);
422 QRadialGradient(qreal cx, qreal cy, qreal centerRadius, qreal fx, qreal fy, qreal focalRadius);
423
425
426 QPointF center() const;
427 void setCenter(const QPointF &center);
428 inline void setCenter(qreal x, qreal y) { setCenter(QPointF(x, y)); }
429
430 QPointF focalPoint() const;
431 void setFocalPoint(const QPointF &focalPoint);
433
434 qreal radius() const;
435 void setRadius(qreal radius);
436
437 qreal centerRadius() const;
438 void setCenterRadius(qreal radius);
439
440 qreal focalRadius() const;
441 void setFocalRadius(qreal radius);
442};
443
444
445class Q_GUI_EXPORT QConicalGradient : public QGradient
446{
447public:
449 QConicalGradient(const QPointF &center, qreal startAngle);
450 QConicalGradient(qreal cx, qreal cy, qreal startAngle);
452
453 QPointF center() const;
454 void setCenter(const QPointF &center);
455 inline void setCenter(qreal x, qreal y) { setCenter(QPointF(x, y)); }
456
457 qreal angle() const;
458 void setAngle(qreal angle);
459};
460
462
463#endif // QBRUSH_H
NSData * m_data
\inmodule QtCore
Definition qatomic.h:112
\inmodule QtGui
Definition qbrush.h:30
void setColor(const QColor &color)
Sets the brush color to the given color.
Definition qbrush.cpp:687
std::unique_ptr< QBrushData, QBrushDataPointerDeleter > DataPtr
Definition qbrush.h:77
bool operator!=(const QBrush &b) const
Returns true if the brush is different from the given brush; otherwise returns false.
Definition qbrush.h:75
const QColor & color() const
Returns the brush color.
Definition qbrush.h:121
Qt::BrushStyle style() const
Returns the brush style.
Definition qbrush.h:120
QTransform transform() const
Definition qbrush.h:122
DataPtr & data_ptr()
Definition qbrush.h:91
bool isDetached() const
Definition qbrush.h:123
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition qcolor.h:31
\inmodule QtGui
Definition qbrush.h:446
void setCenter(qreal x, qreal y)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qbrush.h:455
\inmodule QtCore\reentrant
Definition qdatastream.h:46
\inmodule QtCore
\inmodule QtGui
Definition qbrush.h:135
void setSpread(Spread spread)
Specifies the spread method that should be used for this gradient.
Definition qbrush.h:390
Spread spread() const
Returns the spread method use by this gradient.
Definition qbrush.h:347
InterpolationMode
Definition qbrush.h:161
@ ColorInterpolation
Definition qbrush.h:162
CoordinateMode
Definition qbrush.h:153
@ ObjectBoundingMode
Definition qbrush.h:156
@ LogicalMode
Definition qbrush.h:154
@ StretchToDeviceMode
Definition qbrush.h:155
Spread
Specifies how the area outside the gradient area should be filled.
Definition qbrush.h:146
@ ReflectSpread
Definition qbrush.h:148
@ PadSpread
Definition qbrush.h:147
Type type() const
Returns the type of gradient.
Definition qbrush.h:344
@ LinearGradient
Definition qbrush.h:139
@ ConicalGradient
Definition qbrush.h:141
@ RadialGradient
Definition qbrush.h:140
bool operator!=(const QGradient &other) const
Definition qbrush.h:361
\inmodule QtGui
Definition qimage.h:37
\inmodule QtGui
Definition qbrush.h:394
void setStart(qreal x, qreal y)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qbrush.h:403
void setFinalStop(qreal x, qreal y)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qbrush.h:407
The QPainter class performs low-level painting on widgets and other paint devices.
Definition qpainter.h:46
Returns a copy of the pixmap that is transformed using the given transformation transform and transfo...
Definition qpixmap.h:27
\inmodule QtCore\reentrant
Definition qpoint.h:217
\inmodule QtGui
Definition qbrush.h:412
void setCenter(qreal x, qreal y)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qbrush.h:428
void setFocalPoint(qreal x, qreal y)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qbrush.h:432
The QRasterPaintEngine class enables hardware acceleration of painting operations in Qt for Embedded ...
The QTransform class specifies 2D transformations of a coordinate system.
Definition qtransform.h:20
\inmodule QtCore
Definition qvariant.h:65
Combined button and popup list for selecting options.
GlobalColor
Definition qnamespace.h:27
BrushStyle
@ SolidPattern
Definition brush.cpp:5
Definition image.cpp:4
bool Q_GUI_EXPORT qHasPixmapTexture(const QBrush &brush)
Definition qbrush.cpp:202
QPair< qreal, QColor > QGradientStop
Definition qbrush.h:131
QList< QGradientStop > QGradientStops
Definition qbrush.h:132
Q_GUI_EXPORT QDataStream & operator<<(QDataStream &, const QBrush &)
Definition qbrush.cpp:998
Q_GUI_EXPORT QDataStream & operator>>(QDataStream &, QBrush &)
Definition qbrush.cpp:1074
GLboolean GLboolean GLboolean b
GLint GLint GLint GLint GLint x
[0]
GLenum mode
GLuint GLfloat GLfloat GLfloat GLfloat y1
GLuint GLuint focalPoint
GLuint color
[2]
GLfloat angle
GLenum GLuint texture
GLuint start
GLint y
GLuint GLenum GLenum transform
GLfixed GLfixed GLfixed y2
GLfixed GLfixed x2
static QGradient::CoordinateMode coordinateMode(const QBrush &brush)
Definition qpainter.cpp:80
bool operator==(const QRandomGenerator &rng1, const QRandomGenerator &rng2)
Definition qrandom.cpp:1220
static QT_BEGIN_NAMESPACE void init(QTextBoundaryFinder::BoundaryType type, QStringView str, QCharAttributes *attributes)
#define Q_ENUM(x)
#define Q_GADGET
double qreal
Definition qtypes.h:187
QSharedPointer< T > other(t)
[5]
this swap(other)
alphaGradient setColorAt(0.0, Qt::transparent)
myFilter setColor(QColor(128, 0, 0))
widget render & pixmap
widget setStyle(proxy)
void operator()(QBrushData *d) const noexcept
Definition qbrush.cpp:231
Qt::BrushStyle style
Definition qbrush.h:115
QTransform transform
Definition qbrush.h:117
QAtomicInt ref
Definition qbrush.h:114
QColor color
Definition qbrush.h:116
Definition moc.h:23