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_SHARED(QBrush)
150 /*****************************************************************************
151 QBrush stream functions
152 *****************************************************************************/
154 #ifndef QT_NO_DATASTREAM
155 Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QBrush &);
156 Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QBrush &);
159 #ifndef QT_NO_DEBUG_STREAM
160 Q_GUI_EXPORT QDebug operator<<(QDebug, const QBrush &);
166 Qt::BrushStyle style;
168 QTransform transform;
171 inline Qt::BrushStyle QBrush::style() const { return d->style; }
172 inline const QColor &QBrush::color() const { return d->color; }
173 inline const QMatrix &QBrush::matrix() const { return d->transform.toAffine(); }
174 inline QTransform QBrush::transform() const { return d->transform; }
175 inline bool QBrush::isDetached() const { return d->ref.load() == 1; }
178 /*******************************************************************************
181 class QGradientPrivate;
183 typedef QPair<qreal, QColor> QGradientStop;
184 typedef QVector<QGradientStop> QGradientStops;
186 class Q_GUI_EXPORT QGradient
189 Q_ENUMS(Type Spread CoordinateMode)
204 enum CoordinateMode {
210 enum InterpolationMode {
212 ComponentInterpolation
217 Type type() const { return m_type; }
219 inline void setSpread(Spread spread);
220 Spread spread() const { return m_spread; }
222 void setColorAt(qreal pos, const QColor &color);
224 void setStops(const QGradientStops &stops);
225 QGradientStops stops() const;
227 CoordinateMode coordinateMode() const;
228 void setCoordinateMode(CoordinateMode mode);
230 InterpolationMode interpolationMode() const;
231 void setInterpolationMode(InterpolationMode mode);
233 bool operator==(const QGradient &gradient) const;
234 inline bool operator!=(const QGradient &other) const
235 { return !operator==(other); }
238 friend class QLinearGradient;
239 friend class QRadialGradient;
240 friend class QConicalGradient;
245 QGradientStops m_stops;
248 qreal x1, y1, x2, y2;
251 qreal cx, cy, fx, fy, cradius;
260 inline void QGradient::setSpread(Spread aspread)
261 { m_spread = aspread; }
263 class Q_GUI_EXPORT QLinearGradient : public QGradient
267 QLinearGradient(const QPointF &start, const QPointF &finalStop);
268 QLinearGradient(qreal xStart, qreal yStart, qreal xFinalStop, qreal yFinalStop);
270 QPointF start() const;
271 void setStart(const QPointF &start);
272 inline void setStart(qreal x, qreal y) { setStart(QPointF(x, y)); }
274 QPointF finalStop() const;
275 void setFinalStop(const QPointF &stop);
276 inline void setFinalStop(qreal x, qreal y) { setFinalStop(QPointF(x, y)); }
280 class Q_GUI_EXPORT QRadialGradient : public QGradient
284 QRadialGradient(const QPointF ¢er, qreal radius, const QPointF &focalPoint);
285 QRadialGradient(qreal cx, qreal cy, qreal radius, qreal fx, qreal fy);
287 QRadialGradient(const QPointF ¢er, qreal radius);
288 QRadialGradient(qreal cx, qreal cy, qreal radius);
290 QRadialGradient(const QPointF ¢er, qreal centerRadius, const QPointF &focalPoint, qreal focalRadius);
291 QRadialGradient(qreal cx, qreal cy, qreal centerRadius, qreal fx, qreal fy, qreal focalRadius);
293 QPointF center() const;
294 void setCenter(const QPointF ¢er);
295 inline void setCenter(qreal x, qreal y) { setCenter(QPointF(x, y)); }
297 QPointF focalPoint() const;
298 void setFocalPoint(const QPointF &focalPoint);
299 inline void setFocalPoint(qreal x, qreal y) { setFocalPoint(QPointF(x, y)); }
301 qreal radius() const;
302 void setRadius(qreal radius);
304 qreal centerRadius() const;
305 void setCenterRadius(qreal radius);
307 qreal focalRadius() const;
308 void setFocalRadius(qreal radius);
312 class Q_GUI_EXPORT QConicalGradient : public QGradient
316 QConicalGradient(const QPointF ¢er, qreal startAngle);
317 QConicalGradient(qreal cx, qreal cy, qreal startAngle);
319 QPointF center() const;
320 void setCenter(const QPointF ¢er);
321 inline void setCenter(qreal x, qreal y) { setCenter(QPointF(x, y)); }
324 void setAngle(qreal angle);