23 const QTileRules &rules, QDrawBorderPixmap::DrawingHints hints)
36 sourceMargins *= sourceDpr;
39 const int sourceCenterTop = sourceRect.
top() + sourceMargins.
top();
40 const int sourceCenterLeft = sourceRect.
left() + sourceMargins.
left();
41 const int sourceCenterBottom = sourceRect.
bottom() - sourceMargins.
bottom() + 1;
42 const int sourceCenterRight = sourceRect.
right() - sourceMargins.
right() + 1;
43 const int sourceCenterWidth = sourceCenterRight - sourceCenterLeft;
44 const int sourceCenterHeight = sourceCenterBottom - sourceCenterTop;
46 const int targetCenterTop = targetRect.
top() + targetMargins.
top();
47 const int targetCenterLeft = targetRect.
left() + targetMargins.
left();
48 const int targetCenterBottom = targetRect.
bottom() - targetMargins.
bottom() + 1;
49 const int targetCenterRight = targetRect.
right() - targetMargins.
right() + 1;
50 const int targetCenterWidth = targetCenterRight - targetCenterLeft;
51 const int targetCenterHeight = targetCenterBottom - targetCenterTop;
59 columns =
qMax(3, 2 +
qCeil((targetCenterWidth * sourceDpr) /
qreal(sourceCenterWidth)));
61 rows =
qMax(3, 2 +
qCeil((targetCenterHeight * sourceDpr) /
qreal(sourceCenterHeight)));
63 xTarget.
resize(columns + 1);
66 xTarget[0] = targetRect.
left();
67 xTarget[1] = targetCenterLeft;
68 xTarget[columns - 1] = targetCenterRight;
69 xTarget[columns] = targetRect.
left() + targetRect.
width();
71 yTarget[0] = targetRect.
top();
72 yTarget[1] = targetCenterTop;
73 yTarget[rows - 1] = targetCenterBottom;
74 yTarget[rows] = targetRect.
top() + targetRect.
height();
76 qreal dx = targetCenterWidth;
77 qreal dy = targetCenterHeight;
81 dx = targetCenterWidth;
84 dx = sourceCenterWidth / sourceDpr;
87 dx = targetCenterWidth /
qreal(columns - 2);
91 for (
int i = 2;
i < columns - 1; ++
i)
92 xTarget[
i] = xTarget[
i - 1] + dx;
96 dy = targetCenterHeight;
99 dy = sourceCenterHeight / sourceDpr;
102 dy = targetCenterHeight /
qreal(rows - 2);
106 for (
int i = 2;
i < rows - 1; ++
i)
107 yTarget[
i] = yTarget[
i - 1] + dy;
110 if (targetMargins.
top() > 0 && targetMargins.
left() > 0 && sourceMargins.
top() > 0 && sourceMargins.
left() > 0) {
111 d.x = (0.5 * (xTarget[1] + xTarget[0]));
112 d.y = (0.5 * (yTarget[1] + yTarget[0]));
113 d.sourceLeft = sourceRect.
left();
114 d.sourceTop = sourceRect.
top();
115 d.width = sourceMargins.
left();
116 d.height = sourceMargins.
top();
117 d.scaleX =
qreal(xTarget[1] - xTarget[0]) /
d.width;
118 d.scaleY =
qreal(yTarget[1] - yTarget[0]) /
d.height;
124 if (targetMargins.
top() > 0 && targetMargins.
right() > 0 && sourceMargins.
top() > 0 && sourceMargins.
right() > 0) {
125 d.x = (0.5 * (xTarget[columns] + xTarget[columns - 1]));
126 d.y = (0.5 * (yTarget[1] + yTarget[0]));
127 d.sourceLeft = sourceCenterRight;
128 d.sourceTop = sourceRect.
top();
129 d.width = sourceMargins.
right();
130 d.height = sourceMargins.
top();
131 d.scaleX =
qreal(xTarget[columns] - xTarget[columns - 1]) /
d.width;
132 d.scaleY =
qreal(yTarget[1] - yTarget[0]) /
d.height;
138 if (targetMargins.
bottom() > 0 && targetMargins.
left() > 0 && sourceMargins.
bottom() > 0 && sourceMargins.
left() > 0) {
139 d.x = (0.5 * (xTarget[1] + xTarget[0]));
140 d.y =(0.5 * (yTarget[rows] + yTarget[rows - 1]));
141 d.sourceLeft = sourceRect.
left();
142 d.sourceTop = sourceCenterBottom;
143 d.width = sourceMargins.
left();
144 d.height = sourceMargins.
bottom();
145 d.scaleX =
qreal(xTarget[1] - xTarget[0]) /
d.width;
146 d.scaleY =
qreal(yTarget[rows] - yTarget[rows - 1]) /
d.height;
152 if (targetMargins.
bottom() > 0 && targetMargins.
right() > 0 && sourceMargins.
bottom() > 0 && sourceMargins.
right() > 0) {
153 d.x = (0.5 * (xTarget[columns] + xTarget[columns - 1]));
154 d.y = (0.5 * (yTarget[rows] + yTarget[rows - 1]));
155 d.sourceLeft = sourceCenterRight;
156 d.sourceTop = sourceCenterBottom;
157 d.width = sourceMargins.
right();
158 d.height = sourceMargins.
bottom();
159 d.scaleX =
qreal(xTarget[columns] - xTarget[columns - 1]) /
d.width;
160 d.scaleY =
qreal(yTarget[rows] - yTarget[rows - 1]) /
d.height;
168 if (targetCenterWidth > 0 && sourceCenterWidth > 0) {
169 if (targetMargins.
top() > 0 && sourceMargins.
top() > 0) {
171 d.sourceLeft = sourceCenterLeft;
172 d.sourceTop = sourceRect.
top();
173 d.width = sourceCenterWidth;
174 d.height = sourceMargins.
top();
175 d.y = (0.5 * (yTarget[1] + yTarget[0]));
176 d.scaleX = dx /
d.width;
177 d.scaleY =
qreal(yTarget[1] - yTarget[0]) /
d.height;
178 for (
int i = 1;
i < columns - 1; ++
i) {
179 d.x = (0.5 * (xTarget[
i + 1] + xTarget[
i]));
183 data[
data.size() - 1].width = ((xTarget[columns - 1] - xTarget[columns - 2]) /
d.scaleX);
185 if (targetMargins.
bottom() > 0 && sourceMargins.
bottom() > 0) {
187 d.sourceLeft = sourceCenterLeft;
188 d.sourceTop = sourceCenterBottom;
189 d.width = sourceCenterWidth;
190 d.height = sourceMargins.
bottom();
191 d.y = (0.5 * (yTarget[rows] + yTarget[rows - 1]));
192 d.scaleX = dx /
d.width;
193 d.scaleY =
qreal(yTarget[rows] - yTarget[rows - 1]) /
d.height;
194 for (
int i = 1;
i < columns - 1; ++
i) {
195 d.x = (0.5 * (xTarget[
i + 1] + xTarget[
i]));
199 data[
data.size() - 1].width = ((xTarget[columns - 1] - xTarget[columns - 2]) /
d.scaleX);
204 if (targetCenterHeight > 0 && sourceCenterHeight > 0) {
205 if (targetMargins.
left() > 0 && sourceMargins.
left() > 0) {
207 d.sourceLeft = sourceRect.
left();
208 d.sourceTop = sourceCenterTop;
209 d.width = sourceMargins.
left();
210 d.height = sourceCenterHeight;
211 d.x = (0.5 * (xTarget[1] + xTarget[0]));
212 d.scaleX =
qreal(xTarget[1] - xTarget[0]) /
d.width;
213 d.scaleY = dy /
d.height;
214 for (
int i = 1;
i < rows - 1; ++
i) {
215 d.y = (0.5 * (yTarget[
i + 1] + yTarget[
i]));
219 data[
data.size() - 1].height = ((yTarget[rows - 1] - yTarget[rows - 2]) /
d.scaleY);
221 if (targetMargins.
right() > 0 && sourceMargins.
right() > 0) {
223 d.sourceLeft = sourceCenterRight;
224 d.sourceTop = sourceCenterTop;
225 d.width = sourceMargins.
right();
226 d.height = sourceCenterHeight;
227 d.x = (0.5 * (xTarget[columns] + xTarget[columns - 1]));
228 d.scaleX =
qreal(xTarget[columns] - xTarget[columns - 1]) /
d.width;
229 d.scaleY = dy /
d.height;
230 for (
int i = 1;
i < rows - 1; ++
i) {
231 d.y = (0.5 * (yTarget[
i + 1] + yTarget[
i]));
235 data[
data.size() - 1].height = ((yTarget[rows - 1] - yTarget[rows - 2]) /
d.scaleY);
240 if (targetCenterWidth > 0 && targetCenterHeight > 0 && sourceCenterWidth > 0 && sourceCenterHeight > 0) {
242 d.sourceLeft = sourceCenterLeft;
243 d.sourceTop = sourceCenterTop;
244 d.width = sourceCenterWidth;
245 d.height = sourceCenterHeight;
246 d.scaleX = dx /
d.width;
247 d.scaleY = dy /
d.height;
249 qreal repeatWidth = (xTarget[columns - 1] - xTarget[columns - 2]) /
d.scaleX;
250 qreal repeatHeight = (yTarget[rows - 1] - yTarget[rows - 2]) /
d.scaleY;
252 for (
int j = 1;
j < rows - 1; ++
j) {
253 d.y = (0.5 * (yTarget[
j + 1] + yTarget[
j]));
254 for (
int i = 1;
i < columns - 1; ++
i) {
255 d.x = (0.5 * (xTarget[
i + 1] + xTarget[
i]));
259 data[
data.size() - 1].width = repeatWidth;
262 for (
int i = 1;
i < columns - 1; ++
i)
263 data[
data.size() -
i].height = repeatHeight;
267 if (opaqueData.
size())
269 if (translucentData.
size())
276 : m_innerSourceRect(0, 0, 1, 1)
277 , m_subSourceRect(0, 0, 1, 1)
279 , m_mirrorHorizontally(
false)
280 , m_mirrorVertically(
false)
281 , m_textureIsLayer(
false)
283 , m_tileHorizontal(
false)
284 , m_tileVertical(
false)
285 , m_cachedMirroredPixmapIsDirty(
false)
294 if (
rect == m_targetRect)
302 if (
rect == m_innerTargetRect)
304 m_innerTargetRect =
rect;
310 if (
rect == m_innerSourceRect)
312 m_innerSourceRect =
rect;
318 if (
rect == m_subSourceRect)
320 m_subSourceRect =
rect;
327 m_cachedMirroredPixmapIsDirty =
true;
328 m_textureIsLayer =
static_cast<bool>(qobject_cast<QSGSoftwareLayer*>(
texture));
334 if (mirrorHorizontally == m_mirrorHorizontally && mirrorVertically == m_mirrorVertically)
336 m_mirrorHorizontally = mirrorHorizontally;
337 m_mirrorVertically = mirrorVertically;
338 m_cachedMirroredPixmapIsDirty =
true;
349 if (smooth == m_smooth)
359 if (tileHorizontal == m_tileHorizontal)
362 m_tileHorizontal = tileHorizontal;
369 if (tileVertical == m_tileVertical)
378 if (m_cachedMirroredPixmapIsDirty) {
379 if (m_mirrorHorizontally || m_mirrorVertically || m_textureIsLayer) {
381 (m_mirrorHorizontally ? -1 : 1), 0,
382 0 , (m_textureIsLayer ? -1 : 1) * (m_mirrorVertically ? -1 : 1),
388 if (!m_cachedMirroredPixmap.
isNull())
389 m_cachedMirroredPixmap =
QPixmap();
391 m_cachedMirroredPixmapIsDirty =
false;
397 bool doDirty =
false;
398 QSGLayer *
t = qobject_cast<QSGLayer *>(m_texture);
400 doDirty =
t->updateTexture();
405 m_cachedMirroredPixmapIsDirty = doDirty;
410 int ifactor =
qRound(factor);
412 if (ifactor == 1 || ifactor == 0)
426 const QPixmap &pm = m_mirrorHorizontally || m_mirrorVertically || m_textureIsLayer ? m_cachedMirroredPixmap :
pixmap();
428 if (m_innerTargetRect != m_targetRect) {
430 QMargins margins(m_innerTargetRect.
left() - m_targetRect.
left(), m_innerTargetRect.
top() - m_targetRect.
top(),
434 margins, tilerules, QSGSoftwareHelpers::QDrawBorderPixmap::DrawingHints{});
438 if (m_tileHorizontal || m_tileVertical) {
465 return layer->pixmap();
467 static const QPixmap nullPixmap;
constexpr int bottom() const noexcept
Returns the bottom margin.
constexpr int left() const noexcept
Returns the left margin.
constexpr int right() const noexcept
Returns the right margin.
constexpr int top() const noexcept
Returns the top margin.
This class is used in conjunction with the QPainter::drawPixmapFragments() function to specify how a ...
The QPainter class performs low-level painting on widgets and other paint devices.
void drawPixmapFragments(const PixmapFragment *fragments, int fragmentCount, const QPixmap &pixmap, PixmapFragmentHints hints=PixmapFragmentHints())
void drawTiledPixmap(const QRectF &rect, const QPixmap &pm, const QPointF &offset=QPointF())
Draws a tiled pixmap, inside the given rectangle with its origin at the given position.
void restore()
Restores the current painter state (pops a saved state off the stack).
void save()
Saves the current painter state (pushes the state onto a stack).
void drawPixmap(const QRectF &targetRect, const QPixmap &pixmap, const QRectF &sourceRect)
Draws the rectangular portion source of the given pixmap into the given target in the paint device.
void setRenderHint(RenderHint hint, bool on=true)
Sets the given render hint on the painter if on is true; otherwise clears the render hint.
void setTransform(const QTransform &transform, bool combine=false)
Returns a copy of the pixmap that is transformed using the given transformation transform and transfo...
int height() const
Returns the height of the pixmap.
bool isNull() const
Returns true if this is a null pixmap; otherwise returns false.
int width() const
Returns the width of the pixmap.
QPixmap transformed(const QTransform &, Qt::TransformationMode mode=Qt::FastTransformation) const
\inmodule QtCore\reentrant
\inmodule QtCore\reentrant
constexpr qreal bottom() const noexcept
Returns the y-coordinate of the rectangle's bottom edge.
constexpr qreal y() const noexcept
Returns the y-coordinate of the rectangle's top edge.
constexpr qreal height() const noexcept
Returns the height of the rectangle.
constexpr qreal width() const noexcept
Returns the width of the rectangle.
constexpr qreal x() const noexcept
Returns the x-coordinate of the rectangle's left edge.
constexpr qreal left() const noexcept
Returns the x-coordinate of the rectangle's left edge.
constexpr QRect toRect() const noexcept
Returns a QRect based on the values of this rectangle.
constexpr qreal top() const noexcept
Returns the y-coordinate of the rectangle's top edge.
constexpr qreal right() const noexcept
Returns the x-coordinate of the rectangle's right edge.
\inmodule QtCore\reentrant
constexpr int height() const noexcept
Returns the height of the rectangle.
constexpr int bottom() const noexcept
Returns the y-coordinate of the rectangle's bottom edge.
constexpr int top() const noexcept
Returns the y-coordinate of the rectangle's top edge.
constexpr int left() const noexcept
Returns the x-coordinate of the rectangle's left edge.
constexpr int width() const noexcept
Returns the width of the rectangle.
constexpr int right() const noexcept
Returns the x-coordinate of the rectangle's right edge.
void setGeometry(QSGGeometry *geometry)
Sets the geometry of this node to geometry.
void setMaterial(QSGMaterial *material)
Sets the material of this geometry node to material.
The QSGGeometry class provides low-level storage for graphics primitives in the \l{Qt Quick Scene Gra...
The QSGMaterial class encapsulates rendering state for a shader program.
void markDirty(DirtyState bits)
Notifies all connected renderers that the node has dirty bits.
void setInnerSourceRect(const QRectF &rect) override
void paint(QPainter *painter)
void setTexture(QSGTexture *texture) override
void setSubSourceRect(const QRectF &rect) override
const QPixmap & pixmap() const
void preprocess() override
Override this function to do processing on the node before it is rendered.
void setTargetRect(const QRectF &rect) override
void setVerticalWrapMode(QSGTexture::WrapMode wrapMode) override
void setInnerTargetRect(const QRectF &rect) override
QSGSoftwareInternalImageNode()
void setMirror(bool mirrorHorizontally, bool mirrorVertically) override
void setMipmapFiltering(QSGTexture::Filtering filtering) override
void setHorizontalWrapMode(QSGTexture::WrapMode wrapMode) override
void setFiltering(QSGTexture::Filtering filtering) override
Filtering
Specifies how sampling of texels should filter when texture coordinates are not pixel aligned.
WrapMode
Specifies how the sampler should treat texture coordinates.
constexpr size_type size() const noexcept
void resize(qsizetype sz)
static QMargins normalizedMargins(const QMargins &m)
void qDrawBorderPixmap(QPainter *painter, const QRect &targetRect, const QMargins &targetMarginsIn, const QPixmap &pixmap, const QRect &sourceRect, const QMargins &sourceMarginsIn, const QTileRules &rules, QDrawBorderPixmap::DrawingHints hints)
Combined button and popup list for selecting options.
bool qFuzzyCompare(qfloat16 p1, qfloat16 p2) noexcept
int qRound(qfloat16 d) noexcept
constexpr const T & qMax(const T &a, const T &b)
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLuint GLenum GLenum transform
static Qt::TileRule getTileRule(qreal factor)