diff options
Diffstat (limited to 'src/quick/util/qquickimageprovider.cpp')
-rw-r--r-- | src/quick/util/qquickimageprovider.cpp | 169 |
1 files changed, 152 insertions, 17 deletions
diff --git a/src/quick/util/qquickimageprovider.cpp b/src/quick/util/qquickimageprovider.cpp index 6cecf6f6f6..c4182d9f93 100644 --- a/src/quick/util/qquickimageprovider.cpp +++ b/src/quick/util/qquickimageprovider.cpp @@ -44,13 +44,6 @@ QT_BEGIN_NAMESPACE -class QQuickImageProviderPrivate -{ -public: - QQuickImageProvider::ImageType type; - QQuickImageProvider::Flags flags; -}; - /*! \class QQuickTextureFactory \since 5.0 @@ -105,7 +98,7 @@ QImage QQuickTextureFactory::image() const } /*! - Returns a QQuickTextureFactory holding the given image. + Returns a QQuickTextureFactory holding the given \a image. This is typically used as a helper in QQuickImageResponse::textureFactory. @@ -187,6 +180,8 @@ QString QQuickImageResponse::errorString() const This method is used to communicate that the response is no longer required by the engine. It may be reimplemented to cancel a request in the provider side, however, it is not mandatory. + + A cancelled QQuickImageResponse still needs to emit finished(). */ void QQuickImageResponse::cancel() { @@ -347,6 +342,7 @@ QQuickImageProvider::QQuickImageProvider(ImageType type, Flags flags) { d->type = type; d->flags = flags; + d->isProviderWithOptions = false; } /*! @@ -500,26 +496,165 @@ QQuickAsyncImageProvider::~QQuickAsyncImageProvider() implementation of this method is reentrant. */ + +class QQuickImageProviderOptionsPrivate : public QSharedData +{ +public: + QQuickImageProviderOptionsPrivate() + : autoTransform(QQuickImageProviderOptions::UsePluginDefaultTransform) + , preserveAspectRatioCrop(false) + , preserveAspectRatioFit(false) + { + } + + QQuickImageProviderOptions::AutoTransform autoTransform; + bool preserveAspectRatioCrop; + bool preserveAspectRatioFit; +}; + /*! - \fn QImage QQuickImageProvider::requestImage(const QString &id, QSize *size, const QSize& requestedSize, bool requestedAutoTransform); + \class QQuickImageProviderOptions + \since 5.9 + \brief The QQuickImageProviderOptions class provides options for QQuickImageProviderWithOptions image requests. + \inmodule QtQuick - \internal - For future reference. + \sa QQuickImageProviderWithOptions */ /*! - \fn QPixmap QQuickImageProvider::requestPixmap(const QString &id, QSize *size, const QSize& requestedSize, bool requestedAutoTransform); + \enum QQuickImageProviderOptions::AutoTransform + + Whether the image provider should apply transformation metadata on read(). + + \value UsePluginDefaultTransform Image provider should do its default behavior on whether applying transformation metadata on read or not + \value ApplyTransform Image provider should apply transformation metadata on read + \value DoNotApplyTransform Image provider should not apply transformation metadata on read +*/ + +QQuickImageProviderOptions::QQuickImageProviderOptions() + : d(new QQuickImageProviderOptionsPrivate()) +{ +} - \internal - For future reference. +QQuickImageProviderOptions::~QQuickImageProviderOptions() +{ +} + +QQuickImageProviderOptions::QQuickImageProviderOptions(const QQuickImageProviderOptions &other) + : d(other.d) +{ +} + +QQuickImageProviderOptions& QQuickImageProviderOptions::operator=(const QQuickImageProviderOptions &other) +{ + d = other.d; + return *this; +} + +bool QQuickImageProviderOptions::operator==(const QQuickImageProviderOptions &other) const +{ + return d->autoTransform == other.d->autoTransform && + d->preserveAspectRatioCrop == other.d->preserveAspectRatioCrop && + d->preserveAspectRatioFit == other.d->preserveAspectRatioFit; +} + +/*! + Returns whether the image provider should apply transformation metadata on read(). */ +QQuickImageProviderOptions::AutoTransform QQuickImageProviderOptions::autoTransform() const +{ + return d->autoTransform; +} + +void QQuickImageProviderOptions::setAutoTransform(QQuickImageProviderOptions::AutoTransform autoTransform) +{ + d->autoTransform = autoTransform; +} /*! - \fn QQuickTextureFactory *QQuickImageProvider::requestTexture(const QString &id, QSize *size, const QSize &requestedSize, bool requestedAutoTransform); + Returns whether the image request is for a PreserveAspectCrop Image. + This allows the provider to better optimize the size of the returned image. +*/ +bool QQuickImageProviderOptions::preserveAspectRatioCrop() const +{ + return d->preserveAspectRatioCrop; +} - \internal - For future reference. +void QQuickImageProviderOptions::setPreserveAspectRatioCrop(bool preserveAspectRatioCrop) +{ + d->preserveAspectRatioCrop = preserveAspectRatioCrop; +} + +/*! + Returns whether the image request is for a PreserveAspectFit Image. + This allows the provider to better optimize the size of the returned image. */ +bool QQuickImageProviderOptions::preserveAspectRatioFit() const +{ + return d->preserveAspectRatioFit; +} + +void QQuickImageProviderOptions::setPreserveAspectRatioFit(bool preserveAspectRatioFit) +{ + d->preserveAspectRatioFit = preserveAspectRatioFit; +} + + +QQuickImageProviderWithOptions::QQuickImageProviderWithOptions(ImageType type, Flags flags) + : QQuickAsyncImageProvider() +{ + QQuickImageProvider::d->type = type; + QQuickImageProvider::d->flags = flags; + QQuickImageProvider::d->isProviderWithOptions = true; +} + +QImage QQuickImageProviderWithOptions::requestImage(const QString &id, QSize *size, const QSize& requestedSize) +{ + return requestImage(id, size, requestedSize, QQuickImageProviderOptions()); +} + +QPixmap QQuickImageProviderWithOptions::requestPixmap(const QString &id, QSize *size, const QSize& requestedSize) +{ + return requestPixmap(id, size, requestedSize, QQuickImageProviderOptions()); +} + +QQuickTextureFactory *QQuickImageProviderWithOptions::requestTexture(const QString &id, QSize *size, const QSize &requestedSize) +{ + return requestTexture(id, size, requestedSize, QQuickImageProviderOptions()); +} + +QImage QQuickImageProviderWithOptions::requestImage(const QString &id, QSize *size, const QSize& requestedSize, const QQuickImageProviderOptions &options) +{ + Q_UNUSED(options); + return QQuickAsyncImageProvider::requestImage(id, size, requestedSize); +} + +QPixmap QQuickImageProviderWithOptions::requestPixmap(const QString &id, QSize *size, const QSize& requestedSize, const QQuickImageProviderOptions &options) +{ + Q_UNUSED(options); + return QQuickAsyncImageProvider::requestPixmap(id, size, requestedSize); +} + +QQuickTextureFactory *QQuickImageProviderWithOptions::requestTexture(const QString &id, QSize *size, const QSize &requestedSize, const QQuickImageProviderOptions &options) +{ + Q_UNUSED(options); + return QQuickAsyncImageProvider::requestTexture(id, size, requestedSize); +} + +QQuickImageResponse *QQuickImageProviderWithOptions::requestImageResponse(const QString &id, const QSize &requestedSize) +{ + Q_UNUSED(id); + Q_UNUSED(requestedSize); + if (imageType() == ImageResponse) + qWarning("ImageProvider is of ImageResponse type but has not implemented requestImageResponse()"); + return nullptr; +} + +QQuickImageResponse *QQuickImageProviderWithOptions::requestImageResponse(const QString &id, const QSize &requestedSize, const QQuickImageProviderOptions &options) +{ + Q_UNUSED(options); + return requestImageResponse(id, requestedSize); +} QT_END_NAMESPACE |