From 1c0d4b0133b8a0a0ac21be9af065b94d6df1b94d Mon Sep 17 00:00:00 2001 From: Stefan Date: Wed, 11 May 2022 15:22:13 +0300 Subject: [PATCH] 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 --- .../Components/StatusImageCropPanel.qml | 5 ++-- src/StatusQ/Controls/StatusImageCrop.qml | 27 ++++++++++++++++--- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/StatusQ/Components/StatusImageCropPanel.qml b/src/StatusQ/Components/StatusImageCropPanel.qml index 63548de5..d8b31af9 100644 --- a/src/StatusQ/Components/StatusImageCropPanel.qml +++ b/src/StatusQ/Components/StatusImageCropPanel.qml @@ -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" diff --git a/src/StatusQ/Controls/StatusImageCrop.qml b/src/StatusQ/Controls/StatusImageCrop.qml index e30d61e4..84b21e47 100644 --- a/src/StatusQ/Controls/StatusImageCrop.qml +++ b/src/StatusQ/Controls/StatusImageCrop.qml @@ -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)