diff options
author | Olivier Goffart <ogoffart@trolltech.com> | 2009-05-11 10:46:58 (GMT) |
---|---|---|
committer | Oswald Buddenhagen <oswald.buddenhagen@nokia.com> | 2009-08-11 17:14:52 (GMT) |
commit | caebd2676dda37fb7ab11c3b994fd341f88b0de0 (patch) | |
tree | 44247a9b2a06de4e3a766ea54f28ad5b003ba102 /src/gui | |
parent | c225767b9b50336432e39cd589637df4fe721d62 (diff) | |
download | Qt-caebd2676dda37fb7ab11c3b994fd341f88b0de0.zip Qt-caebd2676dda37fb7ab11c3b994fd341f88b0de0.tar.gz Qt-caebd2676dda37fb7ab11c3b994fd341f88b0de0.tar.bz2 |
Make QFontMetrics::elidedText aware of multi-length strings
Reviewed-by: Oswald Buddenhagen
Task-number: QT-10
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/text/qfontmetrics.cpp | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/src/gui/text/qfontmetrics.cpp b/src/gui/text/qfontmetrics.cpp index 47d3864..5c5320f 100644 --- a/src/gui/text/qfontmetrics.cpp +++ b/src/gui/text/qfontmetrics.cpp @@ -859,8 +859,21 @@ QRect QFontMetrics::tightBoundingRect(const QString &text) const language. */ -QString QFontMetrics::elidedText(const QString &text, Qt::TextElideMode mode, int width, int flags) const -{ +QString QFontMetrics::elidedText(const QString &_text, Qt::TextElideMode mode, int width, int flags) const +{ + 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)); return engine.elidedText(mode, width, flags); } |