Qt 4.8
qbrush.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
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 Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "qbrush.h"
43 #include "qpixmap.h"
44 #include "qbitmap.h"
45 #include "qpixmapcache.h"
46 #include "qdatastream.h"
47 #include "qvariant.h"
48 #include "qline.h"
49 #include "qdebug.h"
50 #include <QtCore/qcoreapplication.h>
51 #include "private/qstylehelper_p.h"
52 #include <QtCore/qnumeric.h>
53 
55 
56 const uchar *qt_patternForBrush(int brushStyle, bool invert)
57 {
58  Q_ASSERT(brushStyle > Qt::SolidPattern && brushStyle < Qt::LinearGradientPattern);
59  if(invert) {
60  static const uchar dense1_pat[] = { 0xff, 0xbb, 0xff, 0xff, 0xff, 0xbb, 0xff, 0xff };
61  static const uchar dense2_pat[] = { 0x77, 0xff, 0xdd, 0xff, 0x77, 0xff, 0xdd, 0xff };
62  static const uchar dense3_pat[] = { 0x55, 0xbb, 0x55, 0xee, 0x55, 0xbb, 0x55, 0xee };
63  static const uchar dense4_pat[] = { 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55 };
64  static const uchar dense5_pat[] = { 0xaa, 0x44, 0xaa, 0x11, 0xaa, 0x44, 0xaa, 0x11 };
65  static const uchar dense6_pat[] = { 0x88, 0x00, 0x22, 0x00, 0x88, 0x00, 0x22, 0x00 };
66  static const uchar dense7_pat[] = { 0x00, 0x44, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00 };
67  static const uchar hor_pat[] = { 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00 };
68  static const uchar ver_pat[] = { 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10 };
69  static const uchar cross_pat[] = { 0x10, 0x10, 0x10, 0xff, 0x10, 0x10, 0x10, 0x10 };
70  static const uchar bdiag_pat[] = { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 };
71  static const uchar fdiag_pat[] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 };
72  static const uchar dcross_pat[] = { 0x81, 0x42, 0x24, 0x18, 0x18, 0x24, 0x42, 0x81 };
73  static const uchar *const pat_tbl[] = {
74  dense1_pat, dense2_pat, dense3_pat, dense4_pat, dense5_pat,
75  dense6_pat, dense7_pat,
76  hor_pat, ver_pat, cross_pat, bdiag_pat, fdiag_pat, dcross_pat };
77  return pat_tbl[brushStyle - Qt::Dense1Pattern];
78  }
79  static const uchar dense1_pat[] = { 0x00, 0x44, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00 };
80  static const uchar dense2_pat[] = { 0x88, 0x00, 0x22, 0x00, 0x88, 0x00, 0x22, 0x00 };
81  static const uchar dense3_pat[] = { 0xaa, 0x44, 0xaa, 0x11, 0xaa, 0x44, 0xaa, 0x11 };
82  static const uchar dense4_pat[] = { 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa };
83  static const uchar dense5_pat[] = { 0x55, 0xbb, 0x55, 0xee, 0x55, 0xbb, 0x55, 0xee };
84  static const uchar dense6_pat[] = { 0x77, 0xff, 0xdd, 0xff, 0x77, 0xff, 0xdd, 0xff };
85  static const uchar dense7_pat[] = { 0xff, 0xbb, 0xff, 0xff, 0xff, 0xbb, 0xff, 0xff };
86  static const uchar hor_pat[] = { 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0xff };
87  static const uchar ver_pat[] = { 0xef, 0xef, 0xef, 0xef, 0xef, 0xef, 0xef, 0xef };
88  static const uchar cross_pat[] = { 0xef, 0xef, 0xef, 0x00, 0xef, 0xef, 0xef, 0xef };
89  static const uchar bdiag_pat[] = { 0x7f, 0xbf, 0xdf, 0xef, 0xf7, 0xfb, 0xfd, 0xfe };
90  static const uchar fdiag_pat[] = { 0xfe, 0xfd, 0xfb, 0xf7, 0xef, 0xdf, 0xbf, 0x7f };
91  static const uchar dcross_pat[] = { 0x7e, 0xbd, 0xdb, 0xe7, 0xe7, 0xdb, 0xbd, 0x7e };
92  static const uchar *const pat_tbl[] = {
93  dense1_pat, dense2_pat, dense3_pat, dense4_pat, dense5_pat,
94  dense6_pat, dense7_pat,
95  hor_pat, ver_pat, cross_pat, bdiag_pat, fdiag_pat, dcross_pat };
96  return pat_tbl[brushStyle - Qt::Dense1Pattern];
97 }
98 
99 QPixmap qt_pixmapForBrush(int brushStyle, bool invert)
100 {
101 
102  QPixmap pm;
103  QString key = QLatin1Literal("$qt-brush$")
104  % HexString<uint>(brushStyle)
105  % QLatin1Char(invert ? '1' : '0');
106  if (!QPixmapCache::find(key, pm)) {
107  pm = QBitmap::fromData(QSize(8, 8), qt_patternForBrush(brushStyle, invert),
109  QPixmapCache::insert(key, pm);
110  }
111 
112  return pm;
113 }
114 
116 {
117 public:
119  : m_initialized(false)
120  {
121  init();
122  }
123 
124  void init()
125  {
126  for (int style = Qt::Dense1Pattern; style <= Qt::DiagCrossPattern; ++style) {
127  int i = style - Qt::Dense1Pattern;
128  m_images[i][0] = QImage(qt_patternForBrush(style, 0), 8, 8, 1, QImage::Format_MonoLSB);
129  m_images[i][1] = QImage(qt_patternForBrush(style, 1), 8, 8, 1, QImage::Format_MonoLSB);
130  }
131  m_initialized = true;
132  }
133 
134  QImage getImage(int brushStyle, bool invert) const
135  {
136  Q_ASSERT(brushStyle >= Qt::Dense1Pattern && brushStyle <= Qt::DiagCrossPattern);
137  if (!m_initialized)
138  const_cast<QBrushPatternImageCache*>(this)->init();
139  return m_images[brushStyle - Qt::Dense1Pattern][invert];
140  }
141 
142  void cleanup() {
143  for (int style = Qt::Dense1Pattern; style <= Qt::DiagCrossPattern; ++style) {
144  int i = style - Qt::Dense1Pattern;
145  m_images[i][0] = QImage();
146  m_images[i][1] = QImage();
147  }
148  m_initialized = false;
149  }
150 
151 private:
154 };
155 
158  {
160  })
161 
163 {
164  qt_brushPatternImageCache()->cleanup();
165 }
166 
167 Q_GUI_EXPORT QImage qt_imageForBrush(int brushStyle, bool invert)
168 {
169  return qt_brushPatternImageCache()->getImage(brushStyle, invert);
170 }
171 
173 {
175  m_has_pixmap_texture = false;
176  m_pixmap = 0;
177  }
179  delete m_pixmap;
180  }
181 
182  void setPixmap(const QPixmap &pm) {
183  delete m_pixmap;
184 
185  if (pm.isNull()) {
186  m_pixmap = 0;
187  m_has_pixmap_texture = false;
188  } else {
189  m_pixmap = new QPixmap(pm);
190  m_has_pixmap_texture = true;
191  }
192 
193  m_image = QImage();
194  }
195 
196  void setImage(const QImage &image) {
197  m_image = image;
198  delete m_pixmap;
199  m_pixmap = 0;
200  m_has_pixmap_texture = false;
201  }
202 
204  if (!m_pixmap) {
205  m_pixmap = new QPixmap(QPixmap::fromImage(m_image));
206  }
207  return *m_pixmap;
208  }
209 
211  if (m_image.isNull() && m_pixmap)
212  m_image = m_pixmap->toImage();
213  return m_image;
214  }
215 
219 };
220 
221 // returns true if the brush has a pixmap (or bitmap) set as the
222 // brush texture, false otherwise
224 {
225  if (brush.style() != Qt::TexturePattern)
226  return false;
227  QTexturedBrushData *tx_data = static_cast<QTexturedBrushData *>(brush.d.data());
228  return tx_data->m_has_pixmap_texture;
229 }
230 
232 {
234 };
235 
237 {
238  static inline void deleteData(QBrushData *d)
239  {
240  switch (d->style) {
241  case Qt::TexturePattern:
242  delete static_cast<QTexturedBrushData*>(d);
243  break;
247  delete static_cast<QGradientBrushData*>(d);
248  break;
249  default:
250  delete d;
251  }
252  }
253 
254  static inline void cleanup(QBrushData *d)
255  {
256  if (d && !d->ref.deref()) {
257  deleteData(d);
258  }
259  }
260 };
261 
344 #ifndef QT_NO_THREAD
345 // Special deleter that only deletes if the ref-count goes to zero
346 template <>
348 {
349 public:
352  : globalStatic(_globalStatic)
353  { }
354 
356  {
357  if (!globalStatic.pointer->ref.deref())
358  delete globalStatic.pointer;
359  globalStatic.pointer = 0;
360  globalStatic.destroyed = true;
361  }
362 };
363 #endif
364 
366  {
367  x->ref = 1;
368  x->style = Qt::BrushStyle(0);
369  x->color = Qt::black;
370  })
371 
372 static bool qbrush_check_type(Qt::BrushStyle style) {
373  switch (style) {
374  case Qt::TexturePattern:
375  qWarning("QBrush: Incorrect use of TexturePattern");
376  break;
380  qWarning("QBrush: Wrong use of a gradient pattern");
381  break;
382  default:
383  return true;
384  }
385  return false;
386 }
387 
396 void QBrush::init(const QColor &color, Qt::BrushStyle style)
397 {
398  switch(style) {
399  case Qt::NoBrush:
400  d.reset(nullBrushInstance());
401  d->ref.ref();
402  if (d->color != color) setColor(color);
403  return;
404  case Qt::TexturePattern:
405  d.reset(new QTexturedBrushData);
406  break;
410  d.reset(new QGradientBrushData);
411  break;
412  default:
413  d.reset(new QBrushData);
414  break;
415  }
416  d->ref = 1;
417  d->style = style;
418  d->color = color;
419 }
420 
427  : d(nullBrushInstance())
428 {
429  Q_ASSERT(d);
430  d->ref.ref();
431 }
432 
440 QBrush::QBrush(const QPixmap &pixmap)
441 {
443  setTexture(pixmap);
444 }
445 
446 
454 QBrush::QBrush(const QImage &image)
455 {
457  setTextureImage(image);
458 }
459 
467 {
468  if (qbrush_check_type(style))
469  init(Qt::black, style);
470  else {
471  d.reset(nullBrushInstance());
472  d->ref.ref();
473  }
474 }
475 
483 {
484  if (qbrush_check_type(style))
485  init(color, style);
486  else {
487  d.reset(nullBrushInstance());
488  d->ref.ref();
489  }
490 }
491 
503 {
504  if (qbrush_check_type(style))
505  init(color, style);
506  else {
507  d.reset(nullBrushInstance());
508  d->ref.ref();
509  }
510 }
511 
522 QBrush::QBrush(const QColor &color, const QPixmap &pixmap)
523 {
524  init(color, Qt::TexturePattern);
525  setTexture(pixmap);
526 }
527 
539 {
540  init(color, Qt::TexturePattern);
541  setTexture(pixmap);
542 }
543 
548 QBrush::QBrush(const QBrush &other)
549  : d(other.d.data())
550 {
551  d->ref.ref();
552 }
553 
562 {
563  Q_ASSERT_X(gradient.type() != QGradient::NoGradient, "QBrush::QBrush",
564  "QGradient should not be used directly, use the linear, radial\n"
565  "or conical gradients instead");
566 
567  const Qt::BrushStyle enum_table[] = {
571  };
572 
573  init(QColor(), enum_table[gradient.type()]);
574  QGradientBrushData *grad = static_cast<QGradientBrushData *>(d.data());
575  grad->gradient = gradient;
576 }
577 
583 {
584 }
585 
587 {
589 }
590 
591 
593 {
594  if (newStyle == d->style && d->ref == 1)
595  return;
596 
598  switch(newStyle) {
599  case Qt::TexturePattern: {
601  if (d->style == Qt::TexturePattern) {
602  QTexturedBrushData *data = static_cast<QTexturedBrushData *>(d.data());
603  if (data->m_has_pixmap_texture)
604  tbd->setPixmap(data->pixmap());
605  else
606  tbd->setImage(data->image());
607  }
608  x.reset(tbd);
609  break;
610  }
614  x.reset(new QGradientBrushData);
615  static_cast<QGradientBrushData *>(x.data())->gradient =
616  static_cast<QGradientBrushData *>(d.data())->gradient;
617  break;
618  default:
619  x.reset(new QBrushData);
620  break;
621  }
622  x->ref = 1;
623  x->style = newStyle;
624  x->color = d->color;
625  x->transform = d->transform;
626  d.reset(x.take());
627 }
628 
629 
641 {
642  if (d == b.d)
643  return *this;
644 
645  b.d->ref.ref();
646  d.reset(b.d.data());
647  return *this;
648 }
649 
650 
665 QBrush::operator QVariant() const
666 {
667  return QVariant(QVariant::Brush, this);
668 }
669 
688 {
689  if (d->style == style)
690  return;
691 
692  if (qbrush_check_type(style)) {
693  detach(style);
694  d->style = style;
695  }
696 }
697 
698 
726 {
727  detach(d->style);
728  d->color = c;
729 }
730 
742 #ifdef QT3_SUPPORT
743 
764 QPixmap *QBrush::pixmap() const
765 {
766  if (d->style != Qt::TexturePattern)
767  return 0;
768  QTexturedBrushData *data = static_cast<QTexturedBrushData*>(d.data());
769  QPixmap &pixmap = data->pixmap();
770  return pixmap.isNull() ? 0 : &pixmap;
771 }
772 #endif
773 
786 {
787  return d->style == Qt::TexturePattern
788  ? (static_cast<QTexturedBrushData *>(d.data()))->pixmap()
789  : QPixmap();
790 }
791 
802 void QBrush::setTexture(const QPixmap &pixmap)
803 {
804  if (!pixmap.isNull()) {
806  QTexturedBrushData *data = static_cast<QTexturedBrushData *>(d.data());
807  data->setPixmap(pixmap);
808  } else {
810  }
811 }
812 
813 
830 {
831  return d->style == Qt::TexturePattern
832  ? (static_cast<QTexturedBrushData *>(d.data()))->image()
833  : QImage();
834 }
835 
836 
856 void QBrush::setTextureImage(const QImage &image)
857 {
858  if (!image.isNull()) {
860  QTexturedBrushData *data = static_cast<QTexturedBrushData *>(d.data());
861  data->setImage(image);
862  } else {
864  }
865 }
866 
867 
872 {
876  return &static_cast<const QGradientBrushData *>(d.data())->gradient;
877  }
878  return 0;
879 }
880 
882 {
883  if (brush.style() == Qt::RadialGradientPattern) {
884  const QGradient *g = brush.gradient();
885  const QRadialGradient *rg = static_cast<const QRadialGradient *>(g);
886 
887  if (!qFuzzyIsNull(rg->focalRadius()))
888  return true;
889 
890  QPointF delta = rg->focalPoint() - rg->center();
891  if (delta.x() * delta.x() + delta.y() * delta.y() > rg->radius() * rg->radius())
892  return true;
893  }
894 
895  return false;
896 }
897 
910 bool QBrush::isOpaque() const
911 {
912  bool opaqueColor = d->color.alpha() == 255;
913 
914  // Test awfully simple case first
915  if (d->style == Qt::SolidPattern)
916  return opaqueColor;
917 
918  if (qt_isExtendedRadialGradient(*this))
919  return false;
920 
924  QGradientStops stops = gradient()->stops();
925  for (int i=0; i<stops.size(); ++i)
926  if (stops.at(i).second.alpha() != 255)
927  return false;
928  return true;
929  } else if (d->style == Qt::TexturePattern) {
930  return qHasPixmapTexture(*this)
933  }
934 
935  return false;
936 }
937 
938 
952 {
953  setTransform(QTransform(matrix));
954 }
955 
969 {
970  detach(d->style);
971  d->transform = matrix;
972 }
973 
974 
1017 bool QBrush::operator==(const QBrush &b) const
1018 {
1019  if (b.d == d)
1020  return true;
1021  if (b.d->style != d->style || b.d->color != d->color || b.d->transform != d->transform)
1022  return false;
1023  switch (d->style) {
1024  case Qt::TexturePattern:
1025  {
1026  const QPixmap &us = (static_cast<QTexturedBrushData *>(d.data()))->pixmap();
1027  const QPixmap &them = (static_cast<QTexturedBrushData *>(b.d.data()))->pixmap();
1028  return ((us.isNull() && them.isNull()) || us.cacheKey() == them.cacheKey());
1029  }
1033  {
1034  const QGradientBrushData *d1 = static_cast<QGradientBrushData *>(d.data());
1035  const QGradientBrushData *d2 = static_cast<QGradientBrushData *>(b.d.data());
1036  return d1->gradient == d2->gradient;
1037  }
1038  default:
1039  return true;
1040  }
1041 }
1042 
1054 #ifndef QT_NO_DEBUG_STREAM
1055 
1059 {
1060 #ifndef Q_BROKEN_DEBUG_STREAM
1061  static const char *BRUSH_STYLES[] = {
1062  "NoBrush",
1063  "SolidPattern",
1064  "Dense1Pattern",
1065  "Dense2Pattern",
1066  "Dense3Pattern",
1067  "Dense4Pattern",
1068  "Dense5Pattern",
1069  "Dense6Pattern",
1070  "Dense7Pattern",
1071  "HorPattern",
1072  "VerPattern",
1073  "CrossPattern",
1074  "BDiagPattern",
1075  "FDiagPattern",
1076  "DiagCrossPattern",
1077  "LinearGradientPattern",
1078  "RadialGradientPattern",
1079  "ConicalGradientPattern",
1080  0, 0, 0, 0, 0, 0,
1081  "TexturePattern" // 24
1082  };
1083 
1084  dbg.nospace() << "QBrush(" << b.color() << ',' << BRUSH_STYLES[b.style()] << ')';
1085  return dbg.space();
1086 #else
1087  qWarning("This compiler doesn't support streaming QBrush to QDebug");
1088  return dbg;
1089  Q_UNUSED(b);
1090 #endif
1091 }
1092 #endif
1093 
1094 /*****************************************************************************
1095  QBrush stream functions
1096  *****************************************************************************/
1097 #ifndef QT_NO_DATASTREAM
1098 
1112 {
1113  quint8 style = (quint8) b.style();
1114  bool gradient_style = false;
1115 
1116  if (style == Qt::LinearGradientPattern || style == Qt::RadialGradientPattern
1117  || style == Qt::ConicalGradientPattern)
1118  gradient_style = true;
1119 
1120  if (s.version() < QDataStream::Qt_4_0 && gradient_style)
1121  style = Qt::NoBrush;
1122 
1123  s << style << b.color();
1124  if (b.style() == Qt::TexturePattern) {
1125  s << b.texture();
1126  } else if (s.version() >= QDataStream::Qt_4_0 && gradient_style) {
1127  const QGradient *gradient = b.gradient();
1128  int type_as_int = int(gradient->type());
1129  s << type_as_int;
1130  if (s.version() >= QDataStream::Qt_4_3) {
1131  s << int(gradient->spread());
1132  s << int(gradient->coordinateMode());
1133  }
1134 
1135  if (s.version() >= QDataStream::Qt_4_5)
1136  s << int(gradient->interpolationMode());
1137 
1138  if (sizeof(qreal) == sizeof(double)) {
1139  s << gradient->stops();
1140  } else {
1141  // ensure that we write doubles here instead of streaming the stops
1142  // directly; otherwise, platforms that redefine qreal might generate
1143  // data that cannot be read on other platforms.
1144  QVector<QGradientStop> stops = gradient->stops();
1145  s << quint32(stops.size());
1146  for (int i = 0; i < stops.size(); ++i) {
1147  const QGradientStop &stop = stops.at(i);
1148  s << QPair<double, QColor>(double(stop.first), stop.second);
1149  }
1150  }
1151 
1152  if (gradient->type() == QGradient::LinearGradient) {
1153  s << static_cast<const QLinearGradient *>(gradient)->start();
1154  s << static_cast<const QLinearGradient *>(gradient)->finalStop();
1155  } else if (gradient->type() == QGradient::RadialGradient) {
1156  s << static_cast<const QRadialGradient *>(gradient)->center();
1157  s << static_cast<const QRadialGradient *>(gradient)->focalPoint();
1158  s << (double) static_cast<const QRadialGradient *>(gradient)->radius();
1159  } else { // type == Conical
1160  s << static_cast<const QConicalGradient *>(gradient)->center();
1161  s << (double) static_cast<const QConicalGradient *>(gradient)->angle();
1162  }
1163  }
1164  if (s.version() >= QDataStream::Qt_4_3)
1165  s << b.transform();
1166  return s;
1167 }
1168 
1183 {
1184  quint8 style;
1185  QColor color;
1186  s >> style;
1187  s >> color;
1188  if (style == Qt::TexturePattern) {
1189  QPixmap pm;
1190  s >> pm;
1191  b = QBrush(color, pm);
1192  } else if (style == Qt::LinearGradientPattern
1193  || style == Qt::RadialGradientPattern
1194  || style == Qt::ConicalGradientPattern) {
1195 
1196  int type_as_int;
1198  QGradientStops stops;
1202 
1203  s >> type_as_int;
1204  type = QGradient::Type(type_as_int);
1205  if (s.version() >= QDataStream::Qt_4_3) {
1206  s >> type_as_int;
1207  spread = QGradient::Spread(type_as_int);
1208  s >> type_as_int;
1209  cmode = QGradient::CoordinateMode(type_as_int);
1210  }
1211 
1212  if (s.version() >= QDataStream::Qt_4_5) {
1213  s >> type_as_int;
1214  imode = QGradient::InterpolationMode(type_as_int);
1215  }
1216 
1217  if (sizeof(qreal) == sizeof(double)) {
1218  s >> stops;
1219  } else {
1220  quint32 numStops;
1221  double n;
1222  QColor c;
1223 
1224  s >> numStops;
1225  for (quint32 i = 0; i < numStops; ++i) {
1226  s >> n >> c;
1227  stops << QPair<qreal, QColor>(n, c);
1228  }
1229  }
1230 
1231  if (type == QGradient::LinearGradient) {
1232  QPointF p1, p2;
1233  s >> p1;
1234  s >> p2;
1235  QLinearGradient lg(p1, p2);
1236  lg.setStops(stops);
1237  lg.setSpread(spread);
1238  lg.setCoordinateMode(cmode);
1239  lg.setInterpolationMode(imode);
1240  b = QBrush(lg);
1241  } else if (type == QGradient::RadialGradient) {
1242  QPointF center, focal;
1243  double radius;
1244  s >> center;
1245  s >> focal;
1246  s >> radius;
1247  QRadialGradient rg(center, radius, focal);
1248  rg.setStops(stops);
1249  rg.setSpread(spread);
1250  rg.setCoordinateMode(cmode);
1251  rg.setInterpolationMode(imode);
1252  b = QBrush(rg);
1253  } else { // type == QGradient::ConicalGradient
1254  QPointF center;
1255  double angle;
1256  s >> center;
1257  s >> angle;
1258  QConicalGradient cg(center, angle);
1259  cg.setStops(stops);
1260  cg.setSpread(spread);
1261  cg.setCoordinateMode(cmode);
1262  cg.setInterpolationMode(imode);
1263  b = QBrush(cg);
1264  }
1265  } else {
1266  b = QBrush(color, (Qt::BrushStyle)style);
1267  }
1268  if (s.version() >= QDataStream::Qt_4_3) {
1270  s >> transform;
1271  b.setTransform(transform);
1272  }
1273  return s;
1274 }
1275 #endif // QT_NO_DATASTREAM
1276 
1277 /*******************************************************************************
1278  * QGradient implementations
1279  */
1280 
1281 
1381  : m_type(NoGradient), dummy(0)
1382 {
1383 }
1384 
1385 
1475 void QGradient::setColorAt(qreal pos, const QColor &color)
1476 {
1477  if ((pos > 1 || pos < 0) && !qIsNaN(pos)) {
1478  qWarning("QGradient::setColorAt: Color position must be specified in the range 0 to 1");
1479  return;
1480  }
1481 
1482  int index = 0;
1483  if (!qIsNaN(pos))
1484  while (index < m_stops.size() && m_stops.at(index).first < pos) ++index;
1485 
1486  if (index < m_stops.size() && m_stops.at(index).first == pos)
1487  m_stops[index].second = color;
1488  else
1489  m_stops.insert(index, QGradientStop(pos, color));
1490 }
1491 
1505 {
1506  m_stops.clear();
1507  for (int i=0; i<stops.size(); ++i)
1508  setColorAt(stops.at(i).first, stops.at(i).second);
1509 }
1510 
1511 
1521 {
1522  if (m_stops.isEmpty()) {
1523  QGradientStops tmp;
1524  tmp << QGradientStop(0, Qt::black) << QGradientStop(1, Qt::white);
1525  return tmp;
1526  }
1527  return m_stops;
1528 }
1529 
1530 #define Q_DUMMY_ACCESSOR union {void *p; uint i;}; p = dummy;
1531 
1564 {
1566  return CoordinateMode(i & 0x03);
1567 }
1568 
1579 {
1581  i &= ~0x03;
1582  i |= uint(mode);
1583  dummy = p;
1584 }
1585 
1608 {
1610  return InterpolationMode((i >> 2) & 0x01);
1611 }
1612 
1624 {
1626  i &= ~(1 << 2);
1627  i |= (uint(mode) << 2);
1628  dummy = p;
1629 }
1630 
1650 bool QGradient::operator==(const QGradient &gradient) const
1651 {
1652  if (gradient.m_type != m_type
1653  || gradient.m_spread != m_spread
1654  || gradient.dummy != dummy) return false;
1655 
1656  if (m_type == LinearGradient) {
1657  if (m_data.linear.x1 != gradient.m_data.linear.x1
1658  || m_data.linear.y1 != gradient.m_data.linear.y1
1659  || m_data.linear.x2 != gradient.m_data.linear.x2
1660  || m_data.linear.y2 != gradient.m_data.linear.y2)
1661  return false;
1662  } else if (m_type == RadialGradient) {
1663  if (m_data.radial.cx != gradient.m_data.radial.cx
1664  || m_data.radial.cy != gradient.m_data.radial.cy
1665  || m_data.radial.fx != gradient.m_data.radial.fx
1666  || m_data.radial.fy != gradient.m_data.radial.fy
1667  || m_data.radial.cradius != gradient.m_data.radial.cradius)
1668  return false;
1669  } else { // m_type == ConicalGradient
1670  if (m_data.conical.cx != gradient.m_data.conical.cx
1671  || m_data.conical.cy != gradient.m_data.conical.cy
1672  || m_data.conical.angle != gradient.m_data.conical.angle)
1673  return false;
1674  }
1675 
1676  return stops() == gradient.stops();
1677 }
1678 
1682 bool QGradient::operator==(const QGradient &gradient)
1683 {
1684  return const_cast<const QGradient *>(this)->operator==(gradient);
1685 }
1686 
1738 {
1740  m_spread = PadSpread;
1741  m_data.linear.x1 = 0;
1742  m_data.linear.y1 = 0;
1743  m_data.linear.x2 = 1;
1744  m_data.linear.y2 = 1;
1745 }
1746 
1747 
1756 QLinearGradient::QLinearGradient(const QPointF &start, const QPointF &finalStop)
1757 {
1759  m_spread = PadSpread;
1760  m_data.linear.x1 = start.x();
1761  m_data.linear.y1 = start.y();
1762  m_data.linear.x2 = finalStop.x();
1763  m_data.linear.y2 = finalStop.y();
1764 }
1765 
1779 QLinearGradient::QLinearGradient(qreal xStart, qreal yStart, qreal xFinalStop, qreal yFinalStop)
1780 {
1782  m_spread = PadSpread;
1783  m_data.linear.x1 = xStart;
1784  m_data.linear.y1 = yStart;
1785  m_data.linear.x2 = xFinalStop;
1786  m_data.linear.y2 = yFinalStop;
1787 }
1788 
1789 
1797 {
1799  return QPointF(m_data.linear.x1, m_data.linear.y1);
1800 }
1801 
1829 {
1831  m_data.linear.x1 = start.x();
1832  m_data.linear.y1 = start.y();
1833 }
1834 
1835 
1857 {
1859  return QPointF(m_data.linear.x2, m_data.linear.y2);
1860 }
1861 
1862 
1876 {
1878  m_data.linear.x2 = stop.x();
1879  m_data.linear.y2 = stop.y();
1880 }
1881 
1882 
1934  qreal radius,
1935  const QPointF &focalPoint)
1936 {
1937  // We have a one pixel buffer zone to avoid numerical instability on the
1938  // circle border
1939  //### this is hacky because technically we should adjust based on current matrix
1940  const qreal compensated_radius = radius - radius * qreal(0.001);
1941  QLineF line(center, focalPoint);
1942  if (line.length() > (compensated_radius))
1943  line.setLength(compensated_radius);
1944  return line.p2();
1945 }
1946 
1960 {
1962  m_spread = PadSpread;
1963  m_data.radial.cx = center.x();
1964  m_data.radial.cy = center.y();
1965  m_data.radial.cradius = radius;
1966 
1967  QPointF adapted_focal = qt_radial_gradient_adapt_focal_point(center, radius, focalPoint);
1968  m_data.radial.fx = adapted_focal.x();
1969  m_data.radial.fy = adapted_focal.y();
1970 }
1971 
1979 {
1981  m_spread = PadSpread;
1982  m_data.radial.cx = center.x();
1983  m_data.radial.cy = center.y();
1984  m_data.radial.cradius = radius;
1985  m_data.radial.fx = center.x();
1986  m_data.radial.fy = center.y();
1987 }
1988 
1989 
2003 {
2005  m_spread = PadSpread;
2006  m_data.radial.cx = cx;
2007  m_data.radial.cy = cy;
2008  m_data.radial.cradius = radius;
2009 
2010  QPointF adapted_focal = qt_radial_gradient_adapt_focal_point(QPointF(cx, cy),
2011  radius,
2012  QPointF(fx, fy));
2013 
2014  m_data.radial.fx = adapted_focal.x();
2015  m_data.radial.fy = adapted_focal.y();
2016 }
2017 
2025 {
2027  m_spread = PadSpread;
2028  m_data.radial.cx = cx;
2029  m_data.radial.cy = cy;
2030  m_data.radial.cradius = radius;
2031  m_data.radial.fx = cx;
2032  m_data.radial.fy = cy;
2033 }
2034 
2035 
2041 {
2043  m_spread = PadSpread;
2044  m_data.radial.cx = 0;
2045  m_data.radial.cy = 0;
2046  m_data.radial.cradius = 1;
2047  m_data.radial.fx = 0;
2048  m_data.radial.fy = 0;
2049 }
2050 
2060 QRadialGradient::QRadialGradient(const QPointF &center, qreal centerRadius, const QPointF &focalPoint, qreal focalRadius)
2061 {
2063  m_spread = PadSpread;
2064  m_data.radial.cx = center.x();
2065  m_data.radial.cy = center.y();
2066  m_data.radial.cradius = centerRadius;
2067 
2068  m_data.radial.fx = focalPoint.x();
2069  m_data.radial.fy = focalPoint.y();
2070  setFocalRadius(focalRadius);
2071 }
2072 
2084 {
2086  m_spread = PadSpread;
2087  m_data.radial.cx = cx;
2088  m_data.radial.cy = cy;
2089  m_data.radial.cradius = centerRadius;
2090 
2091  m_data.radial.fx = fx;
2092  m_data.radial.fy = fy;
2093  setFocalRadius(focalRadius);
2094 }
2095 
2103 {
2105  return QPointF(m_data.radial.cx, m_data.radial.cy);
2106 }
2107 
2135 {
2137  m_data.radial.cx = center.x();
2138  m_data.radial.cy = center.y();
2139 }
2140 
2141 
2151 {
2153  return m_data.radial.cradius;
2154 }
2155 
2156 
2166 {
2168  m_data.radial.cradius = radius;
2169 }
2170 
2183 {
2185  return m_data.radial.cradius;
2186 }
2187 
2195 {
2197  m_data.radial.cradius = radius;
2198 }
2199 
2212 {
2215 
2216  // mask away low three bits
2217  union { float f; quint32 i; } u;
2218  u.i = i & ~0x07;
2219  return u.f;
2220 }
2221 
2229 {
2232 
2233  // Since there's no QGradientData, we only have the dummy void * to
2234  // store additional data in. The three lowest bits are already
2235  // taken, thus we cut the three lowest bits from the significand
2236  // and store the radius as a float.
2237  union { float f; quint32 i; } u;
2238  u.f = float(radius);
2239  // add 0x04 to round up when we drop the three lowest bits
2240  i |= (u.i + 0x04) & ~0x07;
2241  dummy = p;
2242 }
2243 
2252 {
2254  return QPointF(m_data.radial.fx, m_data.radial.fy);
2255 }
2256 
2284 {
2286  m_data.radial.fx = focalPoint.x();
2287  m_data.radial.fy = focalPoint.y();
2288 }
2289 
2290 
2291 
2340 {
2342  m_spread = PadSpread;
2343  m_data.conical.cx = center.x();
2344  m_data.conical.cy = center.y();
2345  m_data.conical.angle = angle;
2346 }
2347 
2348 
2358 {
2360  m_spread = PadSpread;
2361  m_data.conical.cx = cx;
2362  m_data.conical.cy = cy;
2363  m_data.conical.angle = angle;
2364 }
2365 
2366 
2375 {
2377  m_spread = PadSpread;
2378  m_data.conical.cx = 0;
2379  m_data.conical.cy = 0;
2380  m_data.conical.angle = 0;
2381 }
2382 
2383 
2392 {
2394  return QPointF(m_data.conical.cx, m_data.conical.cy);
2395 }
2396 
2397 
2420 {
2422  m_data.conical.cx = center.x();
2423  m_data.conical.cy = center.y();
2424 }
2425 
2434 {
2436  return m_data.conical.angle;
2437 }
2438 
2439 
2453 {
2455  m_data.conical.angle = angle;
2456 }
2457 
2506 #undef Q_DUMMY_ACCESSOR
2507 
struct QGradient::@216::@218 radial
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
struct QGradient::@216::@217 linear
qreal focalRadius() const
Returns the focal radius of this radial gradient in logical coordinates.
Definition: qbrush.cpp:2211
void setFinalStop(const QPointF &stop)
Sets the final stop point of this linear gradient in logical coordinates to stop. ...
Definition: qbrush.cpp:1875
The QDebug class provides an output stream for debugging information.
Definition: qdebug.h:62
void setCenterRadius(qreal radius)
Definition: qbrush.cpp:2194
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
double d
Definition: qnumeric_p.h:62
QLinearGradient()
Constructs a default linear gradient with interpolation area between (0, 0) and (1, 1).
Definition: qbrush.cpp:1737
QPointF focalPoint() const
Returns the focal point of this radial gradient in logical coordinates.
Definition: qbrush.cpp:2251
QGlobalStaticDeleter(QGlobalStatic< QBrushData > &_globalStatic)
Definition: qbrush.cpp:351
#define Q_DUMMY_ACCESSOR
Definition: qbrush.cpp:1530
QGradientStops m_stops
Definition: qbrush.h:262
static QPixmap fromImage(const QImage &image, Qt::ImageConversionFlags flags=Qt::AutoColor)
Converts the given image to a pixmap using the specified flags to control the conversion.
Definition: qpixmap.cpp:2197
QGlobalStatic< QBrushData > & globalStatic
Definition: qbrush.cpp:350
qreal fx
Definition: qbrush.h:268
BrushStyle
Definition: qnamespace.h:1162
The QLatin1Literal class provides a thin wrapper around string literals used in source code...
int type
Definition: qmetatype.cpp:239
QGradient gradient
Definition: qbrush.cpp:233
double qreal
Definition: qglobal.h:1193
unsigned char c[8]
Definition: qnumeric_p.h:62
void setColorAt(qreal pos, const QColor &color)
Creates a stop point at the given position with the given color.
Definition: qbrush.cpp:1475
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
const QColor & color() const
Returns the brush color.
Definition: qbrush.h:183
Q_GUI_EXPORT QImage qt_imageForBrush(int brushStyle, bool invert)
Definition: qbrush.cpp:167
QBrush & operator=(const QBrush &brush)
Assigns the given brush to this brush and returns a reference to this brush.
Definition: qbrush.cpp:640
qreal length() const
Returns the length of the line.
Definition: qline.cpp:698
QImage getImage(int brushStyle, bool invert) const
Definition: qbrush.cpp:134
T * data() const
Returns the value of the pointer referenced by this object.
const QGradient * gradient() const
Returns the gradient describing this brush.
Definition: qbrush.cpp:871
The QMatrix class specifies 2D transformations of a coordinate system.
Definition: qmatrix.h:61
void qAddPostRoutine(QtCleanUpFunction p)
void cleanUp(QBrushData *x)
Definition: qbrush.cpp:586
void setTransform(const QTransform &)
Sets matrix as an explicit transformation matrix on the current brush.
Definition: qbrush.cpp:968
QDebug & nospace()
Clears the stream&#39;s internal flag that records whether the last character was a space and returns a r...
Definition: qdebug.h:92
CoordinateMode coordinateMode() const
Returns the coordinate mode of this gradient.
Definition: qbrush.cpp:1563
void setAngle(qreal angle)
Sets angle to be the start angle for this conical gradient in logical coordinates.
Definition: qbrush.cpp:2452
#define Q_GUI_EXPORT
Definition: qglobal.h:1450
bool isNull() const
Returns true if it is a null image, otherwise returns false.
Definition: qimage.cpp:1542
QScopedPointer< QBrushData, QBrushDataPointerDeleter > d
Definition: qbrush.h:146
void detach(Qt::BrushStyle newStyle)
Definition: qbrush.cpp:592
The QConicalGradient class is used in combination with QBrush to specify a conical gradient brush...
Definition: qbrush.h:329
Type m_type
Definition: qbrush.h:260
static QBitmap fromData(const QSize &size, const uchar *bits, QImage::Format monoFormat=QImage::Format_MonoLSB)
Constructs a bitmap with the given size, and sets the contents to the bits supplied.
Definition: qbitmap.cpp:318
const uchar * qt_patternForBrush(int brushStyle, bool invert)
Definition: qbrush.cpp:56
QRadialGradient()
Constructs a simple radial gradient with the center and focal point at (0, 0) with a radius of 1...
Definition: qbrush.cpp:2040
T * take()
Returns the value of the pointer referenced by this object.
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
bool operator==(const QBrush &b) const
Returns true if the brush is equal to the given brush; otherwise returns false.
Definition: qbrush.cpp:1017
T1 first
Definition: qpair.h:65
T2 second
Definition: qpair.h:66
bool hasAlphaChannel() const
Returns true if the image has a format that respects the alpha channel, otherwise returns false...
Definition: qimage.cpp:6495
QImage & image()
Definition: qbrush.cpp:210
quint16 u
CoordinateMode
This enum specifies how gradient coordinates map to the paint device on which the gradient is used...
Definition: qbrush.h:219
bool destroyed
Definition: qglobal.h:1943
unsigned char quint8
Definition: qglobal.h:934
bool ref()
Atomically increments the value of this QAtomicInt.
The QRadialGradient class is used in combination with QBrush to specify a radial gradient brush...
Definition: qbrush.h:297
The QString class provides a Unicode character string.
Definition: qstring.h:83
static void qt_cleanup_brush_pattern_image_cache()
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QTransform transform() const
Returns the current transformation matrix for the brush.
Definition: qbrush.h:185
void setPixmap(const QPixmap &pm)
Definition: qbrush.cpp:182
qreal angle() const
Returns the start angle of the conical gradient in logical coordinates.
Definition: qbrush.cpp:2433
qreal cy
Definition: qbrush.h:268
bool operator==(const QGradient &gradient) const
Returns true if the gradient is the same as the other gradient specified; otherwise returns false...
Definition: qbrush.cpp:1650
InterpolationMode interpolationMode() const
Returns the interpolation mode of this gradient.
Definition: qbrush.cpp:1607
static QPixmap * find(const QString &key)
GlobalColor
Definition: qnamespace.h:104
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
The QScopedPointer class stores a pointer to a dynamically allocated object, and deletes it upon dest...
QPointF center() const
Returns the center of the conical gradient in logical coordinates.
Definition: qbrush.cpp:2391
friend bool Q_GUI_EXPORT qHasPixmapTexture(const QBrush &brush)
Definition: qbrush.cpp:223
The QLineF class provides a two-dimensional vector using floating point precision.
Definition: qline.h:212
QGradientStops stops() const
Returns the stop points for this gradient.
Definition: qbrush.cpp:1520
static QPointF qt_radial_gradient_adapt_focal_point(const QPointF &center, qreal radius, const QPointF &focalPoint)
Definition: qbrush.cpp:1933
void setSpread(Spread spread)
Specifies the spread method that should be used for this gradient.
Definition: qbrush.h:277
unsigned char uchar
Definition: qglobal.h:994
void setCenter(const QPointF &center)
Sets the center of this conical gradient in logical coordinates to center.
Definition: qbrush.cpp:2419
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
QGradientStop
Typedef for QPair<qreal , QColor>.
QConicalGradient()
Constructs a conical with center at (0, 0) starting the interpolation at angle 0. ...
Definition: qbrush.cpp:2374
QTransform transform
Definition: qbrush.h:179
bool Q_GUI_EXPORT qHasPixmapTexture(const QBrush &brush)
Definition: qbrush.cpp:223
void setInterpolationMode(InterpolationMode mode)
Sets the interpolation mode of this gradient to mode.
Definition: qbrush.cpp:1623
void clear()
Removes all the elements from the vector and releases the memory used by the vector.
Definition: qvector.h:347
void setStyle(Qt::BrushStyle)
Sets the brush style to style.
Definition: qbrush.cpp:687
bool deref()
Atomically decrements the value of this QAtomicInt.
QDataStream & operator<<(QDataStream &stream, const QBrush &brush)
Writes the given brush to the given stream and returns a reference to the stream. ...
Definition: qbrush.cpp:1111
QBasicAtomicPointer< T > pointer
Definition: qglobal.h:1942
Q_CORE_EXPORT void qWarning(const char *,...)
QColor color
Definition: qbrush.h:178
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
Q_GLOBAL_STATIC_WITH_INITIALIZER(QBrushPatternImageCache, qt_brushPatternImageCache, { qAddPostRoutine(qt_cleanup_brush_pattern_image_cache);}) static void qt_cleanup_brush_pattern_image_cache()
Definition: qbrush.cpp:157
static const char * data(const QByteArray &arr)
bool isQBitmap() const
Returns true if this is a QBitmap; otherwise returns false.
Definition: qpixmap.cpp:599
unsigned int uint
Definition: qglobal.h:996
void setLength(qreal len)
Sets the length of the line to the given length.
Definition: qline.h:360
static void cleanup(QBrushData *d)
Definition: qbrush.cpp:254
Type
Specifies the type of gradient.
Definition: qbrush.h:206
Qt::BrushStyle style() const
Returns the brush style.
Definition: qbrush.h:182
QPixmap texture() const
Returns the custom brush pattern, or a null pixmap if no custom brush pattern has been set...
Definition: qbrush.cpp:785
QDataStream & operator>>(QDataStream &stream, QBrush &brush)
Reads the given brush from the given stream and returns a reference to the stream.
Definition: qbrush.cpp:1182
bool isOpaque() const
Returns true if the brush is fully opaque otherwise false.
Definition: qbrush.cpp:910
QPointF start() const
Returns the start point of this linear gradient in logical coordinates.
Definition: qbrush.cpp:1796
union QGradient::@216 m_data
Q_CORE_EXPORT bool qIsNaN(double d)
Returns true if the double {d} is not a number (NaN).
Definition: qnumeric.cpp:55
const QMatrix & matrix() const
Returns the current transformation matrix for the brush.
Definition: qbrush.h:184
void reset(T *other=0)
Deletes the existing object it is pointing to if any, and sets its pointer to other.
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
Spread
Specifies how the area outside the gradient area should be filled.
Definition: qbrush.h:213
Q_CORE_EXPORT QTextStream & center(QTextStream &s)
int version() const
Returns the version number of the data serialization format.
Definition: qdatastream.h:212
void setImage(const QImage &image)
Definition: qbrush.cpp:196
void setColor(const QColor &color)
Sets the brush color to the given color.
Definition: qbrush.cpp:725
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:76
void insert(int i, const T &t)
Inserts value at index position i in the vector.
Definition: qvector.h:362
void setTexture(const QPixmap &pixmap)
Sets the brush pixmap to pixmap.
Definition: qbrush.cpp:802
QPixmap * m_pixmap
Definition: qbrush.cpp:216
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
QAtomicInt ref
Definition: qbrush.h:176
qreal angle(const QPointF &p1, const QPointF &p2)
Qt::BrushStyle style
Definition: qbrush.h:177
Type type() const
Returns the type of gradient.
Definition: qbrush.h:232
ushort alpha
Returns the alpha color component of this color.
Definition: qcolor.h:242
The QLinearGradient class is used in combination with QBrush to specify a linear gradient brush...
Definition: qbrush.h:280
The QGradient class is used in combination with QBrush to specify gradient fills. ...
Definition: qbrush.h:201
qreal angle
Definition: qbrush.h:271
static void deleteData(QBrushData *d)
Definition: qbrush.cpp:238
void setCoordinateMode(CoordinateMode mode)
Sets the coordinate mode of this gradient to mode.
Definition: qbrush.cpp:1578
InterpolationMode
Definition: qbrush.h:225
void setRadius(qreal radius)
Definition: qbrush.cpp:2165
void setMatrix(const QMatrix &mat)
Sets matrix as an explicit transformation matrix on the current brush.
Definition: qbrush.cpp:951
void setTextureImage(const QImage &image)
Sets the brush image to image.
Definition: qbrush.cpp:856
static bool insert(const QString &key, const QPixmap &pixmap)
Inserts a copy of the pixmap pixmap associated with the key into the cache.
int key
void setFocalRadius(qreal radius)
Definition: qbrush.cpp:2228
Q_GUI_EXPORT bool qt_isExtendedRadialGradient(const QBrush &brush)
Definition: qbrush.cpp:881
void setStops(const QGradientStops &stops)
Replaces the current set of stop points with the given stopPoints.
Definition: qbrush.cpp:1504
unsigned int quint32
Definition: qglobal.h:938
QPointF p2() const
Returns the line&#39;s end point.
Definition: qline.h:319
void setCenter(const QPointF &center)
Sets the center of this radial gradient in logical coordinates to center.
Definition: qbrush.cpp:2134
qreal radius() const
Returns the radius of this radial gradient in logical coordinates.
Definition: qbrush.cpp:2150
Spread spread() const
Returns the spread method use by this gradient.
Definition: qbrush.h:235
qint64 cacheKey() const
Returns a number that identifies this QPixmap.
Definition: qpixmap.cpp:1136
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
quint16 index
QPointF center() const
Returns the center of this radial gradient in logical coordinates.
Definition: qbrush.cpp:2102
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
void * dummy
Definition: qbrush.h:274
struct QGradient::@216::@219 conical
static Q_DECL_CONSTEXPR bool qFuzzyIsNull(double d)
Definition: qglobal.h:2043
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
bool isEmpty() const
Returns true if the vector has size 0; otherwise returns false.
Definition: qvector.h:139
The QDataStream class provides serialization of binary data to a QIODevice.
Definition: qdatastream.h:71
QImage m_images[Qt::DiagCrossPattern - Qt::Dense1Pattern+1][2]
Definition: qbrush.cpp:152
~QBrush()
Destroys the brush.
Definition: qbrush.cpp:582
qreal cx
Definition: qbrush.h:268
Spread m_spread
Definition: qbrush.h:261
bool m_has_pixmap_texture
Definition: qbrush.cpp:218
bool isNull() const
Returns true if this is a null pixmap; otherwise returns false.
Definition: qpixmap.cpp:615
qreal centerRadius() const
Returns the center radius of this radial gradient in logical coordinates.
Definition: qbrush.cpp:2182
void setStart(const QPointF &start)
Sets the start point of this linear gradient in logical coordinates to start.
Definition: qbrush.cpp:1828
bool hasAlphaChannel() const
Returns true if the pixmap has a format that respects the alpha channel, otherwise returns false...
Definition: qpixmap.cpp:1965
qreal fy
Definition: qbrush.h:268
QDebug & space()
Writes a space character to the debug stream and returns a reference to the stream.
Definition: qdebug.h:91
QImage textureImage() const
Returns the custom brush pattern, or a null image if no custom brush pattern has been set...
Definition: qbrush.cpp:829
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
void init(const QColor &color, Qt::BrushStyle bs)
Initializes the brush.
Definition: qbrush.cpp:396
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137
QPixmap qt_pixmapForBrush(int brushStyle, bool invert)
Definition: qbrush.cpp:99
QBrush()
Constructs a default black brush with the style Qt::NoBrush (i.e.
Definition: qbrush.cpp:426
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
QPixmap & pixmap()
Definition: qbrush.cpp:203
void setFocalPoint(const QPointF &focalPoint)
Sets the focal point of this radial gradient in logical coordinates to focalPoint.
Definition: qbrush.cpp:2283
QPointF finalStop() const
Returns the final stop point of this linear gradient in logical coordinates.
Definition: qbrush.cpp:1856
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65