Qt 4.8
qbrush.h
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 #ifndef QBRUSH_H
43 #define QBRUSH_H
44 
45 #include <QtCore/qpair.h>
46 #include <QtCore/qpoint.h>
47 #include <QtCore/qvector.h>
48 #include <QtCore/qscopedpointer.h>
49 #include <QtGui/qcolor.h>
50 #include <QtGui/qmatrix.h>
51 #include <QtGui/qtransform.h>
52 #include <QtGui/qimage.h>
53 #include <QtGui/qpixmap.h>
54 
55 #if defined(Q_OS_VXWORKS)
56 # if defined(m_data)
57 # undef m_data
58 # endif
59 # if defined(m_type)
60 # undef m_type
61 # endif
62 #endif
63 
65 
67 
68 QT_MODULE(Gui)
69 
70 struct QBrushData;
71 class QPixmap;
72 class QGradient;
73 class QVariant;
75 
77 {
78 public:
79  QBrush();
81  QBrush(const QColor &color, Qt::BrushStyle bs=Qt::SolidPattern);
83 
84  QBrush(const QColor &color, const QPixmap &pixmap);
85  QBrush(Qt::GlobalColor color, const QPixmap &pixmap);
86  QBrush(const QPixmap &pixmap);
87  QBrush(const QImage &image);
88 
89  QBrush(const QBrush &brush);
90 
91  QBrush(const QGradient &gradient);
92 
93  ~QBrush();
94  QBrush &operator=(const QBrush &brush);
95 #ifdef Q_COMPILER_RVALUE_REFS
96  inline QBrush &operator=(QBrush &&other)
97  { qSwap(d, other.d); return *this; }
98 #endif
99  inline void swap(QBrush &other) { qSwap(d, other.d); }
100 
101  operator QVariant() const;
102 
103  inline Qt::BrushStyle style() const;
104  void setStyle(Qt::BrushStyle);
105 
106  inline const QMatrix &matrix() const;
107  void setMatrix(const QMatrix &mat);
108 
109  inline QTransform transform() const;
110  void setTransform(const QTransform &);
111 
112  QPixmap texture() const;
113  void setTexture(const QPixmap &pixmap);
114 
115  QImage textureImage() const;
116  void setTextureImage(const QImage &image);
117 
118  inline const QColor &color() const;
119  void setColor(const QColor &color);
120  inline void setColor(Qt::GlobalColor color);
121 
122  const QGradient *gradient() const;
123 
124  bool isOpaque() const;
125 
126  bool operator==(const QBrush &b) const;
127  inline bool operator!=(const QBrush &b) const { return !(operator==(b)); }
128 
129 #ifdef QT3_SUPPORT
130  inline QT3_SUPPORT operator const QColor&() const;
131  QT3_SUPPORT QPixmap *pixmap() const;
132  inline QT3_SUPPORT void setPixmap(const QPixmap &pixmap) { setTexture(pixmap); }
133 #endif
134 
135 private:
136 #if defined(Q_WS_X11)
137  friend class QX11PaintEngine;
138 #endif
139  friend class QRasterPaintEngine;
141  friend struct QSpanData;
142  friend class QPainter;
143  friend bool Q_GUI_EXPORT qHasPixmapTexture(const QBrush& brush);
144  void detach(Qt::BrushStyle newStyle);
145  void init(const QColor &color, Qt::BrushStyle bs);
147  void cleanUp(QBrushData *x);
148 
149 public:
150  inline bool isDetached() const;
152  inline DataPtr &data_ptr() { return d; }
153 };
154 
156 { setColor(QColor(acolor)); }
157 
160 
161 /*****************************************************************************
162  QBrush stream functions
163  *****************************************************************************/
164 
165 #ifndef QT_NO_DATASTREAM
168 #endif
169 
170 #ifndef QT_NO_DEBUG_STREAM
172 #endif
173 
175 {
180 };
181 
182 inline Qt::BrushStyle QBrush::style() const { return d->style; }
183 inline const QColor &QBrush::color() const { return d->color; }
184 inline const QMatrix &QBrush::matrix() const { return d->transform.toAffine(); }
185 inline QTransform QBrush::transform() const { return d->transform; }
186 inline bool QBrush::isDetached() const { return d->ref == 1; }
187 
188 #ifdef QT3_SUPPORT
189 inline QBrush::operator const QColor&() const { return d->color; }
190 #endif
191 
192 
193 /*******************************************************************************
194  * QGradients
195  */
196 class QGradientPrivate;
197 
200 
202 {
203  Q_GADGET
205 public:
206  enum Type {
210  NoGradient
211  };
212 
213  enum Spread {
216  RepeatSpread
217  };
218 
219  enum CoordinateMode {
222  ObjectBoundingMode
223  };
224 
227  ComponentInterpolation
228  };
229 
230  QGradient();
231 
232  Type type() const { return m_type; }
233 
234  inline void setSpread(Spread spread);
235  Spread spread() const { return m_spread; }
236 
237  void setColorAt(qreal pos, const QColor &color);
238 
239  void setStops(const QGradientStops &stops);
240  QGradientStops stops() const;
241 
242  CoordinateMode coordinateMode() const;
243  void setCoordinateMode(CoordinateMode mode);
244 
245  InterpolationMode interpolationMode() const;
246  void setInterpolationMode(InterpolationMode mode);
247 
248  bool operator==(const QGradient &gradient) const;
249  inline bool operator!=(const QGradient &other) const
250  { return !operator==(other); }
251 
252  bool operator==(const QGradient &gradient); // ### Qt 5: remove
253 
254 private:
255  friend class QLinearGradient;
256  friend class QRadialGradient;
257  friend class QConicalGradient;
258  friend class QBrush;
259 
263  union {
264  struct {
265  qreal x1, y1, x2, y2;
266  } linear;
267  struct {
268  qreal cx, cy, fx, fy, cradius;
269  } radial;
270  struct {
271  qreal cx, cy, angle;
272  } conical;
273  } m_data;
274  void *dummy;
275 };
276 
277 inline void QGradient::setSpread(Spread aspread)
278 { m_spread = aspread; }
279 
281 {
282 public:
283  QLinearGradient();
284  QLinearGradient(const QPointF &start, const QPointF &finalStop);
285  QLinearGradient(qreal xStart, qreal yStart, qreal xFinalStop, qreal yFinalStop);
286 
287  QPointF start() const;
288  void setStart(const QPointF &start);
289  inline void setStart(qreal x, qreal y) { setStart(QPointF(x, y)); }
290 
291  QPointF finalStop() const;
292  void setFinalStop(const QPointF &stop);
293  inline void setFinalStop(qreal x, qreal y) { setFinalStop(QPointF(x, y)); }
294 };
295 
296 
298 {
299 public:
300  QRadialGradient();
301  QRadialGradient(const QPointF &center, qreal radius, const QPointF &focalPoint);
302  QRadialGradient(qreal cx, qreal cy, qreal radius, qreal fx, qreal fy);
303 
304  QRadialGradient(const QPointF &center, qreal radius);
305  QRadialGradient(qreal cx, qreal cy, qreal radius);
306 
307  QRadialGradient(const QPointF &center, qreal centerRadius, const QPointF &focalPoint, qreal focalRadius);
308  QRadialGradient(qreal cx, qreal cy, qreal centerRadius, qreal fx, qreal fy, qreal focalRadius);
309 
310  QPointF center() const;
311  void setCenter(const QPointF &center);
312  inline void setCenter(qreal x, qreal y) { setCenter(QPointF(x, y)); }
313 
314  QPointF focalPoint() const;
315  void setFocalPoint(const QPointF &focalPoint);
316  inline void setFocalPoint(qreal x, qreal y) { setFocalPoint(QPointF(x, y)); }
317 
318  qreal radius() const;
319  void setRadius(qreal radius);
320 
321  qreal centerRadius() const;
322  void setCenterRadius(qreal radius);
323 
324  qreal focalRadius() const;
325  void setFocalRadius(qreal radius);
326 };
327 
328 
330 {
331 public:
333  QConicalGradient(const QPointF &center, qreal startAngle);
334  QConicalGradient(qreal cx, qreal cy, qreal startAngle);
335 
336  QPointF center() const;
337  void setCenter(const QPointF &center);
338  inline void setCenter(qreal x, qreal y) { setCenter(QPointF(x, y)); }
339 
340  qreal angle() const;
341  void setAngle(qreal angle);
342 };
343 
345 
347 
348 #endif // QBRUSH_H
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
QScopedPointer< QBrushData, QBrushDataPointerDeleter > DataPtr
Definition: qbrush.h:151
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
The QDebug class provides an output stream for debugging information.
Definition: qdebug.h:62
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
double d
Definition: qnumeric_p.h:62
QGradientStops m_stops
Definition: qbrush.h:262
BrushStyle
Definition: qnamespace.h:1162
double qreal
Definition: qglobal.h:1193
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
const QColor & color() const
Returns the brush color.
Definition: qbrush.h:183
#define QT_MODULE(x)
Definition: qglobal.h:2783
void setFocalPoint(qreal x, qreal y)
Sets the focal point of this radial gradient in logical coordinates to (x, y).
Definition: qbrush.h:316
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
void setCenter(qreal x, qreal y)
Sets the center of this radial gradient in logical coordinates to (x, y).
Definition: qbrush.h:312
The QMatrix class specifies 2D transformations of a coordinate system.
Definition: qmatrix.h:61
The QAtomicInt class provides platform-independent atomic operations on integers. ...
Definition: qatomic.h:55
static QGradient::CoordinateMode coordinateMode(const QBrush &brush)
Definition: qpainter.cpp:106
bool isDetached() const
Definition: qbrush.h:186
qreal y2
Definition: qbrush.h:265
#define Q_GUI_EXPORT
Definition: qglobal.h:1450
QScopedPointer< QBrushData, QBrushDataPointerDeleter > d
Definition: qbrush.h:146
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
void setCenter(qreal x, qreal y)
Sets the center of this conical gradient in logical coordinates to (x, y).
Definition: qbrush.h:338
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
Q_GUI_EXPORT QDataStream & operator>>(QDataStream &, QBrush &)
Definition: qbrush.cpp:1182
The QRadialGradient class is used in combination with QBrush to specify a radial gradient brush...
Definition: qbrush.h:297
QTransform transform() const
Returns the current transformation matrix for the brush.
Definition: qbrush.h:185
GlobalColor
Definition: qnamespace.h:104
#define Q_ENUMS(x)
Definition: qobjectdefs.h:84
#define Q_DECLARE_SHARED(TYPE)
Definition: qglobal.h:2214
DataPtr & data_ptr()
Definition: qbrush.h:152
void setSpread(Spread spread)
Specifies the spread method that should be used for this gradient.
Definition: qbrush.h:277
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
QTransform transform
Definition: qbrush.h:179
bool Q_GUI_EXPORT qHasPixmapTexture(const QBrush &brush)
Definition: qbrush.cpp:223
static bool init
void setFinalStop(qreal x, qreal y)
Sets the final stop point of this linear gradient in logical coordinates to x, y. ...
Definition: qbrush.h:293
Q_DECLARE_TYPEINFO(QBrush, Q_MOVABLE_TYPE)
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
bool operator!=(const QGradient &other) const
Returns true if the gradient is the same as the other gradient specified; otherwise returns false...
Definition: qbrush.h:249
Type
Specifies the type of gradient.
Definition: qbrush.h:206
Qt::BrushStyle style() const
Returns the brush style.
Definition: qbrush.h:182
void swap(QBrush &other)
Swaps brush other with this brush.
Definition: qbrush.h:99
const QMatrix & matrix() const
Returns the current transformation matrix for the brush.
Definition: qbrush.h:184
QVector< QGradientStop > QGradientStops
Definition: qbrush.h:199
void qSwap(T &value1, T &value2)
Definition: qglobal.h:2181
Spread
Specifies how the area outside the gradient area should be filled.
Definition: qbrush.h:213
Q_CORE_EXPORT QTextStream & center(QTextStream &s)
#define Q_GADGET
Definition: qobjectdefs.h:173
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
QAtomicInt ref
Definition: qbrush.h:176
qreal angle(const QPointF &p1, const QPointF &p2)
void setStart(qreal x, qreal y)
Sets the start point of this linear gradient in logical coordinates to x, y.
Definition: qbrush.h:289
Qt::BrushStyle style
Definition: qbrush.h:177
Type type() const
Returns the type of gradient.
Definition: qbrush.h:232
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
QPair< qreal, QColor > QGradientStop
Definition: qbrush.h:196
InterpolationMode
Definition: qbrush.h:225
Q_GUI_EXPORT QDataStream & operator<<(QDataStream &, const QBrush &)
Definition: qbrush.cpp:1111
Spread spread() const
Returns the spread method use by this gradient.
Definition: qbrush.h:235
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
The QDataStream class provides serialization of binary data to a QIODevice.
Definition: qdatastream.h:71
The QRasterPaintEngine class enables hardware acceleration of painting operations in Qt for Embedded ...
Spread m_spread
Definition: qbrush.h:261
bool operator!=(const QBrush &b) const
Returns true if the brush is different from the given brush; otherwise returns false.
Definition: qbrush.h:127
qreal fy
Definition: qbrush.h:268
#define QT_END_HEADER
Definition: qglobal.h:137
bool operator==(QBool b1, bool b2)
Definition: qglobal.h:2023
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65