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