diff --git a/src/QmlControls/ScreenTools.qml b/src/QmlControls/ScreenTools.qml index d45108a..5cc5958 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 f7ac820..c2fcbcb 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 71be0f2..24f873e 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