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