source: trunk/src/gui/painting/qpaintengine.h@ 1108

Last change on this file since 1108 was 846, checked in by Dmitry A. Kuminov, 15 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

File size: 11.3 KB
RevLine 
[2]1/****************************************************************************
2**
[846]3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
[561]4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
[2]6**
7** This file is part of the QtGui module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
15**
16** GNU Lesser General Public License Usage
17** Alternatively, this file may be used under the terms of the GNU Lesser
18** General Public License version 2.1 as published by the Free Software
19** Foundation and appearing in the file LICENSE.LGPL included in the
20** packaging of this file. Please review the following information to
21** ensure the GNU Lesser General Public License version 2.1 requirements
22** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23**
[561]24** In addition, as a special exception, Nokia gives you certain additional
25** rights. These rights are described in the Nokia Qt LGPL Exception
26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
[2]27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
[561]36** If you have questions regarding the use of this file, please contact
37** Nokia at [email protected].
[2]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>
[561]47#include <QtCore/qscopedpointer.h>
[2]48#include <QtGui/qpainter.h>
49
50QT_BEGIN_HEADER
51
52QT_BEGIN_NAMESPACE
53
54QT_MODULE(Gui)
55
56class QFontEngine;
57class QLineF;
58class QPaintDevice;
59class QPaintEnginePrivate;
60class QPainterPath;
61class QPointF;
62class QPolygonF;
63class QRectF;
64struct QGlyphLayout;
65class QTextItemInt;
66class QPaintEngineState;
67
68class Q_GUI_EXPORT QTextItem {
69public:
70 enum RenderFlag {
71 RightToLeft = 0x1,
72 Overline = 0x10,
73 Underline = 0x20,
74 StrikeOut = 0x40,
75
76 Dummy = 0xffffffff
77 };
78 Q_DECLARE_FLAGS(RenderFlags, RenderFlag)
79 qreal descent() const;
80 qreal ascent() const;
81 qreal width() const;
82
83 RenderFlags renderFlags() const;
84 QString text() const;
85 QFont font() const;
86};
87Q_DECLARE_TYPEINFO(QTextItem, Q_PRIMITIVE_TYPE);
88
89
90class Q_GUI_EXPORT QPaintEngine
91{
92 Q_DECLARE_PRIVATE(QPaintEngine)
93public:
94 enum PaintEngineFeature {
95 PrimitiveTransform = 0x00000001, // Can transform primitives brushes
96 PatternTransform = 0x00000002, // Can transform pattern brushes
97 PixmapTransform = 0x00000004, // Can transform pixmaps
98 PatternBrush = 0x00000008, // Can fill with pixmaps and standard patterns
99 LinearGradientFill = 0x00000010, // Can fill gradient areas
100 RadialGradientFill = 0x00000020, // Can render radial gradients
101 ConicalGradientFill = 0x00000040, // Can render conical gradients
102 AlphaBlend = 0x00000080, // Can do source over alpha blend
103 PorterDuff = 0x00000100, // Can do general porter duff compositions
104 PainterPaths = 0x00000200, // Can fill, outline and clip paths
105 Antialiasing = 0x00000400, // Can antialias lines
106 BrushStroke = 0x00000800, // Can render brush based pens
107 ConstantOpacity = 0x00001000, // Can render at constant opacity
108 MaskedBrush = 0x00002000, // Can fill with textures that has an alpha channel or mask
109 PerspectiveTransform = 0x00004000, // Can do perspective transformations
110 BlendModes = 0x00008000, // Can do extended Porter&Duff composition
111 ObjectBoundingModeGradients = 0x00010000, // Can do object bounding mode gradients
112 RasterOpModes = 0x00020000, // Can do logical raster operations
113 PaintOutsidePaintEvent = 0x20000000, // Engine is capable of painting outside paint events
114 /* 0x10000000, // Used for emulating
115 QGradient::StretchToDevice,
116 defined in qpainter.cpp
117
118 0x40000000, // Used internally for emulating opaque backgrounds
119 */
120
121 AllFeatures = 0xffffffff // For convenience
122 };
123 Q_DECLARE_FLAGS(PaintEngineFeatures, PaintEngineFeature)
124
125 enum DirtyFlag {
126 DirtyPen = 0x0001,
127 DirtyBrush = 0x0002,
128 DirtyBrushOrigin = 0x0004,
129 DirtyFont = 0x0008,
130 DirtyBackground = 0x0010,
131 DirtyBackgroundMode = 0x0020,
132 DirtyTransform = 0x0040,
133 DirtyClipRegion = 0x0080,
134 DirtyClipPath = 0x0100,
135 DirtyHints = 0x0200,
136 DirtyCompositionMode = 0x0400,
137 DirtyClipEnabled = 0x0800,
138 DirtyOpacity = 0x1000,
139
140 AllDirty = 0xffff
141 };
142 Q_DECLARE_FLAGS(DirtyFlags, DirtyFlag)
143
144 enum PolygonDrawMode {
145 OddEvenMode,
146 WindingMode,
147 ConvexMode,
148 PolylineMode
149 };
150
151 explicit QPaintEngine(PaintEngineFeatures features=0);
152 virtual ~QPaintEngine();
153
154 bool isActive() const { return active; }
155 void setActive(bool newState) { active = newState; }
156
157 virtual bool begin(QPaintDevice *pdev) = 0;
158 virtual bool end() = 0;
159
160 virtual void updateState(const QPaintEngineState &state) = 0;
161
162 virtual void drawRects(const QRect *rects, int rectCount);
163 virtual void drawRects(const QRectF *rects, int rectCount);
164
165 virtual void drawLines(const QLine *lines, int lineCount);
166 virtual void drawLines(const QLineF *lines, int lineCount);
167
168 virtual void drawEllipse(const QRectF &r);
169 virtual void drawEllipse(const QRect &r);
170
171 virtual void drawPath(const QPainterPath &path);
172
173 virtual void drawPoints(const QPointF *points, int pointCount);
174 virtual void drawPoints(const QPoint *points, int pointCount);
175
176 virtual void drawPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode);
177 virtual void drawPolygon(const QPoint *points, int pointCount, PolygonDrawMode mode);
178
179 virtual void drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr) = 0;
180 virtual void drawTextItem(const QPointF &p, const QTextItem &textItem);
181 virtual void drawTiledPixmap(const QRectF &r, const QPixmap &pixmap, const QPointF &s);
182 virtual void drawImage(const QRectF &r, const QImage &pm, const QRectF &sr,
183 Qt::ImageConversionFlags flags = Qt::AutoColor);
184
185 void setPaintDevice(QPaintDevice *device);
186 QPaintDevice *paintDevice() const;
187
188 void setSystemClip(const QRegion &baseClip);
189 QRegion systemClip() const;
190
191 void setSystemRect(const QRect &rect);
192 QRect systemRect() const;
193
194#ifdef Q_WS_WIN
195 virtual HDC getDC() const;
196 virtual void releaseDC(HDC hdc) const;
197#endif
198
199 virtual QPoint coordinateOffset() const;
200
201 enum Type {
202 X11,
203 Windows,
204 QuickDraw, CoreGraphics, MacPrinter,
205 QWindowSystem,
206 PostScript,
207 OpenGL,
208 Picture,
209 SVG,
210 Raster,
211 Direct3D,
212 Pdf,
213 OpenVG,
[561]214 OpenGL2,
215 PaintBuffer,
[2]216
217 User = 50, // first user type id
218 MaxUser = 100 // last user type id
219 };
220 virtual Type type() const = 0;
221
222 inline void fix_neg_rect(int *x, int *y, int *w, int *h);
223
224 inline bool testDirty(DirtyFlags df);
225 inline void setDirty(DirtyFlags df);
226 inline void clearDirty(DirtyFlags df);
227
228 bool hasFeature(PaintEngineFeatures feature) const { return (gccaps & feature) != 0; }
229
230 QPainter *painter() const;
231
232 void syncState();
233 inline bool isExtended() const { return extended; }
234
235protected:
236 QPaintEngine(QPaintEnginePrivate &data, PaintEngineFeatures devcaps=0);
237
238 QPaintEngineState *state;
239 PaintEngineFeatures gccaps;
240
241 uint active : 1;
242 uint selfDestruct : 1;
243 uint extended : 1;
244
[561]245 QScopedPointer<QPaintEnginePrivate> d_ptr;
[2]246
247private:
248 void setAutoDestruct(bool autoDestr) { selfDestruct = autoDestr; }
249 bool autoDestruct() const { return selfDestruct; }
250 Q_DISABLE_COPY(QPaintEngine)
251
[561]252 friend class QPainterReplayer;
[2]253 friend class QFontEngineBox;
254 friend class QFontEngineMac;
255 friend class QFontEngineWin;
256#ifndef QT_NO_FREETYPE
257 friend class QFontEngineFT;
258#endif
259#ifndef QT_NO_QWS_QPF
260 friend class QFontEngineQPF1;
261#endif
262#ifndef QT_NO_QWS_QPF2
263 friend class QFontEngineQPF;
264#endif
265 friend class QPSPrintEngine;
266 friend class QMacPrintEngine;
267 friend class QMacPrintEnginePrivate;
268#ifdef Q_WS_QWS
269 friend class QtopiaPrintEngine;
270 friend class QtopiaPrintEnginePrivate;
271 friend class QProxyFontEngine;
272#endif
273 friend class QPainter;
274 friend class QPainterPrivate;
275 friend class QWidget;
276 friend class QWidgetPrivate;
277 friend class QWin32PaintEngine;
278 friend class QWin32PaintEnginePrivate;
279 friend class QMacCGContext;
280 friend class QPreviewPaintEngine;
[561]281 friend class QX11GLPixmapData;
[2]282};
283
284
285class Q_GUI_EXPORT QPaintEngineState
286{
287public:
288 QPaintEngine::DirtyFlags state() const { return dirtyFlags; }
289
290 QPen pen() const;
291 QBrush brush() const;
292 QPointF brushOrigin() const;
293 QBrush backgroundBrush() const;
294 Qt::BGMode backgroundMode() const;
295 QFont font() const;
296 QMatrix matrix() const;
297 QTransform transform() const;
298
299 Qt::ClipOperation clipOperation() const;
300 QRegion clipRegion() const;
301 QPainterPath clipPath() const;
302 bool isClipEnabled() const;
303
304 QPainter::RenderHints renderHints() const;
305 QPainter::CompositionMode compositionMode() const;
306 qreal opacity() const;
307
308 QPainter *painter() const;
309
310 bool brushNeedsResolving() const;
311 bool penNeedsResolving() const;
312
313protected:
314 friend class QPaintEngine;
315 friend class QRasterPaintEngine;
316 friend class QWidget;
317 friend class QPainter;
318 friend class QPainterPrivate;
319 friend class QMacPrintEnginePrivate;
320
321 QPaintEngine::DirtyFlags dirtyFlags;
322};
323
324//
325// inline functions
326//
327
328inline void QPaintEngine::fix_neg_rect(int *x, int *y, int *w, int *h)
329{
330 if (*w < 0) {
331 *w = -*w;
332 *x -= *w - 1;
333 }
334 if (*h < 0) {
335 *h = -*h;
336 *y -= *h - 1;
337 }
338}
339
340inline bool QPaintEngine::testDirty(DirtyFlags df) {
341 Q_ASSERT(state);
342 return ((state->dirtyFlags & df) != 0);
343}
344
345inline void QPaintEngine::setDirty(DirtyFlags df) {
346 Q_ASSERT(state);
347 state->dirtyFlags |= df;
348}
349
350inline void QPaintEngine::clearDirty(DirtyFlags df)
351{
352 Q_ASSERT(state);
353 state->dirtyFlags &= ~static_cast<uint>(df);
354}
355
356Q_DECLARE_OPERATORS_FOR_FLAGS(QTextItem::RenderFlags)
357Q_DECLARE_OPERATORS_FOR_FLAGS(QPaintEngine::PaintEngineFeatures)
358Q_DECLARE_OPERATORS_FOR_FLAGS(QPaintEngine::DirtyFlags)
359
360QT_END_NAMESPACE
361
362QT_END_HEADER
363
364#endif // QPAINTENGINE_H
Note: See TracBrowser for help on using the repository browser.