2020-11-30 17:03:52 +00:00
|
|
|
import QtQuick 2.13
|
|
|
|
import QtQuick.Dialogs 1.3
|
2021-09-28 15:04:06 +00:00
|
|
|
|
|
|
|
import utils 1.0
|
2021-10-20 10:03:09 +00:00
|
|
|
|
|
|
|
import StatusQ.Controls 0.1
|
|
|
|
|
2021-10-27 21:27:49 +00:00
|
|
|
import shared 1.0
|
|
|
|
import shared.panels 1.0
|
|
|
|
import shared.popups 1.0
|
2020-11-30 17:03:52 +00:00
|
|
|
|
2021-10-14 10:52:56 +00:00
|
|
|
// TODO: replace with StatusModal
|
2020-11-30 17:03:52 +00:00
|
|
|
ModalPopup {
|
|
|
|
id: popup
|
2022-04-04 11:26:30 +00:00
|
|
|
title: qsTr("Profile picture")
|
2020-11-30 17:03:52 +00:00
|
|
|
|
2022-02-04 08:43:55 +00:00
|
|
|
property var profileStore
|
|
|
|
|
|
|
|
property string selectedImage // selectedImage is for us to be able to analyze it before setting it as current
|
|
|
|
property string uploadError
|
2022-03-30 15:30:28 +00:00
|
|
|
property url largeImage: popup.profileStore.profileLargeImage
|
|
|
|
property bool hasIdentityImage: !!popup.profileStore.profileLargeImage
|
2022-02-04 08:43:55 +00:00
|
|
|
|
2020-11-30 17:03:52 +00:00
|
|
|
onClosed: {
|
|
|
|
destroy()
|
|
|
|
}
|
|
|
|
|
|
|
|
onSelectedImageChanged: {
|
|
|
|
if (!selectedImage) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
cropImageModal.open()
|
|
|
|
}
|
|
|
|
|
|
|
|
Item {
|
|
|
|
anchors.fill: parent
|
|
|
|
|
|
|
|
RoundedImage {
|
|
|
|
id: profilePic
|
2021-10-06 09:16:39 +00:00
|
|
|
source: popup.largeImage
|
2020-11-30 17:03:52 +00:00
|
|
|
width: 160
|
|
|
|
height: 160
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
border.width: 1
|
|
|
|
border.color: Style.current.border
|
|
|
|
onClicked: imageDialog.open()
|
|
|
|
}
|
|
|
|
|
|
|
|
StyledText {
|
|
|
|
visible: !!uploadError
|
|
|
|
text: uploadError
|
|
|
|
anchors.left: parent.left
|
|
|
|
anchors.right: parent.right
|
|
|
|
anchors.top: profilePic.bottom
|
|
|
|
horizontalAlignment: Text.AlignHCenter
|
|
|
|
font.pixelSize: 13
|
|
|
|
wrapMode: Text.WordWrap
|
|
|
|
anchors.topMargin: 13
|
|
|
|
font.weight: Font.Thin
|
|
|
|
color: Style.current.danger
|
|
|
|
}
|
|
|
|
|
2021-02-10 20:37:17 +00:00
|
|
|
ImageCropperModal {
|
2020-11-30 17:03:52 +00:00
|
|
|
id: cropImageModal
|
|
|
|
|
2021-02-10 20:37:17 +00:00
|
|
|
selectedImage: popup.selectedImage
|
2021-03-05 16:23:44 +00:00
|
|
|
ratio: "1:1"
|
2022-02-04 08:43:55 +00:00
|
|
|
onCropFinished: {
|
|
|
|
popup.uploadError = popup.profileStore.uploadImage(selectedImage, aX, aY, bX, bY)
|
|
|
|
}
|
2020-11-30 17:03:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
footer: Item {
|
2021-01-13 19:15:52 +00:00
|
|
|
width: parent.width
|
|
|
|
height: uploadBtn.height
|
2020-11-30 17:03:52 +00:00
|
|
|
|
2021-10-20 10:03:09 +00:00
|
|
|
StatusFlatButton {
|
2021-10-06 09:16:39 +00:00
|
|
|
visible: popup.hasIdentityImage
|
2021-10-20 10:03:09 +00:00
|
|
|
type: StatusBaseButton.Type.Danger
|
2022-04-04 11:26:30 +00:00
|
|
|
text: qsTr("Remove")
|
2020-11-30 17:03:52 +00:00
|
|
|
anchors.right: uploadBtn.left
|
|
|
|
anchors.rightMargin: Style.current.padding
|
|
|
|
anchors.bottom: parent.bottom
|
2022-02-04 08:43:55 +00:00
|
|
|
onClicked: {
|
|
|
|
popup.uploadError = popup.profileStore.removeImage()
|
|
|
|
}
|
2020-11-30 17:03:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
StatusButton {
|
|
|
|
id: uploadBtn
|
2022-04-04 11:26:30 +00:00
|
|
|
text: qsTr("Upload")
|
2020-11-30 17:03:52 +00:00
|
|
|
anchors.right: parent.right
|
|
|
|
anchors.bottom: parent.bottom
|
|
|
|
onClicked: {
|
|
|
|
imageDialog.open()
|
|
|
|
}
|
|
|
|
|
|
|
|
FileDialog {
|
|
|
|
id: imageDialog
|
2022-04-04 11:26:30 +00:00
|
|
|
title: qsTr("Please choose an image")
|
2020-11-30 17:03:52 +00:00
|
|
|
folder: shortcuts.pictures
|
|
|
|
nameFilters: [
|
2022-04-04 11:26:30 +00:00
|
|
|
qsTr("Image files (*.jpg *.jpeg *.png)")
|
2020-11-30 17:03:52 +00:00
|
|
|
]
|
|
|
|
onAccepted: {
|
|
|
|
selectedImage = imageDialog.fileUrls[0]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|