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