mirror of
https://invent.kde.org/marcoa/a-la-karte.git
synced 2026-02-10 05:13:08 +00:00
Replace the settings OverlaySheet with a pageStack layer page to avoid header/sidebar overlap. Keep keyboard/gamepad focus navigation and scrolling. Tweak SettingsPage spacing and make grid selection start unselected for better navigation.
101 lines
2.7 KiB
QML
101 lines
2.7 KiB
QML
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
// SPDX-FileCopyrightText: 2024 A-La-Karte Contributors
|
|
|
|
import QtQuick
|
|
import QtQuick.Controls as QQC2
|
|
import org.kde.kirigami as Kirigami
|
|
import org.kde.alakarte
|
|
|
|
GridView {
|
|
id: gridView
|
|
|
|
property int cardSize: App.config.gridSize
|
|
|
|
readonly property int cellPadding: cardSize < 180 ? Kirigami.Units.mediumSpacing : Kirigami.Units.largeSpacing
|
|
|
|
cellWidth: cardSize + cellPadding
|
|
cellHeight: Math.round(cardSize * 1.4) + cellPadding
|
|
|
|
clip: true
|
|
focus: true
|
|
keyNavigationEnabled: true
|
|
keyNavigationWraps: false
|
|
activeFocusOnTab: true
|
|
|
|
currentIndex: -1
|
|
|
|
highlightMoveDuration: Kirigami.Units.shortDuration
|
|
highlightFollowsCurrentItem: true
|
|
|
|
Keys.onUpPressed: navigateUp()
|
|
Keys.onDownPressed: navigateDown()
|
|
Keys.onLeftPressed: navigateLeft()
|
|
Keys.onRightPressed: navigateRight()
|
|
|
|
function navigateUp() {
|
|
if (currentIndex < 0 && count > 0) {
|
|
currentIndex = 0
|
|
return
|
|
}
|
|
if (currentIndex >= columns) {
|
|
currentIndex -= columns
|
|
}
|
|
}
|
|
|
|
function navigateDown() {
|
|
if (currentIndex < 0 && count > 0) {
|
|
currentIndex = 0
|
|
return
|
|
}
|
|
if (currentIndex + columns < count) {
|
|
currentIndex += columns
|
|
}
|
|
}
|
|
|
|
function navigateLeft() {
|
|
if (currentIndex < 0 && count > 0) {
|
|
currentIndex = 0
|
|
return
|
|
}
|
|
if (currentIndex > 0) {
|
|
currentIndex--
|
|
}
|
|
}
|
|
|
|
function navigateRight() {
|
|
if (currentIndex < 0 && count > 0) {
|
|
currentIndex = 0
|
|
return
|
|
}
|
|
if (currentIndex < count - 1) {
|
|
currentIndex++
|
|
}
|
|
}
|
|
|
|
Connections {
|
|
target: GamepadManager
|
|
function onNavigateUp() { if (gridView.activeFocus) gridView.navigateUp() }
|
|
function onNavigateDown() { if (gridView.activeFocus) gridView.navigateDown() }
|
|
function onNavigateLeft() { if (gridView.activeFocus) gridView.navigateLeft() }
|
|
function onNavigateRight() { if (gridView.activeFocus) gridView.navigateRight() }
|
|
function onSelectPressed() {
|
|
if (!gridView.activeFocus) {
|
|
return
|
|
}
|
|
if (gridView.currentIndex < 0 && gridView.count > 0) {
|
|
gridView.currentIndex = 0
|
|
}
|
|
if (gridView.currentItem) {
|
|
if (gridView.currentItem.play) {
|
|
gridView.currentItem.play()
|
|
} else {
|
|
gridView.currentItem.clicked()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
readonly property int columns: Math.max(1, Math.floor(width / cellWidth))
|
|
|
|
QQC2.ScrollBar.vertical: QQC2.ScrollBar {}
|
|
}
|