QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
PlanListInspector.qml
Go to the documentation of this file.
1import QtQuick
2
3import QGroundControl
4import QGroundControl.Controls
5
6import "PlanPanelLogic.js" as Logic
7
8/// Shows a list and an inspector for the selected list entry. When the height allows, the list sits above the inspector. On
9/// short screens the list and the inspector take turns filling the whole area.
10///
11/// The list component exposes contentHeight and may emit itemActivated(). The inspector component may emit backRequested().
12Item {
13 id: root
14
15 property Component listComponent
16 property Component inspectorComponent
17 property bool hasSelection: false
18 property string layoutModeOverride: "" ///< "split" or "drillIn" to bypass the height check
19 property real userListHeight: -1 ///< Set by dragging the divider, negative uses the height of the list content
20
21 readonly property string layoutMode: layoutModeOverride !== "" ? layoutModeOverride : Logic.layoutMode(height, ScreenTools.defaultFontPixelHeight)
22 readonly property bool inspectorVisible: hasSelection && (layoutMode === "split" || _inspectorOpen)
23 readonly property bool listVisible: layoutMode === "split" || !inspectorVisible
24
25 property bool _inspectorOpen: false
26
27 readonly property real _dividerHeight: Math.max(ScreenTools.defaultFontPixelHeight * 0.8, ScreenTools.isMobile ? ScreenTools.minTouchPixels * 0.5 : 0)
28 readonly property real _minListHeight: ScreenTools.defaultFontPixelHeight * 4
29 readonly property real _minInspectorHeight: ScreenTools.defaultFontPixelHeight * 8
30 readonly property real _splitListHeight: {
31 if (userListHeight >= 0) {
32 return Logic.clampedListHeight(userListHeight, height, _dividerHeight, _minListHeight, _minInspectorHeight)
33 }
34 const contentHeight = listLoader.item ? listLoader.item.contentHeight : 0
35 return Math.min(Math.max(contentHeight, ScreenTools.defaultFontPixelHeight * 6), height * 0.4)
36 }
37
38 function openInspector() {
39 _inspectorOpen = true
40 }
41
42 function closeInspector() {
43 _inspectorOpen = false
44 }
45
46 onHasSelectionChanged: {
47 if (!hasSelection) {
48 closeInspector()
49 }
50 }
51
52 onLayoutModeChanged: {
53 if (layoutMode === "drillIn" && hasSelection && !mainWindow.allowViewSwitch(0, false)) {
54 openInspector()
55 } else {
56 closeInspector()
57 }
58 }
59
60 QGCPalette { id: qgcPal }
61
62 // Extends under the divider so only the top corners show as rounded
63 Rectangle {
64 objectName: "planPanel_listBackground"
65 width: root.width
66 height: listLoader.height + radius
67 radius: ScreenTools.defaultBorderRadius
68 color: qgcPal.windowCard
69 visible: root.layoutMode === "split" && root.inspectorVisible
70 }
71
72 Loader {
73 id: listLoader
74
75 objectName: "planPanel_listLoader"
76 x: 0
77 y: 0
78 width: root.width
79 height: root.layoutMode === "split" ? (root.inspectorVisible ? root._splitListHeight : root.height) : root.height
80 visible: root.listVisible
81 sourceComponent: root.listComponent
82 }
83
84 Connections {
85 target: listLoader.item
86 ignoreUnknownSignals: true
87
88 function onItemActivated() {
89 root.openInspector()
90 }
91 }
92
93 Rectangle {
94 id: divider
95
96 objectName: "planPanel_listInspectorDivider"
97 y: root._splitListHeight
98 width: root.width
99 height: root._dividerHeight
100 color: qgcPal.windowCard
101 visible: root.layoutMode === "split" && root.inspectorVisible
102
103 Rectangle {
104 anchors.top: parent.top
105 width: parent.width
106 height: 1
107 color: qgcPal.borderSubtle
108 }
109
110 Rectangle {
111 anchors.centerIn: parent
112 width: ScreenTools.defaultFontPixelHeight * 2.5
113 height: Math.max(ScreenTools.defaultFontPixelHeight * 0.25, 3)
114 radius: height / 2
115 color: dragArea.pressed ? qgcPal.accent : qgcPal.textSecondary
116 }
117
118 MouseArea {
119 id: dragArea
120
121 property real startY: 0
122 property real startHeight: 0
123
124 anchors.fill: parent
125 cursorShape: Qt.SizeVerCursor
126
127 onPressed: (mouse) => {
128 startY = mapToItem(root, mouse.x, mouse.y).y
129 startHeight = root._splitListHeight
130 }
131
132 onPositionChanged: (mouse) => {
133 if (pressed) {
134 root.userListHeight = Logic.clampedListHeight(startHeight + mapToItem(root, mouse.x, mouse.y).y - startY,
135 root.height, root._dividerHeight, root._minListHeight, root._minInspectorHeight)
136 }
137 }
138
139 onDoubleClicked: root.userListHeight = -1
140 }
141 }
142
143 Loader {
144 id: inspectorLoader
145
146 objectName: "planPanel_inspectorLoader"
147 x: 0
148 y: root.layoutMode === "split" ? root._splitListHeight + root._dividerHeight : 0
149 width: root.width
150 height: root.height - y
151 visible: root.inspectorVisible
152 sourceComponent: root.inspectorComponent
153 }
154
155 Connections {
156 target: inspectorLoader.item
157 ignoreUnknownSignals: true
158
159 function onBackRequested() {
160 if (mainWindow.allowViewSwitch()) {
161 root.closeInspector()
162 }
163 }
164 }
165}