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 QPAINTENGINEEX_P_H |
43 | #define QPAINTENGINEEX_P_H |
44 | |
45 | // |
46 | // W A R N I N G |
47 | // ------------- |
48 | // |
49 | // This file is not part of the Qt API. It exists purely as an |
50 | // implementation detail. This header file may change from version to |
51 | // version without notice, or even be removed. |
52 | // |
53 | // We mean it. |
54 | // |
55 | |
56 | #include <QtGui/qpaintengine.h> |
57 | #include <QtGui/qdrawutil.h> |
58 | |
59 | #include <private/qpaintengine_p.h> |
60 | #include <private/qstroker_p.h> |
61 | #include <private/qpainter_p.h> |
62 | #include <private/qvectorpath_p.h> |
63 | |
64 | |
65 | QT_BEGIN_HEADER |
66 | |
67 | QT_BEGIN_NAMESPACE |
68 | |
69 | QT_MODULE(Gui) |
70 | |
71 | class QPainterState; |
72 | class QPaintEngineExPrivate; |
73 | class QStaticTextItem; |
74 | struct StrokeHandler; |
75 | |
76 | struct QIntRect { |
77 | int x1, y1, x2, y2; |
78 | inline void set(const QRect &r) { |
79 | x1 = r.x(); |
80 | y1 = r.y(); |
81 | x2 = r.right() + 1; |
82 | y2 = r.bottom() + 1; |
83 | // We will assume normalized for later... |
84 | Q_ASSERT(x2 >= x1); |
85 | Q_ASSERT(y2 >= y1); |
86 | } |
87 | }; |
88 | |
89 | class QRectVectorPath : public QVectorPath { |
90 | public: |
91 | inline void set(const QRect &r) { |
92 | qreal left = r.x(); |
93 | qreal right = r.x() + r.width(); |
94 | qreal top = r.y(); |
95 | qreal bottom = r.y() + r.height(); |
96 | pts[0] = left; |
97 | pts[1] = top; |
98 | pts[2] = right; |
99 | pts[3] = top; |
100 | pts[4] = right; |
101 | pts[5] = bottom; |
102 | pts[6] = left; |
103 | pts[7] = bottom; |
104 | } |
105 | |
106 | inline void set(const QRectF &r) { |
107 | qreal left = r.x(); |
108 | qreal right = r.x() + r.width(); |
109 | qreal top = r.y(); |
110 | qreal bottom = r.y() + r.height(); |
111 | pts[0] = left; |
112 | pts[1] = top; |
113 | pts[2] = right; |
114 | pts[3] = top; |
115 | pts[4] = right; |
116 | pts[5] = bottom; |
117 | pts[6] = left; |
118 | pts[7] = bottom; |
119 | } |
120 | inline QRectVectorPath(const QRect &r) |
121 | : QVectorPath(pts, 4, 0, QVectorPath::RectangleHint | QVectorPath::ImplicitClose) |
122 | { |
123 | set(r); |
124 | } |
125 | inline QRectVectorPath(const QRectF &r) |
126 | : QVectorPath(pts, 4, 0, QVectorPath::RectangleHint | QVectorPath::ImplicitClose) |
127 | { |
128 | set(r); |
129 | } |
130 | inline QRectVectorPath() |
131 | : QVectorPath(pts, 4, 0, QVectorPath::RectangleHint | QVectorPath::ImplicitClose) |
132 | { } |
133 | |
134 | qreal pts[8]; |
135 | }; |
136 | |
137 | #ifndef QT_NO_DEBUG_STREAM |
138 | QDebug Q_GUI_EXPORT &operator<<(QDebug &, const QVectorPath &path); |
139 | #endif |
140 | |
141 | class QPixmapFilter; |
142 | |
143 | class Q_GUI_EXPORT QPaintEngineEx : public QPaintEngine |
144 | { |
145 | Q_DECLARE_PRIVATE(QPaintEngineEx) |
146 | public: |
147 | QPaintEngineEx(); |
148 | |
149 | virtual QPainterState *createState(QPainterState *orig) const; |
150 | |
151 | virtual void draw(const QVectorPath &path); |
152 | virtual void fill(const QVectorPath &path, const QBrush &brush) = 0; |
153 | virtual void stroke(const QVectorPath &path, const QPen &pen); |
154 | |
155 | virtual void clip(const QVectorPath &path, Qt::ClipOperation op) = 0; |
156 | virtual void clip(const QRect &rect, Qt::ClipOperation op); |
157 | virtual void clip(const QRegion ®ion, Qt::ClipOperation op); |
158 | virtual void clip(const QPainterPath &path, Qt::ClipOperation op); |
159 | |
160 | virtual void clipEnabledChanged() = 0; |
161 | virtual void penChanged() = 0; |
162 | virtual void brushChanged() = 0; |
163 | virtual void brushOriginChanged() = 0; |
164 | virtual void opacityChanged() = 0; |
165 | virtual void compositionModeChanged() = 0; |
166 | virtual void renderHintsChanged() = 0; |
167 | virtual void transformChanged() = 0; |
168 | |
169 | virtual void fillRect(const QRectF &rect, const QBrush &brush); |
170 | virtual void fillRect(const QRectF &rect, const QColor &color); |
171 | |
172 | virtual void drawRoundedRect(const QRectF &rect, qreal xrad, qreal yrad, Qt::SizeMode mode); |
173 | |
174 | virtual void drawRects(const QRect *rects, int rectCount); |
175 | virtual void drawRects(const QRectF *rects, int rectCount); |
176 | |
177 | virtual void drawLines(const QLine *lines, int lineCount); |
178 | virtual void drawLines(const QLineF *lines, int lineCount); |
179 | |
180 | virtual void drawEllipse(const QRectF &r); |
181 | virtual void drawEllipse(const QRect &r); |
182 | |
183 | virtual void drawPath(const QPainterPath &path); |
184 | |
185 | virtual void drawPoints(const QPointF *points, int pointCount); |
186 | virtual void drawPoints(const QPoint *points, int pointCount); |
187 | |
188 | virtual void drawPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode); |
189 | virtual void drawPolygon(const QPoint *points, int pointCount, PolygonDrawMode mode); |
190 | |
191 | virtual void drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr) = 0; |
192 | virtual void drawPixmap(const QPointF &pos, const QPixmap &pm); |
193 | |
194 | virtual void drawImage(const QRectF &r, const QImage &pm, const QRectF &sr, |
195 | Qt::ImageConversionFlags flags = Qt::AutoColor) = 0; |
196 | virtual void drawImage(const QPointF &pos, const QImage &image); |
197 | |
198 | virtual void drawTiledPixmap(const QRectF &r, const QPixmap &pixmap, const QPointF &s); |
199 | |
200 | virtual void drawPixmapFragments(const QPainter::PixmapFragment *fragments, int fragmentCount, const QPixmap &pixmap, |
201 | QPainter::PixmapFragmentHints hints); |
202 | virtual void drawPixmapFragments(const QRectF *targetRects, const QRectF *sourceRects, int fragmentCount, const QPixmap &pixmap, |
203 | QPainter::PixmapFragmentHints hints); |
204 | |
205 | virtual void updateState(const QPaintEngineState &state); |
206 | |
207 | virtual void drawStaticTextItem(QStaticTextItem *); |
208 | |
209 | virtual void setState(QPainterState *s); |
210 | inline QPainterState *state() { return static_cast<QPainterState *>(QPaintEngine::state); } |
211 | inline const QPainterState *state() const { return static_cast<const QPainterState *>(QPaintEngine::state); } |
212 | |
213 | virtual void sync() {} |
214 | |
215 | virtual void beginNativePainting() {} |
216 | virtual void endNativePainting() {} |
217 | |
218 | // Return a pixmap filter of "type" that can render the parameters |
219 | // in "prototype". The returned filter is owned by the engine and |
220 | // will be destroyed when the engine is destroyed. The "prototype" |
221 | // allows the engine to pick different filters based on the parameters |
222 | // that will be requested, and not just the "type". |
223 | virtual QPixmapFilter *pixmapFilter(int /*type*/, const QPixmapFilter * /*prototype*/) { return 0; } |
224 | |
225 | // These flags are needed in the implementation of paint buffers. |
226 | enum Flags |
227 | { |
228 | DoNotEmulate = 0x01, // If set, QPainter will not wrap this engine in an emulation engine. |
229 | IsEmulationEngine = 0x02 // If set, this object is a QEmulationEngine. |
230 | }; |
231 | virtual uint flags() const {return 0;} |
232 | virtual bool supportsTransformations(qreal pixelSize, const QTransform &m) const; |
233 | |
234 | protected: |
235 | QPaintEngineEx(QPaintEngineExPrivate &data); |
236 | }; |
237 | |
238 | class Q_GUI_EXPORT QPaintEngineExPrivate : public QPaintEnginePrivate |
239 | { |
240 | Q_DECLARE_PUBLIC(QPaintEngineEx) |
241 | public: |
242 | QPaintEngineExPrivate(); |
243 | ~QPaintEngineExPrivate(); |
244 | |
245 | void replayClipOperations(); |
246 | bool hasClipOperations() const; |
247 | |
248 | QStroker stroker; |
249 | QDashStroker dasher; |
250 | StrokeHandler *strokeHandler; |
251 | QStrokerOps *activeStroker; |
252 | QPen strokerPen; |
253 | |
254 | QRect exDeviceRect; |
255 | }; |
256 | |
257 | inline uint QVectorPath::polygonFlags(QPaintEngine::PolygonDrawMode mode) { |
258 | switch (mode) { |
259 | case QPaintEngine::ConvexMode: return ConvexPolygonHint | ImplicitClose; |
260 | case QPaintEngine::OddEvenMode: return PolygonHint | OddEvenFill | ImplicitClose; |
261 | case QPaintEngine::WindingMode: return PolygonHint | WindingFill | ImplicitClose; |
262 | case QPaintEngine::PolylineMode: return PolygonHint; |
263 | default: return 0; |
264 | } |
265 | } |
266 | |
267 | QT_END_NAMESPACE |
268 | |
269 | QT_END_HEADER |
270 | |
271 | #endif |
272 | |