From 5b0909315ef7dbf49903769bd8cfa43aaee58755 Mon Sep 17 00:00:00 2001 From: Sam Gillam Date: Fri, 25 Oct 2024 10:41:50 -0600 Subject: [PATCH] Update video fit options The pre-existing "Stretch" option would not fill the screen as expected. The grid lines were also not accurately placed over the video for the "Stretch" option. "Stretch" is also not a great word to use because it hints the video may be transformed in a way were its aspectRatio is different from the original, which is not the case. This commit renames "Stretch" to "Fit" and fixes it so the video fills the screen when in that mode. A new mode was also added called "No Crop" which makes so the entire video is shown (no part of video goes past the bounds of the border of the screen, as would be the case in the other 3 video fit modes if the video width/height aspect ratio does not match the QGC app window width/height aspect ratio --- src/FlightDisplay/FlightDisplayViewVideo.qml | 39 +++++++++++++++----- src/Settings/Video.SettingsGroup.json | 4 +- 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/src/FlightDisplay/FlightDisplayViewVideo.qml b/src/FlightDisplay/FlightDisplayViewVideo.qml index 66701676606..2b998bcedf3 100644 --- a/src/FlightDisplay/FlightDisplayViewVideo.qml +++ b/src/FlightDisplay/FlightDisplayViewVideo.qml @@ -38,6 +38,11 @@ Item { property bool _hasZoom: _camera && _camera.hasZoom property int _fitMode: QGroundControl.settingsManager.videoSettings.videoFit.rawValue + property bool _isMode_FIT_WIDTH: _fitMode === 0 + property bool _isMode_FIT_HEIGHT: _fitMode === 1 + property bool _isMode_FILL: _fitMode === 2 + property bool _isMode_NO_CROP: _fitMode === 3 + function getWidth() { return videoBackground.getWidth() } @@ -79,20 +84,34 @@ Item { color: "black" visible: QGroundControl.videoManager.decoding function getWidth() { - //-- Fit Width or Stretch - if(_fitMode === 0 || _fitMode === 2) { - return parent.width + if(_ar != 0.0){ + if(_isMode_FIT_HEIGHT + || (_isMode_FILL && (root.width/root.height < _ar)) + || (_isMode_NO_CROP && (root.width/root.height > _ar))){ + // This return value has different implications depending on the mode + // For FIT_HEIGHT and FILL + // makes so the video width will be larger than (or equal to) the screen width + // For NO_CROP Mode + // makes so the video width will be smaller than (or equal to) the screen width + return root.height * _ar + } } - //-- Fit Height - return _ar != 0.0 ? parent.height * _ar : parent.width + return root.width } function getHeight() { - //-- Fit Height or Stretch - if(_fitMode === 1 || _fitMode === 2) { - return parent.height + if(_ar != 0.0){ + if(_isMode_FIT_WIDTH + || (_isMode_FILL && (root.width/root.height > _ar)) + || (_isMode_NO_CROP && (root.width/root.height < _ar))){ + // This return value has different implications depending on the mode + // For FIT_WIDTH and FILL + // makes so the video height will be larger than (or equal to) the screen height + // For NO_CROP Mode + // makes so the video height will be smaller than (or equal to) the screen height + return root.width * (1 / _ar) + } } - //-- Fit Width - return _ar != 0.0 ? parent.width * (1 / _ar) : parent.height + return root.height } Component { id: videoBackgroundComponent diff --git a/src/Settings/Video.SettingsGroup.json b/src/Settings/Video.SettingsGroup.json index f1a4b994ce3..b3400c67b9b 100644 --- a/src/Settings/Video.SettingsGroup.json +++ b/src/Settings/Video.SettingsGroup.json @@ -59,8 +59,8 @@ "shortDesc": "Video Display Fit", "longDesc": "Handle Video Aspect Ratio.", "type": "uint32", - "enumStrings": "Fit Width,Fit Height,Stretch", - "enumValues": "0,1,2", + "enumStrings": "Fit Width,Fit Height,Fill,No Crop", + "enumValues": "0,1,2,3", "default": 1 }, {