7#include <QtQuick/qsgtextureprovider.h>
9#include <QtQuick/private/qsgcontext_p.h>
10#include <private/qsgadaptationlayer_p.h>
11#include <private/qnumeric_p.h>
13#include <QtCore/qmath.h>
14#include <QtGui/qpainter.h>
15#include <QtCore/QRunnable>
43 : pixmapChanged(
false)
337 if (
d->fillMode ==
mode)
368 return d->paintedWidth;
374 return d->paintedHeight;
608 if (!
d->currentPix->width() || !
d->currentPix->height()) {
612 const qreal pixWidth =
d->currentPix->width() /
d->devicePixelRatio;
613 const qreal pixHeight =
d->currentPix->height() /
d->devicePixelRatio;
615 const qreal widthScale =
w / pixWidth;
617 const qreal heightScale =
h / pixHeight;
618 if (widthScale <= heightScale) {
620 d->paintedHeight = widthScale * pixHeight;
621 }
else if (heightScale < widthScale) {
622 d->paintedWidth = heightScale * pixWidth;
623 d->paintedHeight =
h;
630 if (!
d->currentPix->width() || !
d->currentPix->height())
632 const qreal pixWidth =
d->currentPix->width() /
d->devicePixelRatio;
633 const qreal pixHeight =
d->currentPix->height() /
d->devicePixelRatio;
636 if (widthScale < heightScale) {
637 widthScale = heightScale;
638 }
else if (heightScale < widthScale) {
639 heightScale = widthScale;
642 d->paintedHeight = heightScale * pixHeight;
643 d->paintedWidth = widthScale * pixWidth;
644 }
else if (
d->fillMode ==
Pad) {
645 d->paintedWidth =
d->currentPix->width() /
d->devicePixelRatio;
646 d->paintedHeight =
d->currentPix->height() /
d->devicePixelRatio;
648 d->paintedWidth =
width();
657 if (newGeometry.
size() != oldGeometry.
size())
679 qWarning(
"QQuickImage::textureProvider: can only be queried on the rendering thread of an exposed window");
694void QQuickImage::invalidateSceneGraph()
698 d->provider =
nullptr;
706 d->provider =
nullptr;
718 d->provider->m_smooth =
d->smooth;
719 d->provider->m_mipmap =
d->mipmap;
720 d->provider->updateTexture(
texture);
730 d->pixmapChanged =
true;
731 node =
d->sceneGraphContext()->createInternalImageNode(
d->sceneGraphRenderContext());
744 xOffset = (
width() - pixWidth) / 2;
750 yOffset = (
height() - pixHeight) / 2;
754 switch (
d->fillMode) {
757 sourceRect =
d->currentPix->rect();
761 targetRect =
QRectF(xOffset, yOffset,
d->paintedWidth,
d->paintedHeight);
762 sourceRect =
d->currentPix->rect();
770 if (wscale > hscale) {
771 int src = (hscale / wscale) *
qreal(
d->currentPix->height());
774 y =
qCeil((
d->currentPix->height() -
src) / 2.);
777 sourceRect =
QRectF(0,
y,
d->currentPix->width(),
src);
780 int src = (wscale / hscale) *
qreal(
d->currentPix->width());
783 x =
qCeil((
d->currentPix->width() -
src) / 2.);
786 sourceRect =
QRectF(
x, 0,
src,
d->currentPix->height());
800 sourceRect =
QRectF(-xOffset, 0,
width(),
d->currentPix->height());
806 sourceRect =
QRectF(0, -yOffset,
d->currentPix->width(),
height());
815 targetRect =
QRectF(
x + xOffset,
y + yOffset,
w,
h);
822 QRectF nsrect(sourceRect.
x() / nsWidth,
823 sourceRect.
y() / nsHeight,
824 sourceRect.
width() / nsWidth,
825 sourceRect.
height() / nsHeight);
827 if (targetRect.isEmpty()
835 if (
d->pixmapChanged) {
842 d->pixmapChanged =
false;
853 node->
setMirror(
d->mirrorHorizontally,
d->mirrorVertically);
870 d->pixmapChanged =
true;
885 if (
d->vAlign == align)
903 if (
d->hAlign == align)
937 if (
d->mipmap == use)
940 emit mipmapChanged(
d->mipmap);
942 d->pixmapChanged =
true;
991#include "moc_qquickimage_p_p.cpp"
993#include "moc_qquickimage_p.cpp"
QQuickPixmap * currentPix
virtual void pixmapChange()
void setPixmap(const QQuickPixmap &pixmap)
QQuickImageTextureProvider * provider
void setImage(const QImage &img)
QSGTexture * texture() const override
Returns a pointer to the texture object.
QQuickImageTextureProvider()
void updateTexture(QSGTexture *texture)
void setFillMode(FillMode)
VAlignment verticalAlignment
void horizontalAlignmentChanged(HAlignment alignment)
QSGNode * updatePaintNode(QSGNode *, UpdatePaintNodeData *) override
Called on the render thread when it is time to sync the state of the item with the scene graph.
QQuickImage(QQuickItem *parent=nullptr)
\qmltype Image \instantiates QQuickImage \inqmlmodule QtQuick\inherits Item
void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override
void updatePaintedGeometry()
\qmlproperty enumeration QtQuick::Image::status \readonly
QSGTextureProvider * textureProvider() const override
Returns the texture provider for an item.
QRectF boundingRect() const override
Returns the extents of the item in its own coordinate system: a rectangle from {0,...
void pixmapChange() override
HAlignment horizontalAlignment
void releaseResources() override
This function is called when an item should release graphics resources which are not already managed ...
void verticalAlignmentChanged(VAlignment alignment)
void setVerticalAlignment(VAlignment align)
void setHorizontalAlignment(HAlignment align)
void paintedGeometryChanged()
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
virtual void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry)
virtual QSGTextureProvider * textureProvider() const
Returns the texture provider for an item.
QQuickWindow * window() const
Returns the window in which this item is rendered.
qreal width
This property holds the width of this item.
bool isComponentComplete() const
Returns true if construction of the QML component is complete; otherwise returns false.
bool heightValid() const
Returns whether the height property has been set explicitly.
bool widthValid() const
Returns whether the width property has been set explicitly.
qreal height
This property holds the height of this item.
void update()
Schedules a call to updatePaintNode() for this item.
virtual bool isTextureProvider() const
Returns true if this item is a texture provider.
void setImplicitSize(qreal, qreal)
void setImage(const QImage &)
void setPixmap(const QQuickPixmap &other)
static void schedule(QQuickWindow *window, QObject *object)
\inmodule QtCore\reentrant
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 QSizeF size() const noexcept
Returns the size of the rectangle.
virtual void setHorizontalWrapMode(QSGTexture::WrapMode wrapMode)=0
virtual void setTexture(QSGTexture *texture)=0
virtual void setTargetRect(const QRectF &rect)=0
virtual void setFiltering(QSGTexture::Filtering filtering)=0
virtual void setSubSourceRect(const QRectF &rect)=0
virtual void setInnerTargetRect(const QRectF &rect)=0
virtual void setAntialiasing(bool antialiasing)
virtual void setMipmapFiltering(QSGTexture::Filtering filtering)=0
virtual void setMirror(bool horizontally, bool vertically)=0
virtual void setVerticalWrapMode(QSGTexture::WrapMode wrapMode)=0
\group qtquick-scenegraph-nodes \title Qt Quick Scene Graph Node classes
The QSGTextureProvider class encapsulates texture based entities in QML.
void textureChanged()
This signal is emitted when the texture changes.
void setHorizontalWrapMode(WrapMode hwrap)
Sets the horizontal wrap mode to hwrap.
void setFiltering(Filtering filter)
Sets the sampling mode to filter.
void setMipmapFiltering(Filtering filter)
Sets the mipmap sampling mode to filter.
WrapMode
Specifies how the sampler should treat texture coordinates.
void setVerticalWrapMode(WrapMode vwrap)
Sets the vertical wrap mode to vwrap.
static QThread * currentThread()
Combined button and popup list for selecting options.
constexpr const T & qMin(const T &a, const T &b)
constexpr const T & qMax(const T &a, const T &b)
static Q_DECL_CONST_FUNCTION bool qt_is_finite(double d)
GLint GLint GLint GLint GLint x
[0]
GLfloat GLfloat GLfloat w
[0]
GLint GLsizei GLsizei height
GLfloat GLfloat GLfloat GLfloat h
GLdouble GLdouble GLdouble GLdouble q