aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/items/qquickimage.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/quick/items/qquickimage.cpp')
-rw-r--r--src/quick/items/qquickimage.cpp153
1 files changed, 91 insertions, 62 deletions
diff --git a/src/quick/items/qquickimage.cpp b/src/quick/items/qquickimage.cpp
index d704681d6a..3aaa59819c 100644
--- a/src/quick/items/qquickimage.cpp
+++ b/src/quick/items/qquickimage.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtQuick module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qquickimage_p.h"
#include "qquickimage_p_p.h"
@@ -129,6 +93,20 @@ QQuickImagePrivate::QQuickImagePrivate()
\li \c ASTC (since Qt 5.13)
\endlist
+ \note The intended vertical orientation of an image in a texture file is not generally well
+ defined. Different texture compression tools have different defaults and options of when to
+ perform vertical flipping of the input image. If an image from a texture file appears upside
+ down, flipping may need to be toggled in the asset conditioning process. Alternatively, the
+ Image element itself can be flipped by either applying a suitable transformation via the
+ transform property or, more conveniently, by setting the mirrorVertically property:
+ \badcode
+ transform: [ Translate { y: -myImage.height }, Scale { yScale: -1 } ]
+ \endcode
+ or
+ \badcode
+ mirrorVertically: true
+ \endcode
+
\note Semi-transparent original images require alpha pre-multiplication
prior to texture compression in order to be correctly displayed in Qt
Quick. This can be done with the following ImageMagick command
@@ -137,6 +115,43 @@ QQuickImagePrivate::QQuickImagePrivate()
convert foo.png \( +clone -alpha Extract \) -channel RGB -compose Multiply -composite foo_pm.png
\endcode
+ Do not confuse container formats, such as, \c KTX, and the format of the
+ actual texture data stored in the container file. For example, reading a
+ \c KTX file is supported on all platforms, independently of what GPU driver is
+ used at run time. However, this does not guarantee that the compressed
+ texture format, used by the data in the file, is supported at run time. For
+ example, if the KTX file contains compressed data with the format
+ \c{ETC2 RGBA8}, and the 3D graphics API implementation used at run time does not
+ support \c ETC2 compressed textures, the Image item will not display
+ anything.
+
+ \note Compressed texture format support is not under Qt's control, and it
+ is up to the application or device developer to ensure the compressed
+ texture data is provided in the appropriate format for the target
+ environment(s).
+
+ Do not assume that compressed format support is specific to a platform. It
+ may also be specific to the driver and 3D API implementation in use on that
+ particular platform. In practice, implementations of different 3D graphics
+ APIs (e.g., Vulkan and OpenGL) on the same platform (e.g., Windows) from
+ the same vendor for the same hardware may offer a different set of
+ compressed texture formats.
+
+ When targeting desktop environments (Windows, macOS, Linux) only, a general
+ recommendation is to consider using the \c{DXTn}/\c{BCn} formats since
+ these tend to have the widest support amongst the implementations of Direct
+ 3D, Vulkan, OpenGL, and Metal on these platforms. In contrast, when
+ targeting mobile or embedded devices, the \c ETC2 or \c ASTC formats are
+ likely to be a better choice since these are typically the formats
+ supported by the OpenGL ES implementations on such hardware.
+
+ An application that intends to run across desktop, mobile, and embedded
+ hardware should plan and design its use of compressed textures carefully.
+ It is highly likely that relying on a single format is not going to be
+ sufficient, and therefore the application will likely need to branch based
+ on the platform to use compressed textures in a format appropriate there,
+ or perhaps to skip using compressed textures in some cases.
+
\section1 Automatic Detection of File Extension
If the \l source URL indicates a non-existing local file or resource, the
@@ -204,10 +219,7 @@ void QQuickImagePrivate::setImage(const QImage &image)
{
Q_Q(QQuickImage);
pix.setImage(image);
-
q->pixmapChange();
- status = pix.isNull() ? QQuickImageBase::Null : QQuickImageBase::Ready;
-
q->update();
}
@@ -215,10 +227,7 @@ void QQuickImagePrivate::setPixmap(const QQuickPixmap &pixmap)
{
Q_Q(QQuickImage);
pix.setPixmap(pixmap);
-
q->pixmapChange();
- status = pix.isNull() ? QQuickImageBase::Null : QQuickImageBase::Ready;
-
q->update();
}
@@ -227,15 +236,15 @@ void QQuickImagePrivate::setPixmap(const QQuickPixmap &pixmap)
Set this property to define what happens when the source image has a different size
than the item.
- \list
- \li Image.Stretch - the image is scaled to fit
- \li Image.PreserveAspectFit - the image is scaled uniformly to fit without cropping
- \li Image.PreserveAspectCrop - the image is scaled uniformly to fill, cropping if necessary
- \li Image.Tile - the image is duplicated horizontally and vertically
- \li Image.TileVertically - the image is stretched horizontally and tiled vertically
- \li Image.TileHorizontally - the image is stretched vertically and tiled horizontally
- \li Image.Pad - the image is not transformed
- \endlist
+
+ \value Image.Stretch the image is scaled to fit
+ \value Image.PreserveAspectFit the image is scaled uniformly to fit without cropping
+ \value Image.PreserveAspectCrop the image is scaled uniformly to fill, cropping if necessary
+ \value Image.Tile the image is duplicated horizontally and vertically
+ \value Image.TileVertically the image is stretched horizontally and tiled vertically
+ \value Image.TileHorizontally the image is stretched vertically and tiled horizontally
+ \value Image.Pad the image is not transformed
+ \br
\table
@@ -343,9 +352,9 @@ void QQuickImage::setFillMode(FillMode mode)
}
/*!
-
\qmlproperty real QtQuick::Image::paintedWidth
\qmlproperty real QtQuick::Image::paintedHeight
+ \readonly
These properties hold the size of the image that is actually painted.
In most cases it is the same as \c width and \c height, but when using an
@@ -367,14 +376,14 @@ qreal QQuickImage::paintedHeight() const
/*!
\qmlproperty enumeration QtQuick::Image::status
+ \readonly
This property holds the status of image loading. It can be one of:
- \list
- \li Image.Null - no image has been set
- \li Image.Ready - the image has been loaded
- \li Image.Loading - the image is currently being loaded
- \li Image.Error - an error occurred while loading the image
- \endlist
+
+ \value Image.Null No image has been set
+ \value Image.Ready The image has been loaded
+ \value Image.Loading The image is currently being loaded
+ \value Image.Error An error occurred while loading the image
Use this status to provide an update or respond to the status change in some way.
For example, you could:
@@ -404,6 +413,7 @@ qreal QQuickImage::paintedHeight() const
/*!
\qmlproperty real QtQuick::Image::progress
+ \readonly
This property holds the progress of image loading, from 0.0 (nothing loaded)
to 1.0 (finished).
@@ -425,7 +435,7 @@ qreal QQuickImage::paintedHeight() const
*/
/*!
- \qmlproperty QSize QtQuick::Image::sourceSize
+ \qmlproperty size QtQuick::Image::sourceSize
This property holds the scaled width and height of the full-frame image.
@@ -478,6 +488,8 @@ qreal QQuickImage::paintedHeight() const
\note \e {Changing this property dynamically causes the image source to be reloaded,
potentially even from the network, if it is not in the disk cache.}
+
+ \sa {Qt Quick Examples - Pointer Handlers}
*/
/*!
@@ -568,6 +580,17 @@ qreal QQuickImage::paintedHeight() const
*/
/*!
+ \qmlproperty bool QtQuick::Image::mirrorVertically
+
+ This property holds whether the image should be vertically inverted
+ (effectively displaying a mirrored image).
+
+ The default value is false.
+
+ \since 6.2
+*/
+
+/*!
\qmlproperty enumeration QtQuick::Image::horizontalAlignment
\qmlproperty enumeration QtQuick::Image::verticalAlignment
@@ -827,7 +850,7 @@ QSGNode *QQuickImage::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *)
node->setTargetRect(targetRect);
node->setInnerTargetRect(targetRect);
node->setSubSourceRect(nsrect);
- node->setMirror(d->mirror);
+ node->setMirror(d->mirrorHorizontally, d->mirrorVertically);
node->setAntialiasing(d->antialiasing);
node->update();
@@ -917,6 +940,8 @@ void QQuickImage::setMipmap(bool use)
emit mipmapChanged(d->mipmap);
d->pixmapChanged = true;
+ if (isComponentComplete())
+ load();
update();
}
@@ -943,3 +968,7 @@ void QQuickImage::setMipmap(bool use)
*/
QT_END_NAMESPACE
+
+#include "moc_qquickimage_p_p.cpp"
+
+#include "moc_qquickimage_p.cpp"