1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation ([email protected])
|
---|
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 [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | #include <private/qemulationpaintengine_p.h>
|
---|
43 | #include <private/qpainter_p.h>
|
---|
44 | #include <private/qtextengine_p.h>
|
---|
45 | #include <qdebug.h>
|
---|
46 |
|
---|
47 | QT_BEGIN_NAMESPACE
|
---|
48 |
|
---|
49 | QEmulationPaintEngine::QEmulationPaintEngine(QPaintEngineEx *engine)
|
---|
50 | : real_engine(engine)
|
---|
51 | {
|
---|
52 | QPaintEngine::state = real_engine->state();
|
---|
53 | }
|
---|
54 |
|
---|
55 |
|
---|
56 | QPaintEngine::Type QEmulationPaintEngine::type() const
|
---|
57 | {
|
---|
58 | return real_engine->type();
|
---|
59 | }
|
---|
60 |
|
---|
61 | bool QEmulationPaintEngine::begin(QPaintDevice *)
|
---|
62 | {
|
---|
63 | return true;
|
---|
64 | }
|
---|
65 |
|
---|
66 | bool QEmulationPaintEngine::end()
|
---|
67 | {
|
---|
68 | return true;
|
---|
69 | }
|
---|
70 |
|
---|
71 |
|
---|
72 | QPainterState *QEmulationPaintEngine::createState(QPainterState *orig) const
|
---|
73 | {
|
---|
74 | return real_engine->createState(orig);
|
---|
75 | }
|
---|
76 |
|
---|
77 | void QEmulationPaintEngine::fill(const QVectorPath &path, const QBrush &brush)
|
---|
78 | {
|
---|
79 | QPainterState *s = state();
|
---|
80 |
|
---|
81 | if (s->bgMode == Qt::OpaqueMode) {
|
---|
82 | Qt::BrushStyle style = brush.style();
|
---|
83 | if (style >= Qt::Dense1Pattern && style <= Qt::DiagCrossPattern)
|
---|
84 | real_engine->fill(path, s->bgBrush);
|
---|
85 | }
|
---|
86 |
|
---|
87 | Qt::BrushStyle style = qbrush_style(brush);
|
---|
88 | if (style >= Qt::LinearGradientPattern && style <= Qt::ConicalGradientPattern) {
|
---|
89 | const QGradient *g = brush.gradient();
|
---|
90 |
|
---|
91 | if (g->coordinateMode() > QGradient::LogicalMode) {
|
---|
92 | if (g->coordinateMode() == QGradient::StretchToDeviceMode) {
|
---|
93 | QBrush copy = brush;
|
---|
94 | QTransform mat = copy.transform();
|
---|
95 | mat.scale(real_engine->painter()->device()->width(), real_engine->painter()->device()->height());
|
---|
96 | copy.setTransform(mat);
|
---|
97 | real_engine->fill(path, copy);
|
---|
98 | return;
|
---|
99 | } else if (g->coordinateMode() == QGradient::ObjectBoundingMode) {
|
---|
100 | QBrush copy = brush;
|
---|
101 | QTransform mat = copy.transform();
|
---|
102 | QRectF r = path.controlPointRect();
|
---|
103 | mat.translate(r.x(), r.y());
|
---|
104 | mat.scale(r.width(), r.height());
|
---|
105 | copy.setTransform(mat);
|
---|
106 | real_engine->fill(path, copy);
|
---|
107 | return;
|
---|
108 | }
|
---|
109 | }
|
---|
110 | }
|
---|
111 |
|
---|
112 | real_engine->fill(path, brush);
|
---|
113 | }
|
---|
114 |
|
---|
115 | void QEmulationPaintEngine::stroke(const QVectorPath &path, const QPen &pen)
|
---|
116 | {
|
---|
117 | QPainterState *s = state();
|
---|
118 |
|
---|
119 | if (s->bgMode == Qt::OpaqueMode && pen.style() > Qt::SolidLine) {
|
---|
120 | QPen bgPen = pen;
|
---|
121 | bgPen.setBrush(s->bgBrush);
|
---|
122 | bgPen.setStyle(Qt::SolidLine);
|
---|
123 | real_engine->stroke(path, bgPen);
|
---|
124 | }
|
---|
125 |
|
---|
126 | QBrush brush = pen.brush();
|
---|
127 | QPen copy = pen;
|
---|
128 | Qt::BrushStyle style = qbrush_style(brush);
|
---|
129 | if (style >= Qt::LinearGradientPattern && style <= Qt::ConicalGradientPattern) {
|
---|
130 | const QGradient *g = brush.gradient();
|
---|
131 |
|
---|
132 | if (g->coordinateMode() > QGradient::LogicalMode) {
|
---|
133 | if (g->coordinateMode() == QGradient::StretchToDeviceMode) {
|
---|
134 | QTransform mat = brush.transform();
|
---|
135 | mat.scale(real_engine->painter()->device()->width(), real_engine->painter()->device()->height());
|
---|
136 | brush.setTransform(mat);
|
---|
137 | copy.setBrush(brush);
|
---|
138 | real_engine->stroke(path, copy);
|
---|
139 | return;
|
---|
140 | } else if (g->coordinateMode() == QGradient::ObjectBoundingMode) {
|
---|
141 | QTransform mat = brush.transform();
|
---|
142 | QRectF r = path.controlPointRect();
|
---|
143 | mat.translate(r.x(), r.y());
|
---|
144 | mat.scale(r.width(), r.height());
|
---|
145 | brush.setTransform(mat);
|
---|
146 | copy.setBrush(brush);
|
---|
147 | real_engine->stroke(path, copy);
|
---|
148 | return;
|
---|
149 | }
|
---|
150 | }
|
---|
151 | }
|
---|
152 |
|
---|
153 | real_engine->stroke(path, pen);
|
---|
154 | }
|
---|
155 |
|
---|
156 | void QEmulationPaintEngine::clip(const QVectorPath &path, Qt::ClipOperation op)
|
---|
157 | {
|
---|
158 | real_engine->clip(path, op);
|
---|
159 | }
|
---|
160 |
|
---|
161 | void QEmulationPaintEngine::drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr)
|
---|
162 | {
|
---|
163 | if (state()->bgMode == Qt::OpaqueMode && pm.isQBitmap())
|
---|
164 | fillBGRect(r);
|
---|
165 | real_engine->drawPixmap(r, pm, sr);
|
---|
166 | }
|
---|
167 |
|
---|
168 | void QEmulationPaintEngine::drawTextItem(const QPointF &p, const QTextItem &textItem)
|
---|
169 | {
|
---|
170 | if (state()->bgMode == Qt::OpaqueMode) {
|
---|
171 | const QTextItemInt &ti = static_cast<const QTextItemInt &>(textItem);
|
---|
172 | QRectF rect(p.x(), p.y() - ti.ascent.toReal(), ti.width.toReal(), (ti.ascent + ti.descent + 1).toReal());
|
---|
173 | fillBGRect(rect);
|
---|
174 | }
|
---|
175 | real_engine->drawTextItem(p, textItem);
|
---|
176 | }
|
---|
177 |
|
---|
178 | void QEmulationPaintEngine::drawTiledPixmap(const QRectF &r, const QPixmap &pixmap, const QPointF &s)
|
---|
179 | {
|
---|
180 | if (state()->bgMode == Qt::OpaqueMode && pixmap.isQBitmap())
|
---|
181 | fillBGRect(r);
|
---|
182 | real_engine->drawTiledPixmap(r, pixmap, s);
|
---|
183 | }
|
---|
184 |
|
---|
185 | void QEmulationPaintEngine::drawImage(const QRectF &r, const QImage &pm, const QRectF &sr, Qt::ImageConversionFlags flags)
|
---|
186 | {
|
---|
187 | real_engine->drawImage(r, pm, sr, flags);
|
---|
188 | }
|
---|
189 |
|
---|
190 | void QEmulationPaintEngine::clipEnabledChanged()
|
---|
191 | {
|
---|
192 | real_engine->clipEnabledChanged();
|
---|
193 | }
|
---|
194 |
|
---|
195 | void QEmulationPaintEngine::penChanged()
|
---|
196 | {
|
---|
197 | real_engine->penChanged();
|
---|
198 | }
|
---|
199 |
|
---|
200 | void QEmulationPaintEngine::brushChanged()
|
---|
201 | {
|
---|
202 | real_engine->brushChanged();
|
---|
203 | }
|
---|
204 |
|
---|
205 | void QEmulationPaintEngine::brushOriginChanged()
|
---|
206 | {
|
---|
207 | real_engine->brushOriginChanged();
|
---|
208 | }
|
---|
209 |
|
---|
210 | void QEmulationPaintEngine::opacityChanged()
|
---|
211 | {
|
---|
212 | real_engine->opacityChanged();
|
---|
213 | }
|
---|
214 |
|
---|
215 | void QEmulationPaintEngine::compositionModeChanged()
|
---|
216 | {
|
---|
217 | real_engine->compositionModeChanged();
|
---|
218 | }
|
---|
219 |
|
---|
220 | void QEmulationPaintEngine::renderHintsChanged()
|
---|
221 | {
|
---|
222 | real_engine->renderHintsChanged();
|
---|
223 | }
|
---|
224 |
|
---|
225 | void QEmulationPaintEngine::transformChanged()
|
---|
226 | {
|
---|
227 | real_engine->transformChanged();
|
---|
228 | }
|
---|
229 |
|
---|
230 | void QEmulationPaintEngine::setState(QPainterState *s)
|
---|
231 | {
|
---|
232 | QPaintEngine::state = s;
|
---|
233 | real_engine->setState(s);
|
---|
234 | }
|
---|
235 |
|
---|
236 |
|
---|
237 | void QEmulationPaintEngine::fillBGRect(const QRectF &r)
|
---|
238 | {
|
---|
239 | qreal pts[] = { r.x(), r.y(), r.x() + r.width(), r.y(),
|
---|
240 | r.x() + r.width(), r.y() + r.height(), r.x(), r.y() + r.height() };
|
---|
241 | QVectorPath vp(pts, 4, 0, QVectorPath::RectangleHint);
|
---|
242 | real_engine->fill(vp, state()->bgBrush);
|
---|
243 | }
|
---|
244 |
|
---|
245 | QT_END_NAMESPACE
|
---|