summaryrefslogtreecommitdiff
path: root/src/gui/text/qfontmetrics.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/text/qfontmetrics.cpp')
-rw-r--r--src/gui/text/qfontmetrics.cpp27
1 files changed, 21 insertions, 6 deletions
diff --git a/src/gui/text/qfontmetrics.cpp b/src/gui/text/qfontmetrics.cpp
index 2f3a7913f5..5b47772351 100644
--- a/src/gui/text/qfontmetrics.cpp
+++ b/src/gui/text/qfontmetrics.cpp
@@ -34,7 +34,7 @@
** met: http://www.gnu.org/copyleft/gpl.html.
**
** If you are unsure which license is appropriate for your use, please
-** contact the sales department at http://www.qtsoftware.com/contact.
+** contact the sales department at http://qt.nokia.com/contact.
** $QT_END_LICENSE$
**
****************************************************************************/
@@ -528,12 +528,14 @@ int QFontMetrics::rightBearing(QChar ch) const
*/
int QFontMetrics::width(const QString &text, int len) const
{
+ int pos = text.indexOf(QLatin1Char('\x9c'));
+ QString txt = (pos == -1) ? text : text.left(pos);
if (len < 0)
- len = text.length();
+ len = txt.length();
if (len == 0)
return 0;
- QTextEngine layout(text, d);
+ QTextEngine layout(txt, d);
layout.ignoreBidi = true;
return qRound(layout.width(0, len));
}
@@ -798,7 +800,7 @@ QRect QFontMetrics::boundingRect(const QRect &rect, int flags, const QString &te
*/
QSize QFontMetrics::size(int flags, const QString &text, int tabStops, int *tabArray) const
{
- return boundingRect(QRect(0,0,0,0), flags, text, tabStops, tabArray).size();
+ return boundingRect(QRect(0,0,0,0), flags | Qt::TextLongestVariant, text, tabStops, tabArray).size();
}
/*!
@@ -859,8 +861,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);
}