5import QGroundControl.Controls
10 height: _pipSize * (9/16)
11 visible: item2 && item2.pipState !== item2.pipState.window && show
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
18 readonly property string _pipExpandedSettingsKey: "IsPIPVisible"
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
30 Component.onCompleted: {
32 _componentComplete = true
35 onItem2Changed: _initForItems()
37 function showWindow() {
38 window.width = _root.width
39 window.height = _root.height
43 function _initForItems() {
44 var item1IsFull = QGroundControl.loadBoolGlobalSetting(item1IsFullSettingsKey, true)
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
51 item1.pipState.state = item1.pipState.fullState
53 _pipOrWindowItem = null
55 _setPipIsExpanded(QGroundControl.loadBoolGlobalSetting(_pipExpandedSettingsKey, true))
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
64 _pipOrWindowItem = item1
67 item1.pipState.state = item1.pipState.fullState
68 item2.pipState.state = item2.pipState.pipState
70 _pipOrWindowItem = item2
73 QGroundControl.saveBoolGlobalSetting(item1IsFullSettingsKey, item1IsFull)
76 function _setPipIsExpanded(isExpanded) {
77 QGroundControl.saveBoolGlobalSetting(_pipExpandedSettingsKey, isExpanded)
78 _isExpanded = isExpanded
85 var item = contentItem.children[0]
87 item.pipState.windowAboutToClose()
88 item.pipState.state = item.pipState.pipState
104 preventStealing: true
106 onClicked: _swapPip()
109 // MouseArea to drag in order to resize the PiP area
112 anchors.fill: pipResizeIcon
113 preventStealing: true
114 cursorShape: Qt.PointingHandCursor
116 property real initialX: 0
117 property real initialWidth: 0
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
126 onReleased: pipResize.anchors.fill = pipResizeIcon
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) {
143 source: "/qmlimages/pipResize.svg"
144 fillMode: Image.PreserveAspectFit
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
154 // Check min/max constraints on pip size when when parent is resized
158 function onWidthChanged() {
159 if (!_componentComplete) {
160 // Wait until first time setup is done
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
175 source: "/qmlimages/PiP.svg"
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
187 onClicked: _pipOrWindowItem.pipState.state = _pipOrWindowItem.pipState.windowState
193 source: "/qmlimages/pipHide.svg"
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
204 onClicked: _root._setPipIsExpanded(false)
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)
218 width: parent.width * 0.75
219 height: parent.height * 0.75
220 sourceSize.height: height
221 source: "/res/buttonRight.svg"
223 fillMode: Image.PreserveAspectFit
224 anchors.verticalCenter: parent.verticalCenter
225 anchors.horizontalCenter: parent.horizontalCenter
229 onClicked: _root._setPipIsExpanded(true)