2021-03-17 14:23:21 -04:00
|
|
|
/*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2020-08-03 13:27:42 -04:00
|
|
|
import QtQuick 2.14
|
|
|
|
import QtQuick.Layouts 1.14
|
|
|
|
import Qt.labs.platform 1.1
|
2020-10-06 13:58:44 +02:00
|
|
|
import QtGraphicalEffects 1.14
|
2021-03-17 14:23:21 -04:00
|
|
|
|
2021-08-23 13:24:08 -04:00
|
|
|
import net.jami.Models 1.1
|
|
|
|
import net.jami.Adapters 1.1
|
|
|
|
import net.jami.Constants 1.1
|
2020-08-03 13:27:42 -04:00
|
|
|
|
2021-07-15 17:20:37 -04:00
|
|
|
Item {
|
2021-06-29 10:39:06 -04:00
|
|
|
id: root
|
2020-11-02 11:44:20 -05:00
|
|
|
|
2021-07-15 17:20:37 -04:00
|
|
|
property bool isPreviewing: false
|
2021-06-29 10:39:06 -04:00
|
|
|
property alias imageId: avatar.imageId
|
2021-08-16 11:05:06 -04:00
|
|
|
property real avatarSize
|
2020-09-10 16:56:47 -04:00
|
|
|
|
2021-08-02 14:52:08 -04:00
|
|
|
signal focusOnPreviousItem
|
|
|
|
signal focusOnNextItem
|
|
|
|
|
2021-07-15 17:20:37 -04:00
|
|
|
width: avatarSize
|
|
|
|
height: boothLayout.height
|
2021-07-14 12:35:12 -04:00
|
|
|
|
2020-11-03 17:28:25 -05:00
|
|
|
function startBooth() {
|
|
|
|
AccountAdapter.startPreviewing(false)
|
2021-07-15 17:20:37 -04:00
|
|
|
isPreviewing = true
|
2020-08-03 13:27:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function stopBooth(){
|
2021-06-29 10:39:06 -04:00
|
|
|
if (!AccountAdapter.hasVideoCall()) {
|
|
|
|
AccountAdapter.stopPreviewing()
|
2020-11-02 11:44:20 -05:00
|
|
|
}
|
2021-07-15 17:20:37 -04:00
|
|
|
isPreviewing = false
|
2020-12-03 13:25:34 -05:00
|
|
|
}
|
|
|
|
|
2021-08-02 14:52:08 -04:00
|
|
|
function focusOnNextPhotoBoothItem () {
|
|
|
|
takePhotoButton.forceActiveFocus()
|
|
|
|
}
|
|
|
|
|
|
|
|
function focusOnPreviousPhotoBoothItem () {
|
2021-08-05 16:08:54 -04:00
|
|
|
if (isPreviewing)
|
|
|
|
clearButton.forceActiveFocus()
|
|
|
|
else
|
|
|
|
importButton.forceActiveFocus()
|
2021-08-02 14:52:08 -04:00
|
|
|
}
|
|
|
|
|
2020-08-03 13:27:42 -04:00
|
|
|
onVisibleChanged: {
|
2021-07-15 17:20:37 -04:00
|
|
|
if (!visible) {
|
2020-08-03 13:27:42 -04:00
|
|
|
stopBooth()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-29 10:39:06 -04:00
|
|
|
JamiFileDialog {
|
|
|
|
id: importFromFileDialog
|
2020-08-03 13:27:42 -04:00
|
|
|
|
2021-08-02 17:31:46 -04:00
|
|
|
objectName: "photoboothImportFromFileDialog"
|
|
|
|
|
2020-08-03 13:27:42 -04:00
|
|
|
mode: JamiFileDialog.OpenFile
|
2020-09-11 17:30:46 -04:00
|
|
|
title: JamiStrings.chooseAvatarImage
|
2020-08-03 13:27:42 -04:00
|
|
|
folder: StandardPaths.writableLocation(StandardPaths.PicturesLocation)
|
|
|
|
|
2021-06-29 10:39:06 -04:00
|
|
|
nameFilters: [
|
|
|
|
qsTr("Image Files") + " (*.png *.jpg *.jpeg)",
|
|
|
|
qsTr("All files") + " (*)"
|
|
|
|
]
|
2020-08-03 13:27:42 -04:00
|
|
|
|
2021-08-02 14:52:08 -04:00
|
|
|
onVisibleChanged: {
|
|
|
|
if (!visible) {
|
|
|
|
rejected()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-03 13:27:42 -04:00
|
|
|
onAccepted: {
|
2021-08-02 14:52:08 -04:00
|
|
|
if (importButton.focusAfterFileDialogClosed) {
|
|
|
|
importButton.focusAfterFileDialogClosed = false
|
|
|
|
importButton.forceActiveFocus()
|
|
|
|
}
|
|
|
|
|
2021-06-29 10:39:06 -04:00
|
|
|
var filePath = UtilsAdapter.getAbsPath(file)
|
|
|
|
AccountAdapter.setCurrentAccountAvatarFile(filePath)
|
2020-08-03 13:27:42 -04:00
|
|
|
}
|
2021-08-02 14:52:08 -04:00
|
|
|
|
|
|
|
onRejected: {
|
|
|
|
if (importButton.focusAfterFileDialogClosed) {
|
|
|
|
importButton.focusAfterFileDialogClosed = false
|
|
|
|
importButton.forceActiveFocus()
|
|
|
|
}
|
|
|
|
}
|
2020-08-03 13:27:42 -04:00
|
|
|
}
|
|
|
|
|
2021-07-15 17:20:37 -04:00
|
|
|
ColumnLayout {
|
|
|
|
id: boothLayout
|
2020-08-03 13:27:42 -04:00
|
|
|
|
2021-07-15 17:20:37 -04:00
|
|
|
spacing: JamiTheme.preferredMarginSize / 2
|
2020-10-19 14:51:31 -04:00
|
|
|
|
2021-07-15 17:20:37 -04:00
|
|
|
Item {
|
|
|
|
id: imageLayer
|
2020-10-19 14:51:31 -04:00
|
|
|
|
2021-07-15 17:20:37 -04:00
|
|
|
Layout.preferredWidth: avatarSize
|
|
|
|
Layout.preferredHeight: avatarSize
|
|
|
|
Layout.alignment: Qt.AlignHCenter
|
2021-06-29 10:39:06 -04:00
|
|
|
|
2021-07-15 17:20:37 -04:00
|
|
|
Avatar {
|
|
|
|
id: avatar
|
2021-06-29 10:39:06 -04:00
|
|
|
|
2021-07-15 17:20:37 -04:00
|
|
|
anchors.fill: parent
|
|
|
|
anchors.margins: 1
|
2021-06-29 10:39:06 -04:00
|
|
|
|
2021-07-15 17:20:37 -04:00
|
|
|
visible: !preview.visible
|
2020-11-03 10:31:02 -05:00
|
|
|
|
2021-07-15 17:20:37 -04:00
|
|
|
fillMode: Image.PreserveAspectCrop
|
|
|
|
showPresenceIndicator: false
|
2020-08-03 13:27:42 -04:00
|
|
|
}
|
|
|
|
|
2021-07-15 17:20:37 -04:00
|
|
|
PhotoboothPreviewRender {
|
|
|
|
id: preview
|
|
|
|
|
|
|
|
anchors.fill: parent
|
|
|
|
anchors.margins: 1
|
2020-08-03 13:27:42 -04:00
|
|
|
|
2021-07-15 17:20:37 -04:00
|
|
|
visible: isPreviewing
|
2020-09-03 21:19:10 -04:00
|
|
|
|
2021-07-15 17:20:37 -04:00
|
|
|
onRenderingStopped: stopBooth()
|
|
|
|
lrcInstance: LRCInstance
|
2020-08-03 13:27:42 -04:00
|
|
|
|
2021-07-15 17:20:37 -04:00
|
|
|
layer.enabled: true
|
|
|
|
layer.effect: OpacityMask {
|
|
|
|
maskSource: Rectangle {
|
|
|
|
width: avatarSize
|
|
|
|
height: avatarSize
|
|
|
|
radius: avatarSize / 2
|
|
|
|
}
|
2021-06-29 10:39:06 -04:00
|
|
|
}
|
2021-07-15 17:20:37 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
2020-08-03 13:27:42 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-15 17:20:37 -04:00
|
|
|
RowLayout {
|
|
|
|
id: buttonsRowLayout
|
2020-08-03 13:27:42 -04:00
|
|
|
|
2021-07-15 17:20:37 -04:00
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.preferredHeight: childrenRect.height
|
|
|
|
Layout.bottomMargin: parent.spacing
|
2020-09-03 09:58:01 -04:00
|
|
|
Layout.alignment: Qt.AlignHCenter
|
2020-08-03 13:27:42 -04:00
|
|
|
|
2021-07-15 17:20:37 -04:00
|
|
|
PushButton {
|
|
|
|
id: takePhotoButton
|
|
|
|
|
2021-08-02 17:31:46 -04:00
|
|
|
objectName: "takePhotoButton"
|
|
|
|
|
2021-07-15 17:20:37 -04:00
|
|
|
Layout.alignment: Qt.AlignHCenter
|
2021-08-02 14:52:08 -04:00
|
|
|
|
2021-07-15 17:20:37 -04:00
|
|
|
radius: JamiTheme.primaryRadius
|
|
|
|
imageColor: JamiTheme.textColor
|
|
|
|
toolTipText: JamiStrings.takePhoto
|
|
|
|
source: isPreviewing ?
|
2021-07-19 23:52:58 -04:00
|
|
|
JamiResources.round_add_a_photo_24dp_svg :
|
|
|
|
JamiResources.baseline_camera_alt_24dp_svg
|
2021-07-15 17:20:37 -04:00
|
|
|
|
2021-08-02 14:52:08 -04:00
|
|
|
Keys.onPressed: function (keyEvent) {
|
2021-08-06 15:29:11 -04:00
|
|
|
if (keyEvent.key === Qt.Key_Enter ||
|
|
|
|
keyEvent.key === Qt.Key_Return) {
|
2021-08-02 14:52:08 -04:00
|
|
|
clicked()
|
|
|
|
keyEvent.accepted = true
|
2021-08-06 15:29:11 -04:00
|
|
|
} else if (keyEvent.key === Qt.Key_Up) {
|
2021-08-02 14:52:08 -04:00
|
|
|
root.focusOnPreviousItem()
|
|
|
|
keyEvent.accepted = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
KeyNavigation.tab: {
|
|
|
|
if (clearButton.visible)
|
|
|
|
return clearButton
|
|
|
|
return importButton
|
|
|
|
}
|
|
|
|
KeyNavigation.down: KeyNavigation.tab
|
|
|
|
|
2021-07-15 17:20:37 -04:00
|
|
|
onClicked: {
|
|
|
|
if (isPreviewing) {
|
|
|
|
flashAnimation.start()
|
|
|
|
AccountAdapter.setCurrentAccountAvatarBase64(
|
|
|
|
preview.takePhoto(avatarSize))
|
|
|
|
stopBooth()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
startBooth()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PushButton {
|
|
|
|
id: clearButton
|
2020-08-07 11:24:18 -04:00
|
|
|
|
2021-08-02 17:31:46 -04:00
|
|
|
objectName: "photoboothViewClearButton"
|
|
|
|
|
2021-07-15 17:20:37 -04:00
|
|
|
Layout.alignment: Qt.AlignHCenter
|
2021-08-02 14:52:08 -04:00
|
|
|
|
2021-08-05 16:08:54 -04:00
|
|
|
visible: isPreviewing || LRCInstance.currentAccountAvatarSet
|
2021-08-02 14:52:08 -04:00
|
|
|
|
2021-07-15 17:20:37 -04:00
|
|
|
radius: JamiTheme.primaryRadius
|
2021-07-19 23:52:58 -04:00
|
|
|
source: JamiResources.round_close_24dp_svg
|
2021-08-05 16:08:54 -04:00
|
|
|
toolTipText: isPreviewing ? JamiStrings.stopTakingPhoto :
|
|
|
|
JamiStrings.clearAvatar
|
2021-07-15 17:20:37 -04:00
|
|
|
imageColor: JamiTheme.textColor
|
2020-10-19 14:51:31 -04:00
|
|
|
|
2021-08-02 14:52:08 -04:00
|
|
|
KeyNavigation.up: takePhotoButton
|
|
|
|
|
|
|
|
Keys.onPressed: function (keyEvent) {
|
2021-08-06 15:29:11 -04:00
|
|
|
if (keyEvent.key === Qt.Key_Enter ||
|
|
|
|
keyEvent.key === Qt.Key_Return) {
|
2021-08-02 14:52:08 -04:00
|
|
|
clicked()
|
|
|
|
takePhotoButton.forceActiveFocus()
|
|
|
|
keyEvent.accepted = true
|
2021-08-06 15:29:11 -04:00
|
|
|
} else if (keyEvent.key === Qt.Key_Down ||
|
2021-08-05 16:08:54 -04:00
|
|
|
keyEvent.key === Qt.Key_Tab) {
|
|
|
|
if (isPreviewing) {
|
|
|
|
root.focusOnNextItem()
|
|
|
|
} else
|
|
|
|
importButton.forceActiveFocus()
|
|
|
|
keyEvent.accepted = true
|
2021-08-02 14:52:08 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-15 17:20:37 -04:00
|
|
|
onClicked: {
|
2020-12-03 13:25:34 -05:00
|
|
|
stopBooth()
|
2021-08-05 16:08:54 -04:00
|
|
|
if (!isPreviewing)
|
|
|
|
AccountAdapter.setCurrentAccountAvatarBase64()
|
2020-08-03 13:27:42 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-15 17:20:37 -04:00
|
|
|
PushButton {
|
|
|
|
id: importButton
|
2020-08-03 13:27:42 -04:00
|
|
|
|
2021-08-02 17:31:46 -04:00
|
|
|
objectName: "photoboothViewImportButton"
|
|
|
|
|
2021-08-02 14:52:08 -04:00
|
|
|
property bool focusAfterFileDialogClosed: false
|
|
|
|
|
2021-07-15 17:20:37 -04:00
|
|
|
Layout.alignment: Qt.AlignHCenter
|
2021-08-02 14:52:08 -04:00
|
|
|
|
2021-08-05 16:08:54 -04:00
|
|
|
visible: !isPreviewing
|
|
|
|
|
2021-07-15 17:20:37 -04:00
|
|
|
radius: JamiTheme.primaryRadius
|
2021-07-19 23:52:58 -04:00
|
|
|
source: JamiResources.round_folder_24dp_svg
|
2021-07-15 17:20:37 -04:00
|
|
|
toolTipText: JamiStrings.importFromFile
|
|
|
|
imageColor: JamiTheme.textColor
|
2020-08-07 11:24:18 -04:00
|
|
|
|
2021-08-02 14:52:08 -04:00
|
|
|
Keys.onPressed: function (keyEvent) {
|
2021-08-06 15:29:11 -04:00
|
|
|
if (keyEvent.key === Qt.Key_Enter ||
|
|
|
|
keyEvent.key === Qt.Key_Return) {
|
2021-08-02 14:52:08 -04:00
|
|
|
focusAfterFileDialogClosed = true
|
|
|
|
clicked()
|
|
|
|
keyEvent.accepted = true
|
2021-08-06 15:29:11 -04:00
|
|
|
} else if (keyEvent.key === Qt.Key_Down ||
|
2021-08-02 14:52:08 -04:00
|
|
|
keyEvent.key === Qt.Key_Tab) {
|
|
|
|
root.focusOnNextItem()
|
|
|
|
keyEvent.accepted = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
KeyNavigation.up: {
|
|
|
|
if (clearButton.visible)
|
|
|
|
return clearButton
|
|
|
|
return takePhotoButton
|
|
|
|
}
|
|
|
|
|
2021-07-15 17:20:37 -04:00
|
|
|
onClicked: {
|
|
|
|
stopBooth()
|
|
|
|
importFromFileDialog.open()
|
|
|
|
}
|
2020-08-03 13:27:42 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|