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

- File List
- File Members

# qpaintengine.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 QPAINTENGINE_H
    00043 #define QPAINTENGINE_H
    00044
    00045 #include <QtCore/qnamespace.h>
    00046 #include <QtCore/qobjectdefs.h>
    00047 #include <QtCore/qscopedpointer.h>
    00048 #include <QtGui/qpainter.h>
    00049
    00050 QT_BEGIN_HEADER
    00051
    00052 QT_BEGIN_NAMESPACE
    00053
    00054 QT_MODULE(Gui)
    00055
    00056 class QFontEngine;
    00057 class QLineF;
    00058 class QPaintDevice;
    00059 class QPaintEnginePrivate;
    00060 class QPainterPath;
    00061 class QPointF;
    00062 class QPolygonF;
    00063 class QRectF;
    00064 struct QGlyphLayout;
    00065 class QTextItemInt;
    00066 class QPaintEngineState;
    00067
    00068 class Q_GUI_EXPORT QTextItem {
    00069 public:
    00070     enum RenderFlag {
    00071         RightToLeft = 0x1,
    00072         Overline = 0x10,
    00073         Underline = 0x20,
    00074         StrikeOut = 0x40,
    00075
    00076         Dummy = 0xffffffff
    00077     };
    00078     Q_DECLARE_FLAGS(RenderFlags, RenderFlag)
    00079     qreal descent() const;
    00080     qreal ascent() const;
    00081     qreal width() const;
    00082
    00083     RenderFlags renderFlags() const;
    00084     QString text() const;
    00085     QFont font() const;
    00086 };
    00087 Q_DECLARE_TYPEINFO(QTextItem, Q_PRIMITIVE_TYPE);
    00088
    00089
    00090 class Q_GUI_EXPORT QPaintEngine
    00091 {
    00092     Q_DECLARE_PRIVATE(QPaintEngine)
    00093 public:
    00094     enum PaintEngineFeature {
    00095         PrimitiveTransform          = 0x00000001, // Can transform primitives brushes
    00096         PatternTransform            = 0x00000002, // Can transform pattern brushes
    00097         PixmapTransform             = 0x00000004, // Can transform pixmaps
    00098         PatternBrush                = 0x00000008, // Can fill with pixmaps and standard patterns
    00099         LinearGradientFill          = 0x00000010, // Can fill gradient areas
    00100         RadialGradientFill          = 0x00000020, // Can render radial gradients
    00101         ConicalGradientFill         = 0x00000040, // Can render conical gradients
    00102         AlphaBlend                  = 0x00000080, // Can do source over alpha blend
    00103         PorterDuff                  = 0x00000100, // Can do general porter duff compositions
    00104         PainterPaths                = 0x00000200, // Can fill, outline and clip paths
    00105         Antialiasing                = 0x00000400, // Can antialias lines
    00106         BrushStroke                 = 0x00000800, // Can render brush based pens
    00107         ConstantOpacity             = 0x00001000, // Can render at constant opacity
    00108         MaskedBrush                 = 0x00002000, // Can fill with textures that has an alpha channel or mask
    00109         PerspectiveTransform        = 0x00004000, // Can do perspective transformations
    00110         BlendModes                  = 0x00008000, // Can do extended Porter&Duff composition
    00111         ObjectBoundingModeGradients = 0x00010000, // Can do object bounding mode gradients
    00112         RasterOpModes               = 0x00020000, // Can do logical raster operations
    00113         PaintOutsidePaintEvent      = 0x20000000, // Engine is capable of painting outside paint events
    00114         /*                          0x10000000, // Used for emulating
    00115                                     QGradient::StretchToDevice,
    00116                                     defined in qpainter.cpp
    00117
    00118                                     0x40000000, // Used internally for emulating opaque backgrounds
    00119         */
    00120
    00121         AllFeatures               = 0xffffffff  // For convenience
    00122     };
    00123     Q_DECLARE_FLAGS(PaintEngineFeatures, PaintEngineFeature)
    00124
    00125     enum DirtyFlag {
    00126         DirtyPen                = 0x0001,
    00127         DirtyBrush              = 0x0002,
    00128         DirtyBrushOrigin        = 0x0004,
    00129         DirtyFont               = 0x0008,
    00130         DirtyBackground         = 0x0010,
    00131         DirtyBackgroundMode     = 0x0020,
    00132         DirtyTransform          = 0x0040,
    00133         DirtyClipRegion         = 0x0080,
    00134         DirtyClipPath           = 0x0100,
    00135         DirtyHints              = 0x0200,
    00136         DirtyCompositionMode    = 0x0400,
    00137         DirtyClipEnabled        = 0x0800,
    00138         DirtyOpacity            = 0x1000,
    00139
    00140         AllDirty                = 0xffff
    00141     };
    00142     Q_DECLARE_FLAGS(DirtyFlags, DirtyFlag)
    00143
    00144     enum PolygonDrawMode {
    00145         OddEvenMode,
    00146         WindingMode,
    00147         ConvexMode,
    00148         PolylineMode
    00149     };
    00150
    00151     explicit QPaintEngine(PaintEngineFeatures features=0);
    00152     virtual ~QPaintEngine();
    00153
    00154     bool isActive() const { return active; }
    00155     void setActive(bool newState) { active = newState; }
    00156
    00157     virtual bool begin(QPaintDevice *pdev) = 0;
    00158     virtual bool end() = 0;
    00159
    00160     virtual void updateState(const QPaintEngineState &state) = 0;
    00161
    00162     virtual void drawRects(const QRect *rects, int rectCount);
    00163     virtual void drawRects(const QRectF *rects, int rectCount);
    00164
    00165     virtual void drawLines(const QLine *lines, int lineCount);
    00166     virtual void drawLines(const QLineF *lines, int lineCount);
    00167
    00168     virtual void drawEllipse(const QRectF &r);
    00169     virtual void drawEllipse(const QRect &r);
    00170
    00171     virtual void drawPath(const QPainterPath &path);
    00172
    00173     virtual void drawPoints(const QPointF *points, int pointCount);
    00174     virtual void drawPoints(const QPoint *points, int pointCount);
    00175
    00176     virtual void drawPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode);
    00177     virtual void drawPolygon(const QPoint *points, int pointCount, PolygonDrawMode mode);
    00178
    00179     virtual void drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr) = 0;
    00180     virtual void drawTextItem(const QPointF &p, const QTextItem &textItem);
    00181     virtual void drawTiledPixmap(const QRectF &r, const QPixmap &pixmap, const QPointF &s);
    00182     virtual void drawImage(const QRectF &r, const QImage &pm, const QRectF &sr,
    00183                            Qt::ImageConversionFlags flags = Qt::AutoColor);
    00184
    00185     void setPaintDevice(QPaintDevice *device);
    00186     QPaintDevice *paintDevice() const;
    00187
    00188     void setSystemClip(const QRegion &baseClip);
    00189     QRegion systemClip() const;
    00190
    00191     void setSystemRect(const QRect &rect);
    00192     QRect systemRect() const;
    00193
    00194 #ifdef Q_WS_WIN
    00195     virtual HDC getDC() const;
    00196     virtual void releaseDC(HDC hdc) const;
    00197 #endif
    00198
    00199     virtual QPoint coordinateOffset() const;
    00200
    00201     enum Type {
    00202         X11,
    00203         Windows,
    00204         QuickDraw, CoreGraphics, MacPrinter,
    00205         QWindowSystem,
    00206         PostScript,
    00207         OpenGL,
    00208         Picture,
    00209         SVG,
    00210         Raster,
    00211         Direct3D,
    00212         Pdf,
    00213         OpenVG,
    00214         OpenGL2,
    00215         PaintBuffer,
    00216
    00217         User = 50,    // first user type id
    00218         MaxUser = 100 // last user type id
    00219     };
    00220     virtual Type type() const = 0;
    00221
    00222     inline void fix_neg_rect(int *x, int *y, int *w, int *h);
    00223
    00224     inline bool testDirty(DirtyFlags df);
    00225     inline void setDirty(DirtyFlags df);
    00226     inline void clearDirty(DirtyFlags df);
    00227
    00228     bool hasFeature(PaintEngineFeatures feature) const { return (gccaps & feature) != 0; }
    00229
    00230     QPainter *painter() const;
    00231
    00232     void syncState();
    00233     inline bool isExtended() const { return extended; }
    00234
    00235 protected:
    00236     QPaintEngine(QPaintEnginePrivate &data, PaintEngineFeatures devcaps=0);
    00237
    00238     QPaintEngineState *state;
    00239     PaintEngineFeatures gccaps;
    00240
    00241     uint active : 1;
    00242     uint selfDestruct : 1;
    00243     uint extended : 1;
    00244
    00245     QScopedPointer<QPaintEnginePrivate> d_ptr;
    00246
    00247 private:
    00248     void setAutoDestruct(bool autoDestr) { selfDestruct = autoDestr; }
    00249     bool autoDestruct() const { return selfDestruct; }
    00250     Q_DISABLE_COPY(QPaintEngine)
    00251
    00252     friend class QPainterReplayer;
    00253     friend class QFontEngineBox;
    00254     friend class QFontEngineMac;
    00255     friend class QFontEngineWin;
    00256 #ifndef QT_NO_FREETYPE
    00257     friend class QFontEngineFT;
    00258 #endif
    00259 #ifndef QT_NO_QWS_QPF
    00260     friend class QFontEngineQPF1;
    00261 #endif
    00262 #ifndef QT_NO_QWS_QPF2
    00263     friend class QFontEngineQPF;
    00264 #endif
    00265     friend class QPSPrintEngine;
    00266     friend class QMacPrintEngine;
    00267     friend class QMacPrintEnginePrivate;
    00268 #ifdef Q_WS_QWS
    00269     friend class QtopiaPrintEngine;
    00270     friend class QtopiaPrintEnginePrivate;
    00271     friend class QProxyFontEngine;
    00272 #endif
    00273     friend class QPainter;
    00274     friend class QPainterPrivate;
    00275     friend class QWidget;
    00276     friend class QWidgetPrivate;
    00277     friend class QWin32PaintEngine;
    00278     friend class QWin32PaintEnginePrivate;
    00279     friend class QMacCGContext;
    00280     friend class QPreviewPaintEngine;
    00281     friend class QX11GLPixmapData;
    00282 };
    00283
    00284
    00285 class Q_GUI_EXPORT QPaintEngineState
    00286 {
    00287 public:
    00288     QPaintEngine::DirtyFlags state() const { return dirtyFlags; }
    00289
    00290     QPen pen() const;
    00291     QBrush brush() const;
    00292     QPointF brushOrigin() const;
    00293     QBrush backgroundBrush() const;
    00294     Qt::BGMode backgroundMode() const;
    00295     QFont font() const;
    00296     QMatrix matrix() const;
    00297     QTransform transform() const;
    00298
    00299     Qt::ClipOperation clipOperation() const;
    00300     QRegion clipRegion() const;
    00301     QPainterPath clipPath() const;
    00302     bool isClipEnabled() const;
    00303
    00304     QPainter::RenderHints renderHints() const;
    00305     QPainter::CompositionMode compositionMode() const;
    00306     qreal opacity() const;
    00307
    00308     QPainter *painter() const;
    00309
    00310     bool brushNeedsResolving() const;
    00311     bool penNeedsResolving() const;
    00312
    00313 protected:
    00314     friend class QPaintEngine;
    00315     friend class QRasterPaintEngine;
    00316     friend class QWidget;
    00317     friend class QPainter;
    00318     friend class QPainterPrivate;
    00319     friend class QMacPrintEnginePrivate;
    00320
    00321     QPaintEngine::DirtyFlags dirtyFlags;
    00322 };
    00323
    00324 //
    00325 // inline functions
    00326 //
    00327
    00328 inline void QPaintEngine::fix_neg_rect(int *x, int *y, int *w, int *h)
    00329 {
    00330     if (*w < 0) {
    00331         *w = -*w;
    00332         *x -= *w - 1;
    00333     }
    00334     if (*h < 0) {
    00335         *h = -*h;
    00336         *y -= *h - 1;
    00337     }
    00338 }
    00339
    00340 inline bool QPaintEngine::testDirty(DirtyFlags df) {
    00341     Q_ASSERT(state);
    00342     return ((state->dirtyFlags & df) != 0);
    00343 }
    00344
    00345 inline void QPaintEngine::setDirty(DirtyFlags df) {
    00346     Q_ASSERT(state);
    00347     state->dirtyFlags |= df;
    00348 }
    00349
    00350 inline void QPaintEngine::clearDirty(DirtyFlags df)
    00351 {
    00352     Q_ASSERT(state);
    00353     state->dirtyFlags &= ~static_cast<uint>(df);
    00354 }
    00355
    00356 Q_DECLARE_OPERATORS_FOR_FLAGS(QTextItem::RenderFlags)
    00357 Q_DECLARE_OPERATORS_FOR_FLAGS(QPaintEngine::PaintEngineFeatures)
    00358 Q_DECLARE_OPERATORS_FOR_FLAGS(QPaintEngine::DirtyFlags)
    00359
    00360 QT_END_NAMESPACE
    00361
    00362 QT_END_HEADER
    00363
    00364 #endif // QPAINTENGINE_H