From 8054795511067b9e52cd334f333317b496761de2 Mon Sep 17 00:00:00 2001 From: Gus Grubba Date: Wed, 8 Aug 2018 21:35:43 -0400 Subject: [PATCH] Deal with unreliable Device Pixel Ratio on mobile platforms. --- src/QmlControls/ScreenTools.qml | 15 ++++++++++- src/ui/preferences/DebugWindow.qml | 40 +++++++++++++++++++++++++++--- 2 files changed, 50 insertions(+), 5 deletions(-) diff --git a/src/QmlControls/ScreenTools.qml b/src/QmlControls/ScreenTools.qml index 3faaf0ba4..5d9da6925 100644 --- a/src/QmlControls/ScreenTools.qml +++ b/src/QmlControls/ScreenTools.qml @@ -54,7 +54,20 @@ Item { readonly property real largeFontPointRatio: 1.5 property real realPixelDensity: QGroundControl.corePlugin.options.devicePixelDensity != 0 ? QGroundControl.corePlugin.options.devicePixelDensity : Screen.pixelDensity - property real realPixelRatio: QGroundControl.corePlugin.options.devicePixelRatio != 0 ? QGroundControl.corePlugin.options.devicePixelRatio : (isMobile ? 1 : Screen.devicePixelRatio) + + property real realPixelRatio: { + //-- If a plugin defines it, just use what it tells us + if (QGroundControl.corePlugin.options.devicePixelRatio != 0) + return QGroundControl.corePlugin.options.devicePixelRatio + //-- Mobile is rather unreliable. They all return 1 for Screen.devicePixelRatio. + if(isMobile) { + // Lets assume it's unlikely you have a tablet over 300mm wide + if((Screen.width / Screen.pixelDensity * Screen.devicePixelRatio) > 300) + return 2 + } + //-- Use whatever the system tells us + return Screen.devicePixelRatio + } property bool isAndroid: ScreenToolsController.isAndroid property bool isiOS: ScreenToolsController.isiOS diff --git a/src/ui/preferences/DebugWindow.qml b/src/ui/preferences/DebugWindow.qml index c070de810..8ffe9b4fa 100644 --- a/src/ui/preferences/DebugWindow.qml +++ b/src/ui/preferences/DebugWindow.qml @@ -160,13 +160,13 @@ QGCView { font.family: ScreenTools.normalFontFamily } Text { - text: Screen.pixelDensity.toFixed(4) - color: qgcPal.text + text: Screen.pixelDensity.toFixed(4) + color: qgcPal.text font.family: ScreenTools.normalFontFamily } Text { - text: qsTr("Font Point Size 13.5") - color: qgcPal.text + text: qsTr("Font Point Size 13.5") + color: qgcPal.text font.pointSize: 13.5 font.family: ScreenTools.normalFontFamily } @@ -218,6 +218,38 @@ QGCView { font.pointSize: 15 font.family: ScreenTools.normalFontFamily } + Text { + text: qsTr("Computed Screen Height:") + color: qgcPal.text + font.family: ScreenTools.normalFontFamily + } + Text { + text: (Screen.height / Screen.pixelDensity * Screen.devicePixelRatio).toFixed(0) + color: qgcPal.text + font.family: ScreenTools.normalFontFamily + } + Text { + text: qsTr("Font Point Size 15.5") + color: qgcPal.text + font.pointSize: 15.5 + font.family: ScreenTools.normalFontFamily + } + Text { + text: qsTr("Computed Screen Width:") + color: qgcPal.text + font.family: ScreenTools.normalFontFamily + } + Text { + text: (Screen.width / Screen.pixelDensity * Screen.devicePixelRatio).toFixed(0) + color: qgcPal.text + font.family: ScreenTools.normalFontFamily + } + Text { + text: qsTr("Font Point Size 16") + color: qgcPal.text + font.pointSize: 16 + font.family: ScreenTools.normalFontFamily + } } Rectangle { -- 2.22.0