SettingsPanel: no longer using hardcoded ID to focus a tab

This commit is contained in:
quadbyte 2025-08-13 09:34:05 -04:00
parent 5fd0e57b91
commit 207310cd24
4 changed files with 48 additions and 9 deletions

View file

@ -84,7 +84,7 @@ Item {
} }
} }
onClicked: { onClicked: {
settingsPanel.currentTabIndex = 5 // Audio tab index settingsPanel.requestedTab = settingsPanel.tabsIds.AUDIO
settingsPanel.isLoaded = true settingsPanel.isLoaded = true
} }
} }

View file

@ -10,13 +10,32 @@ import qs.Widgets
NLoader { NLoader {
id: root id: root
property int currentTabIndex: 0 property var tabsIds: null
property var requestedTab: null
Component.onCompleted: {
// Fill up our ideads
tabsIds = Object.freeze({
"GENERAL": 0,
"BAR": 1,
"TIME_WEATHER": 2,
"SCREEN_RECORDER": 3,
"NETWORK": 4,
"AUDIO": 5,
"DISPLAY": 6,
"WALLPAPER": 7,
"WALLPAPER_SELECTOR": 8,
"MISC": 9,
"ABOUT": 10
})
}
content: Component { content: Component {
NPanel { NPanel {
id: panel id: panel
readonly property real scaling: Scaling.scale(screen) readonly property real scaling: Scaling.scale(screen)
property int currentTabIndex: 0
// Override hide function to animate first // Override hide function to animate first
function hide() { function hide() {
@ -55,47 +74,58 @@ NLoader {
WlrLayershell.keyboardFocus: WlrKeyboardFocus.OnDemand WlrLayershell.keyboardFocus: WlrKeyboardFocus.OnDemand
property var tabsModel: [{ property var tabsModel: [{
"id": root.tabsIds.GENERAL,
"label": "General", "label": "General",
"icon": "tune", "icon": "tune",
"source": "Tabs/General.qml" "source": "Tabs/General.qml"
}, { }, {
"id": root.tabsIds.BAR,
"label": "Bar", "label": "Bar",
"icon": "web_asset", "icon": "web_asset",
"source": "Tabs/Bar.qml" "source": "Tabs/Bar.qml"
}, { }, {
"id": root.tabsIds.TIME_WEATHER,
"label": "Time & Weather", "label": "Time & Weather",
"icon": "schedule", "icon": "schedule",
"source": "Tabs/TimeWeather.qml" "source": "Tabs/TimeWeather.qml"
}, { }, {
"id": root.tabsIds.SCREEN_RECORDER,
"label": "Screen Recorder", "label": "Screen Recorder",
"icon": "videocam", "icon": "videocam",
"source": "Tabs/ScreenRecorder.qml" "source": "Tabs/ScreenRecorder.qml"
}, { }, {
"id": root.tabsIds.NETWORK,
"label": "Network", "label": "Network",
"icon": "wifi", "icon": "wifi",
"source": "Tabs/Network.qml" "source": "Tabs/Network.qml"
}, { }, {
"id": root.tabsIds.AUDIO,
"label": "Audio", "label": "Audio",
"icon": "volume_up", "icon": "volume_up",
"source": "Tabs/Audio.qml" "source": "Tabs/Audio.qml"
}, { }, {
"id": root.tabsIds.DISPLAY,
"label": "Display", "label": "Display",
"icon": "monitor", "icon": "monitor",
"source": "Tabs/Display.qml" "source": "Tabs/Display.qml"
}, { }, {
"id": root.tabsIds.WALLPAPER,
"label": "Wallpaper", "label": "Wallpaper",
"icon": "image", "icon": "image",
"source": "Tabs/Wallpaper.qml" "source": "Tabs/Wallpaper.qml"
}, { }, {
"id": root.tabsIds.WALLPAPER_SELECTOR,
"label": "Wallpaper Selector", "label": "Wallpaper Selector",
"icon": "wallpaper_slideshow", "icon": "wallpaper_slideshow",
"source": "Tabs/WallpaperSelector.qml" "source": "Tabs/WallpaperSelector.qml"
}, // { }, // {
// "id": root.tabsIds.MISC,
// "label": "Misc", // "label": "Misc",
// "icon": "more_horiz", // "icon": "more_horiz",
// "source": "Tabs/Misc.qml" // "source": "Tabs/Misc.qml"
// }, // },
{ {
"id": root.tabsIds.ABOUT,
"label": "About", "label": "About",
"icon": "info", "icon": "info",
"source": "Tabs/About.qml" "source": "Tabs/About.qml"
@ -104,7 +134,18 @@ NLoader {
// Combined visibility change handler // Combined visibility change handler
onVisibleChanged: { onVisibleChanged: {
if (visible) { if (visible) {
// Default to first tab
currentTabIndex = 0 currentTabIndex = 0
// Find the request tab if necessary
if (requestedTab != null) {
for (var i = 0; i < tabsModel.length; i++) {
if (tabsModel[i].id == requestedTab) {
currentTabIndex = i
break
}
}
}
} else if (bgRect.opacityValue > 0) { } else if (bgRect.opacityValue > 0) {
// Start hide animation // Start hide animation
bgRect.scaleValue = 0.8 bgRect.scaleValue = 0.8
@ -150,7 +191,6 @@ NLoader {
NumberAnimation { NumberAnimation {
duration: Style.animationSlow duration: Style.animationSlow
easing.type: Easing.OutExpo easing.type: Easing.OutExpo
} }
} }
@ -158,7 +198,6 @@ NLoader {
NumberAnimation { NumberAnimation {
duration: Style.animationNormal duration: Style.animationNormal
easing.type: Easing.OutQuad easing.type: Easing.OutQuad
} }
} }

View file

@ -58,6 +58,7 @@ NBox {
icon: "settings" icon: "settings"
tooltipText: "Open settings" tooltipText: "Open settings"
onClicked: { onClicked: {
settingsPanel.requestedTab = settingsPanel.tabsIds.GENERAL
settingsPanel.isLoaded = !settingsPanel.isLoaded settingsPanel.isLoaded = !settingsPanel.isLoaded
} }
} }
@ -135,7 +136,6 @@ NBox {
uptimeProcess.running = true uptimeProcess.running = true
} }
Process { Process {
id: shutdownProcess id: shutdownProcess

View file

@ -31,7 +31,7 @@ NBox {
NIconButton { NIconButton {
icon: "image" icon: "image"
onClicked: { onClicked: {
settingsPanel.currentTabIndex = 8 // Audio tab index settingsPanel.requestedTab = settingsPanel.tabsIds.WALLPAPER_SELECTOR
settingsPanel.isLoaded = true settingsPanel.isLoaded = true
} }
} }