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 QtGraphicalEffects 1.0
import net.jami.Models 1.0
ColumnLayout{
property bool takePhotoState: false
property bool hasAvatar: false
property bool isDefaultIcon: false
property string imgBase64: ""
property string fileName: ""
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
signal imageAcquired
signal imageCleared
function startBooth(force = false){
hasAvatar = false
ClientWrapper.accountAdaptor.startPreviewing(force)
takePhotoState = true
}
function stopBooth(){
try{
if(!ClientWrapper.accountAdaptor.hasVideoCall()) {
ClientWrapper.accountAdaptor.stopPreviewing()
}
} catch(erro){console.log("Exception: " + erro.message)}
takePhotoState = false
}
function setAvatarPixmap(avatarPixmapBase64, defaultValue = false){
imgBase64 = avatarPixmapBase64
stopBooth()
if(defaultValue){
isDefaultIcon = defaultValue
}
}
onVisibleChanged: {
if(!visible){
stopBooth()
}
}
JamiFileDialog{
id: importFromFileToAvatar_Dialog
mode: JamiFileDialog.OpenFile
title: qsTr("Choose an image to be the avatar")
folder: StandardPaths.writableLocation(StandardPaths.PicturesLocation)
nameFilters: [ qsTr("Image Files") + " (*.png *.jpg *.jpeg)",qsTr(
"All files") + " (*)"]
onAccepted: {
fileName = file
if(fileName.length === 0) {
imageCleared()
return
}
imgBase64 = ClientWrapper.utilsAdaptor.getCroppedImageBase64FromFile(
ClientWrapper.utilsAdaptor.getAbsPath(fileName),boothWidth)
imageAcquired()
stopBooth()
}
}
spacing: 0
Layout.maximumWidth: boothWidth
Layout.preferredWidth: boothWidth
Layout.minimumWidth: boothWidth
Layout.maximumHeight: 0
Layout.alignment: Qt.AlignHCenter
Label{
id: avatarLabel
visible: !takePhotoState
Layout.maximumWidth: boothWidth
Layout.preferredWidth: boothWidth
Layout.minimumWidth: boothWidth
Layout.maximumHeight: boothWidth
Layout.preferredHeight: boothWidth
Layout.minimumHeight: boothWidth
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
Layout.alignment: Qt.AlignHCenter
background: Rectangle {
id: avatarLabelBackground
anchors.fill: parent
color: "transparent"
Image{
id: avatarImg
anchors.fill: parent
source: {
if(imgBase64.length === 0){
return ""
} else {
return "data:image/png;base64," + imgBase64
}
}
fillMode: Image.PreserveAspectCrop
layer.enabled: true
layer.effect: OpacityMask {
maskSource: Rectangle{
width: avatarImg.width
height: avatarImg.height
radius: {
var size = ((avatarImg.width <= avatarImg.height)? avatarImg.width:avatarImg.height)
return size /2
}
}
}
}
}
}
PhotoboothPreviewRender{
id:previewWidget
onHideBooth:{
stopBooth()
}
visible: takePhotoState
focus: visible
Layout.alignment: Qt.AlignHCenter
Layout.maximumWidth: boothWidth
Layout.preferredWidth: boothWidth
Layout.minimumWidth: boothWidth
Layout.maximumHeight: boothWidth
Layout.preferredHeight: boothWidth
Layout.minimumHeight: boothWidth
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
layer.enabled: true
layer.effect: OpacityMask {
maskSource: Rectangle{
width: previewWidget.width
height: previewWidget.height
radius: {
var size = ((previewWidget.width <= previewWidget.height)? previewWidget.width:previewWidget.height)
return size /2
}
}
}
Label{
id: flashOverlay
anchors.fill: previewWidget
visible: false
color: "#fff"
OpacityAnimator on opacity{
id: flashAnimation
from: 1
to: 0
duration: 600
}
}
}
RowLayout{
Layout.fillWidth: true
Layout.minimumHeight: 30
Layout.maximumHeight: 30
Item{
Layout.fillWidth: true
Layout.fillHeight: true
}
HoverableButton {
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"
Layout.maximumWidth: 30
Layout.preferredWidth: 30
Layout.minimumWidth: 30
Layout.minimumHeight: 30
Layout.preferredHeight: 30
Layout.maximumHeight: 30
text: ""
font.pointSize: 10
font.kerning: true
radius: height / 6
source: {
if(isDefaultIcon){
return addPhotoIconUrl
}
if(takePhotoState) {
return cameraAltIconUrl
}
if(hasAvatar){
return refreshIconUrl
} else {
return addPhotoIconUrl
}
}
onClicked: {
if(!takePhotoState){
imageCleared()
startBooth()
return
} else {
// show flash overlay
flashOverlay.visible = true
flashAnimation.restart()
// run concurrent function call to take photo
imgBase64 = previewWidget.takeCroppedPhotoToBase64(boothWidth)
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
hasAvatar = true
imageAcquired()
stopBooth()
}
}
}
Item{
Layout.fillHeight: true
Layout.minimumWidth: 6
Layout.preferredWidth: 6
Layout.maximumWidth: 6
}
HoverableButton {
id: importButton
Layout.maximumWidth: 30
Layout.preferredWidth: 30
Layout.minimumWidth: 30
Layout.minimumHeight: 30
Layout.preferredHeight: 30
Layout.maximumHeight: 30
text: ""
font.pointSize: 10
font.kerning: true
radius: height / 6
source: "qrc:/images/icons/round-folder-24px.svg"
onClicked: {
importFromFileToAvatar_Dialog.open()
}
}
Item{
Layout.fillWidth: true
Layout.fillHeight: true
}
}
}