6import QGroundControl.Controls
7import QGroundControl.AppSettings
12 z: QGroundControl.zOrderTopMost
14 readonly property real _defaultTextHeight: ScreenTools.defaultFontPixelHeight
15 readonly property real _defaultTextWidth: ScreenTools.defaultFontPixelWidth
16 readonly property real _horizontalMargin: _defaultTextWidth / 2
17 readonly property real _verticalMargin: _defaultTextHeight / 2
19 property bool _first: true
20 property bool _commingFromRIDSettings: false
21 property int _selectedPageIndex: -1
22 property int _selectedSectionIndex: -1
23 property var _expandedPages: ({}) // pageIndex -> bool
24 property int _expandedRevision: 0 // bumped to trigger re-evaluation
25 property string _searchQuery: ""
26 property real _fullListWidth: 0 // Button column width with no search active
28 Binding on _fullListWidth {
29 when: settingsView._searchQuery.trim() === ""
30 value: buttonColumn.implicitWidth
31 restoreMode: Binding.RestoreNone
34 function _setExpanded(pageIndex, value) {
35 _expandedPages[pageIndex] = value
39 function _isExpanded(pageIndex) {
40 void _expandedRevision // create binding dependency
41 return !!_expandedPages[pageIndex]
44 function _pageSections(entry) {
45 return entry && typeof entry.sections === "function" ? entry.sections() : []
48 function _pageAvailable(entry) {
49 if (!entry || entry.name === "Divider" ||
50 (typeof entry.pageVisible === "function" && !entry.pageVisible())) {
54 var sections = _pageSections(entry)
55 return sections.length === 0 || sections.some(function(section) { return section.visible })
58 function _sectionAvailable(sections, sectionIndex) {
59 if (sectionIndex === -1) return true
60 for (var i = 0; i < sections.length; i++) {
61 if (sections[i].index === sectionIndex) return sections[i].visible
66 // A divider shows only between two available pages. When consecutive dividers have no
67 // available page between them, only the first one shows.
68 function _dividerVisible(pageIndex) {
69 if (_searchQuery.trim() !== "") {
73 let hasPageBefore = false
74 for (let i = pageIndex - 1; i >= 0; i--) {
75 let entry = settingsPagesModel.get(i)
76 if (entry.name === "Divider") {
79 if (_pageAvailable(entry)) {
88 for (let j = pageIndex + 1; j < settingsPagesModel.count; j++) {
89 if (_pageAvailable(settingsPagesModel.get(j))) {
96 // Search: returns array of matching section indices for a page, or empty if no match
97 function _matchingSections(pageIndex) {
98 var query = _searchQuery.toLowerCase().trim()
99 if (query === "") return [] // empty = no filtering
101 var entry = settingsPagesModel.get(pageIndex)
102 if (!_pageAvailable(entry)) return []
104 var sections = _pageSections(entry)
106 for (var i = 0; i < sections.length; i++) {
107 if (!sections[i].visible) continue
108 for (var j = 0; j < sections[i].searchTerms.length; j++) {
109 if (sections[i].searchTerms[j].indexOf(query) !== -1) {
110 matches.push(sections[i].index)
118 // Does this page have any search matches? (or is search empty = show all)
119 function _pageMatchesSearch(pageIndex) {
120 if (_searchQuery.trim() === "") return true
121 return _matchingSections(pageIndex).length > 0
124 function _navigateTo(pageIndex, sectionIndex) {
125 var entry = settingsPagesModel.get(pageIndex)
126 if (!entry || entry.name === "Divider") return
127 if (!_pageAvailable(entry)) return
128 if (!_sectionAvailable(_pageSections(entry), sectionIndex)) return
131 _selectedSectionIndex = sectionIndex
133 if (_selectedPageIndex !== pageIndex) {
134 _selectedPageIndex = pageIndex
135 rightPanel.source = url
138 // Apply section filter after the page is loaded
139 if (rightPanel.item && typeof rightPanel.item.sectionFilter !== "undefined") {
140 rightPanel.item.sectionFilter = sectionIndex
144 function _navigateToFirstAvailablePage() {
145 for (var i = 0; i < settingsPagesModel.count; i++) {
146 if (_pageAvailable(settingsPagesModel.get(i))) {
152 _selectedPageIndex = -1
153 _selectedSectionIndex = -1
154 rightPanel.source = ""
157 // settingsPage is the untranslated page name from SettingsPages.json
158 function showSettingsPage(settingsPage) {
159 for (var i = 0; i < settingsPagesModel.count; i++) {
160 var entry = settingsPagesModel.get(i)
161 if (entry && entry.nameKey === settingsPage) {
168 // This need to block click event leakage to underlying map.
173 QGCPalette { id: qgcPal }
175 Component.onCompleted: {
176 if (globals.commingFromRIDIndicator) {
177 globals.commingFromRIDIndicator = false
178 showSettingsPage("Remote ID")
181 if (_selectedPageIndex === -1) {
182 _navigateToFirstAvailablePage()
188 function onLoaded() {
189 if (rightPanel.item && typeof rightPanel.item.sectionFilter !== "undefined") {
190 rightPanel.item.sectionFilter = _selectedSectionIndex
195 SettingsPagesModel { id: settingsPagesModel }
198 anchors.fill: leftPanel
199 anchors.margins: -_horizontalMargin * 2
200 color: qgcPal.windowPanel
201 border.color: qgcPal.borderSubtle
202 radius: ScreenTools.defaultBorderRadius
207 width: Math.max(buttonColumn.implicitWidth, _fullListWidth, ScreenTools.isMobile ? 0 : ScreenTools.defaultFontPixelWidth * 22)
208 anchors.topMargin: _verticalMargin * 1.5
209 anchors.bottomMargin: _verticalMargin * 1.5
210 anchors.top: parent.top
211 anchors.bottom: parent.bottom
212 anchors.leftMargin: _horizontalMargin * 3
213 anchors.left: parent.left
214 spacing: _verticalMargin / 2
218 objectName: "settings_searchField"
219 Layout.fillWidth: true
220 placeholderText: qsTr("Search settings...")
223 settingsView._searchQuery = text
229 objectName: "settings_buttonList"
230 Layout.fillWidth: true
231 Layout.fillHeight: true
232 contentHeight: buttonColumn.height + _verticalMargin
233 flickableDirection: Flickable.VerticalFlick
238 width: buttonList.width
243 model: settingsPagesModel
248 Layout.fillWidth: true
250 required property int index
251 required property var model
253 property string pageName: model.name ?? ""
254 property string pageUrl: model.url ?? ""
255 property string pageIconUrl: model.iconUrl ?? ""
256 property var pageVisible: model.pageVisible ?? function() { return true }
257 property var pageSections: pageVisible() ? settingsView._pageSections(model) : []
258 property var visiblePageSections: pageSections.filter(function(section) {
259 return section.visible
261 property bool pageAvailable: pageVisible() &&
262 (pageSections.length === 0 || visiblePageSections.length > 0)
263 property bool isSelected: settingsView._selectedPageIndex === index
264 property bool hasMultipleSections: visiblePageSections.length > 1
265 property bool isSearching: settingsView._searchQuery.trim() !== ""
266 property bool matchesSearch: pageAvailable && settingsView._pageMatchesSearch(index)
267 property bool isExpanded: hasMultipleSections && (isSearching ? matchesSearch : settingsView._isExpanded(index))
269 onPageSectionsChanged: {
270 let sections = pageSections ?? []
271 let visibleCount = sections.filter(function(section) { return section.visible }).length
272 if (isSelected && pageAvailable && settingsView._selectedSectionIndex !== -1 &&
273 (visibleCount <= 1 ||
274 !settingsView._sectionAvailable(sections, settingsView._selectedSectionIndex))) {
275 settingsView._navigateTo(index, -1)
279 onPageAvailableChanged: {
280 if (isSelected && !pageAvailable) {
281 settingsView._navigateToFirstAvailablePage()
286 if (pageName === "Divider") return settingsView._dividerVisible(index)
287 if (!pageAvailable) return false
288 if (isSearching) return matchesSearch
293 objectName: pageName === "Divider" ? "settingsDivider_" + index : ""
294 visible: pageName === "Divider"
299 Layout.fillWidth: true
300 objectName: "settingsButton_" + (model.nameKey ?? pageName)
302 icon.source: pageIconUrl
303 expandable: hasMultipleSections
305 checked: isSelected && settingsView._selectedSectionIndex === -1
306 visible: pageName !== "Divider" && pageAvailable
309 if (mainWindow.allowViewSwitch()) {
310 settingsView._navigateTo(index, -1)
311 if (hasMultipleSections) {
312 // Toggle expand/collapse when re-clicking the same page
313 if (isSelected && isExpanded) {
314 settingsView._setExpanded(index, false)
315 } else if (!isExpanded) {
316 settingsView._setExpanded(index, true)
323 if (!mainWindow.allowViewSwitch()) {
326 var expanding = !isExpanded
327 settingsView._setExpanded(index, expanding)
328 if (!expanding && isSelected) {
329 settingsView._navigateTo(index, -1)
334 // Section sub-items (indented, shown when page is expanded)
336 model: isExpanded ? visiblePageSections : []
340 Layout.fillWidth: true
341 padding: ScreenTools.defaultFontPixelWidth * 0.75
342 leftPadding: ScreenTools.defaultFontPixelWidth
343 hoverEnabled: !ScreenTools.isMobile
345 property int sectionIndex: modelData.index
346 property bool sectionChecked: pageColumn.isSelected && settingsView._selectedSectionIndex === sectionIndex
347 property bool sectionMatchesSearch: {
348 if (!pageColumn.isSearching) return true
349 var matches = settingsView._matchingSections(pageColumn.index)
350 return matches.indexOf(sectionIndex) !== -1
352 property color textColor: qgcPal.textPrimary
353 visible: sectionMatchesSearch
355 background: Rectangle {
356 color: sectionBtn.sectionChecked || sectionBtn.pressed ? qgcPal.accentSubtle : (sectionBtn.enabled && sectionBtn.hovered ? qgcPal.windowCard : "transparent")
357 border.width: sectionBtn.sectionChecked || sectionBtn.pressed ? 1 : 0
358 border.color: qgcPal.accent
359 radius: ScreenTools.defaultFontPixelWidth / 2
362 contentItem: QGCLabel {
364 color: sectionBtn.textColor
365 font.pointSize: ScreenTools.defaultFontPointSize * 0.9
366 horizontalAlignment: Text.AlignLeft
370 if (mainWindow.allowViewSwitch()) {
371 settingsView._navigateTo(pageColumn.index, sectionIndex)
385 objectName: "settings_rightPanel"
386 anchors.leftMargin: _horizontalMargin * 4
387 anchors.rightMargin: _horizontalMargin
388 anchors.topMargin: _verticalMargin
389 anchors.bottomMargin: _verticalMargin
390 anchors.left: leftPanel.right
391 anchors.right: parent.right
392 anchors.top: parent.top
393 anchors.bottom: parent.bottom