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