~nicohman/signal-rs

ref: ad7bba6ed316afe281e38a8327baf7c1bbf824da signal-rs/qml/Avatar.qml -rw-r--r-- 1.8 KiB
ad7bba6e — nicohman Basic attachments 4 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
68
69
70
71
72
73
74
75
76
import QtQuick 2.12
import QtQuick.Controls 2.5
import QtGraphicalEffects 1.15
import QtQuick.Dialogs 1.3
Item {
	id: avatarItem
	property string tel:""
	property bool rounded: true
	property bool editable: false
	FileDialog {
		id: fd
		title: "Pick a new avatar"
		selectExisting: true
		selectFolder: false
		selectMultiple: false
		onAccepted: {
			var regex = new RegExp("file://");
			var path = fd.fileUrl.toString().replace("file://", "");
			var newAvatar = signal.set_avatar(avatarItem.tel, path);
			//avatarImg.cache = false;
			avatarImg.source = "";
			avatarImg.source = `file://${newAvatar}`;	
			avatarImg.sourceChanged(avatarImg.source);
			//avatarImg.cache = true;
		}
	}
	Image {
		cache: false
		anchors.fill: parent
		id: avatarImg
		Component.onCompleted: {
	        var avatar = signal.avatar(parent.tel);
	        if (avatar !== "") {
	        	avatarImg.source = `file://${avatar}`;
	        } else {
	        	avatarRect.visible = true;
	        	avatarRectLabel.text = new String(signal.resolve_name(parent.tel))[0].toUpperCase();
	        }
		}
		layer.enabled: parent.rounded
		layer.effect: OpacityMask {
			maskSource: Item {
				width: avatarImg.width
				height: avatarImg.height
				Rectangle {
					anchors.centerIn: parent
					width: avatarImg.width
					height: avatarImg.height
					radius: avatarImg.width
				}
			}
		}
		MouseArea {
			anchors.fill: parent
		onClicked: {
			if (avatarItem.editable) {
				fd.visible = true;
			}
		}
	}
	}
	Rectangle {
		id:avatarRect
		anchors.fill: parent
	    color: "grey"
	    radius: 50
	    visible:false
	    Label {
	    	id: avatarRectLabel
	        color: theme.text
	        text: ""
	        anchors.verticalCenter: parent.verticalCenter
	        anchors.horizontalCenter: parent.horizontalCenter
	    }
	}
}