Newer
Older
import QtQuick 2.14
import QtQuick.Controls 2.14
import QtQuick.Layouts 1.14
import QtQuick.Controls.Styles 1.4
import Qt.labs.platform 1.1
import net.jami.Constants 1.0
property int photoState: PhotoboothView.PhotoState.Default
property bool avatarSet: false
// saveToConfig is to specify whether the image should be saved to account config
property bool saveToConfig: false
property var boothImg: ""
enum PhotoState {
Default = 0,
CameraRendering,
Taken
}
readonly property int size: boothWidth +
buttonsRowLayout.height +
JamiTheme.preferredMarginSize / 2
function initUI(useDefaultAvatar = true) {
photoState = PhotoboothView.PhotoState.Default
avatarSet = false
if (useDefaultAvatar)
setAvatarImage(AvatarImage.Mode.Default, "")
}
function startBooth(force = false) {
AccountAdapter.startPreviewing(force)
photoState = PhotoboothView.PhotoState.CameraRendering
if(!AccountAdapter.hasVideoCall()) {
AccountAdapter.stopPreviewing()
}
} catch(erro){console.log("Exception: " + erro.message)}
}
function setAvatarImage(mode = AvatarImage.Mode.FromAccount,
imageId = AccountAdapter.currentAccountId){
if (mode !== AvatarImage.Mode.FromUrl)
avatarImg.enableAnimation = true
else
avatarImg.enableAnimation = false
avatarImg.mode = mode
if (mode === AvatarImage.Mode.Default) {
boothImg = ""
avatarImg.updateImage(imageId)
return
}
if (imageId)
avatarImg.updateImage(imageId)
}
onVisibleChanged: {
if(!visible){
stopBooth()
}
}
JamiFileDialog{
id: importFromFileToAvatar_Dialog
mode: JamiFileDialog.OpenFile
folder: StandardPaths.writableLocation(StandardPaths.PicturesLocation)
nameFilters: [ qsTr("Image Files") + " (*.png *.jpg *.jpeg)",qsTr(
"All files") + " (*)"]
onAccepted: {
avatarSet = true
photoState = PhotoboothView.PhotoState.Default
if (fileName.length === 0) {
SettingsAdapter.clearCurrentAvatar()
setAvatarImage()
setAvatarImage(AvatarImage.Mode.FromFile,
UtilsAdapter.getAbsPath(fileName))
visible: photoState !== PhotoboothView.PhotoState.CameraRendering
Layout.fillWidth: true
Layout.maximumWidth: boothWidth
Layout.alignment: Qt.AlignHCenter
background: Rectangle {
id: avatarLabelBackground
anchors.fill: parent
color: "white"
id: avatarImg
anchors.fill: parent
showPresenceIndicator: false
layer.enabled: true
layer.effect: OpacityMask {
width: avatarImg.width
height: avatarImg.height
radius: {
var size = ((avatarImg.width <= avatarImg.height) ?
avatarImg.width:avatarImg.height)
return size / 2
onImageIsReady: {
if (mode === AvatarImage.Mode.FromUrl)
photoState = PhotoboothView.PhotoState.Taken
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
if (photoState === PhotoboothView.PhotoState.Taken) {
avatarImg.state = ""
avatarImg.state = "flashIn"
} else {
// Once image is loaded (updated), save to boothImg (choose from file)
avatarImg.grabToImage(function(result) {
if (mode !== AvatarImage.Mode.Default)
boothImg = result.image
if (saveToConfig)
SettingsAdapter.setCurrAccAvatar(result.image)
})
}
}
onOpacityChanged: {
if (avatarImg.state === "flashIn" && opacity === 0)
avatarImg.state = "flashOut"
}
states: [
State {
name: "flashIn"
PropertyChanges { target: avatarImg; opacity: 0}
}, State {
name: "flashOut"
PropertyChanges { target: avatarImg; opacity: 1}
}]
transitions: Transition {
NumberAnimation {
properties: "opacity"
easing.type: Easing.Linear
duration: 100
}
onHideBooth: stopBooth()
visible: photoState === PhotoboothView.PhotoState.CameraRendering
focus: visible
Layout.alignment: Qt.AlignHCenter
Layout.preferredWidth: boothWidth
Layout.preferredHeight: boothWidth
layer.enabled: true
layer.effect: OpacityMask {
width: previewWidget.width
height: previewWidget.height
radius: {
var size = ((previewWidget.width <= previewWidget.height) ?
previewWidget.width:previewWidget.height)
return size / 2
Layout.preferredHeight: JamiTheme.preferredFieldHeight
Layout.topMargin: JamiTheme.preferredMarginSize / 2
PushButton {
id: takePhotoButton
property string cameraAltIconUrl: "qrc:/images/icons/baseline-camera_alt-24px.svg"
property string addPhotoIconUrl: "qrc:/images/icons/round-add_a_photo-24px.svg"
property string refreshIconUrl: "qrc:/images/icons/baseline-refresh-24px.svg"
text: ""
font.pointSize: 10
font.kerning: true
imageColor: JamiTheme.textColor
if(photoState === PhotoboothView.PhotoState.Default) {
if(photoState === PhotoboothView.PhotoState.Taken){
if(photoState !== PhotoboothView.PhotoState.CameraRendering){
previewWidget.grabToImage(function(result) {
boothImg = result.image
if (saveToConfig)
SettingsAdapter.setCurrAccAvatar(result.image)
setAvatarImage(AvatarImage.Mode.FromUrl, result.url)
avatarSet = true
PushButton {
Layout.preferredWidth: JamiTheme.preferredFieldHeight
Layout.preferredHeight: JamiTheme.preferredFieldHeight
text: ""
font.pointSize: 10
font.kerning: true
radius: height / 6
source: "qrc:/images/icons/round-folder-24px.svg"
imageColor: JamiTheme.textColor
onClicked: {
importFromFileToAvatar_Dialog.open()
}
}
}
}