source: trunk/src/gui/painting/qemulationpaintengine.cpp@ 5

Last change on this file since 5 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 6.9 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information (qt-info@nokia.com)
5**
6** This file is part of the QtGui module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** 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 are unsure which license is appropriate for your use, please
37** contact the sales department at qt-sales@nokia.com.
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
47QT_BEGIN_NAMESPACE
48
49QEmulationPaintEngine::QEmulationPaintEngine(QPaintEngineEx *engine)
50 : real_engine(engine)
51{
52 QPaintEngine::state = real_engine->state();
53}
54
55
56QPaintEngine::Type QEmulationPaintEngine::type() const
57{
58 return real_engine->type();
59}
60
61bool QEmulationPaintEngine::begin(QPaintDevice *)
62{
63 return true;
64}
65
66bool QEmulationPaintEngine::end()
67{
68 return true;
69}
70
71
72QPainterState *QEmulationPaintEngine::createState(QPainterState *orig) const
73{
74 return real_engine->createState(orig);
75}
76
77void 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 QRealRect r = path.controlPointRect();
103 mat.translate(r.x1, r.y1);
104 mat.scale(r.x2 - r.x1, r.y2 - r.y1);
105 copy.setTransform(mat);
106 real_engine->fill(path, copy);
107 return;
108 }
109 }
110 }
111
112 real_engine->fill(path, brush);
113}
114
115void 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
127 QBrush brush = pen.brush();
128 Qt::BrushStyle style = qbrush_style(brush);
129 if (style >= Qt::LinearGradientPattern && style <= Qt::ConicalGradientPattern) {
130 const QGradient *g = brush.gradient();
131 if (g->coordinateMode() > QGradient::LogicalMode) {
132 QPaintEngineEx::stroke(path, pen);
133 return;
134 }
135 }
136
137 real_engine->stroke(path, pen);
138}
139
140void QEmulationPaintEngine::clip(const QVectorPath &path, Qt::ClipOperation op)
141{
142 real_engine->clip(path, op);
143}
144
145void QEmulationPaintEngine::drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr)
146{
147 if (state()->bgMode == Qt::OpaqueMode && pm.isQBitmap())
148 fillBGRect(r);
149 real_engine->drawPixmap(r, pm, sr);
150}
151
152void QEmulationPaintEngine::drawTextItem(const QPointF &p, const QTextItem &textItem)
153{
154 if (state()->bgMode == Qt::OpaqueMode) {
155 const QTextItemInt &ti = static_cast<const QTextItemInt &>(textItem);
156 QRectF rect(p.x(), p.y() - ti.ascent.toReal(), ti.width.toReal(), (ti.ascent + ti.descent + 1).toReal());
157 fillBGRect(rect);
158 }
159 real_engine->drawTextItem(p, textItem);
160}
161
162void QEmulationPaintEngine::drawTiledPixmap(const QRectF &r, const QPixmap &pixmap, const QPointF &s)
163{
164 if (state()->bgMode == Qt::OpaqueMode && pixmap.isQBitmap())
165 fillBGRect(r);
166 real_engine->drawTiledPixmap(r, pixmap, s);
167}
168
169void QEmulationPaintEngine::drawImage(const QRectF &r, const QImage &pm, const QRectF &sr, Qt::ImageConversionFlags flags)
170{
171 real_engine->drawImage(r, pm, sr, flags);
172}
173
174void QEmulationPaintEngine::clipEnabledChanged()
175{
176 real_engine->clipEnabledChanged();
177}
178
179void QEmulationPaintEngine::penChanged()
180{
181 real_engine->penChanged();
182}
183
184void QEmulationPaintEngine::brushChanged()
185{
186 real_engine->brushChanged();
187}
188
189void QEmulationPaintEngine::brushOriginChanged()
190{
191 real_engine->brushOriginChanged();
192}
193
194void QEmulationPaintEngine::opacityChanged()
195{
196 real_engine->opacityChanged();
197}
198
199void QEmulationPaintEngine::compositionModeChanged()
200{
201 real_engine->compositionModeChanged();
202}
203
204void QEmulationPaintEngine::renderHintsChanged()
205{
206 real_engine->renderHintsChanged();
207}
208
209void QEmulationPaintEngine::transformChanged()
210{
211 real_engine->transformChanged();
212}
213
214void QEmulationPaintEngine::setState(QPainterState *s)
215{
216 QPaintEngine::state = s;
217 real_engine->setState(s);
218}
219
220
221void QEmulationPaintEngine::fillBGRect(const QRectF &r)
222{
223 qreal pts[] = { r.x(), r.y(), r.x() + r.width(), r.y(),
224 r.x() + r.width(), r.y() + r.height(), r.x(), r.y() + r.height() };
225 QVectorPath vp(pts, 4, 0, QVectorPath::RectangleHint);
226 real_engine->fill(vp, state()->bgBrush);
227}
228
229QT_END_NAMESPACE
Note: See TracBrowser for help on using the repository browser.