Qt 4.8
Classes | Typedefs | Functions
qbrush.h File Reference
#include <QtCore/qpair.h>
#include <QtCore/qpoint.h>
#include <QtCore/qvector.h>
#include <QtCore/qscopedpointer.h>
#include <QtGui/qcolor.h>
#include <QtGui/qmatrix.h>
#include <QtGui/qtransform.h>
#include <QtGui/qimage.h>
#include <QtGui/qpixmap.h>

Go to the source code of this file.

Classes

class  QBrush
 The QBrush class defines the fill pattern of shapes drawn by QPainter. More...
 
struct  QBrushData
 
class  QConicalGradient
 The QConicalGradient class is used in combination with QBrush to specify a conical gradient brush. More...
 
class  QGradient
 The QGradient class is used in combination with QBrush to specify gradient fills. More...
 
class  QLinearGradient
 The QLinearGradient class is used in combination with QBrush to specify a linear gradient brush. More...
 
class  QRadialGradient
 The QRadialGradient class is used in combination with QBrush to specify a radial gradient brush. More...
 

Typedefs

typedef QPair< qreal, QColorQGradientStop
 
typedef QVector< QGradientStopQGradientStops
 

Functions

Q_GUI_EXPORT QDataStreamoperator<< (QDataStream &, const QBrush &)
 
Q_GUI_EXPORT QDebug operator<< (QDebug, const QBrush &)
 
Q_GUI_EXPORT QDataStreamoperator>> (QDataStream &, QBrush &)
 
 Q_DECLARE_TYPEINFO (QBrush, Q_MOVABLE_TYPE)
 

Typedef Documentation

◆ QGradientStop

typedef QPair<qreal, QColor> QGradientStop
related

Definition at line 196 of file qbrush.h.

◆ QGradientStops

Definition at line 199 of file qbrush.h.

Function Documentation

◆ operator<<() [1/2]

Q_GUI_EXPORT QDataStream& operator<< ( QDataStream ,
const QBrush  
)
related

Definition at line 1111 of file qbrush.cpp.

Referenced by QBrush::setColor().

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 }
double qreal
Definition: qglobal.h:1193
CoordinateMode coordinateMode() const
Returns the coordinate mode of this gradient.
Definition: qbrush.cpp:1563
T1 first
Definition: qpair.h:65
T2 second
Definition: qpair.h:66
unsigned char quint8
Definition: qglobal.h:934
InterpolationMode interpolationMode() const
Returns the interpolation mode of this gradient.
Definition: qbrush.cpp:1607
QTextStream & center(QTextStream &stream)
Calls QTextStream::setFieldAlignment(QTextStream::AlignCenter) on stream and returns stream...
QGradientStops stops() const
Returns the stop points for this gradient.
Definition: qbrush.cpp:1520
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
qreal angle(const QPointF &p1, const QPointF &p2)
Type type() const
Returns the type of gradient.
Definition: qbrush.h:232
The QGradient class is used in combination with QBrush to specify gradient fills. ...
Definition: qbrush.h:201
unsigned int quint32
Definition: qglobal.h:938
Spread spread() const
Returns the spread method use by this gradient.
Definition: qbrush.h:235
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137

◆ operator<<() [2/2]

Q_GUI_EXPORT QDebug operator<< ( QDebug  dbg,
const QBrush b 
)
Warning
This function is not part of the public interface.

Definition at line 1058 of file qbrush.cpp.

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 }
const QColor & color() const
Returns the brush color.
Definition: qbrush.h:183
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
Q_CORE_EXPORT void qWarning(const char *,...)
Qt::BrushStyle style() const
Returns the brush style.
Definition: qbrush.h:182
QDebug & space()
Writes a space character to the debug stream and returns a reference to the stream.
Definition: qdebug.h:91
#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

◆ operator>>()

Q_GUI_EXPORT QDataStream& operator>> ( QDataStream ,
QBrush  
)
related

Definition at line 1182 of file qbrush.cpp.

Referenced by QBrush::setColor().

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) {
1269  QTransform transform;
1270  s >> transform;
1271  b.setTransform(transform);
1272  }
1273  return s;
1274 }
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
BrushStyle
Definition: qnamespace.h:1162
int type
Definition: qmetatype.cpp:239
double qreal
Definition: qglobal.h:1193
unsigned char c[8]
Definition: qnumeric_p.h:62
The QConicalGradient class is used in combination with QBrush to specify a conical gradient brush...
Definition: qbrush.h:329
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
CoordinateMode
This enum specifies how gradient coordinates map to the paint device on which the gradient is used...
Definition: qbrush.h:219
unsigned char quint8
Definition: qglobal.h:934
The QRadialGradient class is used in combination with QBrush to specify a radial gradient brush...
Definition: qbrush.h:297
QTextStream & center(QTextStream &stream)
Calls QTextStream::setFieldAlignment(QTextStream::AlignCenter) on stream and returns stream...
Type
Specifies the type of gradient.
Definition: qbrush.h:206
Spread
Specifies how the area outside the gradient area should be filled.
Definition: qbrush.h:213
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:76
qreal angle(const QPointF &p1, const QPointF &p2)
The QLinearGradient class is used in combination with QBrush to specify a linear gradient brush...
Definition: qbrush.h:280
InterpolationMode
Definition: qbrush.h:225
unsigned int quint32
Definition: qglobal.h:938
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65

◆ Q_DECLARE_TYPEINFO()

Q_DECLARE_TYPEINFO ( QBrush  ,
Q_MOVABLE_TYPE   
)

Referenced by QBrush::setColor().