-
Notifications
You must be signed in to change notification settings - Fork 5
/
UserFrame.qml
143 lines (125 loc) · 3.99 KB
/
UserFrame.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
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
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
142
143
import QtQuick 2.0
import QtGraphicalEffects 1.0
Item {
id: frame
signal selected(var userName)
signal needClose()
readonly property int m_viewMaxWidth: frame.width - prevUser.width - nextUser.width - 130
property string currentIconPath: usersList.currentItem.iconPath
property string currentUserName: usersList.currentItem.userName
property bool shouldShowBG: false
property alias currentItem: usersList.currentItem
function isMultipleUsers() {
return usersList.count > 1
}
onOpacityChanged: {
shouldShowBG = false
}
onFocusChanged: {
// Active by mouse click
if (focus) {
usersList.currentItem.focus = false
}
}
ImgButton {
id: prevUser
visible: usersList.childrenRect.width > m_viewMaxWidth
anchors.left: parent.left
anchors.verticalCenter: parent.verticalCenter
anchors.margins: 10
normalImg: "icons/angle-left.png"
onClicked: {
usersList.decrementCurrentIndex()
shouldShowBG = true
}
}
ListView {
id: usersList
anchors.centerIn: parent
width: childrenRect.width > m_viewMaxWidth ? m_viewMaxWidth : childrenRect.width
height: 150
model: userModel
clip: true
spacing: 10
orientation: ListView.Horizontal
delegate: Rectangle {
id: item
property string iconPath: icon
property string userName: nameText.text
property bool activeBG: usersList.currentIndex === index && shouldShowBG
border.width: 3
border.color: activeBG || focus ? "#33ffffff" : "transparent"
radius: 8
color: activeBG || focus? "#55000000" : "transparent"
width: 130
height: 150
function select() {
selected(name)
usersList.currentIndex = index
currentIconPath = icon
currentUserName = name
}
UserAvatar {
id: iconButton
width: 100
height: 100
source: icon
onClicked: item.select()
anchors {
top: parent.top
topMargin: 10
horizontalCenter: parent.horizontalCenter
}
}
Text {
id: nameText
width: parent.width - 10
horizontalAlignment: Text.AlignHCenter
text: name
font.family: config.font
font.pointSize: 15
color: "white"
elide: Text.ElideRight
anchors {
bottom: parent.bottom
horizontalCenter: parent.horizontalCenter
bottomMargin: 10
}
}
Keys.onLeftPressed: {
usersList.decrementCurrentIndex()
usersList.currentItem.forceActiveFocus()
}
Keys.onRightPressed: {
usersList.incrementCurrentIndex()
usersList.currentItem.forceActiveFocus()
}
Keys.onEscapePressed: needClose()
Keys.onEnterPressed: item.select()
Keys.onReturnPressed: item.select()
Component.onCompleted: {
if (name === userModel.lastUser) {
item.select()
}
}
}
}
ImgButton {
id: nextUser
visible: usersList.childrenRect.width > m_viewMaxWidth
anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter
anchors.margins: 10
normalImg: "icons/angle-right.png"
onClicked: {
usersList.incrementCurrentIndex()
shouldShowBG = true
}
}
MouseArea {
z: -1
anchors.fill: parent
onClicked: needClose()
}
Keys.onEscapePressed: needClose()
}