Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/gui/painting/qpaintengine.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||||||||
2 | ** | - | ||||||||||||
3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||||||||
4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||||||||
5 | ** | - | ||||||||||||
6 | ** This file is part of the QtGui module of the Qt Toolkit. | - | ||||||||||||
7 | ** | - | ||||||||||||
8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||||||||
9 | ** Commercial License Usage | - | ||||||||||||
10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||
11 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||
12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||
13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||
14 | ** and conditions see http://www.qt.io/terms-conditions. For further | - | ||||||||||||
15 | ** information use the contact form at http://www.qt.io/contact-us. | - | ||||||||||||
16 | ** | - | ||||||||||||
17 | ** GNU Lesser General Public License Usage | - | ||||||||||||
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||
19 | ** General Public License version 2.1 or version 3 as published by the Free | - | ||||||||||||
20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||||||||
21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||||||||
22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||||||||
23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||||||||
24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||||||||
25 | ** | - | ||||||||||||
26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||||||||
27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||||||||
28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||||||||
29 | ** | - | ||||||||||||
30 | ** $QT_END_LICENSE$ | - | ||||||||||||
31 | ** | - | ||||||||||||
32 | ****************************************************************************/ | - | ||||||||||||
33 | #include "qpaintengine.h" | - | ||||||||||||
34 | #include "qpaintengine_p.h" | - | ||||||||||||
35 | #include "qpainter_p.h" | - | ||||||||||||
36 | #include "qpolygon.h" | - | ||||||||||||
37 | #include "qbitmap.h" | - | ||||||||||||
38 | #include <qdebug.h> | - | ||||||||||||
39 | #include <qmath.h> | - | ||||||||||||
40 | #include <qguiapplication.h> | - | ||||||||||||
41 | #include <private/qtextengine_p.h> | - | ||||||||||||
42 | #include <qvarlengtharray.h> | - | ||||||||||||
43 | #include <private/qfontengine_p.h> | - | ||||||||||||
44 | #include <private/qpaintengineex_p.h> | - | ||||||||||||
45 | - | |||||||||||||
46 | - | |||||||||||||
47 | QT_BEGIN_NAMESPACE | - | ||||||||||||
48 | - | |||||||||||||
49 | /*! | - | ||||||||||||
50 | \class QTextItem | - | ||||||||||||
51 | \inmodule QtGui | - | ||||||||||||
52 | - | |||||||||||||
53 | \brief The QTextItem class provides all the information required to draw | - | ||||||||||||
54 | text in a custom paint engine. | - | ||||||||||||
55 | - | |||||||||||||
56 | When you reimplement your own paint engine, you must reimplement | - | ||||||||||||
57 | QPaintEngine::drawTextItem(), a function that takes a QTextItem as | - | ||||||||||||
58 | one of its arguments. | - | ||||||||||||
59 | */ | - | ||||||||||||
60 | - | |||||||||||||
61 | /*! | - | ||||||||||||
62 | \enum QTextItem::RenderFlag | - | ||||||||||||
63 | - | |||||||||||||
64 | \value RightToLeft Render the text from right to left. | - | ||||||||||||
65 | \value Overline Paint a line above the text. | - | ||||||||||||
66 | \value Underline Paint a line under the text. | - | ||||||||||||
67 | \value StrikeOut Paint a line through the text. | - | ||||||||||||
68 | \omitvalue Dummy | - | ||||||||||||
69 | */ | - | ||||||||||||
70 | - | |||||||||||||
71 | - | |||||||||||||
72 | /*! | - | ||||||||||||
73 | \fn qreal QTextItem::descent() const | - | ||||||||||||
74 | - | |||||||||||||
75 | Corresponds to the \l{QFontMetrics::descent()}{descent} of the piece of text that is drawn. | - | ||||||||||||
76 | */ | - | ||||||||||||
77 | qreal QTextItem::descent() const | - | ||||||||||||
78 | { | - | ||||||||||||
79 | const QTextItemInt *ti = static_cast<const QTextItemInt *>(this); | - | ||||||||||||
80 | return ti->descent.toReal(); never executed: return ti->descent.toReal(); | 0 | ||||||||||||
81 | } | - | ||||||||||||
82 | - | |||||||||||||
83 | /*! | - | ||||||||||||
84 | \fn qreal QTextItem::ascent() const | - | ||||||||||||
85 | - | |||||||||||||
86 | Corresponds to the \l{QFontMetrics::ascent()}{ascent} of the piece of text that is drawn. | - | ||||||||||||
87 | */ | - | ||||||||||||
88 | qreal QTextItem::ascent() const | - | ||||||||||||
89 | { | - | ||||||||||||
90 | const QTextItemInt *ti = static_cast<const QTextItemInt *>(this); | - | ||||||||||||
91 | return ti->ascent.toReal(); never executed: return ti->ascent.toReal(); | 0 | ||||||||||||
92 | } | - | ||||||||||||
93 | - | |||||||||||||
94 | /*! | - | ||||||||||||
95 | \fn qreal QTextItem::width() const | - | ||||||||||||
96 | - | |||||||||||||
97 | Specifies the total width of the text to be drawn. | - | ||||||||||||
98 | */ | - | ||||||||||||
99 | qreal QTextItem::width() const | - | ||||||||||||
100 | { | - | ||||||||||||
101 | const QTextItemInt *ti = static_cast<const QTextItemInt *>(this); | - | ||||||||||||
102 | return ti->width.toReal(); never executed: return ti->width.toReal(); | 0 | ||||||||||||
103 | } | - | ||||||||||||
104 | - | |||||||||||||
105 | /*! | - | ||||||||||||
106 | \fn QTextItem::RenderFlags QTextItem::renderFlags() const | - | ||||||||||||
107 | - | |||||||||||||
108 | Returns the render flags used. | - | ||||||||||||
109 | */ | - | ||||||||||||
110 | QTextItem::RenderFlags QTextItem::renderFlags() const | - | ||||||||||||
111 | { | - | ||||||||||||
112 | const QTextItemInt *ti = static_cast<const QTextItemInt *>(this); | - | ||||||||||||
113 | return ti->flags; never executed: return ti->flags; | 0 | ||||||||||||
114 | } | - | ||||||||||||
115 | - | |||||||||||||
116 | /*! | - | ||||||||||||
117 | \fn QString QTextItem::text() const | - | ||||||||||||
118 | - | |||||||||||||
119 | Returns the text that should be drawn. | - | ||||||||||||
120 | */ | - | ||||||||||||
121 | QString QTextItem::text() const | - | ||||||||||||
122 | { | - | ||||||||||||
123 | const QTextItemInt *ti = static_cast<const QTextItemInt *>(this); | - | ||||||||||||
124 | return QString(ti->chars, ti->num_chars); never executed: return QString(ti->chars, ti->num_chars); | 0 | ||||||||||||
125 | } | - | ||||||||||||
126 | - | |||||||||||||
127 | /*! | - | ||||||||||||
128 | \fn QFont QTextItem::font() const | - | ||||||||||||
129 | - | |||||||||||||
130 | Returns the font that should be used to draw the text. | - | ||||||||||||
131 | */ | - | ||||||||||||
132 | QFont QTextItem::font() const | - | ||||||||||||
133 | { | - | ||||||||||||
134 | const QTextItemInt *ti = static_cast<const QTextItemInt *>(this); | - | ||||||||||||
135 | return ti->f ? *ti->f : QGuiApplication::font(); never executed: return ti->f ? *ti->f : QGuiApplication::font();
| 0 | ||||||||||||
136 | } | - | ||||||||||||
137 | - | |||||||||||||
138 | - | |||||||||||||
139 | /*! | - | ||||||||||||
140 | \class QPaintEngine | - | ||||||||||||
141 | \ingroup painting | - | ||||||||||||
142 | \inmodule QtGui | - | ||||||||||||
143 | - | |||||||||||||
144 | \brief The QPaintEngine class provides an abstract definition of how | - | ||||||||||||
145 | QPainter draws to a given device on a given platform. | - | ||||||||||||
146 | - | |||||||||||||
147 | Qt provides several premade implementations of QPaintEngine for the | - | ||||||||||||
148 | different painter backends we support. The primary paint engine | - | ||||||||||||
149 | provided is the raster paint engine, which contains a software | - | ||||||||||||
150 | rasterizer which supports the full feature set on all supported platforms. | - | ||||||||||||
151 | This is the default for painting on QWidget-based classes in e.g. on Windows, | - | ||||||||||||
152 | X11 and \macos, it is the backend for painting on QImage and it is | - | ||||||||||||
153 | used as a fallback for paint engines that do not support a certain | - | ||||||||||||
154 | capability. In addition we provide QPaintEngine implementations for | - | ||||||||||||
155 | OpenGL (accessible through QGLWidget) and printing (which allows using | - | ||||||||||||
156 | QPainter to draw on a QPrinter object). | - | ||||||||||||
157 | - | |||||||||||||
158 | If one wants to use QPainter to draw to a different backend, | - | ||||||||||||
159 | one must subclass QPaintEngine and reimplement all its virtual | - | ||||||||||||
160 | functions. The QPaintEngine implementation is then made available by | - | ||||||||||||
161 | subclassing QPaintDevice and reimplementing the virtual function | - | ||||||||||||
162 | QPaintDevice::paintEngine(). | - | ||||||||||||
163 | - | |||||||||||||
164 | QPaintEngine is created and owned by the QPaintDevice that created it. | - | ||||||||||||
165 | - | |||||||||||||
166 | \sa QPainter, QPaintDevice::paintEngine(), {Paint System} | - | ||||||||||||
167 | */ | - | ||||||||||||
168 | - | |||||||||||||
169 | /*! | - | ||||||||||||
170 | \enum QPaintEngine::PaintEngineFeature | - | ||||||||||||
171 | - | |||||||||||||
172 | This enum is used to describe the features or capabilities that the | - | ||||||||||||
173 | paint engine has. If a feature is not supported by the engine, | - | ||||||||||||
174 | QPainter will do a best effort to emulate that feature through other | - | ||||||||||||
175 | means and pass on an alpha blended QImage to the engine with the | - | ||||||||||||
176 | emulated results. Some features cannot be emulated: AlphaBlend and PorterDuff. | - | ||||||||||||
177 | - | |||||||||||||
178 | \value AlphaBlend The engine can alpha blend primitives. | - | ||||||||||||
179 | \value Antialiasing The engine can use antialising to improve the appearance | - | ||||||||||||
180 | of rendered primitives. | - | ||||||||||||
181 | \value BlendModes The engine supports blending modes. | - | ||||||||||||
182 | \value BrushStroke The engine supports drawing strokes that | - | ||||||||||||
183 | contain brushes as fills, not just solid | - | ||||||||||||
184 | colors (e.g. a dashed gradient line of | - | ||||||||||||
185 | width 2). | - | ||||||||||||
186 | \value ConicalGradientFill The engine supports conical gradient fills. | - | ||||||||||||
187 | \value ConstantOpacity The engine supports the feature provided by | - | ||||||||||||
188 | QPainter::setOpacity(). | - | ||||||||||||
189 | \value LinearGradientFill The engine supports linear gradient fills. | - | ||||||||||||
190 | \value MaskedBrush The engine is capable of rendering brushes that has a | - | ||||||||||||
191 | texture with an alpha channel or a mask. | - | ||||||||||||
192 | \value ObjectBoundingModeGradients The engine has native support for gradients | - | ||||||||||||
193 | with coordinate mode QGradient::ObjectBoundingMode. | - | ||||||||||||
194 | Otherwise, if QPaintEngine::PatternTransform is | - | ||||||||||||
195 | supported, object bounding mode gradients are | - | ||||||||||||
196 | converted to gradients with coordinate mode | - | ||||||||||||
197 | QGradient::LogicalMode and a brush transform for | - | ||||||||||||
198 | the coordinate mapping. | - | ||||||||||||
199 | \value PainterPaths The engine has path support. | - | ||||||||||||
200 | \value PaintOutsidePaintEvent The engine is capable of painting outside of | - | ||||||||||||
201 | paint events. | - | ||||||||||||
202 | \value PatternBrush The engine is capable of rendering brushes with | - | ||||||||||||
203 | the brush patterns specified in Qt::BrushStyle. | - | ||||||||||||
204 | \value PatternTransform The engine has support for transforming brush | - | ||||||||||||
205 | patterns. | - | ||||||||||||
206 | \value PerspectiveTransform The engine has support for performing perspective | - | ||||||||||||
207 | transformations on primitives. | - | ||||||||||||
208 | \value PixmapTransform The engine can transform pixmaps, including | - | ||||||||||||
209 | rotation and shearing. | - | ||||||||||||
210 | \value PorterDuff The engine supports Porter-Duff operations | - | ||||||||||||
211 | \value PrimitiveTransform The engine has support for transforming | - | ||||||||||||
212 | drawing primitives. | - | ||||||||||||
213 | \value RadialGradientFill The engine supports radial gradient fills. | - | ||||||||||||
214 | \value RasterOpModes The engine supports bitwise raster operations. | - | ||||||||||||
215 | \value AllFeatures All of the above features. This enum value is usually | - | ||||||||||||
216 | used as a bit mask. | - | ||||||||||||
217 | */ | - | ||||||||||||
218 | - | |||||||||||||
219 | /*! | - | ||||||||||||
220 | \enum QPaintEngine::PolygonDrawMode | - | ||||||||||||
221 | - | |||||||||||||
222 | \value OddEvenMode The polygon should be drawn using OddEven fill | - | ||||||||||||
223 | rule. | - | ||||||||||||
224 | - | |||||||||||||
225 | \value WindingMode The polygon should be drawn using Winding fill rule. | - | ||||||||||||
226 | - | |||||||||||||
227 | \value ConvexMode The polygon is a convex polygon and can be drawn | - | ||||||||||||
228 | using specialized algorithms where available. | - | ||||||||||||
229 | - | |||||||||||||
230 | \value PolylineMode Only the outline of the polygon should be | - | ||||||||||||
231 | drawn. | - | ||||||||||||
232 | - | |||||||||||||
233 | */ | - | ||||||||||||
234 | - | |||||||||||||
235 | /*! | - | ||||||||||||
236 | \enum QPaintEngine::DirtyFlag | - | ||||||||||||
237 | - | |||||||||||||
238 | \value DirtyPen The pen is dirty and needs to be updated. | - | ||||||||||||
239 | - | |||||||||||||
240 | \value DirtyBrush The brush is dirty and needs to be updated. | - | ||||||||||||
241 | - | |||||||||||||
242 | \value DirtyBrushOrigin The brush origin is dirty and needs to | - | ||||||||||||
243 | updated. | - | ||||||||||||
244 | - | |||||||||||||
245 | \value DirtyFont The font is dirty and needs to be updated. | - | ||||||||||||
246 | - | |||||||||||||
247 | \value DirtyBackground The background is dirty and needs to be | - | ||||||||||||
248 | updated. | - | ||||||||||||
249 | - | |||||||||||||
250 | \value DirtyBackgroundMode The background mode is dirty and needs | - | ||||||||||||
251 | to be updated. | - | ||||||||||||
252 | - | |||||||||||||
253 | \value DirtyTransform The transform is dirty and needs to be | - | ||||||||||||
254 | updated. | - | ||||||||||||
255 | - | |||||||||||||
256 | \value DirtyClipRegion The clip region is dirty and needs to be | - | ||||||||||||
257 | updated. | - | ||||||||||||
258 | - | |||||||||||||
259 | \value DirtyClipPath The clip path is dirty and needs to be | - | ||||||||||||
260 | updated. | - | ||||||||||||
261 | - | |||||||||||||
262 | \value DirtyHints The render hints is dirty and needs to be | - | ||||||||||||
263 | updated. | - | ||||||||||||
264 | - | |||||||||||||
265 | \value DirtyCompositionMode The composition mode is dirty and | - | ||||||||||||
266 | needs to be updated. | - | ||||||||||||
267 | - | |||||||||||||
268 | \value DirtyClipEnabled Whether clipping is enabled or not is | - | ||||||||||||
269 | dirty and needs to be updated. | - | ||||||||||||
270 | - | |||||||||||||
271 | \value DirtyOpacity The constant opacity has changed and needs to | - | ||||||||||||
272 | be updated as part of the state change in | - | ||||||||||||
273 | QPaintEngine::updateState(). | - | ||||||||||||
274 | - | |||||||||||||
275 | \value AllDirty Convenience enum used internally. | - | ||||||||||||
276 | - | |||||||||||||
277 | These types are used by QPainter to trigger lazy updates of the | - | ||||||||||||
278 | various states in the QPaintEngine using | - | ||||||||||||
279 | QPaintEngine::updateState(). | - | ||||||||||||
280 | - | |||||||||||||
281 | A paint engine must update every dirty state. | - | ||||||||||||
282 | */ | - | ||||||||||||
283 | - | |||||||||||||
284 | /*! | - | ||||||||||||
285 | \fn void QPaintEngine::syncState() | - | ||||||||||||
286 | - | |||||||||||||
287 | \internal | - | ||||||||||||
288 | - | |||||||||||||
289 | Updates all dirty states in this engine. This function should ONLY | - | ||||||||||||
290 | be used when drawing with native handles directly and immediate sync | - | ||||||||||||
291 | from QPainters state to the native state is required. | - | ||||||||||||
292 | */ | - | ||||||||||||
293 | void QPaintEngine::syncState() | - | ||||||||||||
294 | { | - | ||||||||||||
295 | Q_ASSERT(state); | - | ||||||||||||
296 | updateState(*state); | - | ||||||||||||
297 | - | |||||||||||||
298 | if (isExtended())
| 0 | ||||||||||||
299 | static_cast<QPaintEngineEx *>(this)->sync(); never executed: static_cast<QPaintEngineEx *>(this)->sync(); | 0 | ||||||||||||
300 | } never executed: end of block | 0 | ||||||||||||
301 | - | |||||||||||||
302 | static QPaintEngine *qt_polygon_recursion = 0; | - | ||||||||||||
303 | struct QT_Point { | - | ||||||||||||
304 | int x; | - | ||||||||||||
305 | int y; | - | ||||||||||||
306 | }; | - | ||||||||||||
307 | - | |||||||||||||
308 | /*! | - | ||||||||||||
309 | \fn void QPaintEngine::drawPolygon(const QPointF *points, int pointCount, | - | ||||||||||||
310 | PolygonDrawMode mode) | - | ||||||||||||
311 | - | |||||||||||||
312 | Reimplement this virtual function to draw the polygon defined | - | ||||||||||||
313 | by the \a pointCount first points in \a points, using mode \a | - | ||||||||||||
314 | mode. | - | ||||||||||||
315 | - | |||||||||||||
316 | \note At least one of the drawPolygon() functions must be reimplemented. | - | ||||||||||||
317 | */ | - | ||||||||||||
318 | void QPaintEngine::drawPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode) | - | ||||||||||||
319 | { | - | ||||||||||||
320 | Q_ASSERT_X(qt_polygon_recursion != this, "QPaintEngine::drawPolygon", | - | ||||||||||||
321 | "At least one drawPolygon function must be implemented"); | - | ||||||||||||
322 | qt_polygon_recursion = this; | - | ||||||||||||
323 | Q_ASSERT(sizeof(QT_Point) == sizeof(QPoint)); | - | ||||||||||||
324 | QVarLengthArray<QT_Point> p(pointCount); | - | ||||||||||||
325 | for (int i = 0; i < pointCount; ++i) {
| 0 | ||||||||||||
326 | p[i].x = qRound(points[i].x()); | - | ||||||||||||
327 | p[i].y = qRound(points[i].y()); | - | ||||||||||||
328 | } never executed: end of block | 0 | ||||||||||||
329 | drawPolygon((QPoint *)p.data(), pointCount, mode); | - | ||||||||||||
330 | qt_polygon_recursion = 0; | - | ||||||||||||
331 | } never executed: end of block | 0 | ||||||||||||
332 | - | |||||||||||||
333 | struct QT_PointF { | - | ||||||||||||
334 | qreal x; | - | ||||||||||||
335 | qreal y; | - | ||||||||||||
336 | }; | - | ||||||||||||
337 | /*! | - | ||||||||||||
338 | \overload | - | ||||||||||||
339 | - | |||||||||||||
340 | Reimplement this virtual function to draw the polygon defined by the | - | ||||||||||||
341 | \a pointCount first points in \a points, using mode \a mode. | - | ||||||||||||
342 | - | |||||||||||||
343 | \note At least one of the drawPolygon() functions must be reimplemented. | - | ||||||||||||
344 | */ | - | ||||||||||||
345 | void QPaintEngine::drawPolygon(const QPoint *points, int pointCount, PolygonDrawMode mode) | - | ||||||||||||
346 | { | - | ||||||||||||
347 | Q_ASSERT_X(qt_polygon_recursion != this, "QPaintEngine::drawPolygon", | - | ||||||||||||
348 | "At least one drawPolygon function must be implemented"); | - | ||||||||||||
349 | qt_polygon_recursion = this; | - | ||||||||||||
350 | Q_ASSERT(sizeof(QT_PointF) == sizeof(QPointF)); | - | ||||||||||||
351 | QVarLengthArray<QT_PointF> p(pointCount); | - | ||||||||||||
352 | for (int i=0; i<pointCount; ++i) {
| 0 | ||||||||||||
353 | p[i].x = points[i].x(); | - | ||||||||||||
354 | p[i].y = points[i].y(); | - | ||||||||||||
355 | } never executed: end of block | 0 | ||||||||||||
356 | drawPolygon((QPointF *)p.data(), pointCount, mode); | - | ||||||||||||
357 | qt_polygon_recursion = 0; | - | ||||||||||||
358 | } never executed: end of block | 0 | ||||||||||||
359 | - | |||||||||||||
360 | /*! | - | ||||||||||||
361 | \enum QPaintEngine::Type | - | ||||||||||||
362 | - | |||||||||||||
363 | \value X11 | - | ||||||||||||
364 | \value Windows | - | ||||||||||||
365 | \value MacPrinter | - | ||||||||||||
366 | \value CoreGraphics \macos's Quartz2D (CoreGraphics) | - | ||||||||||||
367 | \value QuickDraw \macos's QuickDraw | - | ||||||||||||
368 | \value QWindowSystem Qt for Embedded Linux | - | ||||||||||||
369 | \value PostScript (No longer supported) | - | ||||||||||||
370 | \value OpenGL | - | ||||||||||||
371 | \value Picture QPicture format | - | ||||||||||||
372 | \value SVG Scalable Vector Graphics XML format | - | ||||||||||||
373 | \value Raster | - | ||||||||||||
374 | \value Direct3D Windows only, Direct3D based engine | - | ||||||||||||
375 | \value Pdf Portable Document Format | - | ||||||||||||
376 | \value OpenVG | - | ||||||||||||
377 | \value User First user type ID | - | ||||||||||||
378 | \value MaxUser Last user type ID | - | ||||||||||||
379 | \value OpenGL2 | - | ||||||||||||
380 | \value PaintBuffer | - | ||||||||||||
381 | \value Blitter | - | ||||||||||||
382 | \value Direct2D Windows only, Direct2D based engine | - | ||||||||||||
383 | */ | - | ||||||||||||
384 | - | |||||||||||||
385 | /*! | - | ||||||||||||
386 | \fn bool QPaintEngine::isActive() const | - | ||||||||||||
387 | - | |||||||||||||
388 | Returns \c true if the paint engine is actively drawing; otherwise | - | ||||||||||||
389 | returns \c false. | - | ||||||||||||
390 | - | |||||||||||||
391 | \sa setActive() | - | ||||||||||||
392 | */ | - | ||||||||||||
393 | - | |||||||||||||
394 | /*! | - | ||||||||||||
395 | \fn void QPaintEngine::setActive(bool state) | - | ||||||||||||
396 | - | |||||||||||||
397 | Sets the active state of the paint engine to \a state. | - | ||||||||||||
398 | - | |||||||||||||
399 | \sa isActive() | - | ||||||||||||
400 | */ | - | ||||||||||||
401 | - | |||||||||||||
402 | /*! | - | ||||||||||||
403 | \fn bool QPaintEngine::begin(QPaintDevice *pdev) | - | ||||||||||||
404 | - | |||||||||||||
405 | Reimplement this function to initialise your paint engine when | - | ||||||||||||
406 | painting is to start on the paint device \a pdev. Return true if | - | ||||||||||||
407 | the initialization was successful; otherwise return false. | - | ||||||||||||
408 | - | |||||||||||||
409 | \sa end(), isActive() | - | ||||||||||||
410 | */ | - | ||||||||||||
411 | - | |||||||||||||
412 | /*! | - | ||||||||||||
413 | \fn bool QPaintEngine::end() | - | ||||||||||||
414 | - | |||||||||||||
415 | Reimplement this function to finish painting on the current paint | - | ||||||||||||
416 | device. Return true if painting was finished successfully; | - | ||||||||||||
417 | otherwise return false. | - | ||||||||||||
418 | - | |||||||||||||
419 | \sa begin(), isActive() | - | ||||||||||||
420 | */ | - | ||||||||||||
421 | - | |||||||||||||
422 | - | |||||||||||||
423 | /*! | - | ||||||||||||
424 | Draws the first \a pointCount points in the buffer \a points | - | ||||||||||||
425 | */ | - | ||||||||||||
426 | void QPaintEngine::drawPoints(const QPointF *points, int pointCount) | - | ||||||||||||
427 | { | - | ||||||||||||
428 | QPainter *p = painter(); | - | ||||||||||||
429 | if (!p)
| 0 | ||||||||||||
430 | return; never executed: return; | 0 | ||||||||||||
431 | - | |||||||||||||
432 | qreal penWidth = p->pen().widthF(); | - | ||||||||||||
433 | if (penWidth == 0)
| 0 | ||||||||||||
434 | penWidth = 1; never executed: penWidth = 1; | 0 | ||||||||||||
435 | - | |||||||||||||
436 | bool ellipses = p->pen().capStyle() == Qt::RoundCap; | - | ||||||||||||
437 | - | |||||||||||||
438 | p->save(); | - | ||||||||||||
439 | - | |||||||||||||
440 | QTransform transform; | - | ||||||||||||
441 | if (qt_pen_is_cosmetic(p->pen(), p->renderHints())) {
| 0 | ||||||||||||
442 | transform = p->transform(); | - | ||||||||||||
443 | p->setTransform(QTransform()); | - | ||||||||||||
444 | } never executed: end of block | 0 | ||||||||||||
445 | - | |||||||||||||
446 | p->setBrush(p->pen().brush()); | - | ||||||||||||
447 | p->setPen(Qt::NoPen); | - | ||||||||||||
448 | - | |||||||||||||
449 | for (int i=0; i<pointCount; ++i) {
| 0 | ||||||||||||
450 | QPointF pos = transform.map(points[i]); | - | ||||||||||||
451 | QRectF rect(pos.x() - penWidth / 2, pos.y() - penWidth / 2, penWidth, penWidth); | - | ||||||||||||
452 | - | |||||||||||||
453 | if (ellipses)
| 0 | ||||||||||||
454 | p->drawEllipse(rect); never executed: p->drawEllipse(rect); | 0 | ||||||||||||
455 | else | - | ||||||||||||
456 | p->drawRect(rect); never executed: p->drawRect(rect); | 0 | ||||||||||||
457 | } | - | ||||||||||||
458 | - | |||||||||||||
459 | p->restore(); | - | ||||||||||||
460 | } never executed: end of block | 0 | ||||||||||||
461 | - | |||||||||||||
462 | - | |||||||||||||
463 | /*! | - | ||||||||||||
464 | Draws the first \a pointCount points in the buffer \a points | - | ||||||||||||
465 | - | |||||||||||||
466 | The default implementation converts the first \a pointCount QPoints in \a points | - | ||||||||||||
467 | to QPointFs and calls the floating point version of drawPoints. | - | ||||||||||||
468 | - | |||||||||||||
469 | */ | - | ||||||||||||
470 | void QPaintEngine::drawPoints(const QPoint *points, int pointCount) | - | ||||||||||||
471 | { | - | ||||||||||||
472 | Q_ASSERT(sizeof(QT_PointF) == sizeof(QPointF)); | - | ||||||||||||
473 | QT_PointF fp[256]; | - | ||||||||||||
474 | while (pointCount) {
| 0 | ||||||||||||
475 | int i = 0; | - | ||||||||||||
476 | while (i < pointCount && i < 256) {
| 0 | ||||||||||||
477 | fp[i].x = points[i].x(); | - | ||||||||||||
478 | fp[i].y = points[i].y(); | - | ||||||||||||
479 | ++i; | - | ||||||||||||
480 | } never executed: end of block | 0 | ||||||||||||
481 | drawPoints((QPointF *)(void *)fp, i); | - | ||||||||||||
482 | points += i; | - | ||||||||||||
483 | pointCount -= i; | - | ||||||||||||
484 | } never executed: end of block | 0 | ||||||||||||
485 | } never executed: end of block | 0 | ||||||||||||
486 | - | |||||||||||||
487 | /*! | - | ||||||||||||
488 | \fn void QPaintEngine::drawEllipse(const QRectF &rect) | - | ||||||||||||
489 | - | |||||||||||||
490 | Reimplement this function to draw the largest ellipse that can be | - | ||||||||||||
491 | contained within rectangle \a rect. | - | ||||||||||||
492 | - | |||||||||||||
493 | The default implementation calls drawPolygon(). | - | ||||||||||||
494 | */ | - | ||||||||||||
495 | void QPaintEngine::drawEllipse(const QRectF &rect) | - | ||||||||||||
496 | { | - | ||||||||||||
497 | QPainterPath path; | - | ||||||||||||
498 | path.addEllipse(rect); | - | ||||||||||||
499 | if (hasFeature(PainterPaths)) {
| 0 | ||||||||||||
500 | drawPath(path); | - | ||||||||||||
501 | } else { never executed: end of block | 0 | ||||||||||||
502 | QPolygonF polygon = path.toFillPolygon(); | - | ||||||||||||
503 | drawPolygon(polygon.data(), polygon.size(), ConvexMode); | - | ||||||||||||
504 | } never executed: end of block | 0 | ||||||||||||
505 | } | - | ||||||||||||
506 | - | |||||||||||||
507 | /*! | - | ||||||||||||
508 | The default implementation of this function calls the floating | - | ||||||||||||
509 | point version of this function | - | ||||||||||||
510 | */ | - | ||||||||||||
511 | void QPaintEngine::drawEllipse(const QRect &rect) | - | ||||||||||||
512 | { | - | ||||||||||||
513 | drawEllipse(QRectF(rect)); | - | ||||||||||||
514 | } never executed: end of block | 0 | ||||||||||||
515 | - | |||||||||||||
516 | /*! | - | ||||||||||||
517 | \fn void QPaintEngine::drawPixmap(const QRectF &r, const QPixmap | - | ||||||||||||
518 | &pm, const QRectF &sr) | - | ||||||||||||
519 | - | |||||||||||||
520 | Reimplement this function to draw the part of the \a pm | - | ||||||||||||
521 | specified by the \a sr rectangle in the given \a r. | - | ||||||||||||
522 | */ | - | ||||||||||||
523 | - | |||||||||||||
524 | - | |||||||||||||
525 | void qt_fill_tile(QPixmap *tile, const QPixmap &pixmap) | - | ||||||||||||
526 | { | - | ||||||||||||
527 | QPainter p(tile); | - | ||||||||||||
528 | p.drawPixmap(0, 0, pixmap); | - | ||||||||||||
529 | int x = pixmap.width(); | - | ||||||||||||
530 | while (x < tile->width()) {
| 0 | ||||||||||||
531 | p.drawPixmap(x, 0, *tile, 0, 0, x, pixmap.height()); | - | ||||||||||||
532 | x *= 2; | - | ||||||||||||
533 | } never executed: end of block | 0 | ||||||||||||
534 | int y = pixmap.height(); | - | ||||||||||||
535 | while (y < tile->height()) {
| 0 | ||||||||||||
536 | p.drawPixmap(0, y, *tile, 0, 0, tile->width(), y); | - | ||||||||||||
537 | y *= 2; | - | ||||||||||||
538 | } never executed: end of block | 0 | ||||||||||||
539 | } never executed: end of block | 0 | ||||||||||||
540 | - | |||||||||||||
541 | void qt_draw_tile(QPaintEngine *gc, qreal x, qreal y, qreal w, qreal h, | - | ||||||||||||
542 | const QPixmap &pixmap, qreal xOffset, qreal yOffset) | - | ||||||||||||
543 | { | - | ||||||||||||
544 | qreal yPos, xPos, drawH, drawW, yOff, xOff; | - | ||||||||||||
545 | yPos = y; | - | ||||||||||||
546 | yOff = yOffset; | - | ||||||||||||
547 | while(yPos < y + h) {
| 0 | ||||||||||||
548 | drawH = pixmap.height() - yOff; // Cropping first row | - | ||||||||||||
549 | if (yPos + drawH > y + h) // Cropping last row
| 0 | ||||||||||||
550 | drawH = y + h - yPos; never executed: drawH = y + h - yPos; | 0 | ||||||||||||
551 | xPos = x; | - | ||||||||||||
552 | xOff = xOffset; | - | ||||||||||||
553 | while(xPos < x + w) {
| 0 | ||||||||||||
554 | drawW = pixmap.width() - xOff; // Cropping first column | - | ||||||||||||
555 | if (xPos + drawW > x + w) // Cropping last column
| 0 | ||||||||||||
556 | drawW = x + w - xPos; never executed: drawW = x + w - xPos; | 0 | ||||||||||||
557 | if (drawW > 0 && drawH > 0)
| 0 | ||||||||||||
558 | gc->drawPixmap(QRectF(xPos, yPos, drawW, drawH), pixmap, QRectF(xOff, yOff, drawW, drawH)); never executed: gc->drawPixmap(QRectF(xPos, yPos, drawW, drawH), pixmap, QRectF(xOff, yOff, drawW, drawH)); | 0 | ||||||||||||
559 | xPos += drawW; | - | ||||||||||||
560 | xOff = 0; | - | ||||||||||||
561 | } never executed: end of block | 0 | ||||||||||||
562 | yPos += drawH; | - | ||||||||||||
563 | yOff = 0; | - | ||||||||||||
564 | } never executed: end of block | 0 | ||||||||||||
565 | } never executed: end of block | 0 | ||||||||||||
566 | - | |||||||||||||
567 | - | |||||||||||||
568 | /*! | - | ||||||||||||
569 | Reimplement this function to draw the \a pixmap in the given \a | - | ||||||||||||
570 | rect, starting at the given \a p. The pixmap will be | - | ||||||||||||
571 | drawn repeatedly until the \a rect is filled. | - | ||||||||||||
572 | */ | - | ||||||||||||
573 | void QPaintEngine::drawTiledPixmap(const QRectF &rect, const QPixmap &pixmap, const QPointF &p) | - | ||||||||||||
574 | { | - | ||||||||||||
575 | int sw = pixmap.width(); | - | ||||||||||||
576 | int sh = pixmap.height(); | - | ||||||||||||
577 | - | |||||||||||||
578 | if (sw*sh < 8192 && sw*sh < 16*rect.width()*rect.height()) {
| 0 | ||||||||||||
579 | int tw = sw, th = sh; | - | ||||||||||||
580 | while (tw*th < 32678 && tw < rect.width()/2)
| 0 | ||||||||||||
581 | tw *= 2; never executed: tw *= 2; | 0 | ||||||||||||
582 | while (tw*th < 32678 && th < rect.height()/2)
| 0 | ||||||||||||
583 | th *= 2; never executed: th *= 2; | 0 | ||||||||||||
584 | QPixmap tile; | - | ||||||||||||
585 | if (pixmap.depth() == 1) {
| 0 | ||||||||||||
586 | tile = QBitmap(tw, th); | - | ||||||||||||
587 | } else { never executed: end of block | 0 | ||||||||||||
588 | tile = QPixmap(tw, th); | - | ||||||||||||
589 | if (pixmap.hasAlphaChannel())
| 0 | ||||||||||||
590 | tile.fill(Qt::transparent); never executed: tile.fill(Qt::transparent); | 0 | ||||||||||||
591 | } never executed: end of block | 0 | ||||||||||||
592 | qt_fill_tile(&tile, pixmap); | - | ||||||||||||
593 | qt_draw_tile(this, rect.x(), rect.y(), rect.width(), rect.height(), tile, p.x(), p.y()); | - | ||||||||||||
594 | } else { never executed: end of block | 0 | ||||||||||||
595 | qt_draw_tile(this, rect.x(), rect.y(), rect.width(), rect.height(), pixmap, p.x(), p.y()); | - | ||||||||||||
596 | } never executed: end of block | 0 | ||||||||||||
597 | } | - | ||||||||||||
598 | - | |||||||||||||
599 | /*! | - | ||||||||||||
600 | \fn void QPaintEngine::drawImage(const QRectF &rectangle, const QImage | - | ||||||||||||
601 | &image, const QRectF &sr, Qt::ImageConversionFlags flags) | - | ||||||||||||
602 | - | |||||||||||||
603 | Reimplement this function to draw the part of the \a image | - | ||||||||||||
604 | specified by the \a sr rectangle in the given \a rectangle using | - | ||||||||||||
605 | the given conversion flags \a flags, to convert it to a pixmap. | - | ||||||||||||
606 | */ | - | ||||||||||||
607 | - | |||||||||||||
608 | void QPaintEngine::drawImage(const QRectF &r, const QImage &image, const QRectF &sr, | - | ||||||||||||
609 | Qt::ImageConversionFlags flags) | - | ||||||||||||
610 | { | - | ||||||||||||
611 | QRectF baseSize(0, 0, image.width(), image.height()); | - | ||||||||||||
612 | QImage im = image; | - | ||||||||||||
613 | if (baseSize != sr)
| 0 | ||||||||||||
614 | im = im.copy(qFloor(sr.x()), qFloor(sr.y()), never executed: im = im.copy(qFloor(sr.x()), qFloor(sr.y()), qCeil(sr.width()), qCeil(sr.height())); | 0 | ||||||||||||
615 | qCeil(sr.width()), qCeil(sr.height())); never executed: im = im.copy(qFloor(sr.x()), qFloor(sr.y()), qCeil(sr.width()), qCeil(sr.height())); | 0 | ||||||||||||
616 | QPixmap pm = QPixmap::fromImage(im, flags); | - | ||||||||||||
617 | drawPixmap(r, pm, QRectF(QPointF(0, 0), pm.size())); | - | ||||||||||||
618 | } never executed: end of block | 0 | ||||||||||||
619 | - | |||||||||||||
620 | /*! | - | ||||||||||||
621 | \fn Type QPaintEngine::type() const | - | ||||||||||||
622 | - | |||||||||||||
623 | Reimplement this function to return the paint engine \l{Type}. | - | ||||||||||||
624 | */ | - | ||||||||||||
625 | - | |||||||||||||
626 | /*! | - | ||||||||||||
627 | \fn void QPaintEngine::fix_neg_rect(int *x, int *y, int *w, int *h); | - | ||||||||||||
628 | - | |||||||||||||
629 | \internal | - | ||||||||||||
630 | */ | - | ||||||||||||
631 | - | |||||||||||||
632 | /*! | - | ||||||||||||
633 | \fn bool QPaintEngine::testDirty(DirtyFlags df) | - | ||||||||||||
634 | - | |||||||||||||
635 | \internal | - | ||||||||||||
636 | */ | - | ||||||||||||
637 | - | |||||||||||||
638 | /*! | - | ||||||||||||
639 | \fn void QPaintEngine::clearDirty(DirtyFlags df) | - | ||||||||||||
640 | - | |||||||||||||
641 | \internal | - | ||||||||||||
642 | */ | - | ||||||||||||
643 | - | |||||||||||||
644 | /*! | - | ||||||||||||
645 | \fn void QPaintEngine::setDirty(DirtyFlags df) | - | ||||||||||||
646 | - | |||||||||||||
647 | \internal | - | ||||||||||||
648 | */ | - | ||||||||||||
649 | - | |||||||||||||
650 | /*! | - | ||||||||||||
651 | \fn bool QPaintEngine::hasFeature(PaintEngineFeatures feature) const | - | ||||||||||||
652 | - | |||||||||||||
653 | Returns \c true if the paint engine supports the specified \a | - | ||||||||||||
654 | feature; otherwise returns \c false. | - | ||||||||||||
655 | */ | - | ||||||||||||
656 | - | |||||||||||||
657 | /*! | - | ||||||||||||
658 | \fn bool QPaintEngine::isExtended() const | - | ||||||||||||
659 | - | |||||||||||||
660 | \internal | - | ||||||||||||
661 | - | |||||||||||||
662 | Returns \c true if the paint engine is a QPaintEngineEx derivative. | - | ||||||||||||
663 | */ | - | ||||||||||||
664 | - | |||||||||||||
665 | /*! | - | ||||||||||||
666 | \fn void QPaintEngine::updateState(const QPaintEngineState &state) | - | ||||||||||||
667 | - | |||||||||||||
668 | Reimplement this function to update the state of a paint engine. | - | ||||||||||||
669 | - | |||||||||||||
670 | When implemented, this function is responsible for checking the | - | ||||||||||||
671 | paint engine's current \a state and update the properties that are | - | ||||||||||||
672 | changed. Use the QPaintEngineState::state() function to find out | - | ||||||||||||
673 | which properties that must be updated, then use the corresponding | - | ||||||||||||
674 | \l {GetFunction}{get function} to retrieve the current values for | - | ||||||||||||
675 | the given properties. | - | ||||||||||||
676 | - | |||||||||||||
677 | \sa QPaintEngineState | - | ||||||||||||
678 | */ | - | ||||||||||||
679 | - | |||||||||||||
680 | /*! | - | ||||||||||||
681 | Creates a paint engine with the featureset specified by \a caps. | - | ||||||||||||
682 | */ | - | ||||||||||||
683 | - | |||||||||||||
684 | QPaintEngine::QPaintEngine(PaintEngineFeatures caps) | - | ||||||||||||
685 | : state(0), | - | ||||||||||||
686 | gccaps(caps), | - | ||||||||||||
687 | active(0), | - | ||||||||||||
688 | selfDestruct(false), | - | ||||||||||||
689 | extended(false), | - | ||||||||||||
690 | d_ptr(new QPaintEnginePrivate) | - | ||||||||||||
691 | { | - | ||||||||||||
692 | d_ptr->q_ptr = this; | - | ||||||||||||
693 | } never executed: end of block | 0 | ||||||||||||
694 | - | |||||||||||||
695 | /*! | - | ||||||||||||
696 | \internal | - | ||||||||||||
697 | */ | - | ||||||||||||
698 | - | |||||||||||||
699 | QPaintEngine::QPaintEngine(QPaintEnginePrivate &dptr, PaintEngineFeatures caps) | - | ||||||||||||
700 | : state(0), | - | ||||||||||||
701 | gccaps(caps), | - | ||||||||||||
702 | active(0), | - | ||||||||||||
703 | selfDestruct(false), | - | ||||||||||||
704 | extended(false), | - | ||||||||||||
705 | d_ptr(&dptr) | - | ||||||||||||
706 | { | - | ||||||||||||
707 | d_ptr->q_ptr = this; | - | ||||||||||||
708 | } never executed: end of block | 0 | ||||||||||||
709 | - | |||||||||||||
710 | /*! | - | ||||||||||||
711 | Destroys the paint engine. | - | ||||||||||||
712 | */ | - | ||||||||||||
713 | QPaintEngine::~QPaintEngine() | - | ||||||||||||
714 | { | - | ||||||||||||
715 | } | - | ||||||||||||
716 | - | |||||||||||||
717 | /*! | - | ||||||||||||
718 | Returns the paint engine's painter. | - | ||||||||||||
719 | */ | - | ||||||||||||
720 | QPainter *QPaintEngine::painter() const | - | ||||||||||||
721 | { | - | ||||||||||||
722 | return state ? state->painter() : 0; never executed: return state ? state->painter() : 0;
| 0 | ||||||||||||
723 | } | - | ||||||||||||
724 | - | |||||||||||||
725 | /*! | - | ||||||||||||
726 | The default implementation ignores the \a path and does nothing. | - | ||||||||||||
727 | */ | - | ||||||||||||
728 | - | |||||||||||||
729 | void QPaintEngine::drawPath(const QPainterPath &) | - | ||||||||||||
730 | { | - | ||||||||||||
731 | if (hasFeature(PainterPaths)) {
| 0 | ||||||||||||
732 | qWarning("QPaintEngine::drawPath: Must be implemented when feature PainterPaths is set"); | - | ||||||||||||
733 | } never executed: end of block | 0 | ||||||||||||
734 | } never executed: end of block | 0 | ||||||||||||
735 | - | |||||||||||||
736 | /*! | - | ||||||||||||
737 | This function draws the text item \a textItem at position \a p. The | - | ||||||||||||
738 | default implementation of this function converts the text to a | - | ||||||||||||
739 | QPainterPath and paints the resulting path. | - | ||||||||||||
740 | */ | - | ||||||||||||
741 | - | |||||||||||||
742 | void QPaintEngine::drawTextItem(const QPointF &p, const QTextItem &textItem) | - | ||||||||||||
743 | { | - | ||||||||||||
744 | const QTextItemInt &ti = static_cast<const QTextItemInt &>(textItem); | - | ||||||||||||
745 | - | |||||||||||||
746 | QPainterPath path; | - | ||||||||||||
747 | path.setFillRule(Qt::WindingFill); | - | ||||||||||||
748 | if (ti.glyphs.numGlyphs)
| 0 | ||||||||||||
749 | ti.fontEngine->addOutlineToPath(0, 0, ti.glyphs, &path, ti.flags); never executed: ti.fontEngine->addOutlineToPath(0, 0, ti.glyphs, &path, ti.flags); | 0 | ||||||||||||
750 | if (!path.isEmpty()) {
| 0 | ||||||||||||
751 | painter()->save(); | - | ||||||||||||
752 | painter()->setRenderHint(QPainter::Antialiasing, | - | ||||||||||||
753 | bool((painter()->renderHints() & QPainter::TextAntialiasing) | - | ||||||||||||
754 | && !(painter()->font().styleStrategy() & QFont::NoAntialias))); | - | ||||||||||||
755 | painter()->translate(p.x(), p.y()); | - | ||||||||||||
756 | painter()->fillPath(path, painter()->pen().brush()); | - | ||||||||||||
757 | painter()->restore(); | - | ||||||||||||
758 | } never executed: end of block | 0 | ||||||||||||
759 | } never executed: end of block | 0 | ||||||||||||
760 | - | |||||||||||||
761 | /*! | - | ||||||||||||
762 | The default implementation splits the list of lines in \a lines | - | ||||||||||||
763 | into \a lineCount separate calls to drawPath() or drawPolygon() | - | ||||||||||||
764 | depending on the feature set of the paint engine. | - | ||||||||||||
765 | */ | - | ||||||||||||
766 | void QPaintEngine::drawLines(const QLineF *lines, int lineCount) | - | ||||||||||||
767 | { | - | ||||||||||||
768 | for (int i=0; i<lineCount; ++i) {
| 0 | ||||||||||||
769 | QPointF pts[2] = { lines[i].p1(), lines[i].p2() }; | - | ||||||||||||
770 | - | |||||||||||||
771 | if (pts[0] == pts[1]) {
| 0 | ||||||||||||
772 | if (state->pen().capStyle() != Qt::FlatCap)
| 0 | ||||||||||||
773 | drawPoints(pts, 1); never executed: drawPoints(pts, 1); | 0 | ||||||||||||
774 | continue; never executed: continue; | 0 | ||||||||||||
775 | } | - | ||||||||||||
776 | - | |||||||||||||
777 | drawPolygon(pts, 2, PolylineMode); | - | ||||||||||||
778 | } never executed: end of block | 0 | ||||||||||||
779 | } never executed: end of block | 0 | ||||||||||||
780 | - | |||||||||||||
781 | /*! | - | ||||||||||||
782 | \overload | - | ||||||||||||
783 | - | |||||||||||||
784 | The default implementation converts the first \a lineCount lines | - | ||||||||||||
785 | in \a lines to a QLineF and calls the floating point version of | - | ||||||||||||
786 | this function. | - | ||||||||||||
787 | */ | - | ||||||||||||
788 | void QPaintEngine::drawLines(const QLine *lines, int lineCount) | - | ||||||||||||
789 | { | - | ||||||||||||
790 | struct PointF { | - | ||||||||||||
791 | qreal x; | - | ||||||||||||
792 | qreal y; | - | ||||||||||||
793 | }; | - | ||||||||||||
794 | struct LineF { | - | ||||||||||||
795 | PointF p1; | - | ||||||||||||
796 | PointF p2; | - | ||||||||||||
797 | }; | - | ||||||||||||
798 | Q_ASSERT(sizeof(PointF) == sizeof(QPointF)); | - | ||||||||||||
799 | Q_ASSERT(sizeof(LineF) == sizeof(QLineF)); | - | ||||||||||||
800 | LineF fl[256]; | - | ||||||||||||
801 | while (lineCount) {
| 0 | ||||||||||||
802 | int i = 0; | - | ||||||||||||
803 | while (i < lineCount && i < 256) {
| 0 | ||||||||||||
804 | fl[i].p1.x = lines[i].x1(); | - | ||||||||||||
805 | fl[i].p1.y = lines[i].y1(); | - | ||||||||||||
806 | fl[i].p2.x = lines[i].x2(); | - | ||||||||||||
807 | fl[i].p2.y = lines[i].y2(); | - | ||||||||||||
808 | ++i; | - | ||||||||||||
809 | } never executed: end of block | 0 | ||||||||||||
810 | drawLines((QLineF *)(void *)fl, i); | - | ||||||||||||
811 | lines += i; | - | ||||||||||||
812 | lineCount -= i; | - | ||||||||||||
813 | } never executed: end of block | 0 | ||||||||||||
814 | } never executed: end of block | 0 | ||||||||||||
815 | - | |||||||||||||
816 | - | |||||||||||||
817 | /*! | - | ||||||||||||
818 | \overload | - | ||||||||||||
819 | - | |||||||||||||
820 | The default implementation converts the first \a rectCount | - | ||||||||||||
821 | rectangles in the buffer \a rects to a QRectF and calls the | - | ||||||||||||
822 | floating point version of this function. | - | ||||||||||||
823 | */ | - | ||||||||||||
824 | void QPaintEngine::drawRects(const QRect *rects, int rectCount) | - | ||||||||||||
825 | { | - | ||||||||||||
826 | struct RectF { | - | ||||||||||||
827 | qreal x; | - | ||||||||||||
828 | qreal y; | - | ||||||||||||
829 | qreal w; | - | ||||||||||||
830 | qreal h; | - | ||||||||||||
831 | }; | - | ||||||||||||
832 | Q_ASSERT(sizeof(RectF) == sizeof(QRectF)); | - | ||||||||||||
833 | RectF fr[256]; | - | ||||||||||||
834 | while (rectCount) {
| 0 | ||||||||||||
835 | int i = 0; | - | ||||||||||||
836 | while (i < rectCount && i < 256) {
| 0 | ||||||||||||
837 | fr[i].x = rects[i].x(); | - | ||||||||||||
838 | fr[i].y = rects[i].y(); | - | ||||||||||||
839 | fr[i].w = rects[i].width(); | - | ||||||||||||
840 | fr[i].h = rects[i].height(); | - | ||||||||||||
841 | ++i; | - | ||||||||||||
842 | } never executed: end of block | 0 | ||||||||||||
843 | drawRects((QRectF *)(void *)fr, i); | - | ||||||||||||
844 | rects += i; | - | ||||||||||||
845 | rectCount -= i; | - | ||||||||||||
846 | } never executed: end of block | 0 | ||||||||||||
847 | } never executed: end of block | 0 | ||||||||||||
848 | - | |||||||||||||
849 | /*! | - | ||||||||||||
850 | Draws the first \a rectCount rectangles in the buffer \a | - | ||||||||||||
851 | rects. The default implementation of this function calls drawPath() | - | ||||||||||||
852 | or drawPolygon() depending on the feature set of the paint engine. | - | ||||||||||||
853 | */ | - | ||||||||||||
854 | void QPaintEngine::drawRects(const QRectF *rects, int rectCount) | - | ||||||||||||
855 | { | - | ||||||||||||
856 | if (hasFeature(PainterPaths) &&
| 0 | ||||||||||||
857 | !state->penNeedsResolving() &&
| 0 | ||||||||||||
858 | !state->brushNeedsResolving()) {
| 0 | ||||||||||||
859 | for (int i=0; i<rectCount; ++i) {
| 0 | ||||||||||||
860 | QPainterPath path; | - | ||||||||||||
861 | path.addRect(rects[i]); | - | ||||||||||||
862 | if (path.isEmpty())
| 0 | ||||||||||||
863 | continue; never executed: continue; | 0 | ||||||||||||
864 | drawPath(path); | - | ||||||||||||
865 | } never executed: end of block | 0 | ||||||||||||
866 | } else { never executed: end of block | 0 | ||||||||||||
867 | for (int i=0; i<rectCount; ++i) {
| 0 | ||||||||||||
868 | QRectF rf = rects[i]; | - | ||||||||||||
869 | QPointF pts[4] = { QPointF(rf.x(), rf.y()), | - | ||||||||||||
870 | QPointF(rf.x() + rf.width(), rf.y()), | - | ||||||||||||
871 | QPointF(rf.x() + rf.width(), rf.y() + rf.height()), | - | ||||||||||||
872 | QPointF(rf.x(), rf.y() + rf.height()) }; | - | ||||||||||||
873 | drawPolygon(pts, 4, ConvexMode); | - | ||||||||||||
874 | } never executed: end of block | 0 | ||||||||||||
875 | } never executed: end of block | 0 | ||||||||||||
876 | } | - | ||||||||||||
877 | - | |||||||||||||
878 | /*! | - | ||||||||||||
879 | \internal | - | ||||||||||||
880 | Sets the paintdevice that this engine operates on to \a device | - | ||||||||||||
881 | */ | - | ||||||||||||
882 | void QPaintEngine::setPaintDevice(QPaintDevice *device) | - | ||||||||||||
883 | { | - | ||||||||||||
884 | d_func()->pdev = device; | - | ||||||||||||
885 | } never executed: end of block | 0 | ||||||||||||
886 | - | |||||||||||||
887 | /*! | - | ||||||||||||
888 | Returns the device that this engine is painting on, if painting is | - | ||||||||||||
889 | active; otherwise returns 0. | - | ||||||||||||
890 | */ | - | ||||||||||||
891 | QPaintDevice *QPaintEngine::paintDevice() const | - | ||||||||||||
892 | { | - | ||||||||||||
893 | return d_func()->pdev; never executed: return d_func()->pdev; | 0 | ||||||||||||
894 | } | - | ||||||||||||
895 | - | |||||||||||||
896 | - | |||||||||||||
897 | /*! | - | ||||||||||||
898 | \internal | - | ||||||||||||
899 | - | |||||||||||||
900 | Returns the offset from the painters origo to the engines | - | ||||||||||||
901 | origo. This value is used by QPainter for engines who have | - | ||||||||||||
902 | internal double buffering. | - | ||||||||||||
903 | - | |||||||||||||
904 | This function only makes sense when the engine is active. | - | ||||||||||||
905 | */ | - | ||||||||||||
906 | QPoint QPaintEngine::coordinateOffset() const | - | ||||||||||||
907 | { | - | ||||||||||||
908 | return QPoint(); never executed: return QPoint(); | 0 | ||||||||||||
909 | } | - | ||||||||||||
910 | - | |||||||||||||
911 | /*! | - | ||||||||||||
912 | \internal | - | ||||||||||||
913 | - | |||||||||||||
914 | Sets the system clip for this engine. The system clip defines the | - | ||||||||||||
915 | basis area that the engine has to draw in. All clips that are | - | ||||||||||||
916 | set will be an intersection with the system clip. | - | ||||||||||||
917 | - | |||||||||||||
918 | Reset the systemclip to no clip by setting an empty region. | - | ||||||||||||
919 | */ | - | ||||||||||||
920 | void QPaintEngine::setSystemClip(const QRegion ®ion) | - | ||||||||||||
921 | { | - | ||||||||||||
922 | Q_D(QPaintEngine); | - | ||||||||||||
923 | d->systemClip = region; | - | ||||||||||||
924 | // Be backward compatible and only call d->systemStateChanged() | - | ||||||||||||
925 | // if we currently have a system transform/viewport set. | - | ||||||||||||
926 | if (d->hasSystemTransform || d->hasSystemViewport) {
| 0 | ||||||||||||
927 | d->transformSystemClip(); | - | ||||||||||||
928 | d->systemStateChanged(); | - | ||||||||||||
929 | } never executed: end of block | 0 | ||||||||||||
930 | } never executed: end of block | 0 | ||||||||||||
931 | - | |||||||||||||
932 | /*! | - | ||||||||||||
933 | \internal | - | ||||||||||||
934 | - | |||||||||||||
935 | Returns the system clip. The system clip is read only while the | - | ||||||||||||
936 | painter is active. An empty region indicates that system clip | - | ||||||||||||
937 | is not in use. | - | ||||||||||||
938 | */ | - | ||||||||||||
939 | - | |||||||||||||
940 | QRegion QPaintEngine::systemClip() const | - | ||||||||||||
941 | { | - | ||||||||||||
942 | return d_func()->systemClip; never executed: return d_func()->systemClip; | 0 | ||||||||||||
943 | } | - | ||||||||||||
944 | - | |||||||||||||
945 | /*! | - | ||||||||||||
946 | \internal | - | ||||||||||||
947 | - | |||||||||||||
948 | Sets the target rect for drawing within the backing store. This | - | ||||||||||||
949 | function should ONLY be used by the backing store. | - | ||||||||||||
950 | */ | - | ||||||||||||
951 | void QPaintEngine::setSystemRect(const QRect &rect) | - | ||||||||||||
952 | { | - | ||||||||||||
953 | if (isActive()) {
| 0 | ||||||||||||
954 | qWarning("QPaintEngine::setSystemRect: Should not be changed while engine is active"); | - | ||||||||||||
955 | return; never executed: return; | 0 | ||||||||||||
956 | } | - | ||||||||||||
957 | d_func()->systemRect = rect; | - | ||||||||||||
958 | } never executed: end of block | 0 | ||||||||||||
959 | - | |||||||||||||
960 | /*! | - | ||||||||||||
961 | \internal | - | ||||||||||||
962 | - | |||||||||||||
963 | Retrieves the rect for drawing within the backing store. This | - | ||||||||||||
964 | function should ONLY be used by the backing store. | - | ||||||||||||
965 | */ | - | ||||||||||||
966 | QRect QPaintEngine::systemRect() const | - | ||||||||||||
967 | { | - | ||||||||||||
968 | return d_func()->systemRect; never executed: return d_func()->systemRect; | 0 | ||||||||||||
969 | } | - | ||||||||||||
970 | - | |||||||||||||
971 | QPaintEnginePrivate::~QPaintEnginePrivate() | - | ||||||||||||
972 | { | - | ||||||||||||
973 | } | - | ||||||||||||
974 | - | |||||||||||||
975 | void QPaintEnginePrivate::drawBoxTextItem(const QPointF &p, const QTextItemInt &ti) | - | ||||||||||||
976 | { | - | ||||||||||||
977 | if (!ti.glyphs.numGlyphs)
| 0 | ||||||||||||
978 | return; never executed: return; | 0 | ||||||||||||
979 | - | |||||||||||||
980 | // any fixes here should probably also be done in QFontEngineBox::draw | - | ||||||||||||
981 | const int size = qRound(ti.fontEngine->ascent()); | - | ||||||||||||
982 | QVarLengthArray<QFixedPoint> positions; | - | ||||||||||||
983 | QVarLengthArray<glyph_t> glyphs; | - | ||||||||||||
984 | QTransform matrix = QTransform::fromTranslate(p.x(), p.y() - size); | - | ||||||||||||
985 | ti.fontEngine->getGlyphPositions(ti.glyphs, matrix, ti.flags, glyphs, positions); | - | ||||||||||||
986 | if (glyphs.size() == 0)
| 0 | ||||||||||||
987 | return; never executed: return; | 0 | ||||||||||||
988 | - | |||||||||||||
989 | QSize s(size - 3, size - 3); | - | ||||||||||||
990 | - | |||||||||||||
991 | QPainter *painter = q_func()->state->painter(); | - | ||||||||||||
992 | painter->save(); | - | ||||||||||||
993 | painter->setBrush(Qt::NoBrush); | - | ||||||||||||
994 | QPen pen = painter->pen(); | - | ||||||||||||
995 | pen.setWidthF(ti.fontEngine->lineThickness().toReal()); | - | ||||||||||||
996 | painter->setPen(pen); | - | ||||||||||||
997 | for (int k = 0; k < positions.size(); k++)
| 0 | ||||||||||||
998 | painter->drawRect(QRectF(positions[k].toPointF(), s)); never executed: painter->drawRect(QRectF(positions[k].toPointF(), s)); | 0 | ||||||||||||
999 | painter->restore(); | - | ||||||||||||
1000 | } never executed: end of block | 0 | ||||||||||||
1001 | - | |||||||||||||
1002 | QT_END_NAMESPACE | - | ||||||||||||
Source code | Switch to Preprocessed file |