aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/util/qquickstyledtext.cpp
diff options
context:
space:
mode:
authorMichael Brasser <michael.brasser@live.com>2016-06-13 16:52:22 -0500
committerMichael Brasser <michael.brasser@live.com>2016-06-16 13:50:33 +0000
commit6358e1365539d2ea26ec20617b58c0fed11d647e (patch)
tree88a9949f0b6c9128509f30477058896fb7e4da6e /src/quick/util/qquickstyledtext.cpp
parent458b4f0d37955b44c4f129541df2203cb8426296 (diff)
Fix positioning of inline images in StyledText.
Fix horizontal positioning generally, and also address RTL specifically. Change-Id: I8b75c11bc38e39da5cda302ee9b475bf0dc464e8 Task-number: QTBUG-54075 Reviewed-by: Andrew den Exter <andrew.den.exter@qinetic.com.au>
Diffstat (limited to 'src/quick/util/qquickstyledtext.cpp')
-rw-r--r--src/quick/util/qquickstyledtext.cpp15
1 files changed, 10 insertions, 5 deletions
diff --git a/src/quick/util/qquickstyledtext.cpp b/src/quick/util/qquickstyledtext.cpp
index c411207121..6dd9ca882b 100644
--- a/src/quick/util/qquickstyledtext.cpp
+++ b/src/quick/util/qquickstyledtext.cpp
@@ -652,10 +652,13 @@ bool QQuickStyledTextPrivate::parseAnchorAttributes(const QChar *&ch, const QStr
void QQuickStyledTextPrivate::parseImageAttributes(const QChar *&ch, const QString &textIn, QString &textOut)
{
qreal imgWidth = 0.0;
+ QFontMetricsF fm(layout.font());
+ const qreal spaceWidth = fm.width(QChar::Nbsp);
+ const bool trailingSpace = textOut.endsWith(space);
if (!updateImagePositions) {
QQuickStyledTextImgTag *image = new QQuickStyledTextImgTag;
- image->position = textOut.length() + 1;
+ image->position = textOut.length() + (trailingSpace ? 0 : 1);
QPair<QStringRef,QStringRef> attr;
do {
@@ -692,14 +695,16 @@ void QQuickStyledTextPrivate::parseImageAttributes(const QChar *&ch, const QStri
}
imgWidth = image->size.width();
+ image->offset = -std::fmod(imgWidth, spaceWidth) / 2.0;
imgTags->append(image);
} else {
// if we already have a list of img tags for this text
// we only want to update the positions of these tags.
QQuickStyledTextImgTag *image = imgTags->value(nbImages);
- image->position = textOut.length() + 1;
+ image->position = textOut.length() + (trailingSpace ? 0 : 1);
imgWidth = image->size.width();
+ image->offset = -std::fmod(imgWidth, spaceWidth) / 2.0;
QPair<QStringRef,QStringRef> attr;
do {
attr = parseAttribute(ch, textIn);
@@ -707,9 +712,9 @@ void QQuickStyledTextPrivate::parseImageAttributes(const QChar *&ch, const QStri
nbImages++;
}
- QFontMetricsF fm(layout.font());
- QString padding(qFloor(imgWidth / fm.width(QChar::Nbsp)), QChar::Nbsp);
- textOut += QLatin1Char(' ');
+ QString padding(qFloor(imgWidth / spaceWidth), QChar::Nbsp);
+ if (!trailingSpace)
+ textOut += QLatin1Char(' ');
textOut += padding;
textOut += QLatin1Char(' ');
}