AssetExport: Export line height value in pixels

Task-number: QDS-2597
Change-Id: I96db25b08db55c3107931ab31e4b9342be92e644
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Vikas Pachdha
2020-10-23 13:01:04 +02:00
parent 7f44ef76f1
commit ce413d81d0
4 changed files with 20 additions and 1 deletions

View File

@@ -42,7 +42,7 @@ add_qtc_plugin(QmlDesigner
add_qtc_plugin(assetexporterplugin
CONDITION TARGET QmlDesigner
DEPENDS Core ProjectExplorer QmlDesigner Utils Qt5::Qml
DEPENDS Core ProjectExplorer QmlDesigner Utils Qt5::Qml Qt5::QuickPrivate
PUBLIC_INCLUDES assetexporterplugin
SOURCES
assetexporterplugin/assetexportdialog.h assetexporterplugin/assetexportdialog.cpp assetexporterplugin/assetexportdialog.ui

View File

@@ -1,4 +1,5 @@
QT *= qml quick core widgets
QT += quick-private
VPATH += $$PWD

View File

@@ -10,6 +10,12 @@ QtcProduct {
Depends { name: "ProjectExplorer" }
Depends { name: "QmlDesigner" }
Depends { name: "Utils" }
Depends {
name: "Qt"
submodules: [
"quick-private"
]
}
cpp.includePaths: base.concat([
"./",

View File

@@ -28,7 +28,11 @@
#include <QColor>
#include <QFontInfo>
#include <QFontMetricsF>
#include <QHash>
#include <QtMath>
#include <private/qquicktext_p.h>
namespace {
const QHash<QString, QString> AlignMapping{
@@ -86,6 +90,14 @@ QJsonObject TextNodeParser::json(Component &component) const
textDetails.insert(IsMultilineTag, propertyValue("wrapMode").toString().compare("NoWrap") != 0);
// Calculate line height in pixels
QFontMetricsF fm(font);
auto lineHeightMode = propertyValue("lineHeightMode").value<QQuickText::LineHeightMode>();
double lineHeight = propertyValue("lineHeight").toDouble();
qreal lineHeightPx = (lineHeightMode == QQuickText::FixedHeight) ?
lineHeight : qCeil(fm.height()) * lineHeight;
textDetails.insert(LineHeightTag, lineHeightPx);
QJsonObject metadata = jsonObject.value(MetadataTag).toObject();
metadata.insert(TextDetailsTag, textDetails);
jsonObject.insert(MetadataTag, metadata);