summaryrefslogtreecommitdiffstats
path: root/src/extras/text/qtext2dentity.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/extras/text/qtext2dentity.cpp')
-rw-r--r--src/extras/text/qtext2dentity.cpp48
1 files changed, 42 insertions, 6 deletions
diff --git a/src/extras/text/qtext2dentity.cpp b/src/extras/text/qtext2dentity.cpp
index b0c53cb24..f118ff1fe 100644
--- a/src/extras/text/qtext2dentity.cpp
+++ b/src/extras/text/qtext2dentity.cpp
@@ -80,6 +80,12 @@ namespace Qt3DExtras {
* Holds the height of the text's bounding rectangle.
*/
+ /*!
+ * \qmlproperty Qt::Alignment Text2DEntity::alignment
+ *
+ * Holds the alignment of the text.
+ */
+
/*!
* \class Qt3DExtras::QText2DEntity
@@ -108,6 +114,7 @@ QText2DEntityPrivate::QText2DEntityPrivate()
, m_color(QColor(255, 255, 255, 255))
, m_width(0.0f)
, m_height(0.0f)
+ , m_alignment(Qt::AlignTop | Qt::AlignLeft)
{
}
@@ -274,8 +281,9 @@ void QText2DEntityPrivate::setCurrentGlyphRuns(const QList<QGlyphRun> &runs)
delete m_renderers.takeLast();
while (m_renderers.size() < renderData.size()) {
- DistanceFieldTextRenderer *renderer = new DistanceFieldTextRenderer(q_func());
+ DistanceFieldTextRenderer *renderer = new DistanceFieldTextRenderer();
renderer->setColor(m_color);
+ renderer->setParent(q_func());
m_renderers << renderer;
}
@@ -304,6 +312,11 @@ void QText2DEntityPrivate::updateGlyphs()
// collect all GlyphRuns generated by the QTextLayout
if ((m_width > 0.0f || m_height > 0.0f) && !m_text.isEmpty()) {
QTextLayout layout(m_text, m_scaledFont);
+
+ QTextOption textOption = layout.textOption();
+ textOption.setAlignment(m_alignment);
+ layout.setTextOption(textOption);
+
const float lineWidth = m_width / computeActualScale();
float height = 0;
layout.beginLayout();
@@ -331,7 +344,7 @@ void QText2DEntityPrivate::updateGlyphs()
}
/*!
- \property QText2DEntity::font
+ \property Qt3DExtras::QText2DEntity::font
Holds the font for the text item that is displayed
in the Qt Quick scene.
@@ -361,7 +374,7 @@ void QText2DEntity::setFont(const QFont &font)
}
/*!
- \property QText2DEntity::color
+ \property Qt3DExtras::QText2DEntity::color
Holds the color for the text item that is displayed in the Qt
Quick scene.
@@ -386,7 +399,7 @@ void QText2DEntity::setColor(const QColor &color)
}
/*!
- \property QText2DEntity::text
+ \property Qt3DExtras::QText2DEntity::text
Holds the text that is displayed in the Qt Quick scene.
*/
@@ -408,7 +421,7 @@ void QText2DEntity::setText(const QString &text)
}
/*!
- \property QText2DEntity::width
+ \property Qt3DExtras::QText2DEntity::width
Returns the width of the text item that is displayed in the
Qt Quick scene.
@@ -420,7 +433,7 @@ float QText2DEntity::width() const
}
/*!
- \property QText2DEntity::height
+ \property Qt3DExtras::QText2DEntity::height
Returns the height of the text item that is displayed in the
Qt Quick scene.
@@ -451,6 +464,29 @@ void QText2DEntity::setHeight(float height)
}
}
+/*!
+ \property QText2DEntity::alignment
+
+ Returns the alignment of the text item that is displayed in the
+ Qt Quick scene.
+
+ The default alignment is top-left-aligned.
+*/
+Qt::Alignment QText2DEntity::alignment() const
+{
+ Q_D(const QText2DEntity);
+ return d->m_alignment;
+}
+
+void QText2DEntity::setAlignment(Qt::Alignment alignment)
+{
+ Q_D(QText2DEntity);
+ if (alignment != d->m_alignment) {
+ d->m_alignment = alignment;
+ d->updateGlyphs();
+ }
+}
+
} // namespace Qt3DExtras
QT_END_NAMESPACE