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 implicitSliderHeight: defaultFontPixelHeight
115 property real defaultBorderRadius: defaultFontPixelWidth / 2
117 // It's not possible to centralize an even number of pixels, checkBoxIndicatorSize should be an odd number to allow centralization
118 property real checkBoxIndicatorSize: 2 * Math.floor(defaultFontPixelHeight / 2) + 1
119 property real radioButtonIndicatorSize: checkBoxIndicatorSize
121 readonly property string normalFontFamily: ScreenToolsController.normalFontFamily
122 readonly property string fixedFontFamily: ScreenToolsController.fixedFontFamily
123 /* This mostly works but for some reason, reflowWidths() in SetupView doesn't change size.
124 I've disabled (in release builds) until I figure out why. Changes require a restart for now.
127 target: QGroundControl.settingsManager.appSettings.appFontPointSize
128 function onValueChanged() {
129 _setBasePointSize(QGroundControl.settingsManager.appSettings.appFontPointSize.value)
133 onRealPixelDensityChanged: {
134 _setBasePointSize(defaultFontPointSize)
137 function printScreenStats() {
138 console.log('ScreenTools: Screen.width: ' + Screen.width + ' Screen.height: ' + Screen.height + ' Screen.pixelDensity: ' + Screen.pixelDensity)
141 /// Returns the current x position of the mouse in global screen coordinates.
143 return ScreenToolsController.mouseX()
146 /// Returns the current y position of the mouse in global screen coordinates.
148 return ScreenToolsController.mouseY()
152 function _setBasePointSize(pointSize) {
153 _textMeasure.font.pointSize = pointSize
154 defaultFontPointSize = pointSize
155 defaultFontPixelHeight = Math.round(_textMeasure.fontHeight/2.0)*2
156 defaultFontPixelWidth = Math.round(_textMeasure.fontWidth/2.0)*2
157 defaultFontDescent = ScreenToolsController.defaultFontDescent(defaultFontPointSize)
158 smallFontPointSize = defaultFontPointSize * _screenTools.smallFontPointRatio
159 mediumFontPointSize = defaultFontPointSize * _screenTools.mediumFontPointRatio
160 largeFontPointSize = defaultFontPointSize * _screenTools.largeFontPointRatio
161 minTouchPixels = Math.round(minTouchMillimeters * realPixelDensity)
162 if (minTouchPixels / Screen.height > 0.15) {
163 // If using physical sizing takes up too much of the vertical real estate fall back to font based sizing
164 minTouchPixels = defaultFontPixelHeight * 3
166 toolbarHeight = defaultFontPixelHeight * 3
167 toolbarHeight = toolbarHeight * QGroundControl.corePlugin.options.toolbarHeightMultiplier
178 font.family: normalFontFamily
179 property real fontWidth: contentWidth
180 property real fontHeight: contentHeight
181 Component.onCompleted: {
182 //-- First, compute platform, default size
183 if(ScreenToolsController.isMobile) {
184 //-- Check iOS really tiny screens (iPhone 4s/5/5s)
185 if(ScreenToolsController.isiOS) {
186 if(ScreenToolsController.isiOS && Screen.width < 570) {
187 // For iPhone 4s size we don't fit with additional tweaks to fit screen,
188 // we will just drop point size to make things fit. Correct size not yet determined.
189 platformFontPointSize = 12; // This will be lowered in a future pull
191 platformFontPointSize = 14;
193 } else if((Screen.width / realPixelDensity) < 120) {
194 platformFontPointSize = 11;
197 platformFontPointSize = 14;
200 platformFontPointSize = _defaultFont.font.pointSize;
202 //-- See if we are using a custom size
203 var _appFontPointSizeFact = QGroundControl.settingsManager.appSettings.appFontPointSize
204 var baseSize = _appFontPointSizeFact.value
206 if(baseSize < _appFontPointSizeFact.min || baseSize > _appFontPointSizeFact.max) {
207 baseSize = platformFontPointSize;
208 _appFontPointSizeFact.value = baseSize
210 //-- Set size saved in settings
211 _screenTools._setBasePointSize(baseSize);