QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
SettingsGroupLayout.qml
Go to the documentation of this file.
1import QtQuick
2import QtQuick.Layouts
3
4import QGroundControl
5import QGroundControl.Controls
6
7ColumnLayout {
8 id: control
9 spacing: _margins / 2
10 implicitWidth: _contentLayout.implicitWidth + (_margins * 2)
11 implicitHeight: _contentLayout.implicitHeight + (_margins * 2)
12
13 default property alias contentItem: _contentLayout.data
14
15 property alias contentSpacing: _contentLayout.spacing
16
17 property string defaultBorderColor : QGroundControl.globalPalette.groupBorder
18 property string outerBorderColor : defaultBorderColor
19
20 property string defaultHeadingPointSize: ScreenTools.defaultFontPointSize + 1
21 property string headingPointSize: defaultHeadingPointSize
22
23 property string heading
24 property string headingDescription
25 property bool showDividers: true
26 property bool showBorder: true
27
28 property real _margins: ScreenTools.defaultFontPixelHeight / 2
29
30 // We work with a y sorted list of children for divider visibility checks
31 property var _ySortedChildren: {
32 let arr = []
33 for (let c of _contentLayout.children)
34 arr.push(c)
35 arr.sort((a, b) => a.y - b.y)
36 return arr
37 }
38
39 ColumnLayout {
40 Layout.leftMargin: _margins
41 Layout.fillWidth: true
42 spacing: 0
43 visible: heading !== ""
44
45 QGCLabel {
46 text: heading
47 font.pointSize: headingPointSize
48 font.bold: true
49 }
50
51 QGCLabel {
52 Layout.fillWidth: true
53 text: headingDescription
54 wrapMode: Text.WordWrap
55 font.pointSize: ScreenTools.smallFontPointSize
56 visible: headingDescription !== ""
57 }
58 }
59
60 Rectangle {
61 id: outerRect
62 Layout.fillWidth: true
63 implicitWidth: _contentLayout.implicitWidth + (showBorder ? _margins * 2 : 0)
64 implicitHeight: _contentLayout.implicitHeight + (showBorder ? _margins * 2: 0)
65 color: "transparent"
66 border.color: outerBorderColor
67 border.width: showBorder ? 1 : 0
68 radius: ScreenTools.defaultFontPixelHeight / 2
69
70 Repeater {
71 model: showDividers ? _ySortedChildren.length : 0
72
73 Rectangle {
74 x: showBorder ? _margins : 0
75 y: _contentItem ? (_contentItem.y + _contentItem.height + _margins + (showBorder ? _margins : 0)) : 0
76 width: parent.width - (showBorder ? _margins * 2 : 0)
77 height: 1
78 color: QGroundControl.globalPalette.groupBorder
79 visible: _contentItem ? _isContentItemVisible() : false
80
81 property var _contentItem: index < _ySortedChildren.length ? _ySortedChildren[index] : undefined
82
83 function _isRepeater(item) {
84 return item && item.toString().startsWith("QQuickRepeater");
85 }
86
87 function _isContentItemVisible() {
88 if (!_contentItem || !_contentItem.visible || _isRepeater(_contentItem)) {
89 return false
90 }
91 // Any children after this one visually from top to bottom must be visible to show divider
92 for (let i = index + 1; i < _ySortedChildren.length; ++i) {
93 if (!_ySortedChildren[i] || _isRepeater(_ySortedChildren[i])) {
94 continue
95 }
96 if (_ySortedChildren[i].visible) {
97 return true
98 }
99 }
100 return false
101 }
102 }
103 }
104
105 ColumnLayout {
106 id: _contentLayout
107 x: showBorder ? _margins : 0
108 y: showBorder ? _margins : 0
109 width: parent.width - (showBorder ? _margins * 2 : 0)
110 spacing: _margins * (showDividers ? 2 : 1)
111 }
112 }
113}