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