mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-01-28 15:32:50 -05:00
feat: Keybaord Nav to Category Settings
- fix: Escape key to exit settings
This commit is contained in:
@@ -112,9 +112,15 @@ DankModal {
|
|||||||
|
|
||||||
settingsContent: Component {
|
settingsContent: Component {
|
||||||
FocusScope {
|
FocusScope {
|
||||||
|
id: rootScope
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
focus: true
|
focus: true
|
||||||
|
|
||||||
|
Keys.onEscapePressed: event => {
|
||||||
|
settingsModal.hide()
|
||||||
|
event.accepted = true
|
||||||
|
}
|
||||||
|
|
||||||
Column {
|
Column {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
anchors.leftMargin: Theme.spacingL
|
anchors.leftMargin: Theme.spacingL
|
||||||
@@ -172,6 +178,7 @@ DankModal {
|
|||||||
id: sidebar
|
id: sidebar
|
||||||
|
|
||||||
parentModal: settingsModal
|
parentModal: settingsModal
|
||||||
|
focus: true
|
||||||
onCurrentIndexChanged: content.currentIndex = currentIndex
|
onCurrentIndexChanged: content.currentIndex = currentIndex
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,11 +3,13 @@ import qs.Common
|
|||||||
import qs.Modals.Settings
|
import qs.Modals.Settings
|
||||||
import qs.Widgets
|
import qs.Widgets
|
||||||
|
|
||||||
Rectangle {
|
FocusScope {
|
||||||
id: sidebarContainer
|
id: sidebarContainer
|
||||||
|
|
||||||
property int currentIndex: 0
|
property int currentIndex: 0
|
||||||
property var parentModal: null
|
property var parentModal: null
|
||||||
|
|
||||||
|
activeFocusOnTab: true
|
||||||
readonly property var sidebarItems: [{
|
readonly property var sidebarItems: [{
|
||||||
"text": I18n.tr("Personalization"),
|
"text": I18n.tr("Personalization"),
|
||||||
"icon": "person"
|
"icon": "person"
|
||||||
@@ -43,10 +45,66 @@ Rectangle {
|
|||||||
"icon": "info"
|
"icon": "info"
|
||||||
}]
|
}]
|
||||||
|
|
||||||
|
function navigateNext() {
|
||||||
|
currentIndex = (currentIndex + 1) % sidebarItems.length
|
||||||
|
}
|
||||||
|
|
||||||
|
function navigatePrevious() {
|
||||||
|
currentIndex = (currentIndex - 1 + sidebarItems.length) % sidebarItems.length
|
||||||
|
}
|
||||||
|
|
||||||
width: 270
|
width: 270
|
||||||
height: parent.height
|
height: parent.height
|
||||||
color: Theme.surfaceContainer
|
|
||||||
radius: Theme.cornerRadius
|
Component.onCompleted: {
|
||||||
|
forceActiveFocus()
|
||||||
|
}
|
||||||
|
|
||||||
|
Timer {
|
||||||
|
id: refocusTimer
|
||||||
|
interval: 50
|
||||||
|
onTriggered: sidebarContainer.forceActiveFocus()
|
||||||
|
}
|
||||||
|
|
||||||
|
Connections {
|
||||||
|
target: parentModal
|
||||||
|
function onOpened() {
|
||||||
|
refocusTimer.restart()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Keys.onPressed: event => {
|
||||||
|
if (event.key === Qt.Key_Down) {
|
||||||
|
navigateNext()
|
||||||
|
Qt.callLater(() => sidebarContainer.forceActiveFocus())
|
||||||
|
event.accepted = true
|
||||||
|
} else if (event.key === Qt.Key_Up) {
|
||||||
|
navigatePrevious()
|
||||||
|
Qt.callLater(() => sidebarContainer.forceActiveFocus())
|
||||||
|
event.accepted = true
|
||||||
|
} else if (event.key === Qt.Key_Tab && !event.modifiers) {
|
||||||
|
navigateNext()
|
||||||
|
Qt.callLater(() => sidebarContainer.forceActiveFocus())
|
||||||
|
event.accepted = true
|
||||||
|
} else if (event.key === Qt.Key_Backtab || (event.key === Qt.Key_Tab && event.modifiers & Qt.ShiftModifier)) {
|
||||||
|
navigatePrevious()
|
||||||
|
Qt.callLater(() => sidebarContainer.forceActiveFocus())
|
||||||
|
event.accepted = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Rectangle {
|
||||||
|
anchors.fill: parent
|
||||||
|
color: Theme.surfaceContainer
|
||||||
|
radius: Theme.cornerRadius
|
||||||
|
|
||||||
|
MouseArea {
|
||||||
|
anchors.fill: parent
|
||||||
|
onPressed: mouse => {
|
||||||
|
sidebarContainer.forceActiveFocus()
|
||||||
|
mouse.accepted = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Column {
|
Column {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
@@ -133,4 +191,6 @@ Rectangle {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user