1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** Contact: Qt Software Information (qt-info@nokia.com)
|
---|
5 | **
|
---|
6 | ** This file is part of the QtGui module of the Qt Toolkit.
|
---|
7 | **
|
---|
8 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
9 | ** Commercial Usage
|
---|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
11 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
12 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
13 | ** a written agreement between you and Nokia.
|
---|
14 | **
|
---|
15 | ** GNU Lesser General Public License Usage
|
---|
16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
17 | ** General Public License version 2.1 as published by the Free Software
|
---|
18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
19 | ** packaging of this file. Please review the following information to
|
---|
20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
22 | **
|
---|
23 | ** In addition, as a special exception, Nokia gives you certain
|
---|
24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
---|
25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
---|
26 | ** package.
|
---|
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 | **
|
---|
36 | ** If you are unsure which license is appropriate for your use, please
|
---|
37 | ** contact the sales department at qt-sales@nokia.com.
|
---|
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 <QtGui/qpainter.h>
|
---|
48 |
|
---|
49 | QT_BEGIN_HEADER
|
---|
50 |
|
---|
51 | QT_BEGIN_NAMESPACE
|
---|
52 |
|
---|
53 | QT_MODULE(Gui)
|
---|
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 | #ifdef Q_WS_WIN
|
---|
194 | virtual HDC getDC() const;
|
---|
195 | virtual void releaseDC(HDC hdc) const;
|
---|
196 | #endif
|
---|
197 |
|
---|
198 | virtual QPoint coordinateOffset() const;
|
---|
199 |
|
---|
200 | enum Type {
|
---|
201 | X11,
|
---|
202 | Windows,
|
---|
203 | QuickDraw, CoreGraphics, MacPrinter,
|
---|
204 | QWindowSystem,
|
---|
205 | PostScript,
|
---|
206 | OpenGL,
|
---|
207 | Picture,
|
---|
208 | SVG,
|
---|
209 | Raster,
|
---|
210 | Direct3D,
|
---|
211 | Pdf,
|
---|
212 | OpenVG,
|
---|
213 |
|
---|
214 | User = 50, // first user type id
|
---|
215 | MaxUser = 100 // last user type id
|
---|
216 | };
|
---|
217 | virtual Type type() const = 0;
|
---|
218 |
|
---|
219 | inline void fix_neg_rect(int *x, int *y, int *w, int *h);
|
---|
220 |
|
---|
221 | inline bool testDirty(DirtyFlags df);
|
---|
222 | inline void setDirty(DirtyFlags df);
|
---|
223 | inline void clearDirty(DirtyFlags df);
|
---|
224 |
|
---|
225 | bool hasFeature(PaintEngineFeatures feature) const { return (gccaps & feature) != 0; }
|
---|
226 |
|
---|
227 | QPainter *painter() const;
|
---|
228 |
|
---|
229 | void syncState();
|
---|
230 | inline bool isExtended() const { return extended; }
|
---|
231 |
|
---|
232 | protected:
|
---|
233 | QPaintEngine(QPaintEnginePrivate &data, PaintEngineFeatures devcaps=0);
|
---|
234 |
|
---|
235 | QPaintEngineState *state;
|
---|
236 | PaintEngineFeatures gccaps;
|
---|
237 |
|
---|
238 | uint active : 1;
|
---|
239 | uint selfDestruct : 1;
|
---|
240 | uint extended : 1;
|
---|
241 |
|
---|
242 | QPaintEnginePrivate *d_ptr;
|
---|
243 |
|
---|
244 | private:
|
---|
245 | void setAutoDestruct(bool autoDestr) { selfDestruct = autoDestr; }
|
---|
246 | bool autoDestruct() const { return selfDestruct; }
|
---|
247 | Q_DISABLE_COPY(QPaintEngine)
|
---|
248 |
|
---|
249 | friend class QFontEngineBox;
|
---|
250 | friend class QFontEngineMac;
|
---|
251 | friend class QFontEngineWin;
|
---|
252 | #ifndef QT_NO_FREETYPE
|
---|
253 | friend class QFontEngineFT;
|
---|
254 | #endif
|
---|
255 | #ifndef QT_NO_QWS_QPF
|
---|
256 | friend class QFontEngineQPF1;
|
---|
257 | #endif
|
---|
258 | #ifndef QT_NO_QWS_QPF2
|
---|
259 | friend class QFontEngineQPF;
|
---|
260 | #endif
|
---|
261 | friend class QPSPrintEngine;
|
---|
262 | friend class QMacPrintEngine;
|
---|
263 | friend class QMacPrintEnginePrivate;
|
---|
264 | #ifdef Q_WS_QWS
|
---|
265 | friend class QtopiaPrintEngine;
|
---|
266 | friend class QtopiaPrintEnginePrivate;
|
---|
267 | friend class QProxyFontEngine;
|
---|
268 | #endif
|
---|
269 | friend class QPainter;
|
---|
270 | friend class QPainterPrivate;
|
---|
271 | friend class QWidget;
|
---|
272 | friend class QWidgetPrivate;
|
---|
273 | friend class QWin32PaintEngine;
|
---|
274 | friend class QWin32PaintEnginePrivate;
|
---|
275 | friend class QMacCGContext;
|
---|
276 | friend class QPreviewPaintEngine;
|
---|
277 | };
|
---|
278 |
|
---|
279 |
|
---|
280 | class Q_GUI_EXPORT QPaintEngineState
|
---|
281 | {
|
---|
282 | public:
|
---|
283 | QPaintEngine::DirtyFlags state() const { return dirtyFlags; }
|
---|
284 |
|
---|
285 | QPen pen() const;
|
---|
286 | QBrush brush() const;
|
---|
287 | QPointF brushOrigin() const;
|
---|
288 | QBrush backgroundBrush() const;
|
---|
289 | Qt::BGMode backgroundMode() const;
|
---|
290 | QFont font() const;
|
---|
291 | QMatrix matrix() const;
|
---|
292 | QTransform transform() const;
|
---|
293 |
|
---|
294 | Qt::ClipOperation clipOperation() const;
|
---|
295 | QRegion clipRegion() const;
|
---|
296 | QPainterPath clipPath() const;
|
---|
297 | bool isClipEnabled() const;
|
---|
298 |
|
---|
299 | QPainter::RenderHints renderHints() const;
|
---|
300 | QPainter::CompositionMode compositionMode() const;
|
---|
301 | qreal opacity() const;
|
---|
302 |
|
---|
303 | QPainter *painter() const;
|
---|
304 |
|
---|
305 | bool brushNeedsResolving() const;
|
---|
306 | bool penNeedsResolving() const;
|
---|
307 |
|
---|
308 | protected:
|
---|
309 | friend class QPaintEngine;
|
---|
310 | friend class QRasterPaintEngine;
|
---|
311 | friend class QWidget;
|
---|
312 | friend class QPainter;
|
---|
313 | friend class QPainterPrivate;
|
---|
314 | friend class QMacPrintEnginePrivate;
|
---|
315 |
|
---|
316 | QPaintEngine::DirtyFlags dirtyFlags;
|
---|
317 | };
|
---|
318 |
|
---|
319 | //
|
---|
320 | // inline functions
|
---|
321 | //
|
---|
322 |
|
---|
323 | inline void QPaintEngine::fix_neg_rect(int *x, int *y, int *w, int *h)
|
---|
324 | {
|
---|
325 | if (*w < 0) {
|
---|
326 | *w = -*w;
|
---|
327 | *x -= *w - 1;
|
---|
328 | }
|
---|
329 | if (*h < 0) {
|
---|
330 | *h = -*h;
|
---|
331 | *y -= *h - 1;
|
---|
332 | }
|
---|
333 | }
|
---|
334 |
|
---|
335 | inline bool QPaintEngine::testDirty(DirtyFlags df) {
|
---|
336 | Q_ASSERT(state);
|
---|
337 | return ((state->dirtyFlags & df) != 0);
|
---|
338 | }
|
---|
339 |
|
---|
340 | inline void QPaintEngine::setDirty(DirtyFlags df) {
|
---|
341 | Q_ASSERT(state);
|
---|
342 | state->dirtyFlags |= df;
|
---|
343 | }
|
---|
344 |
|
---|
345 | inline void QPaintEngine::clearDirty(DirtyFlags df)
|
---|
346 | {
|
---|
347 | Q_ASSERT(state);
|
---|
348 | state->dirtyFlags &= ~static_cast<uint>(df);
|
---|
349 | }
|
---|
350 |
|
---|
351 | Q_DECLARE_OPERATORS_FOR_FLAGS(QTextItem::RenderFlags)
|
---|
352 | Q_DECLARE_OPERATORS_FOR_FLAGS(QPaintEngine::PaintEngineFeatures)
|
---|
353 | Q_DECLARE_OPERATORS_FOR_FLAGS(QPaintEngine::DirtyFlags)
|
---|
354 |
|
---|
355 | QT_END_NAMESPACE
|
---|
356 |
|
---|
357 | QT_END_HEADER
|
---|
358 |
|
---|
359 | #endif // QPAINTENGINE_H
|
---|