1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtGui module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** 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)
73 struct QBrushDataPointerDeleter;
75 class Q_GUI_EXPORT QBrush
79 QBrush(Qt::BrushStyle bs);
80 QBrush(const QColor &color, Qt::BrushStyle bs=Qt::SolidPattern);
81 QBrush(Qt::GlobalColor color, Qt::BrushStyle bs=Qt::SolidPattern);
83 QBrush(const QColor &color, const QPixmap &pixmap);
84 QBrush(Qt::GlobalColor color, const QPixmap &pixmap);
85 QBrush(const QPixmap &pixmap);
86 QBrush(const QImage &image);
88 QBrush(const QBrush &brush);
90 QBrush(const QGradient &gradient);
93 QBrush &operator=(const QBrush &brush);
94 #ifdef Q_COMPILER_RVALUE_REFS
95 inline QBrush &operator=(QBrush &&other)
96 { qSwap(d, other.d); return *this; }
98 inline void swap(QBrush &other) { qSwap(d, other.d); }
100 operator QVariant() const;
102 inline Qt::BrushStyle style() const;
103 void setStyle(Qt::BrushStyle);
105 inline const QMatrix &matrix() const;
106 void setMatrix(const QMatrix &mat);
108 inline QTransform transform() const;
109 void setTransform(const QTransform &);
111 QPixmap texture() const;
112 void setTexture(const QPixmap &pixmap);
114 QImage textureImage() const;
115 void setTextureImage(const QImage &image);
117 inline const QColor &color() const;
118 void setColor(const QColor &color);
119 inline void setColor(Qt::GlobalColor color);
121 const QGradient *gradient() const;
123 bool isOpaque() const;
125 bool operator==(const QBrush &b) const;
126 inline bool operator!=(const QBrush &b) const { return !(operator==(b)); }
129 friend class QRasterPaintEngine;
130 friend class QRasterPaintEnginePrivate;
131 friend struct QSpanData;
132 friend class QPainter;
133 friend bool Q_GUI_EXPORT qHasPixmapTexture(const QBrush& brush);
134 void detach(Qt::BrushStyle newStyle);
135 void init(const QColor &color, Qt::BrushStyle bs);
136 QScopedPointer<QBrushData, QBrushDataPointerDeleter> d;
137 void cleanUp(QBrushData *x);
140 inline bool isDetached() const;
141 typedef QScopedPointer<QBrushData, QBrushDataPointerDeleter> DataPtr;
142 inline DataPtr &data_ptr() { return d; }
145 inline void QBrush::setColor(Qt::GlobalColor acolor)
146 { setColor(QColor(acolor)); }
148 Q_DECLARE_TYPEINFO(QBrush, Q_MOVABLE_TYPE);
149 Q_DECLARE_SHARED(QBrush)
151 /*****************************************************************************
152 QBrush stream functions
153 *****************************************************************************/
155 #ifndef QT_NO_DATASTREAM
156 Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QBrush &);
157 Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QBrush &);
160 #ifndef QT_NO_DEBUG_STREAM
161 Q_GUI_EXPORT QDebug operator<<(QDebug, const QBrush &);
167 Qt::BrushStyle style;
169 QTransform transform;
172 inline Qt::BrushStyle QBrush::style() const { return d->style; }
173 inline const QColor &QBrush::color() const { return d->color; }
174 inline const QMatrix &QBrush::matrix() const { return d->transform.toAffine(); }
175 inline QTransform QBrush::transform() const { return d->transform; }
176 inline bool QBrush::isDetached() const { return d->ref.load() == 1; }
179 /*******************************************************************************
182 class QGradientPrivate;
184 typedef QPair<qreal, QColor> QGradientStop;
185 typedef QVector<QGradientStop> QGradientStops;
187 class Q_GUI_EXPORT QGradient
190 Q_ENUMS(Type Spread CoordinateMode)
205 enum CoordinateMode {
211 enum InterpolationMode {
213 ComponentInterpolation
218 Type type() const { return m_type; }
220 inline void setSpread(Spread spread);
221 Spread spread() const { return m_spread; }
223 void setColorAt(qreal pos, const QColor &color);
225 void setStops(const QGradientStops &stops);
226 QGradientStops stops() const;
228 CoordinateMode coordinateMode() const;
229 void setCoordinateMode(CoordinateMode mode);
231 InterpolationMode interpolationMode() const;
232 void setInterpolationMode(InterpolationMode mode);
234 bool operator==(const QGradient &gradient) const;
235 inline bool operator!=(const QGradient &other) const
236 { return !operator==(other); }
239 friend class QLinearGradient;
240 friend class QRadialGradient;
241 friend class QConicalGradient;
246 QGradientStops m_stops;
249 qreal x1, y1, x2, y2;
252 qreal cx, cy, fx, fy, cradius;
261 inline void QGradient::setSpread(Spread aspread)
262 { m_spread = aspread; }
264 class Q_GUI_EXPORT QLinearGradient : public QGradient
268 QLinearGradient(const QPointF &start, const QPointF &finalStop);
269 QLinearGradient(qreal xStart, qreal yStart, qreal xFinalStop, qreal yFinalStop);
271 QPointF start() const;
272 void setStart(const QPointF &start);
273 inline void setStart(qreal x, qreal y) { setStart(QPointF(x, y)); }
275 QPointF finalStop() const;
276 void setFinalStop(const QPointF &stop);
277 inline void setFinalStop(qreal x, qreal y) { setFinalStop(QPointF(x, y)); }
281 class Q_GUI_EXPORT QRadialGradient : public QGradient
285 QRadialGradient(const QPointF ¢er, qreal radius, const QPointF &focalPoint);
286 QRadialGradient(qreal cx, qreal cy, qreal radius, qreal fx, qreal fy);
288 QRadialGradient(const QPointF ¢er, qreal radius);
289 QRadialGradient(qreal cx, qreal cy, qreal radius);
291 QRadialGradient(const QPointF ¢er, qreal centerRadius, const QPointF &focalPoint, qreal focalRadius);
292 QRadialGradient(qreal cx, qreal cy, qreal centerRadius, qreal fx, qreal fy, qreal focalRadius);
294 QPointF center() const;
295 void setCenter(const QPointF ¢er);
296 inline void setCenter(qreal x, qreal y) { setCenter(QPointF(x, y)); }
298 QPointF focalPoint() const;
299 void setFocalPoint(const QPointF &focalPoint);
300 inline void setFocalPoint(qreal x, qreal y) { setFocalPoint(QPointF(x, y)); }
302 qreal radius() const;
303 void setRadius(qreal radius);
305 qreal centerRadius() const;
306 void setCenterRadius(qreal radius);
308 qreal focalRadius() const;
309 void setFocalRadius(qreal radius);
313 class Q_GUI_EXPORT QConicalGradient : public QGradient
317 QConicalGradient(const QPointF ¢er, qreal startAngle);
318 QConicalGradient(qreal cx, qreal cy, qreal startAngle);
320 QPointF center() const;
321 void setCenter(const QPointF ¢er);
322 inline void setCenter(qreal x, qreal y) { setCenter(QPointF(x, y)); }
325 void setAngle(qreal angle);