QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
PipView.qml
Go to the documentation of this file.
1import QtQuick
2import QtQuick.Window
3
4import QGroundControl
5import QGroundControl.Controls
6
7Item {
8 id: _root
9 width: _pipSize
10 height: _pipSize * (9/16)
11 visible: item2 && item2.pipState !== item2.pipState.window && show
12
13 property var item1: null // Required
14 property var item2: null // Optional, may come and go
15 property string item1IsFullSettingsKey // Settings key to save whether item1 was saved in full mode
16 property bool show: true
17
18 readonly property string _pipExpandedSettingsKey: "IsPIPVisible"
19
20 property var _fullItem
21 property var _pipOrWindowItem
22 property alias _windowContentItem: window.contentItem
23 property alias _pipContentItem: pipContent
24 property bool _isExpanded: true
25 property real _pipSize: parent.width * 0.2
26 property real _maxSize: 0.75 // Percentage of parent control size
27 property real _minSize: 0.10
28 property bool _componentComplete: false
29
30 Component.onCompleted: {
31 _initForItems()
32 _componentComplete = true
33 }
34
35 onItem2Changed: _initForItems()
36
37 function showWindow() {
38 window.width = _root.width
39 window.height = _root.height
40 window.show()
41 }
42
43 function _initForItems() {
44 var item1IsFull = QGroundControl.loadBoolGlobalSetting(item1IsFullSettingsKey, true)
45 if (item1 && item2) {
46 item1.pipState.state = item1IsFull ? item1.pipState.fullState : item1.pipState.pipState
47 item2.pipState.state = item1IsFull ? item2.pipState.pipState : item2.pipState.fullState
48 _fullItem = item1IsFull ? item1 : item2
49 _pipOrWindowItem = item1IsFull ? item2 : item1
50 } else {
51 item1.pipState.state = item1.pipState.fullState
52 _fullItem = item1
53 _pipOrWindowItem = null
54 }
55 _setPipIsExpanded(QGroundControl.loadBoolGlobalSetting(_pipExpandedSettingsKey, true))
56 }
57
58 function _swapPip() {
59 var item1IsFull = false
60 if (item1.pipState.state === item1.pipState.fullState) {
61 item1.pipState.state = item1.pipState.pipState
62 item2.pipState.state = item2.pipState.fullState
63 _fullItem = item2
64 _pipOrWindowItem = item1
65 item1IsFull = false
66 } else {
67 item1.pipState.state = item1.pipState.fullState
68 item2.pipState.state = item2.pipState.pipState
69 _fullItem = item1
70 _pipOrWindowItem = item2
71 item1IsFull = true
72 }
73 QGroundControl.saveBoolGlobalSetting(item1IsFullSettingsKey, item1IsFull)
74 }
75
76 function _setPipIsExpanded(isExpanded) {
77 QGroundControl.saveBoolGlobalSetting(_pipExpandedSettingsKey, isExpanded)
78 _isExpanded = isExpanded
79 }
80
81 Window {
82 id: window
83 visible: false
84 onClosing: {
85 var item = contentItem.children[0]
86 if (item) {
87 item.pipState.windowAboutToClose()
88 item.pipState.state = item.pipState.pipState
89 }
90 }
91 }
92
93 Item {
94 id: pipContent
95 anchors.fill: parent
96 visible: _isExpanded
97 clip: true
98 }
99
100 MouseArea {
101 id: pipMouseArea
102 anchors.fill: parent
103 enabled: _isExpanded
104 preventStealing: true
105 hoverEnabled: true
106 onClicked: _swapPip()
107 }
108
109 // MouseArea to drag in order to resize the PiP area
110 MouseArea {
111 id: pipResize
112 anchors.fill: pipResizeIcon
113 preventStealing: true
114 cursorShape: Qt.PointingHandCursor
115
116 property real initialX: 0
117 property real initialWidth: 0
118
119 onPressed: (mouse) => {
120 // Remove the anchor so the our mouse coordinates stay in the same original place for drag tracking
121 pipResize.anchors.fill = undefined
122 pipResize.initialX = mouse.x
123 pipResize.initialWidth = _root.width
124 }
125
126 onReleased: pipResize.anchors.fill = pipResizeIcon
127
128 // Drag
129 onPositionChanged: (mouse) => {
130 if (pipResize.pressed) {
131 var parentWidth = _root.parent.width
132 var newWidth = pipResize.initialWidth + mouse.x - pipResize.initialX
133 if (newWidth < parentWidth * _maxSize && newWidth > parentWidth * _minSize) {
134 _pipSize = newWidth
135 }
136 }
137 }
138 }
139
140 // Resize icon
141 Image {
142 id: pipResizeIcon
143 source: "/qmlimages/pipResize.svg"
144 fillMode: Image.PreserveAspectFit
145 mipmap: true
146 anchors.right: parent.right
147 anchors.top: parent.top
148 visible: _isExpanded && (ScreenTools.isMobile || pipMouseArea.containsMouse)
149 height: ScreenTools.defaultFontPixelHeight * 2.5
150 width: ScreenTools.defaultFontPixelHeight * 2.5
151 sourceSize.height: height
152 }
153
154 // Check min/max constraints on pip size when when parent is resized
155 Connections {
156 target: _root.parent
157
158 function onWidthChanged() {
159 if (!_componentComplete) {
160 // Wait until first time setup is done
161 return
162 }
163 var parentWidth = _root.parent.width
164 if (_root.width > parentWidth * _maxSize) {
165 _pipSize = parentWidth * _maxSize
166 } else if (_root.width < parentWidth * _minSize) {
167 _pipSize = parentWidth * _minSize
168 }
169 }
170 }
171
172 // Pip to Window
173 Image {
174 id: popupPIP
175 source: "/qmlimages/PiP.svg"
176 mipmap: true
177 fillMode: Image.PreserveAspectFit
178 anchors.left: parent.left
179 anchors.top: parent.top
180 visible: _isExpanded && !ScreenTools.isMobile && pipMouseArea.containsMouse
181 height: ScreenTools.defaultFontPixelHeight * 2.5
182 width: ScreenTools.defaultFontPixelHeight * 2.5
183 sourceSize.height: height
184
185 MouseArea {
186 anchors.fill: parent
187 onClicked: _pipOrWindowItem.pipState.state = _pipOrWindowItem.pipState.windowState
188 }
189 }
190
191 Image {
192 id: hidePIP
193 source: "/qmlimages/pipHide.svg"
194 mipmap: true
195 fillMode: Image.PreserveAspectFit
196 anchors.left: parent.left
197 anchors.bottom: parent.bottom
198 visible: _isExpanded && (ScreenTools.isMobile || pipMouseArea.containsMouse)
199 height: ScreenTools.defaultFontPixelHeight * 2.5
200 width: ScreenTools.defaultFontPixelHeight * 2.5
201 sourceSize.height: height
202 MouseArea {
203 anchors.fill: parent
204 onClicked: _root._setPipIsExpanded(false)
205 }
206 }
207
208 Rectangle {
209 id: showPip
210 anchors.left : parent.left
211 anchors.bottom: parent.bottom
212 height: ScreenTools.defaultFontPixelHeight * 2
213 width: ScreenTools.defaultFontPixelHeight * 2
214 radius: ScreenTools.defaultFontPixelHeight / 3
215 visible: !_isExpanded
216 color: _fullItem.pipState.isDark ? Qt.rgba(0,0,0,0.75) : Qt.rgba(0,0,0,0.5)
217 Image {
218 width: parent.width * 0.75
219 height: parent.height * 0.75
220 sourceSize.height: height
221 source: "/res/buttonRight.svg"
222 mipmap: true
223 fillMode: Image.PreserveAspectFit
224 anchors.verticalCenter: parent.verticalCenter
225 anchors.horizontalCenter: parent.horizontalCenter
226 }
227 MouseArea {
228 anchors.fill: parent
229 onClicked: _root._setPipIsExpanded(true)
230 }
231 }
232}