From 914b47069b34d2f116fa6df996fcb710f2110d74 Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Fri, 17 Jul 2015 14:33:32 -0700 Subject: [PATCH] Working on line height --- interface/resources/qml/TextOverlayElement.qml | 2 +- interface/src/ui/overlays/TextOverlay.cpp | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/interface/resources/qml/TextOverlayElement.qml b/interface/resources/qml/TextOverlayElement.qml index ac17468c07..0d9dd1eacc 100644 --- a/interface/resources/qml/TextOverlayElement.qml +++ b/interface/resources/qml/TextOverlayElement.qml @@ -17,7 +17,7 @@ TextOverlayElement { font.family: root.fontFamily font.pixelSize: root.fontSize lineHeightMode: Text.FixedHeight - lineHeight: root.fontSize * 1.2 + lineHeight: root.lineHeight } } } diff --git a/interface/src/ui/overlays/TextOverlay.cpp b/interface/src/ui/overlays/TextOverlay.cpp index 5507ef38ac..4c8a0d36e4 100644 --- a/interface/src/ui/overlays/TextOverlay.cpp +++ b/interface/src/ui/overlays/TextOverlay.cpp @@ -47,6 +47,7 @@ private: TEXT_OVERLAY_PROPERTY(QString, textColor, "#ffffffff") TEXT_OVERLAY_PROPERTY(QString, backgroundColor, "#B2000000") TEXT_OVERLAY_PROPERTY(qreal, fontSize, 18) + TEXT_OVERLAY_PROPERTY(qreal, lineHeight, 18) TEXT_OVERLAY_PROPERTY(qreal, leftMargin, 0) TEXT_OVERLAY_PROPERTY(qreal, topMargin, 0) @@ -58,6 +59,7 @@ signals: void textChanged(); void fontFamilyChanged(); void fontSizeChanged(); + void lineHeightChanged(); void leftMarginChanged(); void topMarginChanged(); void textColorChanged(); @@ -167,6 +169,10 @@ void TextOverlay::setProperties(const QScriptValue& properties) { if (font.property("size").isValid()) { setFontSize(font.property("size").toInt32()); } + QFont font(_qmlElement->fontFamily()); + font.setPixelSize(_qmlElement->fontSize()); + QFontMetrics fm(font); + _qmlElement->setlineHeight(fm.lineSpacing() * 1.2); } QScriptValue text = properties.property("text"); @@ -236,9 +242,10 @@ QSizeF TextOverlay::textSize(const QString& text) const { ++lines; } } - QFontMetrics fm(QFont(SANS_FONT_FAMILY, _fontSize)); - QSizeF result = QSizeF(fm.width(text), fm.lineSpacing() * lines); - result.rheight() *= 1.2; + QFont font(_qmlElement->fontFamily()); + font.setPixelSize(_qmlElement->fontSize()); + QFontMetrics fm(font); + QSizeF result = QSizeF(fm.width(text), _qmlElement->lineHeight() * lines); return result; }