diff options
author | Albert Astals Cid <albert.astals@canonical.com> | 2016-07-15 14:21:37 +0200 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2016-11-11 17:20:10 +0000 |
commit | 9c50216c7bbbdb2bb51d4485286bf09e12fb5b62 (patch) | |
tree | 39b9bd552507482b87fceeaedad42e4bf12eca11 /src/quick/items/qquickimage.cpp | |
parent | 6cb21a9296b34d66d7b50d6b38c09294634202e0 (diff) |
Scale images correctly with sourceSize and PreserveAspectCrop/Fit
It also introduces a private QQuickImageProviderWithOptions to allow
passing options to image providers so that they can return more
fine-tuned images. This private class will disappear in Qt6 and the
functionality will be merged into QQuickImageProvider.
Change-Id: I619065d889d21d3a9e1f8e45fdb6076b9657c7ed
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'src/quick/items/qquickimage.cpp')
-rw-r--r-- | src/quick/items/qquickimage.cpp | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/quick/items/qquickimage.cpp b/src/quick/items/qquickimage.cpp index a53d068597..f71a2fbdbd 100644 --- a/src/quick/items/qquickimage.cpp +++ b/src/quick/items/qquickimage.cpp @@ -304,6 +304,15 @@ void QQuickImage::setFillMode(FillMode mode) if (d->fillMode == mode) return; d->fillMode = mode; + if ((mode == PreserveAspectCrop) != d->providerOptions.preserveAspectRatioCrop()) { + d->providerOptions.setPreserveAspectRatioCrop(mode == PreserveAspectCrop); + if (isComponentComplete()) + load(); + } else if ((mode == PreserveAspectFit) != d->providerOptions.preserveAspectRatioFit()) { + d->providerOptions.setPreserveAspectRatioFit(mode == PreserveAspectFit); + if (isComponentComplete()) + load(); + } update(); updatePaintedGeometry(); emit fillModeChanged(); @@ -423,7 +432,9 @@ qreal QQuickImage::paintedHeight() const (The \l fillMode is independent of this.) If both the sourceSize.width and sourceSize.height are set the image will be scaled - down to fit within the specified size, maintaining the image's aspect ratio. The actual + down to fit within the specified size (unless PreserveAspectCrop or PreserveAspectFit + are used, then it will be scaled to match the optimal size for cropping/fitting), + maintaining the image's aspect ratio. The actual size of the image after scaling is available via \l Item::implicitWidth and \l Item::implicitHeight. If the source is an intrinsically scalable image (eg. SVG), this property |