Qt 4.8
qpaintengine.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
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 Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/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 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #ifndef QPAINTENGINE_H
43 #define QPAINTENGINE_H
44 
45 #include <QtCore/qnamespace.h>
46 #include <QtCore/qobjectdefs.h>
47 #include <QtCore/qscopedpointer.h>
48 #include <QtGui/qpainter.h>
49 
51 
53 
54 QT_MODULE(Gui)
55 
56 class QFontEngine;
57 class QLineF;
58 class QPaintDevice;
60 class QPainterPath;
61 class QPointF;
62 class QPolygonF;
63 class QRectF;
64 struct QGlyphLayout;
65 class QTextItemInt;
66 class QPaintEngineState;
67 
69 public:
70  enum RenderFlag {
71  RightToLeft = 0x1,
72  Overline = 0x10,
73  Underline = 0x20,
74  StrikeOut = 0x40,
75 
76  Dummy = 0xffffffff
77  };
78  Q_DECLARE_FLAGS(RenderFlags, RenderFlag)
79  qreal descent() const;
80  qreal ascent() const;
81  qreal width() const;
82 
83  RenderFlags renderFlags() const;
84  QString text() const;
85  QFont font() const;
86 };
88 
89 
91 {
93 public:
95  PrimitiveTransform = 0x00000001, // Can transform primitives brushes
96  PatternTransform = 0x00000002, // Can transform pattern brushes
97  PixmapTransform = 0x00000004, // Can transform pixmaps
98  PatternBrush = 0x00000008, // Can fill with pixmaps and standard patterns
99  LinearGradientFill = 0x00000010, // Can fill gradient areas
100  RadialGradientFill = 0x00000020, // Can render radial gradients
101  ConicalGradientFill = 0x00000040, // Can render conical gradients
102  AlphaBlend = 0x00000080, // Can do source over alpha blend
103  PorterDuff = 0x00000100, // Can do general porter duff compositions
104  PainterPaths = 0x00000200, // Can fill, outline and clip paths
105  Antialiasing = 0x00000400, // Can antialias lines
106  BrushStroke = 0x00000800, // Can render brush based pens
107  ConstantOpacity = 0x00001000, // Can render at constant opacity
108  MaskedBrush = 0x00002000, // Can fill with textures that has an alpha channel or mask
109  PerspectiveTransform = 0x00004000, // Can do perspective transformations
110  BlendModes = 0x00008000, // Can do extended Porter&Duff composition
111  ObjectBoundingModeGradients = 0x00010000, // Can do object bounding mode gradients
112  RasterOpModes = 0x00020000, // Can do logical raster operations
113  PaintOutsidePaintEvent = 0x20000000, // Engine is capable of painting outside paint events
114  /* 0x10000000, // Used for emulating
115  QGradient::StretchToDevice,
116  defined in qpainter.cpp
117 
118  0x40000000, // Used internally for emulating opaque backgrounds
119  */
120 
121  AllFeatures = 0xffffffff // For convenience
122  };
123  Q_DECLARE_FLAGS(PaintEngineFeatures, PaintEngineFeature)
124 
125  enum DirtyFlag {
126  DirtyPen = 0x0001,
127  DirtyBrush = 0x0002,
128  DirtyBrushOrigin = 0x0004,
129  DirtyFont = 0x0008,
130  DirtyBackground = 0x0010,
131  DirtyBackgroundMode = 0x0020,
132  DirtyTransform = 0x0040,
133  DirtyClipRegion = 0x0080,
134  DirtyClipPath = 0x0100,
135  DirtyHints = 0x0200,
136  DirtyCompositionMode = 0x0400,
137  DirtyClipEnabled = 0x0800,
138  DirtyOpacity = 0x1000,
139 
140  AllDirty = 0xffff
141  };
142  Q_DECLARE_FLAGS(DirtyFlags, DirtyFlag)
143 
148  PolylineMode
149  };
150 
151  explicit QPaintEngine(PaintEngineFeatures features=0);
152  virtual ~QPaintEngine();
153 
154  bool isActive() const { return active; }
155  void setActive(bool newState) { active = newState; }
156 
157  virtual bool begin(QPaintDevice *pdev) = 0;
158  virtual bool end() = 0;
159 
160  virtual void updateState(const QPaintEngineState &state) = 0;
161 
162  virtual void drawRects(const QRect *rects, int rectCount);
163  virtual void drawRects(const QRectF *rects, int rectCount);
164 
165  virtual void drawLines(const QLine *lines, int lineCount);
166  virtual void drawLines(const QLineF *lines, int lineCount);
167 
168  virtual void drawEllipse(const QRectF &r);
169  virtual void drawEllipse(const QRect &r);
170 
171  virtual void drawPath(const QPainterPath &path);
172 
173  virtual void drawPoints(const QPointF *points, int pointCount);
174  virtual void drawPoints(const QPoint *points, int pointCount);
175 
176  virtual void drawPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode);
177  virtual void drawPolygon(const QPoint *points, int pointCount, PolygonDrawMode mode);
178 
179  virtual void drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr) = 0;
180  virtual void drawTextItem(const QPointF &p, const QTextItem &textItem);
181  virtual void drawTiledPixmap(const QRectF &r, const QPixmap &pixmap, const QPointF &s);
182  virtual void drawImage(const QRectF &r, const QImage &pm, const QRectF &sr,
183  Qt::ImageConversionFlags flags = Qt::AutoColor);
184 
185  void setPaintDevice(QPaintDevice *device);
186  QPaintDevice *paintDevice() const;
187 
188  void setSystemClip(const QRegion &baseClip);
189  QRegion systemClip() const;
190 
191  void setSystemRect(const QRect &rect);
192  QRect systemRect() const;
193 
194 #ifdef Q_WS_WIN
195  virtual HDC getDC() const;
196  virtual void releaseDC(HDC hdc) const;
197 #endif
198 
199  virtual QPoint coordinateOffset() const;
200 
201  enum Type {
204  QuickDraw, CoreGraphics, MacPrinter,
217 
218  User = 50, // first user type id
219  MaxUser = 100 // last user type id
220  };
221  virtual Type type() const = 0;
222 
223  inline void fix_neg_rect(int *x, int *y, int *w, int *h);
224 
225  inline bool testDirty(DirtyFlags df);
226  inline void setDirty(DirtyFlags df);
227  inline void clearDirty(DirtyFlags df);
228 
229  bool hasFeature(PaintEngineFeatures feature) const { return (gccaps & feature) != 0; }
230 
231  QPainter *painter() const;
232 
233  void syncState();
234  inline bool isExtended() const { return extended; }
235 
236 protected:
237  QPaintEngine(QPaintEnginePrivate &data, PaintEngineFeatures devcaps=0);
238 
240  PaintEngineFeatures gccaps;
241 
245 
247 
248 private:
249  void setAutoDestruct(bool autoDestr) { selfDestruct = autoDestr; }
250  bool autoDestruct() const { return selfDestruct; }
252 
257 #ifndef QT_NO_FREETYPE
258  friend class QFontEngineFT;
259 #endif
260 #ifndef QT_NO_QWS_QPF
261  friend class QFontEngineQPF1;
262 #endif
263 #ifndef QT_NO_QWS_QPF2
264  friend class QFontEngineQPF;
265 #endif
266  friend class QPSPrintEngine;
267  friend class QMacPrintEngine;
269 #ifdef Q_WS_QWS
270  friend class QtopiaPrintEngine;
272  friend class QProxyFontEngine;
273 #endif
274 #ifdef Q_WS_QPA
275  friend class QFontEngineQPA;
276 #endif
277  friend class QPainter;
278  friend class QPainterPrivate;
279  friend class QWidget;
280  friend class QWidgetPrivate;
281  friend class QWin32PaintEngine;
282  friend class QWin32PaintEnginePrivate;
283  friend class QMacCGContext;
284  friend class QPreviewPaintEngine;
285  friend class QX11GLPixmapData;
286 };
287 
288 
290 {
291 public:
292  QPaintEngine::DirtyFlags state() const { return dirtyFlags; }
293 
294  QPen pen() const;
295  QBrush brush() const;
296  QPointF brushOrigin() const;
297  QBrush backgroundBrush() const;
298  Qt::BGMode backgroundMode() const;
299  QFont font() const;
300  QMatrix matrix() const;
301  QTransform transform() const;
302 
303  Qt::ClipOperation clipOperation() const;
304  QRegion clipRegion() const;
305  QPainterPath clipPath() const;
306  bool isClipEnabled() const;
307 
308  QPainter::RenderHints renderHints() const;
309  QPainter::CompositionMode compositionMode() const;
310  qreal opacity() const;
311 
312  QPainter *painter() const;
313 
314  bool brushNeedsResolving() const;
315  bool penNeedsResolving() const;
316 
317 protected:
318  friend class QPaintEngine;
319  friend class QRasterPaintEngine;
320  friend class QWidget;
321  friend class QPainter;
322  friend class QPainterPrivate;
324 
325  QPaintEngine::DirtyFlags dirtyFlags;
326 };
327 
328 //
329 // inline functions
330 //
331 
332 inline void QPaintEngine::fix_neg_rect(int *x, int *y, int *w, int *h)
333 {
334  if (*w < 0) {
335  *w = -*w;
336  *x -= *w - 1;
337  }
338  if (*h < 0) {
339  *h = -*h;
340  *y -= *h - 1;
341  }
342 }
343 
344 inline bool QPaintEngine::testDirty(DirtyFlags df) {
345  Q_ASSERT(state);
346  return ((state->dirtyFlags & df) != 0);
347 }
348 
349 inline void QPaintEngine::setDirty(DirtyFlags df) {
350  Q_ASSERT(state);
351  state->dirtyFlags |= df;
352 }
353 
354 inline void QPaintEngine::clearDirty(DirtyFlags df)
355 {
356  Q_ASSERT(state);
357  state->dirtyFlags &= ~static_cast<uint>(df);
358 }
359 
360 Q_DECLARE_OPERATORS_FOR_FLAGS(QTextItem::RenderFlags)
361 Q_DECLARE_OPERATORS_FOR_FLAGS(QPaintEngine::PaintEngineFeatures)
362 Q_DECLARE_OPERATORS_FOR_FLAGS(QPaintEngine::DirtyFlags)
363 
365 
367 
368 #endif // QPAINTENGINE_H
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
bool testDirty(DirtyFlags df)
Definition: qpaintengine.h:344
QPaintEngine::DirtyFlags state() const
Returns a combination of flags identifying the set of properties that need to be updated when updatin...
Definition: qpaintengine.h:292
int type
Definition: qmetatype.cpp:239
double qreal
Definition: qglobal.h:1193
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
#define QT_MODULE(x)
Definition: qglobal.h:2783
CompositionMode
Defines the modes supported for digital image compositing.
Definition: qpainter.h:138
The QLine class provides a two-dimensional vector using integer precision.
Definition: qline.h:57
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
#define Q_DECLARE_FLAGS(Flags, Enum)
The Q_DECLARE_FLAGS() macro expands to.
Definition: qglobal.h:2348
The QMatrix class specifies 2D transformations of a coordinate system.
Definition: qmatrix.h:61
PaintEngineFeatures gccaps
Definition: qpaintengine.h:240
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
QPaintEngineState * state
Definition: qpaintengine.h:239
void clearDirty(DirtyFlags df)
Definition: qpaintengine.h:354
#define Q_GUI_EXPORT
Definition: qglobal.h:1450
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
#define Q_DISABLE_COPY(Class)
Disables the use of copy constructors and assignment operators for the given Class.
Definition: qglobal.h:2523
QPaintEngine::DirtyFlags dirtyFlags
Definition: qpaintengine.h:325
bool isExtended() const
Returns true if the paint engine is a QPaintEngineEx derivative.
Definition: qpaintengine.h:234
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QPen class defines how a QPainter should draw lines and outlines of shapes.
Definition: qpen.h:64
void setAutoDestruct(bool autoDestr)
Definition: qpaintengine.h:249
DirtyFlag
QPaintEngine::updateState().
Definition: qpaintengine.h:125
The QLineF class provides a two-dimensional vector using floating point precision.
Definition: qline.h:212
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
bool isActive() const
Returns true if the paint engine is actively drawing; otherwise returns false.
Definition: qpaintengine.h:154
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
#define Q_DECLARE_OPERATORS_FOR_FLAGS(Flags)
The Q_DECLARE_OPERATORS_FOR_FLAGS() macro declares global operator|() functions for Flags...
Definition: qglobal.h:2355
void setActive(bool newState)
Sets the active state of the paint engine to state.
Definition: qpaintengine.h:155
static void drawRects(const T *rects, int n, const QTransform &transform, IDirectFBSurface *surface)
Q_DECLARE_TYPEINFO(QTextItem, Q_PRIMITIVE_TYPE)
The QPolygonF class provides a vector of points using floating point precision.
Definition: qpolygon.h:134
Internal QTextItem.
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
static const char * data(const QByteArray &arr)
unsigned int uint
Definition: qglobal.h:996
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
void setDirty(DirtyFlags df)
Definition: qpaintengine.h:349
The QPaintEngine class provides an abstract definition of how QPainter draws to a given device on a g...
Definition: qpaintengine.h:90
QPrinter::PrinterState state
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:76
QScopedPointer< QPaintEnginePrivate > d_ptr
Definition: qpaintengine.h:246
The QFont class specifies a font used for drawing text.
Definition: qfont.h:64
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
static void drawPoints(const T *points, int n, const QTransform &transform, IDirectFBSurface *surface)
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
bool autoDestruct() const
Definition: qpaintengine.h:250
The QPaintEngineState class provides information about the active paint engine&#39;s current state...
Definition: qpaintengine.h:289
#define Q_DECLARE_PRIVATE(Class)
Definition: qglobal.h:2467
The QRasterPaintEngine class enables hardware acceleration of painting operations in Qt for Embedded ...
void fix_neg_rect(int *x, int *y, int *w, int *h)
Definition: qpaintengine.h:332
static void drawLines(const T *lines, int n, const QTransform &transform, IDirectFBSurface *surface)
The QTextItem class provides all the information required to draw text in a custom paint engine...
Definition: qpaintengine.h:68
#define class
static const KeyPair *const end
#define QT_END_HEADER
Definition: qglobal.h:137
BGMode
Definition: qnamespace.h:588
#define text
Definition: qobjectdefs.h:80
bool hasFeature(PaintEngineFeatures feature) const
Returns true if the paint engine supports the specified feature; otherwise returns false...
Definition: qpaintengine.h:229
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65
PaintEngineFeature
This enum is used to describe the features or capabilities that the paint engine has.
Definition: qpaintengine.h:94
ClipOperation
Definition: qnamespace.h:1495