// // TextOverlay.cpp // interface/src/ui/overlays // // Copyright 2014 High Fidelity, Inc. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // #include "TextOverlay.h" #include #include #include #include #include #include #include #include #include #include "Application.h" #include "text/FontFamilies.h" QString const TextOverlay::TYPE = "text"; QUrl const TextOverlay::URL(QString("hifi/overlays/TextOverlay.qml")); // TextOverlay's properties are defined in the QML file specified above. /**jsdoc * These are the properties of a text {@link Overlays.OverlayType|OverlayType}. * @typedef {object} Overlays.TextProperties * * @property {Rect} bounds - The position and size of the rectangle, in pixels. Write-only. * @property {number} x - Integer left, x-coordinate value = bounds.x. Write-only. * @property {number} y - Integer top, y-coordinate value = bounds.y. Write-only. * @property {number} width - Integer width of the rectangle = bounds.width. Write-only. * @property {number} height - Integer height of the rectangle = bounds.height. Write-only. * * @property {number} margin=0 - Sets the leftMargin and topMargin values, in pixels. * Write-only. * @property {number} leftMargin=0 - The left margin's size, in pixels. This value is also used for the right margin. * Write-only. * @property {number} topMargin=0 - The top margin's size, in pixels. This value is also used for the bottom margin. * Write-only. * @property {string} text="" - The text to display. Text does not automatically wrap; use \n for a line break. Text * is clipped to the bounds. Write-only. * @property {number} font.size=18 - The size of the text, in pixels. Write-only. * @property {number} lineHeight=18 - The height of a line of text, in pixels. Write-only. * @property {Color} color=255,255,255 - The color of the text. Synonym: textColor. Write-only. * @property {number} alpha=1.0 - The opacity of the overlay, 0.0 - 1.0. Write-only. * @property {Color} backgroundColor=0,0,0 - The color of the background rectangle. Write-only. * @property {number} backgroundAlpha=0.7 - The opacity of the background rectangle. Write-only. * @property {boolean} visible=true - If true, the overlay is rendered, otherwise it is not rendered. * Write-only. */ TextOverlay::TextOverlay() : QmlOverlay(URL) { } TextOverlay::TextOverlay(const TextOverlay* textOverlay) : QmlOverlay(URL, textOverlay) { } TextOverlay::~TextOverlay() { } TextOverlay* TextOverlay::createClone() const { return new TextOverlay(this); } QSizeF TextOverlay::textSize(const QString& text) const { int lines = 1; foreach(QChar c, text) { if (c == QChar('\n')) { ++lines; } } QFont font(SANS_FONT_FAMILY); font.setPixelSize(18); QFontMetrics fm(font); QSizeF result = QSizeF(fm.width(text), 18 * lines); return result; } void TextOverlay::setTopMargin(float margin) {} void TextOverlay::setLeftMargin(float margin) {} void TextOverlay::setFontSize(float size) {} void TextOverlay::setText(const QString& text) {}