QtBase  v6.3.1
qbrush.h
Go to the documentation of this file.
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 
54 
55 
56 struct QBrushData;
57 class QPixmap;
58 class QGradient;
59 class QVariant;
61 {
62  void operator()(QBrushData *d) const noexcept;
63 };
64 
65 class Q_GUI_EXPORT QBrush
66 {
67 public:
68  QBrush();
72 
73  QBrush(const QColor &color, const QPixmap &pixmap);
75  QBrush(const QPixmap &pixmap);
76  QBrush(const QImage &image);
77 
78  QBrush(const QBrush &brush);
79 
80  QBrush(const QGradient &gradient);
81 
82  ~QBrush();
83  QBrush &operator=(const QBrush &brush);
85  inline void swap(QBrush &other) noexcept
86  { d.swap(other.d); }
87 
88  operator QVariant() const;
89 
90  inline Qt::BrushStyle style() const;
92 
93  inline QTransform transform() const;
94  void setTransform(const QTransform &);
95 
96  QPixmap texture() const;
97  void setTexture(const QPixmap &pixmap);
98 
99  QImage textureImage() const;
100  void setTextureImage(const QImage &image);
101 
102  inline const QColor &color() const;
103  void setColor(const QColor &color);
104  inline void setColor(Qt::GlobalColor color);
105 
106  const QGradient *gradient() const;
107 
108  bool isOpaque() const;
109 
110  bool operator==(const QBrush &b) const;
111  inline bool operator!=(const QBrush &b) const { return !(operator==(b)); }
112 
113  using DataPtr = std::unique_ptr<QBrushData, QBrushDataPointerDeleter>;
114 
115 private:
116  friend class QRasterPaintEngine;
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  DataPtr d;
124 
125 public:
126  inline bool isDetached() const;
127  inline DataPtr &data_ptr() { return d; }
128 };
129 
131 { setColor(QColor(acolor)); }
132 
134 
135 /*****************************************************************************
136  QBrush stream functions
137  *****************************************************************************/
138 
139 #ifndef QT_NO_DATASTREAM
140 Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QBrush &);
141 Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QBrush &);
142 #endif
143 
144 #ifndef QT_NO_DEBUG_STREAM
145 Q_GUI_EXPORT QDebug operator<<(QDebug, const QBrush &);
146 #endif
147 
149 {
154 };
155 
156 inline Qt::BrushStyle QBrush::style() const { return d->style; }
157 inline const QColor &QBrush::color() const { return d->color; }
158 inline QTransform QBrush::transform() const { return d->transform; }
159 inline bool QBrush::isDetached() const { return d->ref.loadRelaxed() == 1; }
160 
161 
162 /*******************************************************************************
163  * QGradients
164  */
165 class QGradientPrivate;
166 
169 
170 class Q_GUI_EXPORT QGradient
171 {
172  Q_GADGET
173 public:
174  enum Type {
178  NoGradient
179  };
180  Q_ENUM(Type)
181 
182  enum Spread {
185  RepeatSpread
186  };
187  Q_ENUM(Spread)
188 
193  ObjectMode
194  };
195  Q_ENUM(CoordinateMode)
196 
199  ComponentInterpolation
200  };
201 
202  enum Preset {
203  WarmFlame = 1,
204  NightFade = 2,
205  SpringWarmth = 3,
206  JuicyPeach = 4,
207  YoungPassion = 5,
208  LadyLips = 6,
209  SunnyMorning = 7,
210  RainyAshville = 8,
211  FrozenDreams = 9,
212  WinterNeva = 10,
213  DustyGrass = 11,
214  TemptingAzure = 12,
215  HeavyRain = 13,
216  AmyCrisp = 14,
217  MeanFruit = 15,
218  DeepBlue = 16,
219  RipeMalinka = 17,
220  CloudyKnoxville = 18,
221  MalibuBeach = 19,
222  NewLife = 20,
223  TrueSunset = 21,
224  MorpheusDen = 22,
225  RareWind = 23,
226  NearMoon = 24,
227  WildApple = 25,
228  SaintPetersburg = 26,
229  PlumPlate = 28,
230  EverlastingSky = 29,
231  HappyFisher = 30,
232  Blessing = 31,
233  SharpeyeEagle = 32,
234  LadogaBottom = 33,
235  LemonGate = 34,
236  ItmeoBranding = 35,
237  ZeusMiracle = 36,
238  OldHat = 37,
239  StarWine = 38,
240  HappyAcid = 41,
241  AwesomePine = 42,
242  NewYork = 43,
243  ShyRainbow = 44,
244  MixedHopes = 46,
245  FlyHigh = 47,
246  StrongBliss = 48,
247  FreshMilk = 49,
248  SnowAgain = 50,
249  FebruaryInk = 51,
250  KindSteel = 52,
251  SoftGrass = 53,
252  GrownEarly = 54,
253  SharpBlues = 55,
254  ShadyWater = 56,
255  DirtyBeauty = 57,
256  GreatWhale = 58,
257  TeenNotebook = 59,
258  PoliteRumors = 60,
259  SweetPeriod = 61,
260  WideMatrix = 62,
261  SoftCherish = 63,
262  RedSalvation = 64,
263  BurningSpring = 65,
264  NightParty = 66,
265  SkyGlider = 67,
266  HeavenPeach = 68,
267  PurpleDivision = 69,
268  AquaSplash = 70,
269  SpikyNaga = 72,
270  LoveKiss = 73,
271  CleanMirror = 75,
272  PremiumDark = 76,
273  ColdEvening = 77,
274  CochitiLake = 78,
275  SummerGames = 79,
276  PassionateBed = 80,
277  MountainRock = 81,
278  DesertHump = 82,
279  JungleDay = 83,
280  PhoenixStart = 84,
281  OctoberSilence = 85,
282  FarawayRiver = 86,
283  AlchemistLab = 87,
284  OverSun = 88,
285  PremiumWhite = 89,
286  MarsParty = 90,
287  EternalConstance = 91,
288  JapanBlush = 92,
289  SmilingRain = 93,
290  CloudyApple = 94,
291  BigMango = 95,
292  HealthyWater = 96,
293  AmourAmour = 97,
294  RiskyConcrete = 98,
295  StrongStick = 99,
296  ViciousStance = 100,
297  PaloAlto = 101,
298  HappyMemories = 102,
299  MidnightBloom = 103,
300  Crystalline = 104,
301  PartyBliss = 106,
302  ConfidentCloud = 107,
303  LeCocktail = 108,
304  RiverCity = 109,
305  FrozenBerry = 110,
306  ChildCare = 112,
307  FlyingLemon = 113,
308  NewRetrowave = 114,
309  HiddenJaguar = 115,
310  AboveTheSky = 116,
311  Nega = 117,
312  DenseWater = 118,
313  Seashore = 120,
314  MarbleWall = 121,
315  CheerfulCaramel = 122,
316  NightSky = 123,
317  MagicLake = 124,
318  YoungGrass = 125,
319  ColorfulPeach = 126,
320  GentleCare = 127,
321  PlumBath = 128,
322  HappyUnicorn = 129,
323  AfricanField = 131,
324  SolidStone = 132,
325  OrangeJuice = 133,
326  GlassWater = 134,
327  NorthMiracle = 136,
328  FruitBlend = 137,
329  MillenniumPine = 138,
330  HighFlight = 139,
331  MoleHall = 140,
332  SpaceShift = 142,
333  ForestInei = 143,
334  RoyalGarden = 144,
335  RichMetal = 145,
336  JuicyCake = 146,
337  SmartIndigo = 147,
338  SandStrike = 148,
339  NorseBeauty = 149,
340  AquaGuidance = 150,
341  SunVeggie = 151,
342  SeaLord = 152,
343  BlackSea = 153,
344  GrassShampoo = 154,
345  LandingAircraft = 155,
346  WitchDance = 156,
347  SleeplessNight = 157,
348  AngelCare = 158,
349  CrystalRiver = 159,
350  SoftLipstick = 160,
351  SaltMountain = 161,
352  PerfectWhite = 162,
353  FreshOasis = 163,
354  StrictNovember = 164,
355  MorningSalad = 165,
356  DeepRelief = 166,
357  SeaStrike = 167,
358  NightCall = 168,
359  SupremeSky = 169,
360  LightBlue = 170,
361  MindCrawl = 171,
362  LilyMeadow = 172,
363  SugarLollipop = 173,
364  SweetDessert = 174,
365  MagicRay = 175,
366  TeenParty = 176,
367  FrozenHeat = 177,
368  GagarinView = 178,
369  FabledSunset = 179,
370  PerfectBlue = 180,
371 
372  NumPresets
373  };
374  Q_ENUM(Preset)
375 
376  QGradient();
377  QGradient(Preset);
378  ~QGradient();
379 
380  Type type() const { return m_type; }
381 
382  inline void setSpread(Spread spread);
383  Spread spread() const { return m_spread; }
384 
385  void setColorAt(qreal pos, const QColor &color);
386 
387  void setStops(const QGradientStops &stops);
388  QGradientStops stops() const;
389 
390  CoordinateMode coordinateMode() const;
391  void setCoordinateMode(CoordinateMode mode);
392 
393  InterpolationMode interpolationMode() const;
394  void setInterpolationMode(InterpolationMode mode);
395 
396  bool operator==(const QGradient &gradient) const;
397  inline bool operator!=(const QGradient &other) const
398  { return !operator==(other); }
399 
401  struct {
403  } linear;
404  struct {
405  qreal cx, cy, fx, fy, cradius, fradius;
406  } radial;
407  struct {
408  qreal cx, cy, angle;
409  } conical;
410  };
411 
412 private:
413  friend class QLinearGradient;
414  friend class QRadialGradient;
415  friend class QConicalGradient;
416  friend class QBrush;
417 
418  Type m_type = NoGradient;
419  Spread m_spread = PadSpread;
420  QGradientStops m_stops;
421  QGradientData m_data;
422  CoordinateMode m_coordinateMode = LogicalMode;
423  InterpolationMode m_interpolationMode = ColorInterpolation;
424 };
425 
426 inline void QGradient::setSpread(Spread aspread)
427 { m_spread = aspread; }
428 
429 class Q_GUI_EXPORT QLinearGradient : public QGradient
430 {
431 public:
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 
447 class Q_GUI_EXPORT QRadialGradient : public QGradient
448 {
449 public:
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);
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 
481 class Q_GUI_EXPORT QConicalGradient : public QGradient
482 {
483 public:
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 
498 
499 #endif // QBRUSH_H
Arabic default style
Definition: afstyles.h:94
The QAtomicInt class provides platform-independent atomic operations on int.
Definition: qatomic.h:158
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:66
void setColor(const QColor &color)
Definition: qbrush.cpp:720
bool operator!=(const QBrush &b) const
Definition: qbrush.h:111
const QColor & color() const
Definition: qbrush.h:157
std::unique_ptr< QBrushData, QBrushDataPointerDeleter > DataPtr
Definition: qbrush.h:113
Qt::BrushStyle style() const
Definition: qbrush.h:156
QTransform transform() const
Definition: qbrush.h:158
DataPtr & data_ptr()
Definition: qbrush.h:127
bool isDetached() const
Definition: qbrush.h:159
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
The QConicalGradient class is used in combination with QBrush to specify a conical gradient brush.
Definition: qbrush.h:482
void setCenter(qreal x, qreal y)
Definition: qbrush.h:491
The QDataStream class provides serialization of binary data to a QIODevice.
Definition: qdatastream.h:66
operator>>(QDataStream &ds, qfloat16 &f)
Definition: qfloat16.cpp:344
operator<<(QDataStream &ds, qfloat16 f)
Definition: qfloat16.cpp:327
The QDebug class provides an output stream for debugging information.
Definition: qdebug.h:65
The QGradient class is used in combination with QBrush to specify gradient fills.
Definition: qbrush.h:171
QGradientStop
Definition: qbrush.h:165
void setSpread(Spread spread)
Definition: qbrush.h:426
Spread spread() const
Definition: qbrush.h:383
InterpolationMode
Definition: qbrush.h:197
@ ColorInterpolation
Definition: qbrush.h:198
CoordinateMode
Definition: qbrush.h:189
@ ObjectBoundingMode
Definition: qbrush.h:192
@ LogicalMode
Definition: qbrush.h:190
@ StretchToDeviceMode
Definition: qbrush.h:191
@ ReflectSpread
Definition: qbrush.h:184
@ PadSpread
Definition: qbrush.h:183
QGradientStops
Definition: qbrush.h:168
Type type() const
Definition: qbrush.h:380
@ LinearGradient
Definition: qbrush.h:175
@ ConicalGradient
Definition: qbrush.h:177
@ RadialGradient
Definition: qbrush.h:176
bool operator!=(const QGradient &other) const
Definition: qbrush.h:397
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:73
The QLinearGradient class is used in combination with QBrush to specify a linear gradient brush.
Definition: qbrush.h:430
void setStart(qreal x, qreal y)
Definition: qbrush.h:439
void setFinalStop(qreal x, qreal y)
Definition: qbrush.h:443
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:82
The QPixmap class is an off-screen image representation that can be used as a paint device.
Definition: qpixmap.h:63
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:242
The QRadialGradient class is used in combination with QBrush to specify a radial gradient brush.
Definition: qbrush.h:448
void setCenter(qreal x, qreal y)
Definition: qbrush.h:464
void setFocalPoint(qreal x, qreal y)
Definition: qbrush.h:468
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:56
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:95
#define inline
Definition: md4c.c:45
GlobalColor
Definition: qnamespace.h:58
BrushStyle
Definition: qnamespace.h:1139
@ SolidPattern
Definition: qnamespace.h:1141
QTextStream & center(QTextStream &stream)
Definition: brush.cpp:52
Definition: image.cpp:51
set set set set set set set macro pixldst1 abits if abits op else op endif endm macro pixldst2 abits if abits op else op endif endm macro pixldst4 abits if abits op else op endif endm macro pixldst0 abits op endm macro pixldst3 mem_operand op endm macro pixldst30 mem_operand op endm macro pixldst abits if abits elseif abits elseif abits elseif abits elseif abits pixldst0 abits else pixldst0 abits pixldst0 abits pixldst0 abits pixldst0 abits endif elseif abits else pixldst0 abits pixldst0 abits endif elseif abits else error unsupported bpp *numpix else pixst endif endm macro vuzp8 reg2 vuzp d d &reg2 endm macro vzip8 reg2 vzip d d &reg2 endm macro pixdeinterleave basereg basereg basereg basereg basereg endif endm macro pixinterleave basereg basereg basereg basereg basereg endif endm macro PF boost_increment endif if endif PF tst PF addne PF subne PF cmp ORIG_W if endif if endif if endif PF subge ORIG_W PF subges if endif if endif if endif endif endm macro cache_preload_simple endif if dst_r_bpp pld[DST_R, #(PREFETCH_DISTANCE_SIMPLE *dst_r_bpp/8)] endif if mask_bpp pld init[MASK, #(PREFETCH_DISTANCE_SIMPLE *mask_bpp/8)] endif endif endm macro ensure_destination_ptr_alignment process_pixblock_tail_head if beq irp skip1 beq endif SRC MASK if dst_r_bpp DST_R else add endif PF add sub src_basereg pixdeinterleave mask_basereg pixdeinterleave dst_r_basereg process_pixblock_head pixblock_size cache_preload_simple process_pixblock_tail pixinterleave dst_w_basereg irp beq endif process_pixblock_tail_head tst beq irp if pixblock_size chunk_size tst beq pixld SRC pixld MASK if DST_R else pixld DST_R endif if src_basereg pixdeinterleave mask_basereg pixdeinterleave dst_r_basereg process_pixblock_head if pixblock_size cache_preload_simple endif process_pixblock_tail pixinterleave dst_w_basereg irp if pixblock_size chunk_size tst beq if DST_W else pixst DST_W else mov ORIG_W endif add lsl if lsl endif if lsl endif lsl endif lsl endif lsl endif subs mov DST_W if regs_shortage str endif bge start_of_loop_label endm macro generate_composite_function
bool Q_GUI_EXPORT qHasPixmapTexture(const QBrush &brush)
Definition: qbrush.cpp:235
std::pair< T1, T2 > QPair
Definition: qcontainerfwd.h:56
QT_END_INCLUDE_NAMESPACE typedef double qreal
Definition: qglobal.h:341
#define QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(Class)
Definition: qglobal.h:563
bool operator==(const QMakeBaseKey &one, const QMakeBaseKey &two)
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
Definition: qopenglext.h:11564
GLfixed GLfixed GLfixed y2
Definition: qopenglext.h:5231
GLfixed GLfixed x2
Definition: qopenglext.h:5231
#define Q_ENUM(x)
Definition: qtmetamacros.h:104
#define Q_GADGET
Definition: qtmetamacros.h:193
#define Q_DECLARE_SHARED(TYPE)
Definition: qtypeinfo.h:197
QSharedPointer< T > other(t)
[5]
this swap(other)
alphaGradient setColorAt(0.0, Qt::transparent)
item setTransform(QTransform().translate(x, y).rotate(45).translate(-x, -y))
myFilter setColor(QColor(128, 0, 0))
widget render & pixmap
widget setStyle(proxy)
Qt::BrushStyle style
Definition: qbrush.h:151
QTransform transform
Definition: qbrush.h:153
QAtomicInt ref
Definition: qbrush.h:150
QColor color
Definition: qbrush.h:152
void operator()(QBrushData *d) const noexcept
Definition: qbrush.cpp:264
Definition: moc.h:48