Verified Commit 3745bd53 authored by Fushan Wen's avatar Fushan Wen 💬
Browse files

applets/userswitcher: port to `PC3.ItemDelegate`

This improves the accessibility.
parent 1b3f2300
Pipeline #212314 passed with stage
in 1 minute and 38 seconds
......@@ -11,10 +11,10 @@ import org.kde.plasma.core 2.1 as PlasmaCore
ListDelegate {
id: item
property alias icon: icon.source
activeFocusOnTab: true
iconItem: PlasmaCore.IconItem {
id: icon
anchors.fill: parent
source: item.icon.name
}
}
......@@ -11,45 +11,21 @@ import org.kde.kirigami 2.20 as Kirigami
import org.kde.plasma.core 2.1 as PlasmaCore
import org.kde.plasma.components 3.0 as PlasmaComponents3
Item {
PlasmaComponents3.ItemDelegate {
id: item
signal clicked()
Layout.fillWidth: true
property alias text: label.text
property alias subText: sublabel.text
property bool interactive: true
property alias iconItem: iconItem.children
readonly property bool containsMouse: area.containsMouse
property Item highlight
highlighted: hovered || activeFocus
// sizing: top-down explicit width, bottom-up implicit height
implicitHeight: row.implicitHeight + 2 * PlasmaCore.Units.smallSpacing
implicitWidth: row.implicitWidth
Layout.fillWidth: true
MouseArea {
id: area
anchors.fill: parent
enabled: item.interactive
hoverEnabled: true
onClicked: item.clicked()
onContainsMouseChanged: {
if (!highlight) {
return
}
if (containsMouse) {
highlight.parent = item
}
}
}
RowLayout {
contentItem: RowLayout {
id: row
anchors.centerIn: parent
width: parent.width - 2 * PlasmaCore.Units.smallSpacing
spacing: PlasmaCore.Units.smallSpacing
Item {
......@@ -64,12 +40,14 @@ Item {
}
ColumnLayout {
id: column
Layout.fillWidth: true
spacing: 0
PlasmaComponents3.Label {
id: label
Layout.fillWidth: true
text: item.text
wrapMode: Text.NoWrap
elide: Text.ElideRight
}
......
......@@ -131,15 +131,6 @@ Item {
id: sessionsModel
}
property Item delegateHighlight: PlasmaExtras.Highlight {
id: delegateHighlight
parent: null
width: parent ? parent.width : undefined
height: parent ? parent.height : undefined
hovered: parent && parent.containsMouse
z: -1 // otherwise it shows ontop of the icon/label and tints them slightly
}
ColumnLayout {
id: column
......@@ -151,7 +142,7 @@ Item {
text: root.displayedName
subText: i18n("Current user")
source: kuser.faceIconUrl.toString()
interactive: false
hoverEnabled: false
interactiveIcon: KCMShell.authorize("kcm_users.desktop").length > 0
onIconClicked: KCMShell.openSystemSettings("kcm_users")
}
......@@ -169,11 +160,16 @@ Item {
id: userList
model: sessionsModel
highlight: PlasmaExtras.Highlight {}
highlightMoveDuration: 0
focus: true
interactive: true
keyNavigationWraps: true
delegate: UserListDelegate {
width: ListView.view.width
activeFocusOnTab: true
highlighted: ListView.view.isCurrentItem || hovered || activeFocus
text: {
if (!model.session) {
return i18nc("Nobody logged in on that session", "Unused")
......@@ -200,9 +196,6 @@ Item {
}
onClicked: sessionsModel.switchUser(model.vtNumber, sessionsModel.shouldLock)
onContainsMouseChanged: {
userList.currentIndex = containsMouse ? index : -1;
}
}
}
}
......@@ -210,8 +203,7 @@ Item {
ActionListDelegate {
id: newSessionButton
text: i18nc("@action", "New Session")
icon: "system-switch-user"
highlight: delegateHighlight
icon.name: "system-switch-user"
visible: sessionsModel.canStartNewSession
onClicked: sessionsModel.startNewSession(sessionsModel.shouldLock)
}
......@@ -219,8 +211,7 @@ Item {
ActionListDelegate {
id: lockScreenButton
text: i18nc("@action", "Lock Screen")
icon: "system-lock-screen"
highlight: delegateHighlight
icon.name: "system-lock-screen"
visible: pmEngine.data["Sleep States"]["LockScreen"]
onClicked: pmEngine.performOperation("lockScreen")
}
......@@ -228,8 +219,7 @@ Item {
ActionListDelegate {
id: leaveButton
text: i18nc("Show a dialog with options to logout/shutdown/restart", "Leave…")
highlight: delegateHighlight
icon: "system-shutdown"
icon.name: "system-shutdown"
onClicked: pmEngine.performOperation("requestShutDown")
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment