From 890833b302a2f69f6122bcb1617114cd2de746d4 Mon Sep 17 00:00:00 2001 From: DoinLakeFlyer Date: Fri, 10 Apr 2020 14:47:03 -0700 Subject: [PATCH] Add support for ScreenTools.defaultFontDescent --- src/QmlControls/ScreenTools.qml | 8 ++++++-- src/QmlControls/ScreenToolsController.cc | 5 +++++ src/QmlControls/ScreenToolsController.h | 14 ++++++++------ 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/QmlControls/ScreenTools.qml b/src/QmlControls/ScreenTools.qml index d45108a2a..5cc595835 100644 --- a/src/QmlControls/ScreenTools.qml +++ b/src/QmlControls/ScreenTools.qml @@ -1,8 +1,8 @@ pragma Singleton -import QtQuick 2.3 +import QtQuick 2.12 import QtQuick.Controls 1.2 -import QtQuick.Window 2.2 +import QtQuick.Window 2.2 import QGroundControl 1.0 import QGroundControl.ScreenToolsController 1.0 @@ -43,6 +43,9 @@ Item { /// your ui elements will reposition themselves appropriately on varying screen sizes and resolutions. property real defaultFontPixelWidth: 10 + /// QFontMetrics::descent for default font at default point size + property real defaultFontDescent: 0 + property real smallFontPointSize: 10 property real mediumFontPointSize: 10 property real largeFontPointSize: 10 @@ -134,6 +137,7 @@ Item { defaultFontPointSize = pointSize defaultFontPixelHeight = Math.round(_textMeasure.fontHeight/2.0)*2 defaultFontPixelWidth = Math.round(_textMeasure.fontWidth/2.0)*2 + defaultFontDescent = ScreenToolsController.defaultFontDescent(defaultFontPointSize) smallFontPointSize = defaultFontPointSize * _screenTools.smallFontPointRatio mediumFontPointSize = defaultFontPointSize * _screenTools.mediumFontPointRatio largeFontPointSize = defaultFontPointSize * _screenTools.largeFontPointRatio diff --git a/src/QmlControls/ScreenToolsController.cc b/src/QmlControls/ScreenToolsController.cc index f7ac82045..c2fcbcbf3 100644 --- a/src/QmlControls/ScreenToolsController.cc +++ b/src/QmlControls/ScreenToolsController.cc @@ -73,3 +73,8 @@ ScreenToolsController::boldFontFamily() const return QString("opensans-demibold"); } } + +double ScreenToolsController::defaultFontDescent(int pointSize) const +{ + return QFontMetrics(QFont(normalFontFamily(), pointSize)).descent(); +} diff --git a/src/QmlControls/ScreenToolsController.h b/src/QmlControls/ScreenToolsController.h index 71be0f273..24f873e99 100644 --- a/src/QmlControls/ScreenToolsController.h +++ b/src/QmlControls/ScreenToolsController.h @@ -47,6 +47,9 @@ public: Q_INVOKABLE int mouseX(void) { return QCursor::pos().x(); } Q_INVOKABLE int mouseY(void) { return QCursor::pos().y(); } + // QFontMetrics::descent for default font + Q_INVOKABLE double defaultFontDescent(int pointSize) const; + #if defined(__mobile__) bool isMobile () const { return true; } #else @@ -103,12 +106,11 @@ public: bool isDebug () { return false; } #endif - bool hasTouch() const; - - QString iOSDevice () const; - QString fixedFontFamily () const; - QString normalFontFamily () const; - QString boldFontFamily () const; + bool hasTouch () const; + QString iOSDevice () const; + QString fixedFontFamily () const; + QString normalFontFamily () const; + QString boldFontFamily () const; }; #endif -- 2.22.0