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 bool isPreviewing: false
property alias imageId: avatar.imageId
required property real avatarSize
width: avatarSize
height: boothLayout.height
function startBooth() {
AccountAdapter.startPreviewing(false)
if (!AccountAdapter.hasVideoCall()) {
AccountAdapter.stopPreviewing()
}
JamiFileDialog {
id: importFromFileDialog
folder: StandardPaths.writableLocation(StandardPaths.PicturesLocation)
nameFilters: [
qsTr("Image Files") + " (*.png *.jpg *.jpeg)",
qsTr("All files") + " (*)"
]
var filePath = UtilsAdapter.getAbsPath(file)
AccountAdapter.setCurrentAccountAvatarFile(filePath)
ColumnLayout {
id: boothLayout
spacing: JamiTheme.preferredMarginSize / 2
Layout.preferredWidth: avatarSize
Layout.preferredHeight: avatarSize
Layout.alignment: Qt.AlignHCenter
anchors.fill: parent
anchors.margins: 1
fillMode: Image.PreserveAspectCrop
showPresenceIndicator: false
PhotoboothPreviewRender {
id: preview
anchors.fill: parent
anchors.margins: 1
onRenderingStopped: stopBooth()
lrcInstance: LRCInstance
layer.enabled: true
layer.effect: OpacityMask {
maskSource: Rectangle {
width: avatarSize
height: avatarSize
radius: avatarSize / 2
}
}
Rectangle {
id: flashRect
anchors.fill: parent
anchors.margins: 0
radius: avatarSize / 2
color: "white"
opacity: 0
SequentialAnimation {
id: flashAnimation
NumberAnimation {
target: flashRect; property: "opacity"
to: 1; duration: 0
}
NumberAnimation {
target: flashRect; property: "opacity"
to: 0; duration: 500
}
RowLayout {
id: buttonsRowLayout
Layout.fillWidth: true
Layout.preferredHeight: childrenRect.height
Layout.bottomMargin: parent.spacing
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
PushButton {
id: takePhotoButton
Layout.alignment: Qt.AlignHCenter
radius: JamiTheme.primaryRadius
imageColor: JamiTheme.textColor
toolTipText: JamiStrings.takePhoto
source: isPreviewing ?
"qrc:/images/icons/round-add_a_photo-24px.svg" :
"qrc:/images/icons/baseline-camera_alt-24px.svg"
onClicked: {
if (isPreviewing) {
flashAnimation.start()
AccountAdapter.setCurrentAccountAvatarBase64(
preview.takePhoto(avatarSize))
stopBooth()
return
}
startBooth()
}
}
PushButton {
id: clearButton
visible: LRCInstance.currentAccountAvatarSet
Layout.alignment: Qt.AlignHCenter
radius: JamiTheme.primaryRadius
source: "qrc:/images/icons/round-close-24px.svg"
toolTipText: JamiStrings.clearAvatar
imageColor: JamiTheme.textColor
stopBooth()
AccountAdapter.setCurrentAccountAvatarBase64()
PushButton {
id: importButton
Layout.alignment: Qt.AlignHCenter
radius: JamiTheme.primaryRadius
source: "qrc:/images/icons/round-folder-24px.svg"
toolTipText: JamiStrings.importFromFile
imageColor: JamiTheme.textColor
onClicked: {
stopBooth()
importFromFileDialog.open()
}