Browse Source

Add support for ScreenTools.defaultFontDescent

QGC4.4
DoinLakeFlyer 5 years ago
parent
commit
890833b302
  1. 8
      src/QmlControls/ScreenTools.qml
  2. 5
      src/QmlControls/ScreenToolsController.cc
  3. 14
      src/QmlControls/ScreenToolsController.h

8
src/QmlControls/ScreenTools.qml

@ -1,8 +1,8 @@
pragma Singleton pragma Singleton
import QtQuick 2.3 import QtQuick 2.12
import QtQuick.Controls 1.2 import QtQuick.Controls 1.2
import QtQuick.Window 2.2 import QtQuick.Window 2.2
import QGroundControl 1.0 import QGroundControl 1.0
import QGroundControl.ScreenToolsController 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. /// your ui elements will reposition themselves appropriately on varying screen sizes and resolutions.
property real defaultFontPixelWidth: 10 property real defaultFontPixelWidth: 10
/// QFontMetrics::descent for default font at default point size
property real defaultFontDescent: 0
property real smallFontPointSize: 10 property real smallFontPointSize: 10
property real mediumFontPointSize: 10 property real mediumFontPointSize: 10
property real largeFontPointSize: 10 property real largeFontPointSize: 10
@ -134,6 +137,7 @@ Item {
defaultFontPointSize = pointSize defaultFontPointSize = pointSize
defaultFontPixelHeight = Math.round(_textMeasure.fontHeight/2.0)*2 defaultFontPixelHeight = Math.round(_textMeasure.fontHeight/2.0)*2
defaultFontPixelWidth = Math.round(_textMeasure.fontWidth/2.0)*2 defaultFontPixelWidth = Math.round(_textMeasure.fontWidth/2.0)*2
defaultFontDescent = ScreenToolsController.defaultFontDescent(defaultFontPointSize)
smallFontPointSize = defaultFontPointSize * _screenTools.smallFontPointRatio smallFontPointSize = defaultFontPointSize * _screenTools.smallFontPointRatio
mediumFontPointSize = defaultFontPointSize * _screenTools.mediumFontPointRatio mediumFontPointSize = defaultFontPointSize * _screenTools.mediumFontPointRatio
largeFontPointSize = defaultFontPointSize * _screenTools.largeFontPointRatio largeFontPointSize = defaultFontPointSize * _screenTools.largeFontPointRatio

5
src/QmlControls/ScreenToolsController.cc

@ -73,3 +73,8 @@ ScreenToolsController::boldFontFamily() const
return QString("opensans-demibold"); return QString("opensans-demibold");
} }
} }
double ScreenToolsController::defaultFontDescent(int pointSize) const
{
return QFontMetrics(QFont(normalFontFamily(), pointSize)).descent();
}

14
src/QmlControls/ScreenToolsController.h

@ -47,6 +47,9 @@ public:
Q_INVOKABLE int mouseX(void) { return QCursor::pos().x(); } Q_INVOKABLE int mouseX(void) { return QCursor::pos().x(); }
Q_INVOKABLE int mouseY(void) { return QCursor::pos().y(); } Q_INVOKABLE int mouseY(void) { return QCursor::pos().y(); }
// QFontMetrics::descent for default font
Q_INVOKABLE double defaultFontDescent(int pointSize) const;
#if defined(__mobile__) #if defined(__mobile__)
bool isMobile () const { return true; } bool isMobile () const { return true; }
#else #else
@ -103,12 +106,11 @@ public:
bool isDebug () { return false; } bool isDebug () { return false; }
#endif #endif
bool hasTouch() const; bool hasTouch () const;
QString iOSDevice () const;
QString iOSDevice () const; QString fixedFontFamily () const;
QString fixedFontFamily () const; QString normalFontFamily () const;
QString normalFontFamily () const; QString boldFontFamily () const;
QString boldFontFamily () const;
}; };
#endif #endif

Loading…
Cancel
Save