| 1 | /**************************************************************************** | 
|---|
| 2 | ** | 
|---|
| 3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). | 
|---|
| 4 | ** All rights reserved. | 
|---|
| 5 | ** Contact: Nokia Corporation (qt-info@nokia.com) | 
|---|
| 6 | ** | 
|---|
| 7 | ** This file is part of the QtGui module of the Qt Toolkit. | 
|---|
| 8 | ** | 
|---|
| 9 | ** $QT_BEGIN_LICENSE:LGPL$ | 
|---|
| 10 | ** Commercial Usage | 
|---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in | 
|---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the | 
|---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in | 
|---|
| 14 | ** a written agreement between you and Nokia. | 
|---|
| 15 | ** | 
|---|
| 16 | ** GNU Lesser General Public License Usage | 
|---|
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser | 
|---|
| 18 | ** General Public License version 2.1 as published by the Free Software | 
|---|
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the | 
|---|
| 20 | ** packaging of this file.  Please review the following information to | 
|---|
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements | 
|---|
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | 
|---|
| 23 | ** | 
|---|
| 24 | ** In addition, as a special exception, Nokia gives you certain additional | 
|---|
| 25 | ** rights.  These rights are described in the Nokia Qt LGPL Exception | 
|---|
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | 
|---|
| 27 | ** | 
|---|
| 28 | ** GNU General Public License Usage | 
|---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU | 
|---|
| 30 | ** General Public License version 3.0 as published by the Free Software | 
|---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the | 
|---|
| 32 | ** packaging of this file.  Please review the following information to | 
|---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be | 
|---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html. | 
|---|
| 35 | ** | 
|---|
| 36 | ** If you have questions regarding the use of this file, please contact | 
|---|
| 37 | ** Nokia at qt-info@nokia.com. | 
|---|
| 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 |  | 
|---|
| 64 | QT_BEGIN_HEADER | 
|---|
| 65 |  | 
|---|
| 66 | QT_BEGIN_NAMESPACE | 
|---|
| 67 |  | 
|---|
| 68 | QT_MODULE(Gui) | 
|---|
| 69 |  | 
|---|
| 70 | struct QBrushData; | 
|---|
| 71 | class QPixmap; | 
|---|
| 72 | class QGradient; | 
|---|
| 73 | class QVariant; | 
|---|
| 74 | struct QBrushDataPointerDeleter; | 
|---|
| 75 |  | 
|---|
| 76 | class Q_GUI_EXPORT QBrush | 
|---|
| 77 | { | 
|---|
| 78 | public: | 
|---|
| 79 | 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); | 
|---|
| 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 | operator QVariant() const; | 
|---|
| 96 |  | 
|---|
| 97 | inline Qt::BrushStyle style() const; | 
|---|
| 98 | void setStyle(Qt::BrushStyle); | 
|---|
| 99 |  | 
|---|
| 100 | inline const QMatrix &matrix() const; | 
|---|
| 101 | void setMatrix(const QMatrix &mat); | 
|---|
| 102 |  | 
|---|
| 103 | inline QTransform transform() const; | 
|---|
| 104 | void setTransform(const QTransform &); | 
|---|
| 105 |  | 
|---|
| 106 | QPixmap texture() const; | 
|---|
| 107 | void setTexture(const QPixmap &pixmap); | 
|---|
| 108 |  | 
|---|
| 109 | QImage textureImage() const; | 
|---|
| 110 | void setTextureImage(const QImage &image); | 
|---|
| 111 |  | 
|---|
| 112 | inline const QColor &color() const; | 
|---|
| 113 | void setColor(const QColor &color); | 
|---|
| 114 | inline void setColor(Qt::GlobalColor color); | 
|---|
| 115 |  | 
|---|
| 116 | const QGradient *gradient() const; | 
|---|
| 117 |  | 
|---|
| 118 | bool isOpaque() const; | 
|---|
| 119 |  | 
|---|
| 120 | bool operator==(const QBrush &b) const; | 
|---|
| 121 | inline bool operator!=(const QBrush &b) const { return !(operator==(b)); } | 
|---|
| 122 |  | 
|---|
| 123 | #ifdef QT3_SUPPORT | 
|---|
| 124 | inline QT3_SUPPORT operator const QColor&() const; | 
|---|
| 125 | QT3_SUPPORT QPixmap *pixmap() const; | 
|---|
| 126 | inline QT3_SUPPORT void setPixmap(const QPixmap &pixmap) { setTexture(pixmap); } | 
|---|
| 127 | #endif | 
|---|
| 128 |  | 
|---|
| 129 | private: | 
|---|
| 130 | #if defined(Q_WS_X11) | 
|---|
| 131 | friend class QX11PaintEngine; | 
|---|
| 132 | #endif | 
|---|
| 133 | friend class QRasterPaintEngine; | 
|---|
| 134 | friend class QRasterPaintEnginePrivate; | 
|---|
| 135 | friend struct QSpanData; | 
|---|
| 136 | friend class QPainter; | 
|---|
| 137 | friend bool Q_GUI_EXPORT qHasPixmapTexture(const QBrush& brush); | 
|---|
| 138 | void detach(Qt::BrushStyle newStyle); | 
|---|
| 139 | void init(const QColor &color, Qt::BrushStyle bs); | 
|---|
| 140 | QScopedPointer<QBrushData, QBrushDataPointerDeleter> d; | 
|---|
| 141 | void cleanUp(QBrushData *x); | 
|---|
| 142 |  | 
|---|
| 143 | public: | 
|---|
| 144 | inline bool isDetached() const; | 
|---|
| 145 | typedef QScopedPointer<QBrushData, QBrushDataPointerDeleter> DataPtr; | 
|---|
| 146 | inline DataPtr &data_ptr() { return d; } | 
|---|
| 147 | }; | 
|---|
| 148 |  | 
|---|
| 149 | inline void QBrush::setColor(Qt::GlobalColor acolor) | 
|---|
| 150 | { setColor(QColor(acolor)); } | 
|---|
| 151 |  | 
|---|
| 152 | Q_DECLARE_TYPEINFO(QBrush, Q_MOVABLE_TYPE); | 
|---|
| 153 | Q_DECLARE_SHARED(QBrush) | 
|---|
| 154 |  | 
|---|
| 155 | /***************************************************************************** | 
|---|
| 156 | QBrush stream functions | 
|---|
| 157 | *****************************************************************************/ | 
|---|
| 158 |  | 
|---|
| 159 | #ifndef QT_NO_DATASTREAM | 
|---|
| 160 | Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QBrush &); | 
|---|
| 161 | Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QBrush &); | 
|---|
| 162 | #endif | 
|---|
| 163 |  | 
|---|
| 164 | #ifndef QT_NO_DEBUG_STREAM | 
|---|
| 165 | Q_GUI_EXPORT QDebug operator<<(QDebug, const QBrush &); | 
|---|
| 166 | #endif | 
|---|
| 167 |  | 
|---|
| 168 | struct QBrushData | 
|---|
| 169 | { | 
|---|
| 170 | QAtomicInt ref; | 
|---|
| 171 | Qt::BrushStyle style; | 
|---|
| 172 | QColor color; | 
|---|
| 173 | QTransform transform; | 
|---|
| 174 | }; | 
|---|
| 175 |  | 
|---|
| 176 | inline Qt::BrushStyle QBrush::style() const { return d->style; } | 
|---|
| 177 | inline const QColor &QBrush::color() const { return d->color; } | 
|---|
| 178 | inline const QMatrix &QBrush::matrix() const { return d->transform.toAffine(); } | 
|---|
| 179 | inline QTransform QBrush::transform() const { return d->transform; } | 
|---|
| 180 | inline bool QBrush::isDetached() const { return d->ref == 1; } | 
|---|
| 181 |  | 
|---|
| 182 | #ifdef QT3_SUPPORT | 
|---|
| 183 | inline QBrush::operator const QColor&() const { return d->color; } | 
|---|
| 184 | #endif | 
|---|
| 185 |  | 
|---|
| 186 |  | 
|---|
| 187 | /******************************************************************************* | 
|---|
| 188 | * QGradients | 
|---|
| 189 | */ | 
|---|
| 190 | class QGradientPrivate; | 
|---|
| 191 |  | 
|---|
| 192 | typedef QPair<qreal, QColor> QGradientStop; | 
|---|
| 193 | typedef QVector<QGradientStop> QGradientStops; | 
|---|
| 194 |  | 
|---|
| 195 | class Q_GUI_EXPORT QGradient | 
|---|
| 196 | { | 
|---|
| 197 | Q_GADGET | 
|---|
| 198 | Q_ENUMS(Type Spread CoordinateMode) | 
|---|
| 199 | public: | 
|---|
| 200 | enum Type { | 
|---|
| 201 | LinearGradient, | 
|---|
| 202 | RadialGradient, | 
|---|
| 203 | ConicalGradient, | 
|---|
| 204 | NoGradient | 
|---|
| 205 | }; | 
|---|
| 206 |  | 
|---|
| 207 | enum Spread { | 
|---|
| 208 | PadSpread, | 
|---|
| 209 | ReflectSpread, | 
|---|
| 210 | RepeatSpread | 
|---|
| 211 | }; | 
|---|
| 212 |  | 
|---|
| 213 | enum CoordinateMode { | 
|---|
| 214 | LogicalMode, | 
|---|
| 215 | StretchToDeviceMode, | 
|---|
| 216 | ObjectBoundingMode | 
|---|
| 217 | }; | 
|---|
| 218 |  | 
|---|
| 219 | enum InterpolationMode { | 
|---|
| 220 | ColorInterpolation, | 
|---|
| 221 | ComponentInterpolation | 
|---|
| 222 | }; | 
|---|
| 223 |  | 
|---|
| 224 | QGradient(); | 
|---|
| 225 |  | 
|---|
| 226 | Type type() const { return m_type; } | 
|---|
| 227 |  | 
|---|
| 228 | inline void setSpread(Spread spread); | 
|---|
| 229 | Spread spread() const { return m_spread; } | 
|---|
| 230 |  | 
|---|
| 231 | void setColorAt(qreal pos, const QColor &color); | 
|---|
| 232 |  | 
|---|
| 233 | void setStops(const QGradientStops &stops); | 
|---|
| 234 | QGradientStops stops() const; | 
|---|
| 235 |  | 
|---|
| 236 | CoordinateMode coordinateMode() const; | 
|---|
| 237 | void setCoordinateMode(CoordinateMode mode); | 
|---|
| 238 |  | 
|---|
| 239 | InterpolationMode interpolationMode() const; | 
|---|
| 240 | void setInterpolationMode(InterpolationMode mode); | 
|---|
| 241 |  | 
|---|
| 242 | bool operator==(const QGradient &gradient) const; | 
|---|
| 243 | inline bool operator!=(const QGradient &other) const | 
|---|
| 244 | { return !operator==(other); } | 
|---|
| 245 |  | 
|---|
| 246 | bool operator==(const QGradient &gradient); // ### Qt 5: remove | 
|---|
| 247 |  | 
|---|
| 248 | private: | 
|---|
| 249 | friend class QLinearGradient; | 
|---|
| 250 | friend class QRadialGradient; | 
|---|
| 251 | friend class QConicalGradient; | 
|---|
| 252 |  | 
|---|
| 253 | Type m_type; | 
|---|
| 254 | Spread m_spread; | 
|---|
| 255 | QGradientStops m_stops; | 
|---|
| 256 | union { | 
|---|
| 257 | struct { | 
|---|
| 258 | qreal x1, y1, x2, y2; | 
|---|
| 259 | } linear; | 
|---|
| 260 | struct { | 
|---|
| 261 | qreal cx, cy, fx, fy, radius; | 
|---|
| 262 | } radial; | 
|---|
| 263 | struct { | 
|---|
| 264 | qreal cx, cy, angle; | 
|---|
| 265 | } conical; | 
|---|
| 266 | } m_data; | 
|---|
| 267 | void *dummy; | 
|---|
| 268 | }; | 
|---|
| 269 |  | 
|---|
| 270 | inline void QGradient::setSpread(Spread aspread) | 
|---|
| 271 | { m_spread = aspread; } | 
|---|
| 272 |  | 
|---|
| 273 | class Q_GUI_EXPORT QLinearGradient : public QGradient | 
|---|
| 274 | { | 
|---|
| 275 | public: | 
|---|
| 276 | QLinearGradient(); | 
|---|
| 277 | QLinearGradient(const QPointF &start, const QPointF &finalStop); | 
|---|
| 278 | QLinearGradient(qreal xStart, qreal yStart, qreal xFinalStop, qreal yFinalStop); | 
|---|
| 279 |  | 
|---|
| 280 | QPointF start() const; | 
|---|
| 281 | void setStart(const QPointF &start); | 
|---|
| 282 | inline void setStart(qreal x, qreal y) { setStart(QPointF(x, y)); } | 
|---|
| 283 |  | 
|---|
| 284 | QPointF finalStop() const; | 
|---|
| 285 | void setFinalStop(const QPointF &stop); | 
|---|
| 286 | inline void setFinalStop(qreal x, qreal y) { setFinalStop(QPointF(x, y)); } | 
|---|
| 287 | }; | 
|---|
| 288 |  | 
|---|
| 289 |  | 
|---|
| 290 | class Q_GUI_EXPORT QRadialGradient : public QGradient | 
|---|
| 291 | { | 
|---|
| 292 | public: | 
|---|
| 293 | QRadialGradient(); | 
|---|
| 294 | QRadialGradient(const QPointF ¢er, qreal radius, const QPointF &focalPoint); | 
|---|
| 295 | QRadialGradient(qreal cx, qreal cy, qreal radius, qreal fx, qreal fy); | 
|---|
| 296 |  | 
|---|
| 297 | QRadialGradient(const QPointF ¢er, qreal radius); | 
|---|
| 298 | QRadialGradient(qreal cx, qreal cy, qreal radius); | 
|---|
| 299 |  | 
|---|
| 300 | QPointF center() const; | 
|---|
| 301 | void setCenter(const QPointF ¢er); | 
|---|
| 302 | inline void setCenter(qreal x, qreal y) { setCenter(QPointF(x, y)); } | 
|---|
| 303 |  | 
|---|
| 304 | QPointF focalPoint() const; | 
|---|
| 305 | void setFocalPoint(const QPointF &focalPoint); | 
|---|
| 306 | inline void setFocalPoint(qreal x, qreal y) { setFocalPoint(QPointF(x, y)); } | 
|---|
| 307 |  | 
|---|
| 308 | qreal radius() const; | 
|---|
| 309 | void setRadius(qreal radius); | 
|---|
| 310 | }; | 
|---|
| 311 |  | 
|---|
| 312 |  | 
|---|
| 313 | class Q_GUI_EXPORT QConicalGradient : public QGradient | 
|---|
| 314 | { | 
|---|
| 315 | public: | 
|---|
| 316 | QConicalGradient(); | 
|---|
| 317 | QConicalGradient(const QPointF ¢er, qreal startAngle); | 
|---|
| 318 | QConicalGradient(qreal cx, qreal cy, qreal startAngle); | 
|---|
| 319 |  | 
|---|
| 320 | QPointF center() const; | 
|---|
| 321 | void setCenter(const QPointF ¢er); | 
|---|
| 322 | inline void setCenter(qreal x, qreal y) { setCenter(QPointF(x, y)); } | 
|---|
| 323 |  | 
|---|
| 324 | qreal angle() const; | 
|---|
| 325 | void setAngle(qreal angle); | 
|---|
| 326 | }; | 
|---|
| 327 |  | 
|---|
| 328 | QT_END_NAMESPACE | 
|---|
| 329 |  | 
|---|
| 330 | QT_END_HEADER | 
|---|
| 331 |  | 
|---|
| 332 | #endif // QBRUSH_H | 
|---|