1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtGui module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
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>
55 #if defined(Q_OS_VXWORKS)
74 struct QBrushDataPointerDeleter;
76 class Q_GUI_EXPORT QBrush
80 QBrush(Qt::BrushStyle bs);
81 QBrush(const QColor &color, Qt::BrushStyle bs=Qt::SolidPattern);
82 QBrush(Qt::GlobalColor color, Qt::BrushStyle bs=Qt::SolidPattern);
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);
89 QBrush(const QBrush &brush);
91 QBrush(const QGradient &gradient);
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; }
99 inline void swap(QBrush &other) { qSwap(d, other.d); }
101 operator QVariant() const;
103 inline Qt::BrushStyle style() const;
104 void setStyle(Qt::BrushStyle);
106 inline const QMatrix &matrix() const;
107 void setMatrix(const QMatrix &mat);
109 inline QTransform transform() const;
110 void setTransform(const QTransform &);
112 QPixmap texture() const;
113 void setTexture(const QPixmap &pixmap);
115 QImage textureImage() const;
116 void setTextureImage(const QImage &image);
118 inline const QColor &color() const;
119 void setColor(const QColor &color);
120 inline void setColor(Qt::GlobalColor color);
122 const QGradient *gradient() const;
124 bool isOpaque() const;
126 bool operator==(const QBrush &b) const;
127 inline bool operator!=(const QBrush &b) const { return !(operator==(b)); }
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); }
136 #if defined(Q_WS_X11)
137 friend class QX11PaintEngine;
139 friend class QRasterPaintEngine;
140 friend class QRasterPaintEnginePrivate;
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);
146 QScopedPointer<QBrushData, QBrushDataPointerDeleter> d;
147 void cleanUp(QBrushData *x);
150 inline bool isDetached() const;
151 typedef QScopedPointer<QBrushData, QBrushDataPointerDeleter> DataPtr;
152 inline DataPtr &data_ptr() { return d; }
155 inline void QBrush::setColor(Qt::GlobalColor acolor)
156 { setColor(QColor(acolor)); }
158 Q_DECLARE_TYPEINFO(QBrush, Q_MOVABLE_TYPE);
159 Q_DECLARE_SHARED(QBrush)
161 /*****************************************************************************
162 QBrush stream functions
163 *****************************************************************************/
165 #ifndef QT_NO_DATASTREAM
166 Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QBrush &);
167 Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QBrush &);
170 #ifndef QT_NO_DEBUG_STREAM
171 Q_GUI_EXPORT QDebug operator<<(QDebug, const QBrush &);
177 Qt::BrushStyle style;
179 QTransform transform;
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; }
189 inline QBrush::operator const QColor&() const { return d->color; }
193 /*******************************************************************************
196 class QGradientPrivate;
198 typedef QPair<qreal, QColor> QGradientStop;
199 typedef QVector<QGradientStop> QGradientStops;
201 class Q_GUI_EXPORT QGradient
204 Q_ENUMS(Type Spread CoordinateMode)
219 enum CoordinateMode {
225 enum InterpolationMode {
227 ComponentInterpolation
232 Type type() const { return m_type; }
234 inline void setSpread(Spread spread);
235 Spread spread() const { return m_spread; }
237 void setColorAt(qreal pos, const QColor &color);
239 void setStops(const QGradientStops &stops);
240 QGradientStops stops() const;
242 CoordinateMode coordinateMode() const;
243 void setCoordinateMode(CoordinateMode mode);
245 InterpolationMode interpolationMode() const;
246 void setInterpolationMode(InterpolationMode mode);
248 bool operator==(const QGradient &gradient) const;
249 inline bool operator!=(const QGradient &other) const
250 { return !operator==(other); }
253 friend class QLinearGradient;
254 friend class QRadialGradient;
255 friend class QConicalGradient;
260 QGradientStops m_stops;
263 qreal x1, y1, x2, y2;
266 qreal cx, cy, fx, fy, cradius;
275 inline void QGradient::setSpread(Spread aspread)
276 { m_spread = aspread; }
278 class Q_GUI_EXPORT QLinearGradient : public QGradient
282 QLinearGradient(const QPointF &start, const QPointF &finalStop);
283 QLinearGradient(qreal xStart, qreal yStart, qreal xFinalStop, qreal yFinalStop);
285 QPointF start() const;
286 void setStart(const QPointF &start);
287 inline void setStart(qreal x, qreal y) { setStart(QPointF(x, y)); }
289 QPointF finalStop() const;
290 void setFinalStop(const QPointF &stop);
291 inline void setFinalStop(qreal x, qreal y) { setFinalStop(QPointF(x, y)); }
295 class Q_GUI_EXPORT QRadialGradient : public QGradient
299 QRadialGradient(const QPointF ¢er, qreal radius, const QPointF &focalPoint);
300 QRadialGradient(qreal cx, qreal cy, qreal radius, qreal fx, qreal fy);
302 QRadialGradient(const QPointF ¢er, qreal radius);
303 QRadialGradient(qreal cx, qreal cy, qreal radius);
305 QRadialGradient(const QPointF ¢er, qreal centerRadius, const QPointF &focalPoint, qreal focalRadius);
306 QRadialGradient(qreal cx, qreal cy, qreal centerRadius, qreal fx, qreal fy, qreal focalRadius);
308 QPointF center() const;
309 void setCenter(const QPointF ¢er);
310 inline void setCenter(qreal x, qreal y) { setCenter(QPointF(x, y)); }
312 QPointF focalPoint() const;
313 void setFocalPoint(const QPointF &focalPoint);
314 inline void setFocalPoint(qreal x, qreal y) { setFocalPoint(QPointF(x, y)); }
316 qreal radius() const;
317 void setRadius(qreal radius);
319 qreal centerRadius() const;
320 void setCenterRadius(qreal radius);
322 qreal focalRadius() const;
323 void setFocalRadius(qreal radius);
327 class Q_GUI_EXPORT QConicalGradient : public QGradient
331 QConicalGradient(const QPointF ¢er, qreal startAngle);
332 QConicalGradient(qreal cx, qreal cy, qreal startAngle);
334 QPointF center() const;
335 void setCenter(const QPointF ¢er);
336 inline void setCenter(qreal x, qreal y) { setCenter(QPointF(x, y)); }
339 void setAngle(qreal angle);