- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files
- Directories
- Examples

- File List
- File Members

# qbrush.h

Go to the documentation of this file.

    00001 /****************************************************************************
    00002 **
    00003 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
    00004 ** All rights reserved.
    00005 ** Contact: Nokia Corporation (qt-info@nokia.com)
    00006 **
    00007 ** This file is part of the QtGui module of the Qt Toolkit.
    00008 **
    00009 ** $QT_BEGIN_LICENSE:LGPL$
    00010 ** Commercial Usage
    00011 ** Licensees holding valid Qt Commercial licenses may use this file in
    00012 ** accordance with the Qt Commercial License Agreement provided with the
    00013 ** Software or, alternatively, in accordance with the terms contained in
    00014 ** a written agreement between you and Nokia.
    00015 **
    00016 ** GNU Lesser General Public License Usage
    00017 ** Alternatively, this file may be used under the terms of the GNU Lesser
    00018 ** General Public License version 2.1 as published by the Free Software
    00019 ** Foundation and appearing in the file LICENSE.LGPL included in the
    00020 ** packaging of this file.  Please review the following information to
    00021 ** ensure the GNU Lesser General Public License version 2.1 requirements
    00022 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    00023 **
    00024 ** In addition, as a special exception, Nokia gives you certain additional
    00025 ** rights.  These rights are described in the Nokia Qt LGPL Exception
    00026 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this module.
    00027 **
    00028 ** GNU General Public License Usage
    00029 ** Alternatively, this file may be used under the terms of the GNU
    00030 ** General Public License version 3.0 as published by the Free Software
    00031 ** Foundation and appearing in the file LICENSE.GPL included in the
    00032 ** packaging of this file.  Please review the following information to
    00033 ** ensure the GNU General Public License version 3.0 requirements will be
    00034 ** met: http://www.gnu.org/copyleft/gpl.html.
    00035 **
    00036 ** If you have questions regarding the use of this file, please contact
    00037 ** Nokia at qt-info@nokia.com.
    00038 ** $QT_END_LICENSE$
    00039 **
    00040 ****************************************************************************/
    00041
    00042 #ifndef QBRUSH_H
    00043 #define QBRUSH_H
    00044
    00045 #include <QtCore/qpair.h>
    00046 #include <QtCore/qpoint.h>
    00047 #include <QtCore/qvector.h>
    00048 #include <QtCore/qscopedpointer.h>
    00049 #include <QtGui/qcolor.h>
    00050 #include <QtGui/qmatrix.h>
    00051 #include <QtGui/qtransform.h>
    00052 #include <QtGui/qimage.h>
    00053 #include <QtGui/qpixmap.h>
    00054
    00055 #if defined(Q_OS_VXWORKS)
    00056 #  if defined(m_data)
    00057 #    undef m_data
    00058 #  endif
    00059 #  if defined(m_type)
    00060 #    undef m_type
    00061 #  endif
    00062 #endif
    00063
    00064 QT_BEGIN_HEADER
    00065
    00066 QT_BEGIN_NAMESPACE
    00067
    00068 QT_MODULE(Gui)
    00069
    00070 struct QBrushData;
    00071 class QPixmap;
    00072 class QGradient;
    00073 class QVariant;
    00074 struct QBrushDataPointerDeleter;
    00075
    00076 class Q_GUI_EXPORT QBrush
    00077 {
    00078 public:
    00079     QBrush();
    00080     QBrush(Qt::BrushStyle bs);
    00081     QBrush(const QColor &color, Qt::BrushStyle bs=Qt::SolidPattern);
    00082     QBrush(Qt::GlobalColor color, Qt::BrushStyle bs=Qt::SolidPattern);
    00083
    00084     QBrush(const QColor &color, const QPixmap &pixmap);
    00085     QBrush(Qt::GlobalColor color, const QPixmap &pixmap);
    00086     QBrush(const QPixmap &pixmap);
    00087     QBrush(const QImage &image);
    00088
    00089     QBrush(const QBrush &brush);
    00090
    00091     QBrush(const QGradient &gradient);
    00092
    00093     ~QBrush();
    00094     QBrush &operator=(const QBrush &brush);
    00095     operator QVariant() const;
    00096
    00097     inline Qt::BrushStyle style() const;
    00098     void setStyle(Qt::BrushStyle);
    00099
    00100     inline const QMatrix &matrix() const;
    00101     void setMatrix(const QMatrix &mat);
    00102
    00103     inline QTransform transform() const;
    00104     void setTransform(const QTransform &);
    00105
    00106     QPixmap texture() const;
    00107     void setTexture(const QPixmap &pixmap);
    00108
    00109     QImage textureImage() const;
    00110     void setTextureImage(const QImage &image);
    00111
    00112     inline const QColor &color() const;
    00113     void setColor(const QColor &color);
    00114     inline void setColor(Qt::GlobalColor color);
    00115
    00116     const QGradient *gradient() const;
    00117
    00118     bool isOpaque() const;
    00119
    00120     bool operator==(const QBrush &b) const;
    00121     inline bool operator!=(const QBrush &b) const { return !(operator==(b)); }
    00122
    00123 #ifdef QT3_SUPPORT
    00124     inline QT3_SUPPORT operator const QColor&() const;
    00125     QT3_SUPPORT QPixmap *pixmap() const;
    00126     inline QT3_SUPPORT void setPixmap(const QPixmap &pixmap) { setTexture(pixmap); }
    00127 #endif
    00128
    00129 private:
    00130 #if defined(Q_WS_X11)
    00131     friend class QX11PaintEngine;
    00132 #endif
    00133     friend class QRasterPaintEngine;
    00134     friend class QRasterPaintEnginePrivate;
    00135     friend struct QSpanData;
    00136     friend class QPainter;
    00137     friend bool Q_GUI_EXPORT qHasPixmapTexture(const QBrush& brush);
    00138     void detach(Qt::BrushStyle newStyle);
    00139     void init(const QColor &color, Qt::BrushStyle bs);
    00140     QScopedPointer<QBrushData, QBrushDataPointerDeleter> d;
    00141     void cleanUp(QBrushData *x);
    00142
    00143 public:
    00144     inline bool isDetached() const;
    00145     typedef QScopedPointer<QBrushData, QBrushDataPointerDeleter> DataPtr;
    00146     inline DataPtr &data_ptr() { return d; }
    00147 };
    00148
    00149 inline void QBrush::setColor(Qt::GlobalColor acolor)
    00150 { setColor(QColor(acolor)); }
    00151
    00152 Q_DECLARE_TYPEINFO(QBrush, Q_MOVABLE_TYPE);
    00153 Q_DECLARE_SHARED(QBrush)
    00154
    00155 /*****************************************************************************
    00156   QBrush stream functions
    00157  *****************************************************************************/
    00158
    00159 #ifndef QT_NO_DATASTREAM
    00160 Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QBrush &);
    00161 Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QBrush &);
    00162 #endif
    00163
    00164 #ifndef QT_NO_DEBUG_STREAM
    00165 Q_GUI_EXPORT QDebug operator<<(QDebug, const QBrush &);
    00166 #endif
    00167
    00168 struct QBrushData
    00169 {
    00170     QAtomicInt ref;
    00171     Qt::BrushStyle style;
    00172     QColor color;
    00173     QTransform transform;
    00174 };
    00175
    00176 inline Qt::BrushStyle QBrush::style() const { return d->style; }
    00177 inline const QColor &QBrush::color() const { return d->color; }
    00178 inline const QMatrix &QBrush::matrix() const { return d->transform.toAffine(); }
    00179 inline QTransform QBrush::transform() const { return d->transform; }
    00180 inline bool QBrush::isDetached() const { return d->ref == 1; }
    00181
    00182 #ifdef QT3_SUPPORT
    00183 inline QBrush::operator const QColor&() const { return d->color; }
    00184 #endif
    00185
    00186
    00187 /*******************************************************************************
    00188  * QGradients
    00189  */
    00190 class QGradientPrivate;
    00191
    00192 typedef QPair<qreal, QColor> QGradientStop;
    00193 typedef QVector<QGradientStop> QGradientStops;
    00194
    00195 class Q_GUI_EXPORT QGradient
    00196 {
    00197     Q_GADGET
    00198     Q_ENUMS(Type Spread CoordinateMode)
    00199 public:
    00200     enum Type {
    00201         LinearGradient,
    00202         RadialGradient,
    00203         ConicalGradient,
    00204         NoGradient
    00205     };
    00206
    00207     enum Spread {
    00208         PadSpread,
    00209         ReflectSpread,
    00210         RepeatSpread
    00211     };
    00212
    00213     enum CoordinateMode {
    00214         LogicalMode,
    00215         StretchToDeviceMode,
    00216         ObjectBoundingMode
    00217     };
    00218
    00219     enum InterpolationMode {
    00220         ColorInterpolation,
    00221         ComponentInterpolation
    00222     };
    00223
    00224     QGradient();
    00225
    00226     Type type() const { return m_type; }
    00227
    00228     inline void setSpread(Spread spread);
    00229     Spread spread() const { return m_spread; }
    00230
    00231     void setColorAt(qreal pos, const QColor &color);
    00232
    00233     void setStops(const QGradientStops &stops);
    00234     QGradientStops stops() const;
    00235
    00236     CoordinateMode coordinateMode() const;
    00237     void setCoordinateMode(CoordinateMode mode);
    00238
    00239     InterpolationMode interpolationMode() const;
    00240     void setInterpolationMode(InterpolationMode mode);
    00241
    00242     bool operator==(const QGradient &gradient) const;
    00243     inline bool operator!=(const QGradient &other) const
    00244     { return !operator==(other); }
    00245
    00246     bool operator==(const QGradient &gradient); // ### Qt 5: remove
    00247
    00248 private:
    00249     friend class QLinearGradient;
    00250     friend class QRadialGradient;
    00251     friend class QConicalGradient;
    00252
    00253     Type m_type;
    00254     Spread m_spread;
    00255     QGradientStops m_stops;
    00256     union {
    00257         struct {
    00258             qreal x1, y1, x2, y2;
    00259         } linear;
    00260         struct {
    00261             qreal cx, cy, fx, fy, radius;
    00262         } radial;
    00263         struct {
    00264             qreal cx, cy, angle;
    00265         } conical;
    00266     } m_data;
    00267     void *dummy;
    00268 };
    00269
    00270 inline void QGradient::setSpread(Spread aspread)
    00271 { m_spread = aspread; }
    00272
    00273 class Q_GUI_EXPORT QLinearGradient : public QGradient
    00274 {
    00275 public:
    00276     QLinearGradient();
    00277     QLinearGradient(const QPointF &start, const QPointF &finalStop);
    00278     QLinearGradient(qreal xStart, qreal yStart, qreal xFinalStop, qreal yFinalStop);
    00279
    00280     QPointF start() const;
    00281     void setStart(const QPointF &start);
    00282     inline void setStart(qreal x, qreal y) { setStart(QPointF(x, y)); }
    00283
    00284     QPointF finalStop() const;
    00285     void setFinalStop(const QPointF &stop);
    00286     inline void setFinalStop(qreal x, qreal y) { setFinalStop(QPointF(x, y)); }
    00287 };
    00288
    00289
    00290 class Q_GUI_EXPORT QRadialGradient : public QGradient
    00291 {
    00292 public:
    00293     QRadialGradient();
    00294     QRadialGradient(const QPointF &center, qreal radius, const QPointF &focalPoint);
    00295     QRadialGradient(qreal cx, qreal cy, qreal radius, qreal fx, qreal fy);
    00296
    00297     QRadialGradient(const QPointF &center, qreal radius);
    00298     QRadialGradient(qreal cx, qreal cy, qreal radius);
    00299
    00300     QPointF center() const;
    00301     void setCenter(const QPointF &center);
    00302     inline void setCenter(qreal x, qreal y) { setCenter(QPointF(x, y)); }
    00303
    00304     QPointF focalPoint() const;
    00305     void setFocalPoint(const QPointF &focalPoint);
    00306     inline void setFocalPoint(qreal x, qreal y) { setFocalPoint(QPointF(x, y)); }
    00307
    00308     qreal radius() const;
    00309     void setRadius(qreal radius);
    00310 };
    00311
    00312
    00313 class Q_GUI_EXPORT QConicalGradient : public QGradient
    00314 {
    00315 public:
    00316     QConicalGradient();
    00317     QConicalGradient(const QPointF &center, qreal startAngle);
    00318     QConicalGradient(qreal cx, qreal cy, qreal startAngle);
    00319
    00320     QPointF center() const;
    00321     void setCenter(const QPointF &center);
    00322     inline void setCenter(qreal x, qreal y) { setCenter(QPointF(x, y)); }
    00323
    00324     qreal angle() const;
    00325     void setAngle(qreal angle);
    00326 };
    00327
    00328 QT_END_NAMESPACE
    00329
    00330 QT_END_HEADER
    00331
    00332 #endif // QBRUSH_H