src/gui/painting/qpaintengine.h

Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** Copyright (C) 1992-2006 Trolltech ASA. All rights reserved.
00004 **
00005 ** This file is part of the QtGui module of the Qt Toolkit.
00006 **
00007 ** This file may be used under the terms of the GNU General Public
00008 ** License version 2.0 as published by the Free Software Foundation
00009 ** and appearing in the file LICENSE.GPL included in the packaging of
00010 ** this file.  Please review the following information to ensure GNU
00011 ** General Public Licensing requirements will be met:
00012 ** http://www.trolltech.com/products/qt/opensource.html
00013 **
00014 ** If you are unsure which license is appropriate for your use, please
00015 ** review the following information:
00016 ** http://www.trolltech.com/products/qt/licensing.html or contact the
00017 ** sales department at sales@trolltech.com.
00018 **
00019 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00020 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00021 **
00022 ****************************************************************************/
00023 
00024 #ifndef QPAINTENGINE_H
00025 #define QPAINTENGINE_H
00026 
00027 #include <QtCore/qnamespace.h>
00028 #include <QtCore/qobjectdefs.h>
00029 #include <QtGui/qpainter.h>
00030 
00031 QT_BEGIN_HEADER
00032 
00033 QT_MODULE(Gui)
00034 
00035 class QFontEngine;
00036 class QLineF;
00037 class QPaintDevice;
00038 class QPaintEnginePrivate;
00039 class QPainterPath;
00040 class QPointF;
00041 class QPolygonF;
00042 class QRectF;
00043 struct QGlyphLayout;
00044 class QTextItemInt;
00045 class QPaintEngineState;
00046 
00047 class Q_GUI_EXPORT QTextItem {
00048 public:
00049     enum RenderFlag {
00050         RightToLeft = 0x1,
00051         Overline = 0x10,
00052         Underline = 0x20,
00053         StrikeOut = 0x40,
00054 
00055         Dummy = 0xffffffff
00056     };
00057     Q_DECLARE_FLAGS(RenderFlags, RenderFlag)
00058     qreal descent() const;
00059     qreal ascent() const;
00060     qreal width() const;
00061 
00062     RenderFlags renderFlags() const;
00063     QString text() const;
00064     QFont font() const;
00065 };
00066 Q_DECLARE_TYPEINFO(QTextItem, Q_PRIMITIVE_TYPE);
00067 
00068 
00069 class Q_GUI_EXPORT QPaintEngine
00070 {
00071     Q_DECLARE_PRIVATE(QPaintEngine)
00072 public:
00073     enum PaintEngineFeature {
00074         PrimitiveTransform        = 0x00000001, // Can transform primitives brushes
00075         PatternTransform          = 0x00000002, // Can transform pattern brushes
00076         PixmapTransform           = 0x00000004, // Can transform pixmaps
00077         PatternBrush              = 0x00000008, // Can fill with pixmaps and standard patterns
00078         LinearGradientFill      = 0x00000010, // Can fill gradient areas
00079         RadialGradientFill        = 0x00000020, // Can render radial gradients
00080         ConicalGradientFill       = 0x00000040, // Can render conical gradients
00081   AlphaBlend                = 0x00000080, // Can do source over alpha blend
00082   PorterDuff                = 0x00000100, // Can do general porter duff compositions
00083         PainterPaths              = 0x00000200, // Can fill, outline and clip paths
00084         Antialiasing              = 0x00000400, // Can antialias lines
00085         BrushStroke               = 0x00000800, // Can render brush based pens
00086         ConstantOpacity           = 0x00001000, // Can render at constant opacity
00087         MaskedBrush               = 0x00002000, // Can fill with textures that has an alpha channel or mask
00088         PaintOutsidePaintEvent    = 0x20000000, // Engine is capable of painting outside paint events
00089         /*                          0x10000000, // Used for emulating
00090                                     QGradient::StretchToDevice,
00091                                     defined in qpainter.cpp
00092 
00093                                     0x40000000, // Used internally for emulating opaque backgrounds
00094         */
00095 
00096         AllFeatures               = 0xffffffff  // For convenience
00097     };
00098     Q_DECLARE_FLAGS(PaintEngineFeatures, PaintEngineFeature)
00099 
00100     enum DirtyFlag {
00101         DirtyPen                = 0x0001,
00102         DirtyBrush              = 0x0002,
00103         DirtyBrushOrigin        = 0x0004,
00104         DirtyFont               = 0x0008,
00105         DirtyBackground         = 0x0010,
00106         DirtyBackgroundMode     = 0x0020,
00107         DirtyTransform          = 0x0040,
00108         DirtyClipRegion         = 0x0080,
00109         DirtyClipPath           = 0x0100,
00110         DirtyHints              = 0x0200,
00111         DirtyCompositionMode    = 0x0400,
00112         DirtyClipEnabled        = 0x0800,
00113         DirtyOpacity            = 0x1000,
00114 
00115         AllDirty                = 0xffff
00116     };
00117     Q_DECLARE_FLAGS(DirtyFlags, DirtyFlag)
00118 
00119     enum PolygonDrawMode {
00120         OddEvenMode,
00121         WindingMode,
00122         ConvexMode,
00123         PolylineMode
00124     };
00125 
00126     explicit QPaintEngine(PaintEngineFeatures features=0);
00127     virtual ~QPaintEngine();
00128 
00129     bool isActive() const { return active; }
00130     void setActive(bool newState) { active = newState; }
00131 
00132     virtual bool begin(QPaintDevice *pdev) = 0;
00133     virtual bool end() = 0;
00134 
00135     virtual void updateState(const QPaintEngineState &state) = 0;
00136 
00137     virtual void drawRects(const QRect *rects, int rectCount);
00138     virtual void drawRects(const QRectF *rects, int rectCount);
00139 
00140     virtual void drawLines(const QLine *lines, int lineCount);
00141     virtual void drawLines(const QLineF *lines, int lineCount);
00142 
00143     virtual void drawEllipse(const QRectF &r);
00144     virtual void drawEllipse(const QRect &r);
00145 
00146     virtual void drawPath(const QPainterPath &path);
00147 
00148     virtual void drawPoints(const QPointF *points, int pointCount);
00149     virtual void drawPoints(const QPoint *points, int pointCount);
00150 
00151     virtual void drawPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode);
00152     virtual void drawPolygon(const QPoint *points, int pointCount, PolygonDrawMode mode);
00153 
00154     virtual void drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr) = 0;
00155     virtual void drawTextItem(const QPointF &p, const QTextItem &textItem);
00156     virtual void drawTiledPixmap(const QRectF &r, const QPixmap &pixmap, const QPointF &s);
00157     virtual void drawImage(const QRectF &r, const QImage &pm, const QRectF &sr,
00158                            Qt::ImageConversionFlags flags = Qt::AutoColor);
00159 
00160     void setPaintDevice(QPaintDevice *device);
00161     QPaintDevice *paintDevice() const;
00162 
00163     void setSystemClip(const QRegion &baseClip);
00164     QRegion systemClip() const;
00165 
00166     void setSystemRect(const QRect &rect);
00167     QRect systemRect() const;
00168 
00169 #ifdef Q_WS_WIN
00170     virtual HDC getDC() const;
00171     virtual void releaseDC(HDC hdc) const;
00172 #endif
00173 
00174     virtual QPoint coordinateOffset() const;
00175 
00176     enum Type {
00177         X11,
00178         Windows,
00179         QuickDraw, CoreGraphics, MacPrinter,
00180         QWindowSystem,
00181         PostScript,
00182         OpenGL,
00183         Picture,
00184         SVG,
00185         Raster,
00186 
00187         User = 50,    // first user type id
00188         MaxUser = 100 // last user type id
00189     };
00190     virtual Type type() const = 0;
00191 
00192     inline void fix_neg_rect(int *x, int *y, int *w, int *h);
00193 
00194     inline bool testDirty(DirtyFlags df);
00195     inline void setDirty(DirtyFlags df);
00196     inline void clearDirty(DirtyFlags df);
00197 
00198     bool hasFeature(PaintEngineFeatures feature) const { return (gccaps & feature) != 0; }
00199 
00200     QPainter *painter() const;
00201 
00202     inline void syncState() { Q_ASSERT(state); updateState(*state); }
00203 
00204 protected:
00205     QPaintEngine(QPaintEnginePrivate &data, PaintEngineFeatures devcaps=0);
00206 
00207     QPaintEngineState *state;
00208     PaintEngineFeatures gccaps;
00209 
00210     uint active : 1;
00211     uint selfDestruct : 1;
00212 
00213     QPaintEnginePrivate *d_ptr;
00214 
00215 private:
00216     void setAutoDestruct(bool autoDestr) { selfDestruct = autoDestr; }
00217     bool autoDestruct() const { return selfDestruct; }
00218     Q_DISABLE_COPY(QPaintEngine)
00219 
00220     friend class QFontEngineBox;
00221     friend class QFontEngineMac;
00222     friend class QFontEngineWin;
00223 #ifndef QT_NO_FREETYPE
00224     friend class QFontEngineFT;
00225 #endif
00226 #ifndef QT_NO_QWS_QPF
00227     friend class QFontEngineQPF;
00228 #endif
00229     friend class QPSPrintEngine;
00230     friend class QMacPrintEngine;
00231     friend class QMacPrintEnginePrivate;
00232 #ifdef Q_WS_QWS
00233     friend class QtopiaPrintEngine;
00234     friend class QtopiaPrintEnginePrivate;
00235 #endif
00236     friend class QPainter;
00237     friend class QPainterPrivate;
00238     friend class QWidget;
00239     friend class QWin32PaintEngine;
00240     friend class QWin32PaintEnginePrivate;
00241     friend class QMacCGContext;
00242 };
00243 
00244 
00245 class Q_GUI_EXPORT QPaintEngineState
00246 {
00247 public:
00248     QPaintEngine::DirtyFlags state() const { return dirtyFlags; }
00249 
00250     QPen pen() const;
00251     QBrush brush() const;
00252     QPointF brushOrigin() const;
00253     QBrush backgroundBrush() const;
00254     Qt::BGMode backgroundMode() const;
00255     QFont font() const;
00256     QMatrix matrix() const;
00257 
00258     Qt::ClipOperation clipOperation() const;
00259     QRegion clipRegion() const;
00260     QPainterPath clipPath() const;
00261     bool isClipEnabled() const;
00262 
00263     QPainter::RenderHints renderHints() const;
00264     QPainter::CompositionMode compositionMode() const;
00265     qreal opacity() const;
00266 
00267     QPainter *painter() const;
00268 
00269 protected:
00270     friend class QPaintEngine;
00271     friend class QPainter;
00272     friend class QPainterPrivate;
00273 
00274     QPaintEngine::DirtyFlags dirtyFlags;
00275 };
00276 
00277 //
00278 // inline functions
00279 //
00280 
00281 inline void QPaintEngine::fix_neg_rect(int *x, int *y, int *w, int *h)
00282 {
00283     if (*w < 0) {
00284         *w = -*w;
00285         *x -= *w - 1;
00286     }
00287     if (*h < 0) {
00288         *h = -*h;
00289         *y -= *h - 1;
00290     }
00291 }
00292 
00293 inline bool QPaintEngine::testDirty(DirtyFlags df) {
00294     Q_ASSERT(state);
00295     return ((state->dirtyFlags & df) != 0);
00296 }
00297 
00298 inline void QPaintEngine::setDirty(DirtyFlags df) {
00299     Q_ASSERT(state);
00300     state->dirtyFlags |= df;
00301 }
00302 
00303 inline void QPaintEngine::clearDirty(DirtyFlags df)
00304 {
00305     Q_ASSERT(state);
00306     state->dirtyFlags &= ~static_cast<uint>(df);
00307 }
00308 
00309 Q_DECLARE_OPERATORS_FOR_FLAGS(QTextItem::RenderFlags)
00310 Q_DECLARE_OPERATORS_FOR_FLAGS(QPaintEngine::PaintEngineFeatures)
00311 Q_DECLARE_OPERATORS_FOR_FLAGS(QPaintEngine::DirtyFlags)
00312 
00313 QT_END_HEADER
00314 
00315 #endif // QPAINTENGINE_H

Generated on Thu Mar 15 11:55:25 2007 for Qt 4.2 User's Guide by  doxygen 1.5.1