Debian Codegraph @

src/GUI/qml/Section.qml

raw
1 import QtQuick 2.4
2
3 import FlightGear.Launcher 1.0
4 import FlightGear 1.0
5
6 Item {
7 id: root
8 property alias title: headerTitle.text
9 property alias contents: contentBox.children
10 property alias showAdvanced: advancedToggle.open
11 property string settingGroup: ""
12 property string summary: ""
13 readonly property bool haveAdvancedSettings: anyAdvancedSettings(contents)
14
15 implicitWidth: parent.width
16 implicitHeight: headerRect.height + contentBox.height + (Style.margin * 2)
17
18 signal apply();
19
20 function saveState()
21 {
22 for (var i = 0; i < contents.length; i++) {
23 contents[i].saveState();
24 }
25 }
26
27 function anyAdvancedSettings(items)
28 {
29 for (var i = 0; i < items.length; i++) {
30 if (items[i].advanced === true) return true;
31 }
32
33 return false;
34 }
35
36 // we determine the initial open/close state of the advanced section
37 // based on whether any of the advanced settings are non-default
38 function anyNonDefaultAdvancedSettings(items)
39 {
40 for (var i = 0; i < items.length; i++) {
41 var control = items[i];
42 if (control.advanced === true) {
43 if (!control.__isDefault && !control.hidden) {
44 //console.info("Non-default advanced setting:" + control.label + ","
45 // + control.defaultValue + " != " + control.value) ;
46 return true;
47 }
48 }
49 }
50
51 return false;
52 }
53
54 Connections {
55 target: _config
56 function onCollect() { root.apply(); }
57 }
58
59 Component.onCompleted: {
60 // use this as a trigger to decide the initial open/close state
61 if (anyNonDefaultAdvancedSettings(contents)) {
62 showAdvanced = true;
63 }
64 }
65
66 Rectangle {
67 id: headerRect
68 width: parent.width
69 height: headerTitle.height + (Style.margin * 2)
70
71 color: Style.themeColor
72 border.width: 1
73 border.color: Style.frameColor
74
75 Text {
76 id: headerTitle
77 color: Style.themeContrastTextColor
78 anchors.verticalCenter: parent.verticalCenter
79 font.bold: true
80 font.pixelSize: Style.subHeadingFontPixelSize
81 anchors.left: parent.left
82 anchors.leftMargin: Style.inset
83 }
84
85 AdvancedSettingsToggle
86 {
87 id: advancedToggle
88 anchors.right: parent.right
89 anchors.verticalCenter: parent.verticalCenter
90 height: parent.height
91 visible: root.haveAdvancedSettings
92
93 GettingStartedTip {
94 tipId: "expandSectionTip"
95 enabled: root.haveAdvancedSettings
96
97 anchors {
98 horizontalCenter: parent.horizontalCenter
99 top: parent.bottom
100 }
101 arrow: GettingStartedTip.TopRight
102 text: qsTr("Click here to show advanced settings in this section")
103 }
104 }
105 }
106
107
108 MouseArea {
109 anchors.fill: contentBox
110 onClicked: {
111 // take focus back from any active control
112 root.focus = true
113 }
114 }
115
116 Column {
117 id: contentBox
118 anchors.top: headerRect.bottom
119 anchors.topMargin: Style.margin
120 width: parent.width
121 spacing: Style.margin * 2
122
123 // this is here so SettingControl 's parent (which is us)
124 // can be used to find the advanced toggle state
125 property alias showAdvanced: advancedToggle.open
126 }
127
128 // bottom spacing item
129 Item {
130 height: Style.margin
131 width: parent.width
132 anchors.top: contentBox.bottom
133 }
134 }