Newer
Older
/*
* Copyright (C) 2020 by Savoir-faire Linux
* Author: Mingrui Zhang <mingrui.zhang@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import QtQuick 2.14
import QtQuick.Controls 2.14
import QtQuick.Layouts 1.14
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 alias saveToConfig: avatarImg.saveToConfig
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)

Ming Rui Zhang
committed
setAvatarImage(AvatarImage.AvatarMode.Default, "")
function startBooth() {
AccountAdapter.startPreviewing(false)
photoState = PhotoboothView.PhotoState.CameraRendering
if(!AccountAdapter.hasVideoCall()) {
AccountAdapter.stopPreviewing()
}
} catch(erro){console.log("Exception: " + erro.message)}
}

Ming Rui Zhang
committed
function setAvatarImage(mode = AvatarImage.AvatarMode.FromAccount,
imageId = LRCInstance.currentAccountId){

Ming Rui Zhang
committed
if (mode !== AvatarImage.AvatarMode.FromBase64)
avatarImg.enableFadeAnimation = true

Ming Rui Zhang
committed
avatarImg.enableFadeAnimation = false

Ming Rui Zhang
committed
avatarImg.avatarMode = mode

Ming Rui Zhang
committed
if (mode === AvatarImage.AvatarMode.Default) {
avatarImg.updateImage(imageId)
return
}
if (imageId)
avatarImg.updateImage(imageId)
function manualSaveToConfig() {
avatarImg.saveAvatarToConfig()
}
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()

Ming Rui Zhang
committed
setAvatarImage(AvatarImage.AvatarMode.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"
anchors.centerIn: avatarLabelBackground
width: avatarLabelBackground.width + avatarImg.spinningAnimationWidth
height: avatarLabelBackground.height + avatarImg.spinningAnimationWidth
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: {

Ming Rui Zhang
committed
if (avatarMode === AvatarImage.AvatarMode.FromBase64)
photoState = PhotoboothView.PhotoState.Taken
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
if (photoState === PhotoboothView.PhotoState.Taken) {
avatarImg.state = ""
avatarImg.state = "flashIn"
}
}
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"
imageColor: JamiTheme.textColor
if(photoState === PhotoboothView.PhotoState.Default) {
if(photoState === PhotoboothView.PhotoState.Taken){
if(photoState !== PhotoboothView.PhotoState.CameraRendering){

Ming Rui Zhang
committed
setAvatarImage(AvatarImage.AvatarMode.FromBase64,
previewWidget.takePhoto(boothWidth))
avatarSet = true
stopBooth()
PushButton {
Layout.preferredWidth: JamiTheme.preferredFieldHeight
Layout.preferredHeight: JamiTheme.preferredFieldHeight
radius: height / 6
source: "qrc:/images/icons/round-folder-24px.svg"
imageColor: JamiTheme.textColor
onClicked: {
importFromFileToAvatar_Dialog.open()
}
}
}
}