Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qemulationpaintengine.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include <private/qemulationpaintengine_p.h>
5#include <private/qpainter_p.h>
6#include <private/qtextengine_p.h>
7#include <qdebug.h>
8
10
16
17
22
24{
25 return true;
26}
27
29{
30 return true;
31}
32
33
38
39static inline void combineXForm(QBrush *brush, const QRectF &r)
40{
41 QTransform t(r.width(), 0, 0, r.height(), r.x(), r.y());
42 if (brush->gradient() && brush->gradient()->coordinateMode() != QGradient::ObjectMode)
43 brush->setTransform(t * brush->transform()); // compat mode
44 else
45 brush->setTransform(brush->transform() * t);
46}
47
49{
51
52 if (s->bgMode == Qt::OpaqueMode) {
53 Qt::BrushStyle style = brush.style();
54 if ((style >= Qt::Dense1Pattern && style <= Qt::DiagCrossPattern) || (style == Qt::TexturePattern ))
55 real_engine->fill(path, s->bgBrush);
56 }
57
60 QGradient::CoordinateMode coMode = brush.gradient()->coordinateMode();
61 if (coMode > QGradient::LogicalMode) {
64 QRectF r = (coMode == QGradient::StretchToDeviceMode) ? QRectF(0, 0, d->width(), d->height()) : path.controlPointRect();
67 return;
68 }
69 } else if (style == Qt::TexturePattern) {
70 qreal dpr = qHasPixmapTexture(brush) ? brush.texture().devicePixelRatio() : brush.textureImage().devicePixelRatio();
71 if (!qFuzzyCompare(dpr, qreal(1.0))) {
73 combineXForm(&copy, QRectF(0, 0, 1.0/dpr, 1.0/dpr));
75 return;
76 }
77 }
78
80}
81
83{
85
86 if (s->bgMode == Qt::OpaqueMode && pen.style() > Qt::SolidLine) {
87 QPen bgPen = pen;
88 bgPen.setBrush(s->bgBrush);
89 bgPen.setStyle(Qt::SolidLine);
90 real_engine->stroke(path, bgPen);
91 }
92
93 QBrush brush = pen.brush();
94 QPen copy = pen;
96 if (style >= Qt::LinearGradientPattern && style <= Qt::ConicalGradientPattern ) {
97 QGradient::CoordinateMode coMode = brush.gradient()->coordinateMode();
98 if (coMode > QGradient::LogicalMode) {
100 QRectF r = (coMode == QGradient::StretchToDeviceMode) ? QRectF(0, 0, d->width(), d->height()) : path.controlPointRect();
102 copy.setBrush(brush);
104 return;
105 }
106 }
107
108 real_engine->stroke(path, pen);
109}
110
115
116void QEmulationPaintEngine::drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr)
117{
118 if (state()->bgMode == Qt::OpaqueMode && pm.isQBitmap())
119 fillBGRect(r);
120 real_engine->drawPixmap(r, pm, sr);
121}
122
124{
125 if (state()->bgMode == Qt::OpaqueMode) {
126 const QTextItemInt &ti = static_cast<const QTextItemInt &>(textItem);
127 QRectF rect(p.x(), p.y() - ti.ascent.toReal(), ti.width.toReal(), (ti.ascent + ti.descent).toReal());
128 fillBGRect(rect);
129 }
130
131 QPainterState *s = state();
132 Qt::BrushStyle style = qbrush_style(s->pen.brush());
134 {
135 QPen savedPen = s->pen;
136 QGradient g = *s->pen.brush().gradient();
137
138 if (g.coordinateMode() > QGradient::LogicalMode) {
139 QBrush copy = s->pen.brush();
140 const QPaintDevice *d = real_engine->painter()->device();
141 const QTextItemInt &ti = static_cast<const QTextItemInt &>(textItem);
142 QRectF r = (g.coordinateMode() == QGradient::StretchToDeviceMode) ?
143 QRectF(0, 0, d->width(), d->height()) :
144 QRectF(p.x(), p.y() - ti.ascent.toReal(), ti.width.toReal(), (ti.ascent + ti.descent + 1).toReal());
146 g.setCoordinateMode(QGradient::LogicalMode);
147 QBrush brush(g);
148 brush.setTransform(copy.transform());
149 s->pen.setBrush(brush);
150 penChanged();
151 real_engine->drawTextItem(p, textItem);
152 s->pen = savedPen;
153 penChanged();
154 return;
155 }
156 }
157
158 real_engine->drawTextItem(p, textItem);
159}
160
165
167{
168 if (state()->bgMode == Qt::OpaqueMode && pixmap.isQBitmap())
169 fillBGRect(r);
171}
172
173void QEmulationPaintEngine::drawImage(const QRectF &r, const QImage &pm, const QRectF &sr, Qt::ImageConversionFlags flags)
174{
175 real_engine->drawImage(r, pm, sr, flags);
176}
177
182
187
192
197
202
207
212
217
223
228
233
234void QEmulationPaintEngine::fillBGRect(const QRectF &r)
235{
236 qreal pts[] = { r.x(), r.y(), r.x() + r.width(), r.y(),
237 r.x() + r.width(), r.y() + r.height(), r.x(), r.y() + r.height() };
238 QVectorPath vp(pts, 4, nullptr, QVectorPath::RectangleHint);
239 real_engine->fill(vp, state()->bgBrush);
240}
241
\inmodule QtGui
Definition qbrush.h:30
Type type() const override
Reimplement this function to return the paint engine \l{Type}.
void drawTextItem(const QPointF &p, const QTextItem &textItem) override
This function draws the text item textItem at position p.
void drawTiledPixmap(const QRectF &r, const QPixmap &pixmap, const QPointF &s) override
Reimplement this function to draw the pixmap in the given rect, starting at the given p.
void setState(QPainterState *s) override
void stroke(const QVectorPath &path, const QPen &pen) override
void drawImage(const QRectF &r, const QImage &pm, const QRectF &sr, Qt::ImageConversionFlags flags) override
Reimplement this function to draw the part of the image specified by the sr rectangle in the given re...
QEmulationPaintEngine(QPaintEngineEx *engine)
bool end() override
Reimplement this function to finish painting on the current paint device.
void drawStaticTextItem(QStaticTextItem *item) override
void clip(const QVectorPath &path, Qt::ClipOperation op) override
bool begin(QPaintDevice *pdev) override
Reimplement this function to initialise your paint engine when painting is to start on the paint devi...
void drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr) override
Reimplement this function to draw the part of the pm specified by the sr rectangle in the given r.
void fill(const QVectorPath &path, const QBrush &brush) override
QPainterState * createState(QPainterState *orig) const override
\inmodule QtGui
Definition qbrush.h:135
CoordinateMode
Definition qbrush.h:153
@ LogicalMode
Definition qbrush.h:154
@ StretchToDeviceMode
Definition qbrush.h:155
@ ObjectMode
Definition qbrush.h:157
\inmodule QtGui
Definition qimage.h:37
virtual void renderHintsChanged()=0
virtual void penChanged()=0
virtual void stroke(const QVectorPath &path, const QPen &pen)
virtual void beginNativePainting()
virtual void drawImage(const QRectF &r, const QImage &pm, const QRectF &sr, Qt::ImageConversionFlags flags=Qt::AutoColor) override=0
Reimplement this function to draw the part of the image specified by the sr rectangle in the given re...
virtual void clip(const QVectorPath &path, Qt::ClipOperation op)=0
virtual void clipEnabledChanged()=0
virtual void endNativePainting()
virtual void fill(const QVectorPath &path, const QBrush &brush)=0
virtual void opacityChanged()=0
virtual void drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr) override=0
Reimplement this function to draw the part of the pm specified by the sr rectangle in the given r.
virtual void compositionModeChanged()=0
QPainterState * state()
virtual void brushOriginChanged()=0
virtual QPainterState * createState(QPainterState *orig) const
virtual void drawTiledPixmap(const QRectF &r, const QPixmap &pixmap, const QPointF &s) override
Reimplement this function to draw the pixmap in the given rect, starting at the given p.
virtual void brushChanged()=0
virtual void transformChanged()=0
virtual void setState(QPainterState *s)
virtual void drawStaticTextItem(QStaticTextItem *)
virtual void drawTextItem(const QPointF &p, const QTextItem &textItem)
This function draws the text item textItem at position p.
QPainter * painter() const
Returns the paint engine's painter.
QPaintEngineState * state
virtual Type type() const =0
Reimplement this function to return the paint engine \l{Type}.
Type
\value X11 \value Windows \value MacPrinter \value CoreGraphics \macos's Quartz2D (CoreGraphics) \val...
QPaintDevice * device() const
Returns the paint device on which this painter is currently painting, or \nullptr if the painter is n...
\inmodule QtGui
Definition qpen.h:28
void setBrush(const QBrush &brush)
Sets the brush used to fill strokes generated with this pen to the given brush.
Definition qpen.cpp:726
QBrush brush() const
Returns the brush used to fill strokes generated with this pen.
Definition qpen.cpp:715
Qt::PenStyle style() const
Returns the pen style.
Definition qpen.cpp:366
Returns a copy of the pixmap that is transformed using the given transformation transform and transfo...
Definition qpixmap.h:27
bool isQBitmap() const
Returns true if this is a QBitmap; otherwise returns false.
Definition qpixmap.cpp:443
\inmodule QtCore\reentrant
Definition qpoint.h:217
\inmodule QtCore\reentrant
Definition qrect.h:484
Internal QTextItem.
\inmodule QtGui
The QTransform class specifies 2D transformations of a coordinate system.
Definition qtransform.h:20
rect
[4]
Combined button and popup list for selecting options.
ClipOperation
@ OpaqueMode
Definition qnamespace.h:508
@ SolidLine
BrushStyle
@ DiagCrossPattern
@ Dense1Pattern
@ TexturePattern
@ LinearGradientPattern
@ ConicalGradientPattern
Definition brush.cpp:5
static jboolean copy(JNIEnv *, jobject)
bool Q_GUI_EXPORT qHasPixmapTexture(const QBrush &brush)
Definition qbrush.cpp:202
static void combineXForm(QBrush *brush, const QRectF &r)
bool qFuzzyCompare(qfloat16 p1, qfloat16 p2) noexcept
Definition qfloat16.h:333
GLboolean r
[2]
GLbitfield flags
GLboolean GLboolean g
GLdouble s
[6]
Definition qopenglext.h:235
GLdouble GLdouble t
Definition qopenglext.h:243
GLsizei const GLchar *const * path
GLfloat GLfloat p
[1]
Qt::BrushStyle qbrush_style(const QBrush &b)
Definition qpainter_p.h:63
static QT_BEGIN_NAMESPACE qreal dpr(const QWindow *w)
double qreal
Definition qtypes.h:187
QGraphicsItem * item
widget render & pixmap
QJSEngine engine
[0]