Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
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// Qt-Security score:significant reason:default
4
5#ifndef QBRUSH_H
6#define QBRUSH_H
7
8#include <QtGui/qtguiglobal.h>
9#include <QtCore/qlist.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
17QT_BEGIN_NAMESPACE
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();
33 QBrush(Qt::BrushStyle bs);
34 QBrush(const QColor &color, Qt::BrushStyle bs=Qt::SolidPattern);
35 QBrush(Qt::GlobalColor color, Qt::BrushStyle bs=Qt::SolidPattern);
36
37 QBrush(const QColor &color, const QPixmap &pixmap);
38 QBrush(Qt::GlobalColor 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 QBrush &operator=(Qt::BrushStyle style);
53 QBrush &operator=(QColor color);
54 QBrush &operator=(Qt::GlobalColor color) { return operator=(QColor(color)); }
55
56 operator QVariant() const;
57
58 inline Qt::BrushStyle style() const;
59 void setStyle(Qt::BrushStyle);
60
61 inline QTransform transform() const;
62 void setTransform(const QTransform &);
63
64 QPixmap texture() const;
65 void setTexture(const QPixmap &pixmap);
66
67 QImage textureImage() const;
68 void setTextureImage(const QImage &image);
69
70 inline const QColor &color() const;
71 void setColor(const QColor &color);
72 inline void setColor(Qt::GlobalColor color);
73
74 const QGradient *gradient() const;
75
76 bool isOpaque() const;
77
78 bool operator==(const QBrush &b) const;
79 inline bool operator!=(const QBrush &b) const { return !(operator==(b)); }
80
81 using DataPtr = std::unique_ptr<QBrushData, QBrushDataPointerDeleter>;
82
83private:
84 friend class QRasterPaintEngine;
85 friend class QRasterPaintEnginePrivate;
86 friend struct QSpanData;
87 friend class QPainter;
88 friend bool Q_GUI_EXPORT qHasPixmapTexture(const QBrush& brush);
89
90 bool doCompareEqualColor(QColor rhs) const noexcept;
91 friend bool comparesEqual(const QBrush &lhs, QColor rhs) noexcept
92 {
93 return lhs.doCompareEqualColor(rhs);
94 }
95 Q_DECLARE_EQUALITY_COMPARABLE(QBrush, QColor)
96 Q_DECLARE_EQUALITY_COMPARABLE(QBrush, Qt::GlobalColor)
97
98 bool doCompareEqualStyle(Qt::BrushStyle rhs) const noexcept;
99 friend bool comparesEqual(const QBrush &lhs, Qt::BrushStyle rhs) noexcept
100 {
101 return lhs.doCompareEqualStyle(rhs);
102 }
103 Q_DECLARE_EQUALITY_COMPARABLE(QBrush, Qt::BrushStyle)
104
105 void detach(Qt::BrushStyle newStyle);
106 void init(const QColor &color, Qt::BrushStyle bs);
107 DataPtr d;
108
109public:
110 inline bool isDetached() const;
111 inline DataPtr &data_ptr() { return d; }
112};
113
114inline void QBrush::setColor(Qt::GlobalColor acolor)
115{ setColor(QColor(acolor)); }
116
118
119/*****************************************************************************
120 QBrush stream functions
121 *****************************************************************************/
122
123#ifndef QT_NO_DATASTREAM
124Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QBrush &);
125Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QBrush &);
126#endif
127
128#ifndef QT_NO_DEBUG_STREAM
129Q_GUI_EXPORT QDebug operator<<(QDebug, const QBrush &);
130#endif
131
142
143inline Qt::BrushStyle QBrush::style() const { return d->style; }
144inline const QColor &QBrush::color() const { return d->color; }
145inline QTransform QBrush::transform() const { return d->transform; }
146inline bool QBrush::isDetached() const { return d->ref.loadRelaxed() == 1; }
147
148
149/*******************************************************************************
150 * QGradients
151 */
152class QGradientPrivate;
153
156
157class Q_GUI_EXPORT QGradient
158{
159 Q_GADGET
160public:
161 enum Type {
162 LinearGradient,
163 RadialGradient,
164 ConicalGradient,
165 NoGradient
166 };
167 Q_ENUM(Type)
168
169 enum Spread {
170 PadSpread,
171 ReflectSpread,
172 RepeatSpread
173 };
174 Q_ENUM(Spread)
175
176 enum CoordinateMode {
177 LogicalMode,
178 StretchToDeviceMode,
179 ObjectBoundingMode,
180 ObjectMode
181 };
182 Q_ENUM(CoordinateMode)
183
184 enum InterpolationMode {
185 ColorInterpolation,
186 ComponentInterpolation
187 };
188
189 enum Preset {
190 WarmFlame = 1,
191 NightFade = 2,
192 SpringWarmth = 3,
193 JuicyPeach = 4,
194 YoungPassion = 5,
195 LadyLips = 6,
196 SunnyMorning = 7,
197 RainyAshville = 8,
198 FrozenDreams = 9,
199 WinterNeva = 10,
200 DustyGrass = 11,
201 TemptingAzure = 12,
202 HeavyRain = 13,
203 AmyCrisp = 14,
204 MeanFruit = 15,
205 DeepBlue = 16,
206 RipeMalinka = 17,
207 CloudyKnoxville = 18,
208 MalibuBeach = 19,
209 NewLife = 20,
210 TrueSunset = 21,
211 MorpheusDen = 22,
212 RareWind = 23,
213 NearMoon = 24,
214 WildApple = 25,
215 SaintPetersburg = 26,
216 PlumPlate = 28,
217 EverlastingSky = 29,
218 HappyFisher = 30,
219 Blessing = 31,
220 SharpeyeEagle = 32,
221 LadogaBottom = 33,
222 LemonGate = 34,
223 ItmeoBranding = 35,
224 ZeusMiracle = 36,
225 OldHat = 37,
226 StarWine = 38,
227 HappyAcid = 41,
228 AwesomePine = 42,
229 NewYork = 43,
230 ShyRainbow = 44,
231 MixedHopes = 46,
232 FlyHigh = 47,
233 StrongBliss = 48,
234 FreshMilk = 49,
235 SnowAgain = 50,
236 FebruaryInk = 51,
237 KindSteel = 52,
238 SoftGrass = 53,
239 GrownEarly = 54,
240 SharpBlues = 55,
241 ShadyWater = 56,
242 DirtyBeauty = 57,
243 GreatWhale = 58,
244 TeenNotebook = 59,
245 PoliteRumors = 60,
246 SweetPeriod = 61,
247 WideMatrix = 62,
248 SoftCherish = 63,
249 RedSalvation = 64,
250 BurningSpring = 65,
251 NightParty = 66,
252 SkyGlider = 67,
253 HeavenPeach = 68,
254 PurpleDivision = 69,
255 AquaSplash = 70,
256 SpikyNaga = 72,
257 LoveKiss = 73,
258 CleanMirror = 75,
259 PremiumDark = 76,
260 ColdEvening = 77,
261 CochitiLake = 78,
262 SummerGames = 79,
263 PassionateBed = 80,
264 MountainRock = 81,
265 DesertHump = 82,
266 JungleDay = 83,
267 PhoenixStart = 84,
268 OctoberSilence = 85,
269 FarawayRiver = 86,
270 AlchemistLab = 87,
271 OverSun = 88,
272 PremiumWhite = 89,
273 MarsParty = 90,
274 EternalConstance = 91,
275 JapanBlush = 92,
276 SmilingRain = 93,
277 CloudyApple = 94,
278 BigMango = 95,
279 HealthyWater = 96,
280 AmourAmour = 97,
281 RiskyConcrete = 98,
282 StrongStick = 99,
283 ViciousStance = 100,
284 PaloAlto = 101,
285 HappyMemories = 102,
286 MidnightBloom = 103,
287 Crystalline = 104,
288 PartyBliss = 106,
289 ConfidentCloud = 107,
290 LeCocktail = 108,
291 RiverCity = 109,
292 FrozenBerry = 110,
293 ChildCare = 112,
294 FlyingLemon = 113,
295 NewRetrowave = 114,
296 HiddenJaguar = 115,
297 AboveTheSky = 116,
298 Nega = 117,
299 DenseWater = 118,
300 Seashore = 120,
301 MarbleWall = 121,
302 CheerfulCaramel = 122,
303 NightSky = 123,
304 MagicLake = 124,
305 YoungGrass = 125,
306 ColorfulPeach = 126,
307 GentleCare = 127,
308 PlumBath = 128,
309 HappyUnicorn = 129,
310 AfricanField = 131,
311 SolidStone = 132,
312 OrangeJuice = 133,
313 GlassWater = 134,
314 NorthMiracle = 136,
315 FruitBlend = 137,
316 MillenniumPine = 138,
317 HighFlight = 139,
318 MoleHall = 140,
319 SpaceShift = 142,
320 ForestInei = 143,
321 RoyalGarden = 144,
322 RichMetal = 145,
323 JuicyCake = 146,
324 SmartIndigo = 147,
325 SandStrike = 148,
326 NorseBeauty = 149,
327 AquaGuidance = 150,
328 SunVeggie = 151,
329 SeaLord = 152,
330 BlackSea = 153,
331 GrassShampoo = 154,
332 LandingAircraft = 155,
333 WitchDance = 156,
334 SleeplessNight = 157,
335 AngelCare = 158,
336 CrystalRiver = 159,
337 SoftLipstick = 160,
338 SaltMountain = 161,
339 PerfectWhite = 162,
340 FreshOasis = 163,
341 StrictNovember = 164,
342 MorningSalad = 165,
343 DeepRelief = 166,
344 SeaStrike = 167,
345 NightCall = 168,
346 SupremeSky = 169,
347 LightBlue = 170,
348 MindCrawl = 171,
349 LilyMeadow = 172,
350 SugarLollipop = 173,
351 SweetDessert = 174,
352 MagicRay = 175,
353 TeenParty = 176,
354 FrozenHeat = 177,
355 GagarinView = 178,
356 FabledSunset = 179,
357 PerfectBlue = 180,
358
359 NumPresets
360 };
361 Q_ENUM(Preset)
362
363 QGradient();
364 QGradient(Preset);
365 ~QGradient();
366
367 Type type() const { return m_type; }
368
369 inline void setSpread(Spread spread);
370 Spread spread() const { return m_spread; }
371
372 void setColorAt(qreal pos, const QColor &color);
373
374 void setStops(const QGradientStops &stops);
375 QGradientStops stops() const;
376
377 CoordinateMode coordinateMode() const;
378 void setCoordinateMode(CoordinateMode mode);
379
380 InterpolationMode interpolationMode() const;
381 void setInterpolationMode(InterpolationMode mode);
382
383 bool operator==(const QGradient &gradient) const;
384 inline bool operator!=(const QGradient &other) const
385 { return !operator==(other); }
386
387 union QGradientData {
388 struct {
389 qreal x1, y1, x2, y2;
390 } linear;
391 struct {
392 qreal cx, cy, fx, fy, cradius, fradius;
393 } radial;
394 struct {
395 qreal cx, cy, angle;
396 } conical;
397 };
398
399private:
400 friend class QLinearGradient;
401 friend class QRadialGradient;
402 friend class QConicalGradient;
403 friend class QBrush;
404
405 Type m_type = NoGradient;
406 Spread m_spread = PadSpread;
407 QGradientStops m_stops;
408 QGradientData m_data;
409 CoordinateMode m_coordinateMode = LogicalMode;
410 InterpolationMode m_interpolationMode = ColorInterpolation;
411};
412
413inline void QGradient::setSpread(Spread aspread)
414{ m_spread = aspread; }
415
416class Q_GUI_EXPORT QLinearGradient : public QGradient
417{
418public:
419 QLinearGradient();
420 QLinearGradient(const QPointF &start, const QPointF &finalStop);
421 QLinearGradient(qreal xStart, qreal yStart, qreal xFinalStop, qreal yFinalStop);
422 ~QLinearGradient();
423
424 QPointF start() const;
425 void setStart(const QPointF &start);
426 inline void setStart(qreal x, qreal y) { setStart(QPointF(x, y)); }
427
428 QPointF finalStop() const;
429 void setFinalStop(const QPointF &stop);
430 inline void setFinalStop(qreal x, qreal y) { setFinalStop(QPointF(x, y)); }
431};
432
433
434class Q_GUI_EXPORT QRadialGradient : public QGradient
435{
436public:
437 QRadialGradient();
438 QRadialGradient(const QPointF &center, qreal radius, const QPointF &focalPoint);
439 QRadialGradient(qreal cx, qreal cy, qreal radius, qreal fx, qreal fy);
440
441 QRadialGradient(const QPointF &center, qreal radius);
442 QRadialGradient(qreal cx, qreal cy, qreal radius);
443
444 QRadialGradient(const QPointF &center, qreal centerRadius, const QPointF &focalPoint, qreal focalRadius);
445 QRadialGradient(qreal cx, qreal cy, qreal centerRadius, qreal fx, qreal fy, qreal focalRadius);
446
447 ~QRadialGradient();
448
449 QPointF center() const;
450 void setCenter(const QPointF &center);
451 inline void setCenter(qreal x, qreal y) { setCenter(QPointF(x, y)); }
452
453 QPointF focalPoint() const;
454 void setFocalPoint(const QPointF &focalPoint);
455 inline void setFocalPoint(qreal x, qreal y) { setFocalPoint(QPointF(x, y)); }
456
457 qreal radius() const;
458 void setRadius(qreal radius);
459
460 qreal centerRadius() const;
461 void setCenterRadius(qreal radius);
462
463 qreal focalRadius() const;
464 void setFocalRadius(qreal radius);
465};
466
467
468class Q_GUI_EXPORT QConicalGradient : public QGradient
469{
470public:
471 QConicalGradient();
472 QConicalGradient(const QPointF &center, qreal startAngle);
473 QConicalGradient(qreal cx, qreal cy, qreal startAngle);
474 ~QConicalGradient();
475
476 QPointF center() const;
477 void setCenter(const QPointF &center);
478 inline void setCenter(qreal x, qreal y) { setCenter(QPointF(x, y)); }
479
480 qreal angle() const;
481 void setAngle(qreal angle);
482};
483
484QT_END_NAMESPACE
485
486#endif // QBRUSH_H
\inmodule QtGui
Definition qbrush.h:30
\inmodule QtGui
Definition qbrush.h:469
\inmodule QtCore\reentrant
Definition qdatastream.h:50
\inmodule QtGui
Definition qbrush.h:158
\inmodule QtGui
Definition qbrush.h:417
\inmodule QtGui
Definition qbrush.h:435
Combined button and popup list for selecting options.
QList< QGradientStop > QGradientStops
Definition qbrush.h:155
std::pair< qreal, QColor > QGradientStop
Definition qbrush.h:154
Q_CORE_EXPORT QDebug operator<<(QDebug debug, QDir::Filters filters)
Definition qdir.cpp:2582
void qRegisterGuiVariant()
void operator()(QBrushData *d) const noexcept
Definition qbrush.cpp:251
Qt::BrushStyle style
Definition qbrush.h:135
QBrushData()=default
QTransform transform
Definition qbrush.h:137
QAtomicInt ref
Definition qbrush.h:134
QColor color
Definition qbrush.h:136
static const QtPrivate::QMetaTypeInterface * interfaceForType(int type)
static bool convert(const void *from, int fromTypeId, void *to, int toTypeId)