Qt 4.8
qemulationpaintengine.cpp
Go to the documentation of this file.
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 #include <private/qemulationpaintengine_p.h>
43 #include <private/qpainter_p.h>
44 #include <private/qtextengine_p.h>
45 #include <qdebug.h>
46 
48 
50  : real_engine(engine)
51 {
53 }
54 
55 
57 {
58  return real_engine->type();
59 }
60 
62 {
63  return true;
64 }
65 
67 {
68  return true;
69 }
70 
71 
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 
93  QBrush copy = brush;
94  QTransform mat = copy.transform();
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 
134  QTransform mat = brush.transform();
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 
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 
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 
176  QPainterState *s = state();
177  Qt::BrushStyle style = qbrush_style(s->pen.brush());
178  if (style >= Qt::LinearGradientPattern && style <= Qt::ConicalGradientPattern)
179  {
180  QPen savedPen = s->pen;
181  QGradient g = *s->pen.brush().gradient();
182 
184  QTransform mat = s->pen.brush().transform();
187  } else if (g.coordinateMode() == QGradient::ObjectBoundingMode) {
188  const QTextItemInt &ti = static_cast<const QTextItemInt &>(textItem);
189  QRectF r(p.x(), p.y() - ti.ascent.toReal(), ti.width.toReal(), (ti.ascent + ti.descent + 1).toReal());
190  mat.translate(r.x(), r.y());
191  mat.scale(r.width(), r.height());
192  }
194  QBrush brush(g);
195  brush.setTransform(mat);
196  s->pen.setBrush(brush);
197  penChanged();
198  real_engine->drawTextItem(p, textItem);
199  s->pen = savedPen;
200  penChanged();
201  return;
202  }
203  }
204 
205  real_engine->drawTextItem(p, textItem);
206 }
207 
209 {
211 }
212 
213 void QEmulationPaintEngine::drawTiledPixmap(const QRectF &r, const QPixmap &pixmap, const QPointF &s)
214 {
215  if (state()->bgMode == Qt::OpaqueMode && pixmap.isQBitmap())
216  fillBGRect(r);
217  real_engine->drawTiledPixmap(r, pixmap, s);
218 }
219 
220 void QEmulationPaintEngine::drawImage(const QRectF &r, const QImage &pm, const QRectF &sr, Qt::ImageConversionFlags flags)
221 {
222  real_engine->drawImage(r, pm, sr, flags);
223 }
224 
225 void QEmulationPaintEngine::drawPixmapFragments(const QPainter::PixmapFragment *fragments, int fragmentCount, const QPixmap &pixmap,
226  QPainter::PixmapFragmentHints hints)
227 {
228  if (state()->bgMode == Qt::OpaqueMode && pixmap.isQBitmap()) {
229  qreal oldOpacity = real_engine->state()->opacity;
230  QTransform oldTransform = real_engine->state()->matrix;
231 
232  for (int i = 0; i < fragmentCount; ++i) {
233  QTransform transform = oldTransform;
234  transform.translate(fragments[i].x, fragments[i].y);
235  transform.rotate(fragments[i].rotation);
236  real_engine->state()->opacity = oldOpacity * fragments[i].opacity;
237  real_engine->state()->matrix = transform;
240 
241  qreal w = fragments[i].scaleX * fragments[i].width;
242  qreal h = fragments[i].scaleY * fragments[i].height;
243  fillBGRect(QRectF(-0.5 * w, -0.5 * h, w, h));
244  }
245 
246  real_engine->state()->opacity = oldOpacity;
247  real_engine->state()->matrix = oldTransform;
250  }
251 
252  real_engine->drawPixmapFragments(fragments, fragmentCount, pixmap, hints);
253 }
254 
255 void QEmulationPaintEngine::drawPixmapFragments(const QRectF *targetRects, const QRectF *sourceRects, int fragmentCount, const QPixmap &pixmap,
256  QPainter::PixmapFragmentHints hints)
257 {
258  if (state()->bgMode == Qt::OpaqueMode && pixmap.isQBitmap()) {
259  for (int i = 0; i < fragmentCount; ++i)
260  fillBGRect(targetRects[i]);
261  }
262 
263  real_engine->drawPixmapFragments(targetRects, sourceRects, fragmentCount, pixmap, hints);
264 }
265 
267 {
269 }
270 
272 {
274 }
275 
277 {
279 }
280 
282 {
284 }
285 
287 {
289 }
290 
292 {
294 }
295 
297 {
299 }
300 
302 {
304 }
305 
307 {
309  real_engine->setState(s);
310 }
311 
313 {
315 }
316 
318 {
320 }
321 
323 {
324  qreal pts[] = { r.x(), r.y(), r.x() + r.width(), r.y(),
325  r.x() + r.width(), r.y() + r.height(), r.x(), r.y() + r.height() };
327  real_engine->fill(vp, state()->bgBrush);
328 }
329 
QPaintDevice * device() const
Returns the paint device on which this painter is currently painting, or 0 if the painter is not acti...
Definition: qpainter.cpp:1530
qreal scaleY
the vertical scale of the target rectangle.
Definition: qpainter.h:112
qreal y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:667
BrushStyle
Definition: qnamespace.h:1162
virtual void stroke(const QVectorPath &path, const QPen &pen)
virtual void setState(QPainterState *s)
qreal width
the width of the source rectangle and is used to calculate the width of the target rectangle...
Definition: qpainter.h:109
virtual void compositionModeChanged()=0
double qreal
Definition: qglobal.h:1193
virtual void penChanged()=0
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
void fillBGRect(const QRectF &r)
virtual void clipEnabledChanged()=0
void setBrush(const QBrush &brush)
Sets the brush used to fill strokes generated with this pen to the given brush.
Definition: qpen.cpp:808
virtual void transformChanged()=0
const QGradient * gradient() const
Returns the gradient describing this brush.
Definition: qbrush.cpp:871
Qt::BrushStyle qbrush_style(const QBrush &b)
Definition: qpainter_p.h:96
QPaintEngineState * state
Definition: qpaintengine.h:239
void setTransform(const QTransform &)
Sets matrix as an explicit transformation matrix on the current brush.
Definition: qbrush.cpp:968
virtual void drawImage(const QRectF &r, const QImage &pm, const QRectF &sr, Qt::ImageConversionFlags flags=Qt::AutoColor)=0
Reimplement this function to draw the part of the image specified by the sr rectangle in the given re...
Qt::PenStyle style() const
Returns the pen style.
Definition: qpen.cpp:428
CoordinateMode coordinateMode() const
Returns the coordinate mode of this gradient.
Definition: qbrush.cpp:1563
int height() const
Definition: qpaintdevice.h:92
virtual void drawPixmapFragments(const QPainter::PixmapFragment *fragments, int fragmentCount, const QPixmap &pixmap, QPainter::PixmapFragmentHints hints)
virtual void drawTiledPixmap(const QRectF &r, const QPixmap &pixmap, const QPointF &s)
Reimplement this function to draw the pixmap in the given rect, starting at the given p...
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
virtual bool begin(QPaintDevice *pdev)
Reimplement this function to initialise your paint engine when painting is to start on the paint devi...
virtual void beginNativePainting()
QTransform matrix
Definition: qpainter_p.h:161
QTransform & translate(qreal dx, qreal dy)
Moves the coordinate system dx along the x axis and dy along the y axis, and returns a reference to t...
Definition: qtransform.cpp:417
qreal opacity
the opacity of the target rectangle, where 0.0 is fully transparent and 1.0 is fully opaque...
Definition: qpainter.h:114
QTransform transform() const
Returns the current transformation matrix for the brush.
Definition: qbrush.h:185
The QPen class defines how a QPainter should draw lines and outlines of shapes.
Definition: qpen.h:64
virtual void fill(const QVectorPath &path, const QBrush &brush)
virtual void brushOriginChanged()=0
QBrush bgBrush
Definition: qpainter_p.h:154
virtual QPainterState * createState(QPainterState *orig) const
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
virtual void drawPixmapFragments(const QPainter::PixmapFragment *fragments, int fragmentCount, const QPixmap &pixmap, QPainter::PixmapFragmentHints hints)
virtual void renderHintsChanged()=0
QRectF controlPointRect() const
virtual void stroke(const QVectorPath &path, const QPen &pen)
QEmulationPaintEngine(QPaintEngineEx *engine)
virtual void clip(const QVectorPath &path, Qt::ClipOperation op)
QPainter * painter() const
Returns the paint engine&#39;s painter.
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
int width() const
Definition: qpaintdevice.h:91
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
virtual void endNativePainting()
virtual void brushChanged()=0
qreal height() const
Returns the height of the rectangle.
Definition: qrect.h:710
QTransform & rotate(qreal a, Qt::Axis axis=Qt::ZAxis)
Rotates the coordinate system counterclockwise by the given angle about the specified axis and return...
Definition: qtransform.cpp:615
virtual Type type() const =0
Reimplement this function to return the paint engine Type.
Internal QTextItem.
virtual uint flags() const
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
bool isQBitmap() const
Returns true if this is a QBitmap; otherwise returns false.
Definition: qpixmap.cpp:599
qreal width() const
Returns the width of the rectangle.
Definition: qrect.h:707
virtual void setState(QPainterState *s)
virtual bool end()
Reimplement this function to finish painting on the current paint device.
QBrush brush() const
Returns the brush used to fill strokes generated with this pen.
Definition: qpen.cpp:797
Qt::BrushStyle style() const
Returns the brush style.
Definition: qbrush.h:182
virtual void opacityChanged()=0
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:76
virtual void drawTextItem(const QPointF &p, const QTextItem &textItem)
This function draws the text item textItem at position p.
virtual void drawStaticTextItem(QStaticTextItem *item)
virtual void drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr)=0
Reimplement this function to draw the part of the pm specified by the sr rectangle in the given r...
The QGradient class is used in combination with QBrush to specify gradient fills. ...
Definition: qbrush.h:201
qreal x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:664
This class is used in conjunction with the QPainter::drawPixmapFragments() function to specify how a ...
Definition: qpainter.h:103
virtual Type type() const
Reimplement this function to return the paint engine Type.
qreal scaleX
the horizontal scale of the target rectangle.
Definition: qpainter.h:111
void setCoordinateMode(CoordinateMode mode)
Sets the coordinate mode of this gradient to mode.
Definition: qbrush.cpp:1578
virtual void drawStaticTextItem(QStaticTextItem *)
qreal toReal() const
Definition: qfixed_p.h:77
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
virtual void fill(const QVectorPath &path, const QBrush &brush)=0
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
virtual void drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr)
Reimplement this function to draw the part of the pm specified by the sr rectangle in the given r...
QTransform & scale(qreal sx, qreal sy)
Scales the coordinate system by sx horizontally and sy vertically, and returns a reference to the mat...
Definition: qtransform.cpp:485
Qt::BGMode bgMode
Definition: qpainter_p.h:171
virtual void drawImage(const QRectF &r, const QImage &pm, const QRectF &sr, Qt::ImageConversionFlags flags)
Reimplement this function to draw the part of the image specified by the sr rectangle in the given re...
The QTextItem class provides all the information required to draw text in a custom paint engine...
Definition: qpaintengine.h:68
qreal height
the height of the source rectangle and is used to calculate the height of the target rectangle...
Definition: qpainter.h:110
virtual void drawTiledPixmap(const QRectF &r, const QPixmap &pixmap, const QPointF &s)
Reimplement this function to draw the pixmap in the given rect, starting at the given p...
QPainterState * state()
static qreal toReal(Register *reg, int type, bool *ok=0)
void setStyle(Qt::PenStyle)
Sets the pen style to the given style.
Definition: qpen.cpp:450
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65
ClipOperation
Definition: qnamespace.h:1495
virtual void clip(const QVectorPath &path, Qt::ClipOperation op)=0
virtual QPainterState * createState(QPainterState *orig) const
virtual void drawTextItem(const QPointF &p, const QTextItem &textItem)
This function draws the text item textItem at position p.