1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtGui module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #ifndef QPAINTENGINE_H
43 #define QPAINTENGINE_H
45 #include <QtCore/qnamespace.h>
46 #include <QtCore/qobjectdefs.h>
47 #include <QtCore/qscopedpointer.h>
48 #include <QtGui/qpainter.h>
58 class QPaintEnginePrivate;
65 class QPaintEngineState;
67 class Q_GUI_EXPORT QTextItem {
77 Q_DECLARE_FLAGS(RenderFlags, RenderFlag)
78 qreal descent() const;
82 RenderFlags renderFlags() const;
86 Q_DECLARE_TYPEINFO(QTextItem, Q_PRIMITIVE_TYPE);
89 class Q_GUI_EXPORT QPaintEngine
91 Q_DECLARE_PRIVATE(QPaintEngine)
93 enum PaintEngineFeature {
94 PrimitiveTransform = 0x00000001, // Can transform primitives brushes
95 PatternTransform = 0x00000002, // Can transform pattern brushes
96 PixmapTransform = 0x00000004, // Can transform pixmaps
97 PatternBrush = 0x00000008, // Can fill with pixmaps and standard patterns
98 LinearGradientFill = 0x00000010, // Can fill gradient areas
99 RadialGradientFill = 0x00000020, // Can render radial gradients
100 ConicalGradientFill = 0x00000040, // Can render conical gradients
101 AlphaBlend = 0x00000080, // Can do source over alpha blend
102 PorterDuff = 0x00000100, // Can do general porter duff compositions
103 PainterPaths = 0x00000200, // Can fill, outline and clip paths
104 Antialiasing = 0x00000400, // Can antialias lines
105 BrushStroke = 0x00000800, // Can render brush based pens
106 ConstantOpacity = 0x00001000, // Can render at constant opacity
107 MaskedBrush = 0x00002000, // Can fill with textures that has an alpha channel or mask
108 PerspectiveTransform = 0x00004000, // Can do perspective transformations
109 BlendModes = 0x00008000, // Can do extended Porter&Duff composition
110 ObjectBoundingModeGradients = 0x00010000, // Can do object bounding mode gradients
111 RasterOpModes = 0x00020000, // Can do logical raster operations
112 PaintOutsidePaintEvent = 0x20000000, // Engine is capable of painting outside paint events
113 /* 0x10000000, // Used for emulating
114 QGradient::StretchToDevice,
115 defined in qpainter.cpp
117 0x40000000, // Used internally for emulating opaque backgrounds
120 AllFeatures = 0xffffffff // For convenience
122 Q_DECLARE_FLAGS(PaintEngineFeatures, PaintEngineFeature)
127 DirtyBrushOrigin = 0x0004,
129 DirtyBackground = 0x0010,
130 DirtyBackgroundMode = 0x0020,
131 DirtyTransform = 0x0040,
132 DirtyClipRegion = 0x0080,
133 DirtyClipPath = 0x0100,
135 DirtyCompositionMode = 0x0400,
136 DirtyClipEnabled = 0x0800,
137 DirtyOpacity = 0x1000,
141 Q_DECLARE_FLAGS(DirtyFlags, DirtyFlag)
143 enum PolygonDrawMode {
150 explicit QPaintEngine(PaintEngineFeatures features=0);
151 virtual ~QPaintEngine();
153 bool isActive() const { return active; }
154 void setActive(bool newState) { active = newState; }
156 virtual bool begin(QPaintDevice *pdev) = 0;
157 virtual bool end() = 0;
159 virtual void updateState(const QPaintEngineState &state) = 0;
161 virtual void drawRects(const QRect *rects, int rectCount);
162 virtual void drawRects(const QRectF *rects, int rectCount);
164 virtual void drawLines(const QLine *lines, int lineCount);
165 virtual void drawLines(const QLineF *lines, int lineCount);
167 virtual void drawEllipse(const QRectF &r);
168 virtual void drawEllipse(const QRect &r);
170 virtual void drawPath(const QPainterPath &path);
172 virtual void drawPoints(const QPointF *points, int pointCount);
173 virtual void drawPoints(const QPoint *points, int pointCount);
175 virtual void drawPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode);
176 virtual void drawPolygon(const QPoint *points, int pointCount, PolygonDrawMode mode);
178 virtual void drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr) = 0;
179 virtual void drawTextItem(const QPointF &p, const QTextItem &textItem);
180 virtual void drawTiledPixmap(const QRectF &r, const QPixmap &pixmap, const QPointF &s);
181 virtual void drawImage(const QRectF &r, const QImage &pm, const QRectF &sr,
182 Qt::ImageConversionFlags flags = Qt::AutoColor);
184 void setPaintDevice(QPaintDevice *device);
185 QPaintDevice *paintDevice() const;
187 void setSystemClip(const QRegion &baseClip);
188 QRegion systemClip() const;
190 void setSystemRect(const QRect &rect);
191 QRect systemRect() const;
194 virtual QPoint coordinateOffset() const;
199 QuickDraw, CoreGraphics, MacPrinter,
213 User = 50, // first user type id
214 MaxUser = 100 // last user type id
216 virtual Type type() const = 0;
218 inline void fix_neg_rect(int *x, int *y, int *w, int *h);
220 inline bool testDirty(DirtyFlags df);
221 inline void setDirty(DirtyFlags df);
222 inline void clearDirty(DirtyFlags df);
224 bool hasFeature(PaintEngineFeatures feature) const { return (gccaps & feature) != 0; }
226 QPainter *painter() const;
229 inline bool isExtended() const { return extended; }
232 QPaintEngine(QPaintEnginePrivate &data, PaintEngineFeatures devcaps=0);
234 QPaintEngineState *state;
235 PaintEngineFeatures gccaps;
238 uint selfDestruct : 1;
241 QScopedPointer<QPaintEnginePrivate> d_ptr;
244 void setAutoDestruct(bool autoDestr) { selfDestruct = autoDestr; }
245 bool autoDestruct() const { return selfDestruct; }
246 Q_DISABLE_COPY(QPaintEngine)
248 friend class QPainterReplayer;
249 friend class QFontEngineBox;
250 friend class QFontEngineMac;
251 friend class QFontEngineWin;
252 #ifndef QT_NO_QWS_QPF
253 friend class QFontEngineQPF1;
255 #ifndef QT_NO_QWS_QPF2
256 friend class QFontEngineQPF;
258 friend class QPSPrintEngine;
259 friend class QMacPrintEngine;
260 friend class QMacPrintEnginePrivate;
261 friend class QFontEngineQPA;
262 friend class QPainter;
263 friend class QPainterPrivate;
264 friend class QWidget;
265 friend class QWidgetPrivate;
266 friend class QWin32PaintEngine;
267 friend class QWin32PaintEnginePrivate;
268 friend class QMacCGContext;
269 friend class QPreviewPaintEngine;
270 friend class QX11GLPlatformPixmap;
274 class Q_GUI_EXPORT QPaintEngineState
277 QPaintEngine::DirtyFlags state() const { return dirtyFlags; }
280 QBrush brush() const;
281 QPointF brushOrigin() const;
282 QBrush backgroundBrush() const;
283 Qt::BGMode backgroundMode() const;
285 QMatrix matrix() const;
286 QTransform transform() const;
288 Qt::ClipOperation clipOperation() const;
289 QRegion clipRegion() const;
290 QPainterPath clipPath() const;
291 bool isClipEnabled() const;
293 QPainter::RenderHints renderHints() const;
294 QPainter::CompositionMode compositionMode() const;
295 qreal opacity() const;
297 QPainter *painter() const;
299 bool brushNeedsResolving() const;
300 bool penNeedsResolving() const;
303 friend class QPaintEngine;
304 friend class QRasterPaintEngine;
305 friend class QWidget;
306 friend class QPainter;
307 friend class QPainterPrivate;
308 friend class QMacPrintEnginePrivate;
310 QPaintEngine::DirtyFlags dirtyFlags;
317 inline void QPaintEngine::fix_neg_rect(int *x, int *y, int *w, int *h)
329 inline bool QPaintEngine::testDirty(DirtyFlags df) {
331 return ((state->dirtyFlags & df) != 0);
334 inline void QPaintEngine::setDirty(DirtyFlags df) {
336 state->dirtyFlags |= df;
339 inline void QPaintEngine::clearDirty(DirtyFlags df)
342 state->dirtyFlags &= ~static_cast<uint>(df);
345 Q_DECLARE_OPERATORS_FOR_FLAGS(QTextItem::RenderFlags)
346 Q_DECLARE_OPERATORS_FOR_FLAGS(QPaintEngine::PaintEngineFeatures)
347 Q_DECLARE_OPERATORS_FOR_FLAGS(QPaintEngine::DirtyFlags)
353 #endif // QPAINTENGINE_H