summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOlivier Goffart <ogoffart@trolltech.com>2009-11-19 10:32:48 (GMT)
committerOlivier Goffart <ogoffart@trolltech.com>2009-11-19 10:50:33 (GMT)
commita73e660fd05bafc402d63d71e811a621e46f452d (patch)
tree6f7a4e35cbbf0026b4007ca0dfa5d8b03570b781
parentbaab5f7e77c1216ede839766c97abef1a708b365 (diff)
downloadQt-a73e660fd05bafc402d63d71e811a621e46f452d.zip
Qt-a73e660fd05bafc402d63d71e811a621e46f452d.tar.gz
Qt-a73e660fd05bafc402d63d71e811a621e46f452d.tar.bz2
Fixed Multi-length strings not implemented for float functions
Task-number: QTBUG-5963 Reviewed-by: Oswald Buddenhagen Reviewed-by: Eskil
-rw-r--r--src/gui/text/qfontmetrics.cpp22
-rw-r--r--tests/auto/qfontmetrics/tst_qfontmetrics.cpp14
2 files changed, 31 insertions, 5 deletions
diff --git a/src/gui/text/qfontmetrics.cpp b/src/gui/text/qfontmetrics.cpp
index b8c1b33..3d3f1e1 100644
--- a/src/gui/text/qfontmetrics.cpp
+++ b/src/gui/text/qfontmetrics.cpp
@@ -1367,10 +1367,13 @@ qreal QFontMetricsF::rightBearing(QChar ch) const
*/
qreal QFontMetricsF::width(const QString &text) const
{
+ int pos = text.indexOf(QLatin1Char('\x9c'));
+ int len = (pos != -1) ? pos : text.length();
+
QTextEngine layout(text, d.data());
layout.ignoreBidi = true;
layout.itemize();
- return layout.width(0, text.length()).toReal();
+ return layout.width(0, len).toReal();
}
/*!
@@ -1587,7 +1590,7 @@ QRectF QFontMetricsF::boundingRect(const QRectF &rect, int flags, const QString&
*/
QSizeF QFontMetricsF::size(int flags, const QString &text, int tabStops, int *tabArray) const
{
- return boundingRect(QRectF(), flags, text, tabStops, tabArray).size();
+ return boundingRect(QRectF(), flags | Qt::TextLongestVariant, text, tabStops, tabArray).size();
}
/*!
@@ -1642,7 +1645,20 @@ QRectF QFontMetricsF::tightBoundingRect(const QString &text) const
*/
QString QFontMetricsF::elidedText(const QString &text, Qt::TextElideMode mode, qreal width, int flags) const
{
- QStackTextEngine engine(text, QFont(d.data()));
+ QString _text = text;
+ if (!(flags & Qt::TextLongestVariant)) {
+ int posA = 0;
+ int posB = _text.indexOf(QLatin1Char('\x9c'));
+ while (posB >= 0) {
+ QString portion = _text.mid(posA, posB - posA);
+ if (size(flags, portion).width() <= width)
+ return portion;
+ posA = posB + 1;
+ posB = _text.indexOf(QLatin1Char('\x9c'), posA);
+ }
+ _text = _text.mid(posA);
+ }
+ QStackTextEngine engine(_text, QFont(d.data()));
return engine.elidedText(mode, QFixed::fromReal(width), flags);
}
diff --git a/tests/auto/qfontmetrics/tst_qfontmetrics.cpp b/tests/auto/qfontmetrics/tst_qfontmetrics.cpp
index e80f8e0..efb1b56 100644
--- a/tests/auto/qfontmetrics/tst_qfontmetrics.cpp
+++ b/tests/auto/qfontmetrics/tst_qfontmetrics.cpp
@@ -72,6 +72,7 @@ private slots:
void veryNarrowElidedText();
void averageCharWidth();
void elidedMultiLength();
+ void elidedMultiLengthF();
void bearingIncludedInBoundingRect();
};
@@ -218,13 +219,13 @@ void tst_QFontMetrics::averageCharWidth()
QVERIFY(fmf.averageCharWidth() != 0);
}
-void tst_QFontMetrics::elidedMultiLength()
+template<class FontMetrics> void elidedMultiLength_helper()
{
QString text1 = "Long Text 1\x9cShorter\x9csmall";
QString text1_long = "Long Text 1";
QString text1_short = "Shorter";
QString text1_small = "small";
- QFontMetrics fm = QFontMetrics(QFont());
+ FontMetrics fm = FontMetrics(QFont());
int width_long = fm.size(0, text1_long).width();
QCOMPARE(fm.elidedText(text1,Qt::ElideRight, 8000), text1_long);
QCOMPARE(fm.elidedText(text1,Qt::ElideRight, width_long + 1), text1_long);
@@ -238,7 +239,16 @@ void tst_QFontMetrics::elidedMultiLength()
QString text1_el = QString::fromLatin1("s") + ellipsisChar;
int width_small = fm.width(text1_el);
QCOMPARE(fm.elidedText(text1,Qt::ElideRight, width_small + 1), text1_el);
+}
+void tst_QFontMetrics::elidedMultiLength()
+{
+ elidedMultiLength_helper<QFontMetrics>();
+}
+
+void tst_QFontMetrics::elidedMultiLengthF()
+{
+ elidedMultiLength_helper<QFontMetricsF>();
}
void tst_QFontMetrics::bearingIncludedInBoundingRect()