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