2024-10-15 19:26:12 +00:00
|
|
|
import QtQuick 2.15
|
|
|
|
import QtQuick.Controls 2.15
|
2024-11-01 09:13:00 +00:00
|
|
|
import QtQuick.Layouts 1.15
|
2022-08-08 09:46:48 +00:00
|
|
|
import QtQuick.Dialogs 1.3
|
2022-05-23 11:29:58 +00:00
|
|
|
|
2024-11-01 09:13:00 +00:00
|
|
|
import StatusQ 0.1
|
2022-05-23 11:29:58 +00:00
|
|
|
import StatusQ.Components 0.1
|
|
|
|
import StatusQ.Controls 0.1
|
|
|
|
import StatusQ.Core 0.1
|
|
|
|
import StatusQ.Core.Theme 0.1
|
|
|
|
import StatusQ.Popups 0.1
|
2024-11-01 09:13:00 +00:00
|
|
|
import StatusQ.Popups.Dialog 0.1
|
2022-05-23 11:29:58 +00:00
|
|
|
|
|
|
|
import utils 1.0
|
|
|
|
|
|
|
|
Item {
|
|
|
|
id: root
|
2022-08-18 07:38:47 +00:00
|
|
|
objectName: "imageCropWorkflow"
|
2022-05-23 11:29:58 +00:00
|
|
|
|
2022-11-08 18:30:50 +00:00
|
|
|
property var callback: null
|
2022-06-01 14:00:57 +00:00
|
|
|
property alias aspectRatio: imageCropper.aspectRatio
|
|
|
|
property alias windowStyle: imageCropper.windowStyle
|
2022-05-31 09:07:45 +00:00
|
|
|
/*required*/ property string imageFileDialogTitle: ""
|
|
|
|
/*required*/ property string title: ""
|
|
|
|
/*required*/ property string acceptButtonText: ""
|
|
|
|
property bool roundedImage: true
|
|
|
|
|
2022-05-23 11:29:58 +00:00
|
|
|
signal imageCropped(var image, var cropRect)
|
2023-02-07 14:21:32 +00:00
|
|
|
signal done()
|
2022-05-23 11:29:58 +00:00
|
|
|
|
|
|
|
function chooseImageToCrop() {
|
|
|
|
fileDialog.open()
|
|
|
|
}
|
|
|
|
|
2022-08-18 07:38:47 +00:00
|
|
|
function cropImage(imageUrl) {
|
|
|
|
imageCropper.source = imageUrl
|
|
|
|
imageCropperModal.open()
|
|
|
|
}
|
|
|
|
|
2022-05-23 11:29:58 +00:00
|
|
|
FileDialog {
|
|
|
|
id: fileDialog
|
|
|
|
|
2022-05-31 09:07:45 +00:00
|
|
|
title: root.imageFileDialogTitle
|
2022-06-01 14:00:57 +00:00
|
|
|
folder: root.userSelectedImage ? imageCropper.source.substr(0, imageCropper.source.lastIndexOf("/")) : shortcuts.pictures
|
2024-11-01 09:13:00 +00:00
|
|
|
nameFilters: [qsTr("Supported image formats (%1)").arg(UrlUtils.validImageNameFilters)]
|
2022-05-23 11:29:58 +00:00
|
|
|
onAccepted: {
|
|
|
|
if (fileDialog.fileUrls.length > 0) {
|
2024-11-01 09:13:00 +00:00
|
|
|
const url = fileDialog.fileUrls[0]
|
|
|
|
if (Utils.isValidDragNDropImage(url))
|
|
|
|
cropImage(url)
|
|
|
|
else
|
|
|
|
errorDialog.open()
|
2022-05-23 11:29:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} // FileDialog
|
|
|
|
|
2024-11-01 09:13:00 +00:00
|
|
|
StatusDialog {
|
|
|
|
id: errorDialog
|
|
|
|
title: qsTr("Image format not supported")
|
|
|
|
width: 480
|
|
|
|
contentItem: ColumnLayout {
|
|
|
|
StatusBaseText {
|
|
|
|
Layout.fillWidth: true
|
|
|
|
wrapMode: Text.WordWrap
|
|
|
|
text: qsTr("Format of the image you chose is not supported. Most probably you picked a file that is invalid, corrupted or has a wrong file extension.")
|
|
|
|
}
|
|
|
|
StatusBaseText {
|
|
|
|
Layout.fillWidth: true
|
|
|
|
font.pixelSize: Theme.additionalTextSize
|
|
|
|
text: qsTr("Supported image extensions: %1").arg(UrlUtils.allValidImageExtensions)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
standardButtons: Dialog.Ok
|
|
|
|
} // StatusDialog
|
|
|
|
|
2022-05-23 11:29:58 +00:00
|
|
|
StatusModal {
|
|
|
|
id: imageCropperModal
|
|
|
|
|
2023-05-23 12:46:16 +00:00
|
|
|
headerSettings.title: root.title
|
2022-05-23 11:29:58 +00:00
|
|
|
|
2022-05-31 09:07:45 +00:00
|
|
|
width: root.roundedImage ? 480 : 580
|
2022-05-23 11:29:58 +00:00
|
|
|
StatusImageCropPanel {
|
2022-06-01 14:00:57 +00:00
|
|
|
id: imageCropper
|
2022-08-18 07:38:47 +00:00
|
|
|
objectName: "profileImageCropper"
|
2022-05-23 11:29:58 +00:00
|
|
|
|
2022-05-23 17:36:48 +00:00
|
|
|
implicitHeight: root.roundedImage ? 350 : 370
|
2022-05-23 11:29:58 +00:00
|
|
|
|
|
|
|
anchors {
|
2022-08-18 07:38:47 +00:00
|
|
|
fill: parent
|
2024-10-15 19:26:12 +00:00
|
|
|
leftMargin: Theme.bigPadding + Theme.halfPadding / 2
|
|
|
|
rightMargin: Theme.bigPadding + Theme.halfPadding / 2
|
|
|
|
topMargin: Theme.bigPadding
|
|
|
|
bottomMargin: Theme.bigPadding
|
2022-05-31 09:07:45 +00:00
|
|
|
}
|
2022-05-23 11:29:58 +00:00
|
|
|
|
2022-05-31 09:07:45 +00:00
|
|
|
margins: root.roundedImage ? 10 : 20
|
|
|
|
windowStyle: root.roundedImage ? StatusImageCrop.WindowStyle.Rounded : StatusImageCrop.WindowStyle.Rectangular
|
2022-05-23 11:29:58 +00:00
|
|
|
enableCheckers: true
|
|
|
|
}
|
|
|
|
|
|
|
|
rightButtons: [
|
|
|
|
StatusButton {
|
2022-08-18 07:38:47 +00:00
|
|
|
objectName: "imageCropperAcceptButton"
|
2022-05-31 09:07:45 +00:00
|
|
|
text: root.acceptButtonText
|
2022-05-23 11:29:58 +00:00
|
|
|
|
2022-06-01 14:00:57 +00:00
|
|
|
enabled: imageCropper.sourceSize.width > 0 && imageCropper.sourceSize.height > 0
|
2022-05-23 11:29:58 +00:00
|
|
|
|
|
|
|
onClicked: {
|
2022-06-01 14:00:57 +00:00
|
|
|
root.imageCropped(imageCropper.source, imageCropper.cropRect)
|
2022-05-23 11:29:58 +00:00
|
|
|
imageCropperModal.close()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
2023-02-07 14:21:32 +00:00
|
|
|
onClosed: root.done()
|
2022-05-23 11:29:58 +00:00
|
|
|
} // StatusModal
|
|
|
|
} // Item
|
|
|
|
|