From 2acdf6cf4e07d6d598daebfe3e7d1dfb488ebcb3 Mon Sep 17 00:00:00 2001 From: "Patrick J.P" Date: Wed, 18 Apr 2018 19:36:28 -0300 Subject: [PATCH] FlightDisplayView: Correct windows crash with video popup Signed-off-by: Patrick J.P --- src/FlightDisplay/FlightDisplayView.qml | 63 +++++++++++++++++++------ 1 file changed, 49 insertions(+), 14 deletions(-) diff --git a/src/FlightDisplay/FlightDisplayView.qml b/src/FlightDisplay/FlightDisplayView.qml index 584253356..d363af171 100644 --- a/src/FlightDisplay/FlightDisplayView.qml +++ b/src/FlightDisplay/FlightDisplayView.qml @@ -212,7 +212,23 @@ QGCView { _flightVideo.state = "unpopup" videoWindow.visible = false } + } + /* This timer will startVideo again after the popup window appears and is loaded. + * Such approach was the only one to avoid a crash for windows users + */ + Timer { + id: videoPopUpTimer + interval: 2000; + running: false; + repeat: false + onTriggered: { + // If state is popup, the next one will be popup-finished + if (_flightVideo.state == "popup") { + _flightVideo.state = "popup-finished" + } + QGroundControl.videoManager.startVideo() + } } QGCMapPalette { id: mapPal; lightColors: _mainIsMap ? _flightMap.isSatelliteMap : true } @@ -270,6 +286,20 @@ QGCView { anchors.left: _panel.left anchors.bottom: _panel.bottom visible: QGroundControl.videoManager.hasVideo && (!_mainIsMap || _isPipVisible) + + onParentChanged: { + /* If video comes back from popup + * correct anchors. + * Such thing is not possible with ParentChange. + */ + if(parent == _panel) { + // Do anchors again after popup + anchors.left = _panel.left + anchors.bottom = _panel.bottom + anchors.margins = ScreenTools.defaultFontPixelHeight + } + } + states: [ State { name: "pipMode" @@ -296,36 +326,41 @@ QGCView { State { name: "popup" StateChangeScript { - script: QGroundControl.videoManager.stopVideo() + script: { + // Stop video, restart it again with Timer + // Avoiding crashs if ParentChange is not yet done + QGroundControl.videoManager.stopVideo() + videoPopUpTimer.running = true + } } + PropertyChanges { + target: _flightVideoPipControl + inPopup: true + } + }, + State { + name: "popup-finished" ParentChange { target: _flightVideo parent: videoItem x: 0 y: 0 - width: videoWindow.width - height: videoWindow.height - } - PropertyChanges { - target: _flightVideoPipControl - inPopup: true + width: videoItem.width + height: videoItem.height } }, State { name: "unpopup" StateChangeScript { - script: QGroundControl.videoManager.stopVideo() + script: { + QGroundControl.videoManager.stopVideo() + videoPopUpTimer.running = true + } } ParentChange { target: _flightVideo parent: _panel } - PropertyChanges { - target: _flightVideo - anchors.left: _panel.left - anchors.bottom: _panel.bottom - anchors.margins: ScreenTools.defaultFontPixelHeight - } PropertyChanges { target: _flightVideoPipControl inPopup: false -- 2.22.0