diff options
author | Simon Hausmann <simon.hausmann@qt.io> | 2017-04-07 14:48:56 +0200 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@qt.io> | 2017-04-07 12:53:23 +0000 |
commit | 017350a8a9b4ac866c9b79186bf5a1dd6f6f06ec (patch) | |
tree | f98070d9bf0bd5659d34355b5eb9647637874187 /src/quick/util/qquickimageprovider.cpp | |
parent | b361a59c699fca02379c149cf0b9c59490a1ba62 (diff) | |
parent | 67d1d7843ab5e1c904c8f0f76eadb9fc3f1bbb17 (diff) |
Merge remote-tracking branch 'origin/5.9' into dev
Conflicts:
src/qml/jit/qv4assembler.cpp
src/qml/jit/qv4assembler_p.h
src/qml/jit/qv4isel_masm.cpp
src/qml/jsruntime/qv4vme_moth.cpp
Change-Id: I865d794e550a263387a39ca8d051ebf48b70cbc0
Diffstat (limited to 'src/quick/util/qquickimageprovider.cpp')
-rw-r--r-- | src/quick/util/qquickimageprovider.cpp | 45 |
1 files changed, 44 insertions, 1 deletions
diff --git a/src/quick/util/qquickimageprovider.cpp b/src/quick/util/qquickimageprovider.cpp index 0ceed7f681..c4a98c69f9 100644 --- a/src/quick/util/qquickimageprovider.cpp +++ b/src/quick/util/qquickimageprovider.cpp @@ -613,7 +613,6 @@ void QQuickImageProviderOptions::setPreserveAspectRatioFit(bool preserveAspectRa d->preserveAspectRatioFit = preserveAspectRatioFit; } - QQuickImageProviderWithOptions::QQuickImageProviderWithOptions(ImageType type, Flags flags) : QQuickAsyncImageProvider() { @@ -670,5 +669,49 @@ QQuickImageResponse *QQuickImageProviderWithOptions::requestImageResponse(const return requestImageResponse(id, requestedSize); } +/*! + Returns the recommended scaled image size for loading and storage. This is + calculated according to the native pixel size of the image \a originalSize, + the requested sourceSize \a requestedSize, the image file format \a format, + and \a options. If the calculation otherwise concludes that scaled loading + is not recommended, an invalid size is returned. +*/ +QSize QQuickImageProviderWithOptions::loadSize(const QSize &originalSize, const QSize &requestedSize, const QByteArray &format, const QQuickImageProviderOptions &options) +{ + QSize res; + if ((requestedSize.width() <= 0 && requestedSize.height() <= 0) || originalSize.isEmpty()) + return res; + + const bool preserveAspectCropOrFit = options.preserveAspectRatioCrop() || options.preserveAspectRatioFit(); + const bool force_scale = (format == "svg" || format == "svgz"); + + qreal ratio = 0.0; + if (requestedSize.width() && (preserveAspectCropOrFit || force_scale || requestedSize.width() < originalSize.width())) { + ratio = qreal(requestedSize.width()) / originalSize.width(); + } + if (requestedSize.height() && (preserveAspectCropOrFit || force_scale || requestedSize.height() < originalSize.height())) { + qreal hr = qreal(requestedSize.height()) / originalSize.height(); + if (ratio == 0.0) + ratio = hr; + else if (!preserveAspectCropOrFit && (hr < ratio)) + ratio = hr; + else if (preserveAspectCropOrFit && (hr > ratio)) + ratio = hr; + } + if (ratio > 0.0) { + res.setHeight(qRound(originalSize.height() * ratio)); + res.setWidth(qRound(originalSize.width() * ratio)); + } + return res; +} + +QQuickImageProviderWithOptions *QQuickImageProviderWithOptions::checkedCast(QQuickImageProvider *provider) +{ + if (provider && provider->d && provider->d->isProviderWithOptions) + return static_cast<QQuickImageProviderWithOptions *>(provider); + + return nullptr; +} + QT_END_NAMESPACE |