Skip to content

Commit

Permalink
Deal with unreliable Device Pixel Ratio on mobile platforms.
Browse files Browse the repository at this point in the history
  • Loading branch information
dogmaphobic committed Aug 9, 2018
1 parent bac7281 commit 8054795
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 5 deletions.
15 changes: 14 additions & 1 deletion src/QmlControls/ScreenTools.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
40 changes: 36 additions & 4 deletions src/ui/preferences/DebugWindow.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 8054795

Please sign in to comment.