]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Fix wrong text eliding in some corner cases.
authorEmmanuel Pescosta <emmanuelpescosta099@gmail.com>
Mon, 4 Aug 2014 17:43:07 +0000 (19:43 +0200)
committerEmmanuel Pescosta <emmanuelpescosta099@gmail.com>
Mon, 4 Aug 2014 17:43:07 +0000 (19:43 +0200)
BUG: 337104
FIXED-IN: 4.14.0
REVIEW: 119546

src/kitemviews/kstandarditemlistwidget.cpp

index 998acc06655fd37932cfb2be3d087b4ebe05adfa..6407efc225c14d1cd2da8f3b60b43eb678ab5aae 100644 (file)
@@ -1136,14 +1136,24 @@ void KStandardItemListWidget::updateIconsLayoutTextCache()
             const int textLength = line.textStart() + line.textLength();
             if (textLength < nameText.length()) {
                 // Elide the last line of the text
-                QString lastTextLine = nameText.mid(line.textStart());
-                lastTextLine = m_customizedFontMetrics.elidedText(lastTextLine,
-                                                                  Qt::ElideRight,
-                                                                  maxWidth);
-                const QString elidedText = nameText.left(line.textStart()) + lastTextLine;
-                nameTextInfo->staticText.setText(elidedText);
-
-                const qreal lastLineWidth = m_customizedFontMetrics.boundingRect(lastTextLine).width();
+                qreal elidingWidth = maxWidth;
+                qreal lastLineWidth;
+                do {
+                    QString lastTextLine = nameText.mid(line.textStart());
+                    lastTextLine = m_customizedFontMetrics.elidedText(lastTextLine,
+                                                                      Qt::ElideRight,
+                                                                      elidingWidth);
+                    const QString elidedText = nameText.left(line.textStart()) + lastTextLine;
+                    nameTextInfo->staticText.setText(elidedText);
+
+                    lastLineWidth = m_customizedFontMetrics.boundingRect(lastTextLine).width();
+
+                    // We do the text eliding in a loop with decreasing width (1 px / iteration)
+                    // to avoid problems related to different width calculation code paths
+                    // within Qt. (see bug 337104)
+                    elidingWidth -= 1.0;
+                } while (lastLineWidth > maxWidth);
+
                 nameWidth = qMax(nameWidth, lastLineWidth);
             }
             break;