2021-02-10 20:37:17 +00:00
|
|
|
import QtQuick 2.13
|
|
|
|
import QtQuick.Controls 2.13
|
|
|
|
import QtQuick.Layouts 1.13
|
2021-09-28 15:04:06 +00:00
|
|
|
|
|
|
|
import utils 1.0
|
2021-10-14 10:52:56 +00:00
|
|
|
import "../"
|
|
|
|
import "../status"
|
|
|
|
import "../controls"
|
2021-02-10 20:37:17 +00:00
|
|
|
|
2021-10-14 10:52:56 +00:00
|
|
|
// TODO: replace with StatusModal
|
2021-02-10 20:37:17 +00:00
|
|
|
ModalPopup {
|
|
|
|
property string selectedImage
|
2021-03-29 12:28:41 +00:00
|
|
|
property string ratio: "1:1"
|
|
|
|
property int aX: 0
|
|
|
|
property int aY: 0
|
|
|
|
property int bX: 0
|
|
|
|
property int bY: 0
|
2021-02-10 20:37:17 +00:00
|
|
|
signal cropFinished(aX: int, aY: int, bX: int, bY: int)
|
|
|
|
|
|
|
|
id: cropImageModal
|
|
|
|
width: image.width + 50
|
|
|
|
height: image.height + 170
|
2021-07-16 20:22:50 +00:00
|
|
|
//% "Crop your image (optional)"
|
|
|
|
title: qsTrId("crop-your-image--optional-")
|
2021-02-10 20:37:17 +00:00
|
|
|
|
|
|
|
Image {
|
|
|
|
id: image
|
|
|
|
width: 400
|
|
|
|
source: cropImageModal.selectedImage
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
fillMode: Image.PreserveAspectFit
|
|
|
|
}
|
|
|
|
|
|
|
|
ImageCropper {
|
|
|
|
id: imageCropper
|
|
|
|
x: image.x
|
|
|
|
y: image.y
|
|
|
|
image: image
|
2021-03-05 16:23:44 +00:00
|
|
|
ratio: cropImageModal.ratio
|
2021-03-29 12:28:41 +00:00
|
|
|
onReadyChanged: {
|
|
|
|
if (ready) {
|
|
|
|
// cropImageModal.calculateCrop()
|
|
|
|
cropImageModal.aX = Qt.binding(function() {
|
|
|
|
const aXPercent = imageCropper.selectorRectangle.x / image.width
|
|
|
|
return Math.round(aXPercent * image.sourceSize.width)
|
|
|
|
})
|
|
|
|
cropImageModal.aY = Qt.binding(function() {
|
|
|
|
const aYPercent = imageCropper.selectorRectangle.y / image.height
|
|
|
|
return Math.round(aYPercent * image.sourceSize.height)
|
|
|
|
})
|
|
|
|
cropImageModal.bX = Qt.binding(function() {
|
|
|
|
const bXPercent = (imageCropper.selectorRectangle.x + imageCropper.selectorRectangle.width) / image.width
|
|
|
|
return Math.round(bXPercent * image.sourceSize.width)
|
|
|
|
})
|
|
|
|
cropImageModal.bY = Qt.binding(function() {
|
|
|
|
const bYPercent = (imageCropper.selectorRectangle.y + imageCropper.selectorRectangle.height) / image.height
|
|
|
|
return Math.round(bYPercent * image.sourceSize.height)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-10 20:37:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
footer: StatusButton {
|
|
|
|
id: doneBtn
|
2021-07-16 20:22:50 +00:00
|
|
|
//% "Finish"
|
|
|
|
text: qsTrId("finish")
|
2021-02-10 20:37:17 +00:00
|
|
|
anchors.right: parent.right
|
|
|
|
anchors.bottom: parent.bottom
|
|
|
|
onClicked: {
|
|
|
|
const aXPercent = imageCropper.selectorRectangle.x / image.width
|
|
|
|
const aYPercent = imageCropper.selectorRectangle.y / image.height
|
|
|
|
const bXPercent = (imageCropper.selectorRectangle.x + imageCropper.selectorRectangle.width) / image.width
|
|
|
|
const bYPercent = (imageCropper.selectorRectangle.y + imageCropper.selectorRectangle.height) / image.height
|
|
|
|
|
|
|
|
|
|
|
|
const aX = Math.round(aXPercent * image.sourceSize.width)
|
|
|
|
const aY = Math.round(aYPercent * image.sourceSize.height)
|
|
|
|
|
|
|
|
const bX = Math.round(bXPercent * image.sourceSize.width)
|
|
|
|
const bY = Math.round(bYPercent * image.sourceSize.height)
|
|
|
|
|
|
|
|
cropImageModal.cropFinished(aX, aY, bX, bY)
|
|
|
|
cropImageModal.close()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|