forked from qt-creator/qt-creator
Utils: Introduce StyleHelper::uiFontLineHeight
The "Text tokens" which are defined in Figma have an additional line height value. This change adds a getter function for the line heights. Change-Id: I9513ac2f689292baf6e2c0a52fca8a1ec7f14dc1 Reviewed-by: Cristian Adam <cristian.adam@qt.io>
This commit is contained in:
@@ -1002,6 +1002,14 @@ QFont StyleHelper::uiFont(UiElement element)
|
||||
return font;
|
||||
}
|
||||
|
||||
int StyleHelper::uiFontLineHeight(UiElement element)
|
||||
{
|
||||
const UiFontMetrics &metrics = uiFontMetrics(element);
|
||||
const qreal lineHeightToPixelSizeRatio = qreal(metrics.lineHeight) / metrics.pixelSize;
|
||||
const QFontInfo fontInfo(uiFont(element));
|
||||
return qCeil(fontInfo.pixelSize() * lineHeightToPixelSizeRatio);
|
||||
}
|
||||
|
||||
QString StyleHelper::fontToCssProperties(const QFont &font)
|
||||
{
|
||||
const QString fontSize = font.pixelSize() != -1 ? QString::number(font.pixelSize()) + "px"
|
||||
|
@@ -114,6 +114,7 @@ QTCREATOR_UTILS_EXPORT QColor toolBarDropShadowColor();
|
||||
QTCREATOR_UTILS_EXPORT QColor notTooBrightHighlightColor();
|
||||
|
||||
QTCREATOR_UTILS_EXPORT QFont uiFont(UiElement element);
|
||||
QTCREATOR_UTILS_EXPORT int uiFontLineHeight(UiElement element);
|
||||
QTCREATOR_UTILS_EXPORT QString fontToCssProperties(const QFont &font);
|
||||
|
||||
// Sets the base color and makes sure all top level widgets are updated
|
||||
|
@@ -43,8 +43,9 @@ int main(int argc, char *argv[])
|
||||
sampleLabel->setFont(font);
|
||||
sampleLabel->setSizePolicy(uiElementLabel->sizePolicy());
|
||||
QFontInfo fontInfo(font);
|
||||
const QString pixelMetrics = QString::fromLatin1("Pixel size: %1")
|
||||
.arg(fontInfo.pixelSize());
|
||||
const QString pixelMetrics = QString::fromLatin1("Pixel size: %1, line height: %2")
|
||||
.arg(fontInfo.pixelSize())
|
||||
.arg(StyleHelper::uiFontLineHeight(uiElement.uiElement));
|
||||
auto *metricsLabel = new QLabel(pixelMetrics);
|
||||
fontLabels.addItems({uiElementLabel, sampleLabel, st, font.toString(), metricsLabel, br});
|
||||
}
|
||||
|
Reference in New Issue
Block a user