sddm-patema/UserFrame.qml

137 lines
3.8 KiB
QML
Raw Normal View History

2016-04-05 16:19:00 +02:00
import QtQuick 2.0
import QtGraphicalEffects 1.0
2016-04-05 17:13:59 +02:00
Item {
2016-04-05 16:19:00 +02:00
id: frame
signal selected(var userName)
signal needClose()
readonly property int m_viewMaxWidth: frame.width - prevUser.width - nextUser.width - 130
2016-04-07 16:11:13 +02:00
property string currentIconPath: usersList.currentItem.iconPath
property string currentUserName: usersList.currentItem.userName
2020-03-17 18:16:10 +01:00
property bool showBG: false
2016-04-09 05:02:10 +02:00
property alias currentItem: usersList.currentItem
2016-04-05 16:19:00 +02:00
function isMultipleUsers() {
return usersList.count > 1
}
onOpacityChanged: {
2020-03-17 18:16:10 +01:00
showBG = false
}
2016-04-09 05:02:10 +02:00
onFocusChanged: {
2020-03-17 18:16:10 +01:00
if(focus) {
2016-04-09 05:02:10 +02:00
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()
2020-03-17 18:16:10 +01:00
showBG = true
}
}
2016-04-05 16:19:00 +02:00
ListView {
id: usersList
anchors.centerIn: parent
2020-03-17 18:16:10 +01:00
width: childrenRect.width > m_viewMaxWidth ?
m_viewMaxWidth : childrenRect.width
height: 150
2016-04-05 16:19:00 +02:00
model: userModel
clip: true
spacing: 10
2016-04-05 16:19:00 +02:00
orientation: ListView.Horizontal
delegate: Rectangle {
2016-04-09 05:02:10 +02:00
id: item
2016-04-05 16:19:00 +02:00
property string iconPath: icon
property string userName: nameText.text
2020-03-17 18:16:10 +01:00
property bool activeBG: usersList.currentIndex === index && showBG
border.width: 3
2016-04-09 05:02:10 +02:00
border.color: activeBG || focus ? "#33ffffff" : "transparent"
radius: 8
2016-04-09 05:02:10 +02:00
color: activeBG || focus? "#55000000" : "transparent"
2016-04-05 16:19:00 +02:00
width: 130
2016-04-06 16:49:13 +02:00
height: 150
2016-04-05 16:19:00 +02:00
2016-04-09 05:02:10 +02:00
function select() {
selected(name)
usersList.currentIndex = index
currentIconPath = icon
currentUserName = name
}
2016-04-06 16:49:13 +02:00
UserAvatar {
2016-04-05 16:19:00 +02:00
id: iconButton
anchors.top: parent.top
anchors.horizontalCenter: parent.horizontalCenter
2020-03-17 18:16:10 +01:00
width: 122
height: 122
2016-04-06 16:49:13 +02:00
source: icon
2016-04-09 05:02:10 +02:00
onClicked: item.select()
2016-04-05 16:19:00 +02:00
}
Text {
id: nameText
width: parent.width
anchors.bottom: parent.bottom
anchors.horizontalCenter: parent.horizontalCenter
horizontalAlignment: Text.AlignHCenter
text: name
font.pointSize: 15
color: "white"
wrapMode: Text.WordWrap
}
2016-04-07 16:11:13 +02:00
2016-04-09 05:02:10 +02:00
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()
2016-04-07 16:11:13 +02:00
Component.onCompleted: {
2020-03-17 18:16:10 +01:00
if(name === userModel.lastUser) {
2016-04-09 05:02:10 +02:00
item.select()
2016-04-07 16:11:13 +02:00
}
}
2016-04-05 16:19:00 +02:00
}
}
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()
2020-03-17 18:16:10 +01:00
showBG = true
}
}
2016-04-05 16:19:00 +02:00
MouseArea {
z: -1
anchors.fill: parent
onClicked: needClose()
}
2016-04-09 05:02:10 +02:00
Keys.onEscapePressed: needClose()
2016-04-05 16:19:00 +02:00
}