Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit bb6c51b0 authored by Frederik Gladhorn's avatar Frederik Gladhorn

Handle keyboard in action selector OSD

Summary:
The OSD is not all that bad, but it was only usable with the mouse.
Change it so that left-right and tab navigates and space/return confirms
the selection.

BUG: 395804

Reviewers: #plasma, davidedmundson

Subscribers: broulik, davidedmundson, plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D14165
parent 5238ae3a
......@@ -36,15 +36,16 @@ PlasmaCore.Dialog {
height: Math.min(units.gridUnit * 15, Screen.desktopAvailableHeight / 5)
width: buttonRow.width
PlasmaComponents.ButtonRow {
Row {
id: buttonRow
exclusive: false
spacing: theme.defaultFont.pointSize
height: parent.height - label.height - ((units.smallSpacing/2) * 3)
width: (actionRepeater.count * height) + ((actionRepeater.count - 1) * buttonRow.spacing);
Repeater {
id: actionRepeater
property int currentIndex: 0
model: [
{
iconSource: "osd-shutd-laptop",
......@@ -78,6 +79,7 @@ PlasmaCore.Dialog {
}
]
delegate: PlasmaComponents.Button {
property var action: modelData.action
Accessible.name: modelData.label
PlasmaCore.IconItem {
source: modelData.iconSource
......@@ -88,9 +90,29 @@ PlasmaCore.Dialog {
height: parent.height
width: height
onHoveredChanged: root.infoText = (hovered ? modelData.label : "")
onHoveredChanged: {
actionRepeater.currentIndex = index
}
onClicked: root.clicked(action)
activeFocusOnTab: true
onClicked: root.clicked(modelData.action)
// use checked only indirectly, since its binding will break
property bool current: index == actionRepeater.currentIndex
onCurrentChanged: {
if (current) {
checked = true
root.infoText = modelData.label
forceActiveFocus()
} else {
checked = false
}
}
onActiveFocusChanged: {
if (activeFocus) {
actionRepeater.currentIndex = index
}
}
}
}
}
......@@ -114,6 +136,44 @@ PlasmaCore.Dialog {
}
Component.onCompleted: print("OsdSelector loaded...");
function next() {
var index = actionRepeater.currentIndex + 1
if (index >= actionRepeater.count) {
index = 0
}
actionRepeater.currentIndex = index
}
function previous() {
var index = actionRepeater.currentIndex - 1
if (index < 0) {
index = actionRepeater.count - 1
}
actionRepeater.currentIndex = index
}
Keys.onPressed: {
if (event.key === Qt.Key_Return || event.key === Qt.Key_Enter) {
event.accepted = true
clicked(buttonRow.children[actionRepeater.currentIndex].action)
return
}
if (event.key === Qt.Key_Right) {
event.accepted = true
next()
return
}
if (event.key === Qt.Key_Left) {
event.accepted = true
previous()
return
}
if (event.key === Qt.Key_Escape) {
event.accepted = true
clicked(OsdAction.NoAction)
return
}
}
}
}
Markdown is supported
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