10 The ScreenTools Singleton provides information on QGC's standard font metrics. It also provides information on screen
11 size which can be used to adjust user interface for varying available screen real estate.
13 QGC has four standard font sizes: default, small, medium and large. The QGC controls use the default font for display and you should use this font
14 for most text within the system that is drawn using something other than a standard QGC control. The small font is smaller than the default font.
15 The medium and large fonts are larger than the default font.
19 import QGroundControl.Controls
22 anchors.margins: ScreenTools.defaultFontPixelWidth
29 //-- The point and pixel font size values are computed at runtime
31 property real defaultFontPointSize: 10
32 property real platformFontPointSize: 10
34 readonly property real smallFontPointRatio: 0.75
35 readonly property real mediumFontPointRatio: 1.25
36 readonly property real largeFontPointRatio: 1.5
38 /// You can use these properties to position ui elements in a screen resolution independent manner. Using fixed positioning values should not
39 /// be done. All positioning should be done using anchors or a ratio of the defaultFontPixelHeight and defaultFontPixelWidth values. This way
40 /// your ui elements will reposition themselves appropriately on varying screen sizes and resolutions.
41 property real defaultFontPixelHeight: 10
42 property real largeFontPixelHeight: defaultFontPixelHeight * largeFontPointRatio
43 property real mediumFontPixelHeight: defaultFontPixelHeight * mediumFontPointRatio
44 property real smallFontPixelHeight: defaultFontPixelHeight * smallFontPointRatio
46 /// You can use these properties to position ui elements in a screen resolution independent manner. Using fixed positioning values should not
47 /// be done. All positioning should be done using anchors or a ratio of the defaultFontPixelHeight and defaultFontPixelWidth values. This way
48 /// your ui elements will reposition themselves appropriately on varying screen sizes and resolutions.
49 property real defaultFontPixelWidth: 10
50 property real largeFontPixelWidth: defaultFontPixelWidth * largeFontPointRatio
51 property real mediumFontPixelWidth: defaultFontPixelWidth * mediumFontPointRatio
52 property real smallFontPixelWidth: defaultFontPixelWidth * smallFontPointRatio
54 /// QFontMetrics::descent for default font at default point size
55 property real defaultFontDescent: 0
57 /// The default amount of space in between controls in a dialog
58 property real defaultDialogControlSpacing: defaultFontPixelHeight / 2
60 property real smallFontPointSize: 10
61 property real mediumFontPointSize: 10
62 property real largeFontPointSize: 10
64 property real toolbarHeight: 0
66 property real realPixelDensity: {
67 //-- If a plugin defines it, just use what it tells us
68 if(QGroundControl.corePlugin.options.devicePixelDensity != 0) {
69 return QGroundControl.corePlugin.options.devicePixelDensity
71 //-- Android is rather unreliable
73 // Lets assume it's unlikely you have a tablet over 300mm wide
74 if((Screen.width / Screen.pixelDensity) > 300) {
75 return Screen.pixelDensity * 2
78 //-- Let's use what the system tells us
79 return Screen.pixelDensity
82 // These properties allow us to create simulated mobile sizing for a desktop build.
83 // This makes testing the UI for smaller mobile sizing much easier.
84 // The 731x411 size is the size of the Herelink screen which is our target lower bound
85 property real screenWidth: ScreenToolsController.fakeMobile ? 731 : Screen.width
86 property real screenHeight: ScreenToolsController.fakeMobile ? 411 : Screen.height
88 property bool isAndroid: ScreenToolsController.isAndroid
89 property bool isiOS: ScreenToolsController.isiOS
90 property bool isMobile: ScreenToolsController.isMobile
91 property bool isFakeMobile: ScreenToolsController.fakeMobile
92 property bool isWindows: ScreenToolsController.isWindows
93 property bool isDebug: ScreenToolsController.isDebug
94 property bool isMac: ScreenToolsController.isMacOS
95 property bool isLinux: ScreenToolsController.isLinux
96 property bool isTinyScreen: (Screen.width / realPixelDensity) < 120 // 120mm
97 property bool isShortScreen: ((Screen.height / realPixelDensity) < 120) || (ScreenToolsController.isMobile && ((Screen.height / Screen.width) < 0.6))
98 property bool isHugeScreen: (Screen.width / realPixelDensity) >= (23.5 * 25.4) // 27" monitor
99 property bool isSerialAvailable: ScreenToolsController.isSerialAvailable
101 readonly property real minTouchMillimeters: 5 ///< Minimum touch size in millimeters
102 property real minTouchPixels: 0 ///< Minimum touch size in pixels (calculatedd from minTouchMillimeters and realPixelDensity)
104 // The implicit heights/widths for our custom control set
105 property real implicitButtonWidth: Math.round(defaultFontPixelWidth * 5.0)
106 property real implicitButtonHeight: Math.round(defaultFontPixelHeight * 1.6)
107 property real implicitCheckBoxHeight: Math.round(defaultFontPixelHeight * 1.0)
108 property real implicitRadioButtonHeight: implicitCheckBoxHeight
109 property real implicitTextFieldWidth: defaultFontPixelWidth * 10
110 property real implicitTextFieldHeight: implicitButtonHeight
111 property real implicitComboBoxHeight: implicitButtonHeight
112 property real implicitComboBoxWidth: implicitButtonWidth
113 property real comboBoxPadding: defaultFontPixelWidth
114 property real controlVerticalPadding: Math.round(defaultFontPixelHeight * 0.3)
115 property real implicitSliderHeight: defaultFontPixelHeight
116 property real defaultBorderRadius: defaultFontPixelWidth / 2
118 // It's not possible to centralize an even number of pixels, checkBoxIndicatorSize should be an odd number to allow centralization
119 property real checkBoxIndicatorSize: 2 * Math.floor(defaultFontPixelHeight / 2) + 1
120 property real radioButtonIndicatorSize: checkBoxIndicatorSize
122 readonly property string normalFontFamily: ScreenToolsController.normalFontFamily
123 readonly property string fixedFontFamily: ScreenToolsController.fixedFontFamily
124 /* This mostly works but for some reason, reflowWidths() in SetupView doesn't change size.
125 I've disabled (in release builds) until I figure out why. Changes require a restart for now.
128 target: QGroundControl.settingsManager.appSettings.uiScalePercent
129 function onValueChanged() {
130 var pct = QGroundControl.settingsManager.appSettings.uiScalePercent.value
131 _setBasePointSize(platformFontPointSize * pct / 100)
135 onRealPixelDensityChanged: {
136 _setBasePointSize(defaultFontPointSize)
139 function printScreenStats() {
140 console.log('ScreenTools: Screen.width: ' + Screen.width + ' Screen.height: ' + Screen.height + ' Screen.pixelDensity: ' + Screen.pixelDensity)
143 /// Returns the current x position of the mouse in global screen coordinates.
145 return ScreenToolsController.mouseX()
148 /// Returns the current y position of the mouse in global screen coordinates.
150 return ScreenToolsController.mouseY()
154 function _setBasePointSize(pointSize) {
155 _textMeasure.font.pointSize = pointSize
156 defaultFontPointSize = pointSize
157 defaultFontPixelHeight = Math.round(_textMeasure.fontHeight/2.0)*2
158 defaultFontPixelWidth = Math.round(_textMeasure.fontWidth/2.0)*2
159 defaultFontDescent = ScreenToolsController.defaultFontDescent(defaultFontPointSize)
160 smallFontPointSize = defaultFontPointSize * _screenTools.smallFontPointRatio
161 mediumFontPointSize = defaultFontPointSize * _screenTools.mediumFontPointRatio
162 largeFontPointSize = defaultFontPointSize * _screenTools.largeFontPointRatio
163 minTouchPixels = Math.round(minTouchMillimeters * realPixelDensity)
164 if (minTouchPixels / Screen.height > 0.15) {
165 // If using physical sizing takes up too much of the vertical real estate fall back to font based sizing
166 minTouchPixels = defaultFontPixelHeight * 3
168 toolbarHeight = defaultFontPixelHeight * 3
169 toolbarHeight = toolbarHeight * QGroundControl.corePlugin.options.toolbarHeightMultiplier
180 font.family: normalFontFamily
181 property real fontWidth: contentWidth
182 property real fontHeight: contentHeight
183 Component.onCompleted: {
184 //-- First, compute platform, default size
185 if(ScreenToolsController.isMobile) {
186 //-- Check iOS really tiny screens (iPhone 4s/5/5s)
187 if(ScreenToolsController.isiOS) {
188 if(ScreenToolsController.isiOS && Screen.width < 570) {
189 // For iPhone 4s size we don't fit with additional tweaks to fit screen,
190 // we will just drop point size to make things fit. Correct size not yet determined.
191 platformFontPointSize = 12; // This will be lowered in a future pull
193 platformFontPointSize = 14;
195 } else if((Screen.width / realPixelDensity) < 120) {
196 platformFontPointSize = 11;
199 platformFontPointSize = 14;
202 platformFontPointSize = _defaultFont.font.pointSize;
204 //-- See if we are using a custom size
205 var _uiScalePercentFact = QGroundControl.settingsManager.appSettings.uiScalePercent
206 var pct = _uiScalePercentFact.value
208 if(pct < _uiScalePercentFact.min || pct > _uiScalePercentFact.max) {
210 _uiScalePercentFact.value = pct
212 //-- Set size saved in settings
213 _screenTools._setBasePointSize(platformFontPointSize * pct / 100);