diff --git a/kded/qml/OsdSelector.qml b/kded/qml/OsdSelector.qml --- a/kded/qml/OsdSelector.qml +++ b/kded/qml/OsdSelector.qml @@ -28,7 +28,6 @@ id: root location: PlasmaCore.Types.Floating type: PlasmaCore.Dialog.Normal - visible: true property string infoText signal clicked(int actionId) @@ -39,13 +38,14 @@ PlasmaComponents.ButtonRow { id: buttonRow - exclusive: false + exclusive: true 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", @@ -79,6 +79,7 @@ } ] delegate: PlasmaComponents.Button { + property var action: modelData.action PlasmaCore.IconItem { source: modelData.iconSource height: buttonRow.height - ((units.smallSpacing / 2) * 3) @@ -88,9 +89,29 @@ 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,7 +135,39 @@ } 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.onEscapePressed: clicked("dialog-cancel") + Keys.onPressed: { + if (event.key === Qt.Key_Return || event.key === Qt.Key_Enter) { + event.accepted = true + clicked(buttonRow.checkedButton.action) + return + } + if (event.key === Qt.Key_Right) { + event.accepted = true + next() + return + } + if (event.key === Qt.Key_Left) { + previous() + return + } + } } }