forked from m-wynn/sddm_wynn-theme
-
Notifications
You must be signed in to change notification settings - Fork 0
/
UserAvatar.qml
44 lines (39 loc) · 1.02 KB
/
UserAvatar.qml
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
import QtQuick 2.2
Canvas {
id: avatar
property string source: ""
property color m_strokeStyle: "#ffffff"
signal clicked()
onSourceChanged: delayPaintTimer.running = true
onPaint: {
var ctx = getContext("2d");
ctx.beginPath()
ctx.ellipse(0, 0, width, height)
ctx.clip()
ctx.drawImage(source, 0, 0, width, height)
ctx.strokeStyle = avatar.m_strokeStyle
ctx.lineWidth = 6
ctx.stroke()
}
MouseArea {
anchors.fill: parent
hoverEnabled: true
onEntered: {
m_strokeStyle = "#77ffffff"
avatar.requestPaint()
}
onExited: {
m_strokeStyle = "#ffffffff"
avatar.requestPaint()
}
onClicked: avatar.clicked()
}
// Fixme: paint() not affect event if source is not empty in initialization
Timer {
id: delayPaintTimer
repeat: false
interval: 150
onTriggered: avatar.requestPaint()
running: true
}
}