Make QRegion not need to be friends with QVector
[profile/ivi/qtbase.git] / src / gui / painting / qpaintengine.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
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.
16 **
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.
20 **
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.
28 **
29 ** Other Usage
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.
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef QPAINTENGINE_H
43 #define QPAINTENGINE_H
44
45 #include <QtCore/qnamespace.h>
46 #include <QtCore/qobjectdefs.h>
47 #include <QtCore/qscopedpointer.h>
48 #include <QtGui/qpainter.h>
49
50 QT_BEGIN_HEADER
51
52 QT_BEGIN_NAMESPACE
53
54
55 class QFontEngine;
56 class QLineF;
57 class QPaintDevice;
58 class QPaintEnginePrivate;
59 class QPainterPath;
60 class QPointF;
61 class QPolygonF;
62 class QRectF;
63 struct QGlyphLayout;
64 class QTextItemInt;
65 class QPaintEngineState;
66
67 class Q_GUI_EXPORT QTextItem {
68 public:
69     enum RenderFlag {
70         RightToLeft = 0x1,
71         Overline = 0x10,
72         Underline = 0x20,
73         StrikeOut = 0x40,
74
75         Dummy = 0xffffffff
76     };
77     Q_DECLARE_FLAGS(RenderFlags, RenderFlag)
78     qreal descent() const;
79     qreal ascent() const;
80     qreal width() const;
81
82     RenderFlags renderFlags() const;
83     QString text() const;
84     QFont font() const;
85 };
86 Q_DECLARE_TYPEINFO(QTextItem, Q_PRIMITIVE_TYPE);
87
88
89 class Q_GUI_EXPORT QPaintEngine
90 {
91     Q_DECLARE_PRIVATE(QPaintEngine)
92 public:
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
116
117                                     0x40000000, // Used internally for emulating opaque backgrounds
118         */
119
120         AllFeatures               = 0xffffffff  // For convenience
121     };
122     Q_DECLARE_FLAGS(PaintEngineFeatures, PaintEngineFeature)
123
124     enum DirtyFlag {
125         DirtyPen                = 0x0001,
126         DirtyBrush              = 0x0002,
127         DirtyBrushOrigin        = 0x0004,
128         DirtyFont               = 0x0008,
129         DirtyBackground         = 0x0010,
130         DirtyBackgroundMode     = 0x0020,
131         DirtyTransform          = 0x0040,
132         DirtyClipRegion         = 0x0080,
133         DirtyClipPath           = 0x0100,
134         DirtyHints              = 0x0200,
135         DirtyCompositionMode    = 0x0400,
136         DirtyClipEnabled        = 0x0800,
137         DirtyOpacity            = 0x1000,
138
139         AllDirty                = 0xffff
140     };
141     Q_DECLARE_FLAGS(DirtyFlags, DirtyFlag)
142
143     enum PolygonDrawMode {
144         OddEvenMode,
145         WindingMode,
146         ConvexMode,
147         PolylineMode
148     };
149
150     explicit QPaintEngine(PaintEngineFeatures features=0);
151     virtual ~QPaintEngine();
152
153     bool isActive() const { return active; }
154     void setActive(bool newState) { active = newState; }
155
156     virtual bool begin(QPaintDevice *pdev) = 0;
157     virtual bool end() = 0;
158
159     virtual void updateState(const QPaintEngineState &state) = 0;
160
161     virtual void drawRects(const QRect *rects, int rectCount);
162     virtual void drawRects(const QRectF *rects, int rectCount);
163
164     virtual void drawLines(const QLine *lines, int lineCount);
165     virtual void drawLines(const QLineF *lines, int lineCount);
166
167     virtual void drawEllipse(const QRectF &r);
168     virtual void drawEllipse(const QRect &r);
169
170     virtual void drawPath(const QPainterPath &path);
171
172     virtual void drawPoints(const QPointF *points, int pointCount);
173     virtual void drawPoints(const QPoint *points, int pointCount);
174
175     virtual void drawPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode);
176     virtual void drawPolygon(const QPoint *points, int pointCount, PolygonDrawMode mode);
177
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);
183
184     void setPaintDevice(QPaintDevice *device);
185     QPaintDevice *paintDevice() const;
186
187     void setSystemClip(const QRegion &baseClip);
188     QRegion systemClip() const;
189
190     void setSystemRect(const QRect &rect);
191     QRect systemRect() const;
192
193
194     virtual QPoint coordinateOffset() const;
195
196     enum Type {
197         X11,
198         Windows,
199         QuickDraw, CoreGraphics, MacPrinter,
200         QWindowSystem,
201         PostScript,
202         OpenGL,
203         Picture,
204         SVG,
205         Raster,
206         Direct3D,
207         Pdf,
208         OpenVG,
209         OpenGL2,
210         PaintBuffer,
211         Blitter,
212
213         User = 50,    // first user type id
214         MaxUser = 100 // last user type id
215     };
216     virtual Type type() const = 0;
217
218     inline void fix_neg_rect(int *x, int *y, int *w, int *h);
219
220     inline bool testDirty(DirtyFlags df);
221     inline void setDirty(DirtyFlags df);
222     inline void clearDirty(DirtyFlags df);
223
224     bool hasFeature(PaintEngineFeatures feature) const { return (gccaps & feature) != 0; }
225
226     QPainter *painter() const;
227
228     void syncState();
229     inline bool isExtended() const { return extended; }
230
231 protected:
232     QPaintEngine(QPaintEnginePrivate &data, PaintEngineFeatures devcaps=0);
233
234     QPaintEngineState *state;
235     PaintEngineFeatures gccaps;
236
237     uint active : 1;
238     uint selfDestruct : 1;
239     uint extended : 1;
240
241     QScopedPointer<QPaintEnginePrivate> d_ptr;
242
243 private:
244     void setAutoDestruct(bool autoDestr) { selfDestruct = autoDestr; }
245     bool autoDestruct() const { return selfDestruct; }
246     Q_DISABLE_COPY(QPaintEngine)
247
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;
254 #endif
255 #ifndef QT_NO_QWS_QPF2
256     friend class QFontEngineQPF;
257 #endif
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;
271 };
272
273
274 class Q_GUI_EXPORT QPaintEngineState
275 {
276 public:
277     QPaintEngine::DirtyFlags state() const { return dirtyFlags; }
278
279     QPen pen() const;
280     QBrush brush() const;
281     QPointF brushOrigin() const;
282     QBrush backgroundBrush() const;
283     Qt::BGMode backgroundMode() const;
284     QFont font() const;
285     QMatrix matrix() const;
286     QTransform transform() const;
287
288     Qt::ClipOperation clipOperation() const;
289     QRegion clipRegion() const;
290     QPainterPath clipPath() const;
291     bool isClipEnabled() const;
292
293     QPainter::RenderHints renderHints() const;
294     QPainter::CompositionMode compositionMode() const;
295     qreal opacity() const;
296
297     QPainter *painter() const;
298
299     bool brushNeedsResolving() const;
300     bool penNeedsResolving() const;
301
302 protected:
303     friend class QPaintEngine;
304     friend class QRasterPaintEngine;
305     friend class QWidget;
306     friend class QPainter;
307     friend class QPainterPrivate;
308     friend class QMacPrintEnginePrivate;
309
310     QPaintEngine::DirtyFlags dirtyFlags;
311 };
312
313 //
314 // inline functions
315 //
316
317 inline void QPaintEngine::fix_neg_rect(int *x, int *y, int *w, int *h)
318 {
319     if (*w < 0) {
320         *w = -*w;
321         *x -= *w - 1;
322     }
323     if (*h < 0) {
324         *h = -*h;
325         *y -= *h - 1;
326     }
327 }
328
329 inline bool QPaintEngine::testDirty(DirtyFlags df) {
330     Q_ASSERT(state);
331     return ((state->dirtyFlags & df) != 0);
332 }
333
334 inline void QPaintEngine::setDirty(DirtyFlags df) {
335     Q_ASSERT(state);
336     state->dirtyFlags |= df;
337 }
338
339 inline void QPaintEngine::clearDirty(DirtyFlags df)
340 {
341     Q_ASSERT(state);
342     state->dirtyFlags &= ~static_cast<uint>(df);
343 }
344
345 Q_DECLARE_OPERATORS_FOR_FLAGS(QTextItem::RenderFlags)
346 Q_DECLARE_OPERATORS_FOR_FLAGS(QPaintEngine::PaintEngineFeatures)
347 Q_DECLARE_OPERATORS_FOR_FLAGS(QPaintEngine::DirtyFlags)
348
349 QT_END_NAMESPACE
350
351 QT_END_HEADER
352
353 #endif // QPAINTENGINE_H