Skip to content
Snippets Groups Projects
Commit ab4c68ad authored by Andreas Traczyk's avatar Andreas Traczyk
Browse files

avatars: add clear feature to photobooth

A property is provided to notify of changes to the content of the
current account's stored avatar. If one is stored, then a button
used to clear the avatar becomes available.

Gitlab: #473
Change-Id: I37640acaea3ca43e5abd14678d68b4eeebb3829e
parent 27553074
No related branches found
No related tags found
Loading
...@@ -26,39 +26,34 @@ import net.jami.Models 1.0 ...@@ -26,39 +26,34 @@ import net.jami.Models 1.0
import net.jami.Adapters 1.0 import net.jami.Adapters 1.0
import net.jami.Constants 1.0 import net.jami.Constants 1.0
ColumnLayout { Item {
id: root id: root
enum Mode { Static, Previewing } property bool isPreviewing: false
property int mode: PhotoboothView.Mode.Static
property alias imageId: avatar.imageId property alias imageId: avatar.imageId
required property real avatarSize
property int size: 224 width: avatarSize
height: boothLayout.height
signal avatarSet
function startBooth() { function startBooth() {
AccountAdapter.startPreviewing(false) AccountAdapter.startPreviewing(false)
mode = PhotoboothView.Mode.Previewing isPreviewing = true
} }
function stopBooth(){ function stopBooth(){
if (!AccountAdapter.hasVideoCall()) { if (!AccountAdapter.hasVideoCall()) {
AccountAdapter.stopPreviewing() AccountAdapter.stopPreviewing()
} }
mode = PhotoboothView.Mode.Static isPreviewing = false
} }
onVisibleChanged: { onVisibleChanged: {
if (visible) { if (!visible) {
mode = PhotoboothView.Mode.Static
} else {
stopBooth() stopBooth()
} }
} }
spacing: 0
JamiFileDialog { JamiFileDialog {
id: importFromFileDialog id: importFromFileDialog
...@@ -74,125 +69,139 @@ ColumnLayout { ...@@ -74,125 +69,139 @@ ColumnLayout {
onAccepted: { onAccepted: {
var filePath = UtilsAdapter.getAbsPath(file) var filePath = UtilsAdapter.getAbsPath(file)
AccountAdapter.setCurrentAccountAvatarFile(filePath) AccountAdapter.setCurrentAccountAvatarFile(filePath)
avatarSet()
} }
} }
Item { ColumnLayout {
id: imageLayer id: boothLayout
Layout.preferredWidth: size
Layout.preferredHeight: size
Layout.alignment: Qt.AlignHCenter
Avatar {
id: avatar
anchors.fill: parent spacing: JamiTheme.preferredMarginSize / 2
anchors.margins: 1
visible: !preview.visible Item {
id: imageLayer
fillMode: Image.PreserveAspectCrop Layout.preferredWidth: avatarSize
showPresenceIndicator: false Layout.preferredHeight: avatarSize
} Layout.alignment: Qt.AlignHCenter
PhotoboothPreviewRender {
id: preview
anchors.fill: parent Avatar {
anchors.margins: 1 id: avatar
visible: mode === PhotoboothView.Mode.Previewing anchors.fill: parent
anchors.margins: 1
onRenderingStopped: stopBooth() visible: !preview.visible
lrcInstance: LRCInstance
layer.enabled: true fillMode: Image.PreserveAspectCrop
layer.effect: OpacityMask { showPresenceIndicator: false
maskSource: Rectangle {
width: size
height: size
radius: size / 2
}
} }
}
Rectangle { PhotoboothPreviewRender {
id: flashRect id: preview
anchors.fill: parent
anchors.margins: 1
anchors.fill: parent visible: isPreviewing
anchors.margins: 0
radius: size / 2
color: "white"
opacity: 0
SequentialAnimation { onRenderingStopped: stopBooth()
id: flashAnimation lrcInstance: LRCInstance
NumberAnimation { layer.enabled: true
target: flashRect; property: "opacity" layer.effect: OpacityMask {
to: 1; duration: 0 maskSource: Rectangle {
width: avatarSize
height: avatarSize
radius: avatarSize / 2
}
} }
NumberAnimation { }
target: flashRect; property: "opacity"
to: 0; duration: 500 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 { RowLayout {
id: buttonsRowLayout id: buttonsRowLayout
Layout.fillWidth: true
Layout.preferredHeight: JamiTheme.preferredFieldHeight
Layout.topMargin: JamiTheme.preferredMarginSize / 2
Layout.alignment: Qt.AlignHCenter
PushButton {
id: takePhotoButton
Layout.fillWidth: true
Layout.preferredHeight: childrenRect.height
Layout.bottomMargin: parent.spacing
Layout.alignment: Qt.AlignHCenter Layout.alignment: Qt.AlignHCenter
radius: JamiTheme.primaryRadius
imageColor: JamiTheme.textColor PushButton {
toolTipText: JamiStrings.takePhoto 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
source: mode === PhotoboothView.Mode.Static ? visible: LRCInstance.currentAccountAvatarSet
"qrc:/images/icons/baseline-camera_alt-24px.svg" : Layout.alignment: Qt.AlignHCenter
"qrc:/images/icons/round-add_a_photo-24px.svg" radius: JamiTheme.primaryRadius
source: "qrc:/images/icons/round-close-24px.svg"
toolTipText: JamiStrings.clearAvatar
imageColor: JamiTheme.textColor
onClicked: { onClicked: {
if (mode === PhotoboothView.Mode.Previewing) {
flashAnimation.start()
AccountAdapter.setCurrentAccountAvatarBase64(
preview.takePhoto(size))
avatarSet()
stopBooth() stopBooth()
return AccountAdapter.setCurrentAccountAvatarBase64()
} }
startBooth()
} }
}
PushButton {
id: importButton
Layout.preferredWidth: JamiTheme.preferredFieldHeight
Layout.preferredHeight: JamiTheme.preferredFieldHeight
Layout.alignment: Qt.AlignHCenter
radius: JamiTheme.primaryRadius PushButton {
source: "qrc:/images/icons/round-folder-24px.svg" id: importButton
toolTipText: JamiStrings.importFromFile Layout.alignment: Qt.AlignHCenter
imageColor: JamiTheme.textColor radius: JamiTheme.primaryRadius
source: "qrc:/images/icons/round-folder-24px.svg"
toolTipText: JamiStrings.importFromFile
imageColor: JamiTheme.textColor
onClicked: { onClicked: {
stopBooth() stopBooth()
importFromFileDialog.open() importFromFileDialog.open()
}
} }
} }
} }
......
...@@ -400,6 +400,7 @@ Item { ...@@ -400,6 +400,7 @@ Item {
// PhotoBoothView // PhotoBoothView
property string chooseAvatarImage: qsTr("Choose a picture as avatar") property string chooseAvatarImage: qsTr("Choose a picture as avatar")
property string importFromFile: qsTr("Import avatar from image file") property string importFromFile: qsTr("Import avatar from image file")
property string clearAvatar: qsTr("Clear avatar image")
property string takePhoto: qsTr("Take photo") property string takePhoto: qsTr("Take photo")
// PluginSettingsPage // PluginSettingsPage
......
...@@ -44,8 +44,21 @@ LRCInstance::LRCInstance(migrateCallback willMigrateCb, ...@@ -44,8 +44,21 @@ LRCInstance::LRCInstance(migrateCallback willMigrateCb,
accountModel().setTopAccount(currentAccountId_); accountModel().setTopAccount(currentAccountId_);
Q_EMIT accountListChanged(); Q_EMIT accountListChanged();
auto profileInfo = getCurrentAccountInfo().profileInfo;
// update type // update type
set_currentAccountType(getCurrentAccountInfo().profileInfo.type); set_currentAccountType(profileInfo.type);
// notify if the avatar is stored locally
set_currentAccountAvatarSet(!profileInfo.avatar.isEmpty());
});
connect(&accountModel(), &NewAccountModel::profileUpdated, [this](const QString& id) {
if (id != currentAccountId_)
return;
auto profileInfo = getCurrentAccountInfo().profileInfo;
set_currentAccountAvatarSet(!getCurrentAccountInfo().profileInfo.avatar.isEmpty());
}); });
// set the current account if any // set the current account if any
......
...@@ -57,6 +57,7 @@ class LRCInstance : public QObject ...@@ -57,6 +57,7 @@ class LRCInstance : public QObject
QML_PROPERTY(QString, selectedConvUid) QML_PROPERTY(QString, selectedConvUid)
QML_PROPERTY(QString, currentAccountId) QML_PROPERTY(QString, currentAccountId)
QML_RO_PROPERTY(lrc::api::profile::Type, currentAccountType) QML_RO_PROPERTY(lrc::api::profile::Type, currentAccountType)
QML_PROPERTY(bool, currentAccountAvatarSet)
public: public:
explicit LRCInstance(migrateCallback willMigrateCb = {}, explicit LRCInstance(migrateCallback willMigrateCb = {},
......
...@@ -66,12 +66,10 @@ ColumnLayout { ...@@ -66,12 +66,10 @@ ColumnLayout {
PhotoboothView { PhotoboothView {
id: currentAccountAvatar id: currentAccountAvatar
Layout.fillWidth: true
Layout.alignment: Qt.AlignCenter Layout.alignment: Qt.AlignCenter
imageId: LRCInstance.currentAccountId imageId: LRCInstance.currentAccountId
avatarSize: 180
size: 180
} }
MaterialLineEdit { MaterialLineEdit {
......
...@@ -32,11 +32,10 @@ Rectangle { ...@@ -32,11 +32,10 @@ Rectangle {
// trigger a default avatar prior to account generation // trigger a default avatar prior to account generation
property string createdAccountId: "dummy" property string createdAccountId: "dummy"
property int preferredHeight: profilePageColumnLayout.implicitHeight property int preferredHeight: profilePageColumnLayout.implicitHeight
property var showBottom: false property bool showBottom: false
property alias displayName: aliasEdit.text property alias displayName: aliasEdit.text
property bool isRdv: false property bool isRdv: false
property alias avatarBooth: setAvatarWidget property alias avatarBooth: setAvatarWidget
property bool avatarSet
signal leavePage signal leavePage
signal saveProfile signal saveProfile
...@@ -45,7 +44,6 @@ Rectangle { ...@@ -45,7 +44,6 @@ Rectangle {
createdAccountId = "dummy" createdAccountId = "dummy"
clearAllTextFields() clearAllTextFields()
saveProfileBtn.spinnerTriggered = true saveProfileBtn.spinnerTriggered = true
avatarSet = false
} }
function clearAllTextFields() { function clearAllTextFields() {
...@@ -99,13 +97,14 @@ Rectangle { ...@@ -99,13 +97,14 @@ Rectangle {
id: setAvatarWidget id: setAvatarWidget
Layout.alignment: Qt.AlignCenter Layout.alignment: Qt.AlignCenter
Layout.preferredWidth: size
Layout.fillHeight: true
imageId: createdAccountId imageId: createdAccountId
onAvatarSet: root.avatarSet = true avatarSize: 200
size: 200 onVisibleChanged: {
if (visible)
LRCInstance.currentAccountAvatarSet = false
}
} }
MaterialLineEdit { MaterialLineEdit {
...@@ -127,7 +126,7 @@ Rectangle { ...@@ -127,7 +126,7 @@ Rectangle {
fieldLayoutWidth: saveProfileBtn.width fieldLayoutWidth: saveProfileBtn.width
onTextEdited: { onTextEdited: {
if (root.avatarSet) if (LRCInstance.currentAccountAvatarSet)
return return
if (text.length === 0) { if (text.length === 0) {
lastFirstChar = "" lastFirstChar = ""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment