improvement(StatusImageCrop): add option to limit to fill

Currently only fit image is supported as minimum limit
This change sdds option to fill crop window with image as
minimum zoom which is required by status-go crop function
This commit is contained in:
Stefan 2022-05-11 15:22:13 +03:00 committed by Michał Cieślak
parent f1ddedd2b9
commit 0d8bbcde8f
2 changed files with 26 additions and 6 deletions

View File

@ -264,12 +264,11 @@ Item {
enabled: root.interactive
from: 1
from: cropEditor.minZoomScale
to: cropEditor.maxZoomScale
value: cropEditor.zoomScale
live: false
onMoved: cropEditor.setCropRect(cropEditor.getZoomRect(valueAt(visualPosition)))
to: 10
}
StatusIcon {
icon: "add-circle"

View File

@ -94,6 +94,21 @@ Item {
*/
property real wallTransparency: 0.7
/*!
\qmlproperty bool StatusImageCrop::allowZoomToFitAllContent
\c true to limit the content to fit at minimum zoom; that's it, the user will see the entire image
in the crop window, in case of aspect-ratio mismatch, allowing transparent/no-content borders in the crop window.
\c false to limit the content to fill at minimum zoom; that's it, the user will see only part of the image
in the crop window in case of aspect-ratio mismatch. This way, we don't allow transparent/no-content space
*/
property bool allowZoomToFitAllContent: false
/*!
\qmlproperty real StatusImageCrop::minZoomScale
Minimum allowed zoom. This is 1 if \c allowZoomToFitAllContent is true else depends on the
source aspect ratio.
*/
readonly property real minZoomScale: allowZoomToFitAllContent ? 1 : d.zoomToFill
/*!
\qmlproperty real StatusImageCrop::maxZoomScale
Don't allow to zoom in more than maxZoomScale factor
@ -166,8 +181,8 @@ Item {
nZoom = root.maxZoomScale
n = root.getZoomRect(nZoom)
}
else if(nZoom < 1) {
nZoom = 1
else if(nZoom < root.minZoomScale) {
nZoom = root.minZoomScale
n = root.getZoomRect(nZoom)
}
@ -248,8 +263,14 @@ Item {
QtObject {
id: d
property rect cropRect: fillContentInSquaredWindow(sourceSize)
property rect cropRect: fillContentInSquaredWindow(root.sourceSize)
onCropRectChanged: windowRect.requestPaint()
readonly property real zoomToFill: {
const rectangle = fillContentInSquaredWindow(root.sourceSize)
return d.currentZoom(root.sourceSize, Qt.size(rectangle.width, rectangle.height))
}
property rect cropWindow
// Probably called from render thread, run async
signal updateCropWindow(rect newRect)