1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation (qt-info@nokia.com)
|
---|
6 | **
|
---|
7 | ** This file is part of the QtGui module of the Qt Toolkit.
|
---|
8 | **
|
---|
9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
10 | ** Commercial Usage
|
---|
11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
14 | ** a written agreement between you and Nokia.
|
---|
15 | **
|
---|
16 | ** GNU Lesser General Public License Usage
|
---|
17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
18 | ** General Public License version 2.1 as published by the Free Software
|
---|
19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
20 | ** packaging of this file. Please review the following information to
|
---|
21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
23 | **
|
---|
24 | ** In addition, as a special exception, Nokia gives you certain additional
|
---|
25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
---|
26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you have questions regarding the use of this file, please contact
|
---|
37 | ** Nokia at qt-info@nokia.com.
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | #ifndef QPAINTER_P_H
|
---|
43 | #define QPAINTER_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/qbrush.h"
|
---|
57 | #include "QtGui/qfont.h"
|
---|
58 | #include "QtGui/qpen.h"
|
---|
59 | #include "QtGui/qregion.h"
|
---|
60 | #include "QtGui/qmatrix.h"
|
---|
61 | #include "QtGui/qpainter.h"
|
---|
62 | #include "QtGui/qpainterpath.h"
|
---|
63 | #include "QtGui/qpaintengine.h"
|
---|
64 | #include <QtCore/qhash.h>
|
---|
65 |
|
---|
66 | #include <private/qpen_p.h>
|
---|
67 |
|
---|
68 | QT_BEGIN_NAMESPACE
|
---|
69 |
|
---|
70 | class QPaintEngine;
|
---|
71 | class QEmulationPaintEngine;
|
---|
72 | class QPaintEngineEx;
|
---|
73 |
|
---|
74 | struct QTLWExtra;
|
---|
75 |
|
---|
76 | struct DataPtrContainer {
|
---|
77 | void *ptr;
|
---|
78 | };
|
---|
79 |
|
---|
80 | inline void *data_ptr(const QTransform &t) { return (DataPtrContainer *) &t; }
|
---|
81 | inline bool qtransform_fast_equals(const QTransform &a, const QTransform &b) { return data_ptr(a) == data_ptr(b); }
|
---|
82 |
|
---|
83 | // QPen inline functions...
|
---|
84 | inline QPen::DataPtr &data_ptr(const QPen &p) { return const_cast<QPen &>(p).data_ptr(); }
|
---|
85 | inline bool qpen_fast_equals(const QPen &a, const QPen &b) { return data_ptr(a) == data_ptr(b); }
|
---|
86 | inline QBrush qpen_brush(const QPen &p) { return data_ptr(p)->brush; }
|
---|
87 | inline qreal qpen_widthf(const QPen &p) { return data_ptr(p)->width; }
|
---|
88 | inline Qt::PenStyle qpen_style(const QPen &p) { return data_ptr(p)->style; }
|
---|
89 | inline Qt::PenCapStyle qpen_capStyle(const QPen &p) { return data_ptr(p)->capStyle; }
|
---|
90 | inline Qt::PenJoinStyle qpen_joinStyle(const QPen &p) { return data_ptr(p)->joinStyle; }
|
---|
91 |
|
---|
92 | // QBrush inline functions...
|
---|
93 | inline QBrush::DataPtr &data_ptr(const QBrush &p) { return const_cast<QBrush &>(p).data_ptr(); }
|
---|
94 | inline bool qbrush_fast_equals(const QBrush &a, const QBrush &b) { return data_ptr(a) == data_ptr(b); }
|
---|
95 | inline Qt::BrushStyle qbrush_style(const QBrush &b) { return data_ptr(b)->style; }
|
---|
96 | inline const QColor &qbrush_color(const QBrush &b) { return data_ptr(b)->color; }
|
---|
97 | inline bool qbrush_has_transform(const QBrush &b) { return data_ptr(b)->transform.type() > QTransform::TxNone; }
|
---|
98 |
|
---|
99 | class QPainterClipInfo
|
---|
100 | {
|
---|
101 | public:
|
---|
102 | enum ClipType { RegionClip, PathClip, RectClip, RectFClip };
|
---|
103 |
|
---|
104 | QPainterClipInfo(const QPainterPath &p, Qt::ClipOperation op, const QTransform &m) :
|
---|
105 | clipType(PathClip), matrix(m), operation(op), path(p) { }
|
---|
106 |
|
---|
107 | QPainterClipInfo(const QRegion &r, Qt::ClipOperation op, const QTransform &m) :
|
---|
108 | clipType(RegionClip), matrix(m), operation(op), region(r) { }
|
---|
109 |
|
---|
110 | QPainterClipInfo(const QRect &r, Qt::ClipOperation op, const QTransform &m) :
|
---|
111 | clipType(RectClip), matrix(m), operation(op), rect(r) { }
|
---|
112 |
|
---|
113 | QPainterClipInfo(const QRectF &r, Qt::ClipOperation op, const QTransform &m) :
|
---|
114 | clipType(RectFClip), matrix(m), operation(op), rectf(r) { }
|
---|
115 |
|
---|
116 | ClipType clipType;
|
---|
117 | QTransform matrix;
|
---|
118 | Qt::ClipOperation operation;
|
---|
119 | QPainterPath path;
|
---|
120 | QRegion region;
|
---|
121 | QRect rect;
|
---|
122 | QRectF rectf;
|
---|
123 |
|
---|
124 | // ###
|
---|
125 | // union {
|
---|
126 | // QRegionData *d;
|
---|
127 | // QPainterPathPrivate *pathData;
|
---|
128 |
|
---|
129 | // struct {
|
---|
130 | // int x, y, w, h;
|
---|
131 | // } rectData;
|
---|
132 | // struct {
|
---|
133 | // qreal x, y, w, h;
|
---|
134 | // } rectFData;
|
---|
135 | // };
|
---|
136 |
|
---|
137 | };
|
---|
138 |
|
---|
139 |
|
---|
140 | class Q_GUI_EXPORT QPainterState : public QPaintEngineState
|
---|
141 | {
|
---|
142 | public:
|
---|
143 | QPainterState();
|
---|
144 | QPainterState(const QPainterState *s);
|
---|
145 | virtual ~QPainterState();
|
---|
146 | void init(QPainter *p);
|
---|
147 |
|
---|
148 | QPointF brushOrigin;
|
---|
149 | QFont font;
|
---|
150 | QFont deviceFont;
|
---|
151 | QPen pen;
|
---|
152 | QBrush brush;
|
---|
153 | QBrush bgBrush; // background brush
|
---|
154 | QRegion clipRegion;
|
---|
155 | QPainterPath clipPath;
|
---|
156 | Qt::ClipOperation clipOperation;
|
---|
157 | QPainter::RenderHints renderHints;
|
---|
158 | QList<QPainterClipInfo> clipInfo; // ### Make me smaller and faster to copy around...
|
---|
159 | QTransform worldMatrix; // World transformation matrix, not window and viewport
|
---|
160 | QTransform matrix; // Complete transformation matrix,
|
---|
161 | QTransform redirectionMatrix;
|
---|
162 | int wx, wy, ww, wh; // window rectangle
|
---|
163 | int vx, vy, vw, vh; // viewport rectangle
|
---|
164 | qreal opacity;
|
---|
165 |
|
---|
166 | uint WxF:1; // World transformation
|
---|
167 | uint VxF:1; // View transformation
|
---|
168 | uint clipEnabled:1;
|
---|
169 |
|
---|
170 | Qt::BGMode bgMode;
|
---|
171 | QPainter *painter;
|
---|
172 | Qt::LayoutDirection layoutDirection;
|
---|
173 | QPainter::CompositionMode composition_mode;
|
---|
174 | uint emulationSpecifier;
|
---|
175 | uint changeFlags;
|
---|
176 | };
|
---|
177 |
|
---|
178 | struct QPainterDummyState
|
---|
179 | {
|
---|
180 | QFont font;
|
---|
181 | QPen pen;
|
---|
182 | QBrush brush;
|
---|
183 | QTransform transform;
|
---|
184 | };
|
---|
185 |
|
---|
186 | class QPainterPrivate
|
---|
187 | {
|
---|
188 | Q_DECLARE_PUBLIC(QPainter)
|
---|
189 | public:
|
---|
190 | QPainterPrivate(QPainter *painter)
|
---|
191 | : q_ptr(painter), d_ptrs(0), state(0), dummyState(0), txinv(0), inDestructor(false), d_ptrs_size(0),
|
---|
192 | refcount(1), device(0), original_device(0), helper_device(0), engine(0), emulationEngine(0),
|
---|
193 | extended(0)
|
---|
194 | {
|
---|
195 | }
|
---|
196 |
|
---|
197 | ~QPainterPrivate();
|
---|
198 |
|
---|
199 | QPainter *q_ptr;
|
---|
200 | QPainterPrivate **d_ptrs;
|
---|
201 |
|
---|
202 | QPainterState *state;
|
---|
203 | QVector<QPainterState*> states;
|
---|
204 |
|
---|
205 | mutable QPainterDummyState *dummyState;
|
---|
206 |
|
---|
207 | QTransform invMatrix;
|
---|
208 | uint txinv:1;
|
---|
209 | uint inDestructor : 1;
|
---|
210 | uint d_ptrs_size;
|
---|
211 | uint refcount;
|
---|
212 |
|
---|
213 | enum DrawOperation { StrokeDraw = 0x1,
|
---|
214 | FillDraw = 0x2,
|
---|
215 | StrokeAndFillDraw = 0x3
|
---|
216 | };
|
---|
217 |
|
---|
218 | QPainterDummyState *fakeState() const {
|
---|
219 | if (!dummyState)
|
---|
220 | dummyState = new QPainterDummyState();
|
---|
221 | return dummyState;
|
---|
222 | }
|
---|
223 |
|
---|
224 | void updateEmulationSpecifier(QPainterState *s);
|
---|
225 | void updateStateImpl(QPainterState *state);
|
---|
226 | void updateState(QPainterState *state);
|
---|
227 |
|
---|
228 | void draw_helper(const QPainterPath &path, DrawOperation operation = StrokeAndFillDraw);
|
---|
229 | void drawStretchedGradient(const QPainterPath &path, DrawOperation operation);
|
---|
230 | void drawOpaqueBackground(const QPainterPath &path, DrawOperation operation);
|
---|
231 | void drawGlyphs(const quint32 *glyphArray, const QPointF *positionArray, int glyphCount);
|
---|
232 |
|
---|
233 | void updateMatrix();
|
---|
234 | void updateInvMatrix();
|
---|
235 |
|
---|
236 | int rectSubtraction() const {
|
---|
237 | return state->pen.style() != Qt::NoPen && state->pen.width() == 0 ? 1 : 0;
|
---|
238 | }
|
---|
239 |
|
---|
240 | void checkEmulation();
|
---|
241 |
|
---|
242 | static QPainterPrivate *get(QPainter *painter)
|
---|
243 | {
|
---|
244 | return painter->d_ptr.data();
|
---|
245 | }
|
---|
246 |
|
---|
247 | QTransform viewTransform() const;
|
---|
248 | static bool attachPainterPrivate(QPainter *q, QPaintDevice *pdev);
|
---|
249 | void detachPainterPrivate(QPainter *q);
|
---|
250 |
|
---|
251 | QPaintDevice *device;
|
---|
252 | QPaintDevice *original_device;
|
---|
253 | QPaintDevice *helper_device;
|
---|
254 | QPaintEngine *engine;
|
---|
255 | QEmulationPaintEngine *emulationEngine;
|
---|
256 | QPaintEngineEx *extended;
|
---|
257 | QBrush colorBrush; // for fill with solid color
|
---|
258 | };
|
---|
259 |
|
---|
260 | Q_GUI_EXPORT void qt_draw_helper(QPainterPrivate *p, const QPainterPath &path, QPainterPrivate::DrawOperation operation);
|
---|
261 | Q_GUI_EXPORT void qt_draw_glyphs(QPainter *painter, const quint32 *glyphArray,
|
---|
262 | const QPointF *positionArray, int glyphCount);
|
---|
263 |
|
---|
264 | QString qt_generate_brush_key(const QBrush &brush);
|
---|
265 |
|
---|
266 | QT_END_NAMESPACE
|
---|
267 |
|
---|
268 | #endif // QPAINTER_P_H
|
---|