sddm-patema/SessionFrame.qml

159 lines
4.5 KiB
QML
Raw Normal View History

2016-04-05 13:42:21 +02:00
import QtQuick 2.0
import QtGraphicalEffects 1.0
2016-04-05 17:13:59 +02:00
Item {
2016-04-05 13:42:21 +02:00
id: frame
signal selected(var index)
signal needClose()
2020-03-17 18:16:10 +01:00
function calcMaxWidth() {
return frame.width - prevSession.width - nextSession.width - 230;
}
readonly property int m_viewMaxWidth: calcMaxWidth()
property bool showBG: false
property var sessionTypeList: ["deepin", "enlightenment", "fluxbox",
"gnome", "kde", "lxde", "ubuntu"]
2016-04-09 05:02:10 +02:00
property alias currentItem: sessionList.currentItem
2016-04-05 13:42:21 +02:00
function getIconName(sessionName) {
2020-03-17 18:16:10 +01:00
for(var item in sessionTypeList) {
2016-04-05 13:42:21 +02:00
var str = sessionTypeList[item]
var index = sessionName.toLowerCase().indexOf(str)
2020-03-17 18:16:10 +01:00
if(index >= 0) {
2016-04-05 13:42:21 +02:00
return str
}
}
return "unknow"
}
2016-04-07 14:10:16 +02:00
function getCurrentSessionIconIndicator() {
return sessionList.currentItem.iconIndicator;
2016-04-05 13:42:21 +02:00
}
function isMultipleSessions() {
return sessionList.count > 1
}
onOpacityChanged: {
2020-03-17 18:16:10 +01:00
showBG = false
}
2016-04-09 05:02:10 +02:00
onFocusChanged: {
// Active by mouse click
2020-03-17 18:16:10 +01:00
if(focus) {
2016-04-09 05:02:10 +02:00
sessionList.currentItem.focus = false
}
}
ImgButton {
id: prevSession
visible: sessionList.childrenRect.width > m_viewMaxWidth
anchors.left: parent.left
anchors.verticalCenter: parent.verticalCenter
anchors.margins: 10
normalImg: "icons/angle-left.png"
onClicked: {
sessionList.decrementCurrentIndex()
2020-03-17 18:16:10 +01:00
showBG = true
}
}
2016-04-05 13:42:21 +02:00
ListView {
id: sessionList
anchors.centerIn: parent
2020-03-17 18:16:10 +01:00
width: childrenRect.width > m_viewMaxWidth ?
m_viewMaxWidth : childrenRect.width
height: 150
clip: true
2016-04-05 13:42:21 +02:00
model: sessionModel
currentIndex: sessionModel.lastIndex
orientation: ListView.Horizontal
spacing: 10
delegate: Rectangle {
2016-04-07 14:10:16 +02:00
property string iconIndicator: iconButton.indicator
2020-03-17 18:16:10 +01:00
property bool activeBG: sessionList.currentIndex === index && showBG
2016-04-05 13:42:21 +02:00
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"
width: 230
2016-04-07 14:10:16 +02:00
height: 150
2016-04-05 13:42:21 +02:00
ImgButton {
2016-04-05 13:42:21 +02:00
id: iconButton
anchors.top: parent.top
anchors.horizontalCenter: parent.horizontalCenter
2016-04-07 14:10:16 +02:00
width: 100
height: 100
2016-04-05 13:42:21 +02:00
normalImg: ("%1normal.png").arg(prefix)
hoverImg: ("%1hover.png").arg(prefix)
pressImg: ("%1press.png").arg(prefix)
2016-04-07 14:10:16 +02:00
2020-03-17 18:16:10 +01:00
property var prefix: ("icons/sessionicon/%1_")
.arg(getIconName(name))
property var indicator: ("icons/%1_indicator_normal.png")
.arg(getIconName(name))
2016-04-07 14:10:16 +02:00
2016-04-05 13:42:21 +02:00
onClicked: {
selected(index)
sessionList.currentIndex = index
}
}
Text {
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-09 05:02:10 +02:00
Keys.onLeftPressed: {
sessionList.decrementCurrentIndex()
sessionList.currentItem.forceActiveFocus()
}
Keys.onRightPressed: {
sessionList.incrementCurrentIndex()
sessionList.currentItem.forceActiveFocus()
}
Keys.onEscapePressed: needClose()
Keys.onEnterPressed: {
selected(index)
sessionList.currentIndex = index
}
Keys.onReturnPressed: {
selected(index)
sessionList.currentIndex = index
}
2016-04-05 13:42:21 +02:00
}
}
ImgButton {
id: nextSession
visible: sessionList.childrenRect.width > m_viewMaxWidth
anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter
anchors.margins: 10
normalImg: "icons/angle-right.png"
onClicked: {
sessionList.incrementCurrentIndex()
2020-03-17 18:16:10 +01:00
showBG = true
}
}
2016-04-05 13:42:21 +02:00
MouseArea {
z: -1
anchors.fill: parent
onClicked: needClose()
}
2016-04-09 05:02:10 +02:00
Keys.onEscapePressed: needClose()
2016-04-05 13:42:21 +02:00
}