]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Elide the texts if the user shrinks the column-widths
authorPeter Penz <peter.penz19@gmail.com>
Sun, 2 Oct 2011 15:33:41 +0000 (17:33 +0200)
committerPeter Penz <peter.penz19@gmail.com>
Sun, 2 Oct 2011 15:34:18 +0000 (17:34 +0200)
src/kitemviews/kfileitemlistwidget.cpp
src/kitemviews/kitemlistheader.cpp
src/kitemviews/kitemlistview.cpp

index 7cf1b4df1a826235cd8b5cbdd80eea2bc74ad00e..3d47285215eec6d6681046afcb1271b3aa434976 100644 (file)
@@ -119,12 +119,29 @@ void KFileItemListWidget::paint(QPainter* painter, const QStyleOptionGraphicsIte
     painter->setPen(textColor());
     painter->drawStaticText(m_textPos[Name], m_text[Name]);
 
+    bool clipAdditionalInfoBounds = false;
+    if (m_layout == DetailsLayout) {
+        // Prevent a possible overlapping of the additional-information texts
+        // with the icon. This can happen if the user has minimized the width
+        // of the name-column to a very small value.
+        const qreal minX = m_pixmapPos.x() + m_pixmap.width() + 4 * itemListStyleOption.margin;
+        if (m_textPos[Name + 1].x() < minX) {
+            clipAdditionalInfoBounds = true;
+            painter->save();
+            painter->setClipRect(minX, 0, size().width() - minX, size().height(), Qt::IntersectClip);
+        }
+    }
+
     painter->setPen(m_additionalInfoTextColor);
     painter->setFont(itemListStyleOption.font);
     for (int i = Name + 1; i < TextIdCount; ++i) {
         painter->drawStaticText(m_textPos[i], m_text[i]);
     }
 
+    if (clipAdditionalInfoBounds) {
+        painter->restore();
+    }
+
 #ifdef KFILEITEMLISTWIDGET_DEBUG
     painter->setPen(Qt::red);
     painter->setBrush(Qt::NoBrush);
@@ -631,13 +648,23 @@ void KFileItemListWidget::updateDetailsLayoutTextCache()
     foreach (const QByteArray& role, m_sortedVisibleRoles) {
         const TextId textId = roleTextId(role);
 
-        const QString text = roleText(role, values);
-        m_text[textId].setText(text);
-
-        const qreal requiredWidth = option.fontMetrics.width(text);
-        m_textPos[textId] = QPointF(x + columnMargin, y);
+        QString text = roleText(role, values);
 
+        // Elide the text in case it does not fit into the available column-width
+        qreal requiredWidth = option.fontMetrics.width(text);
         const qreal columnWidth = visibleRolesSizes().value(role, QSizeF(0, 0)).width();
+        qreal availableTextWidth = columnWidth - 2 * columnMargin;
+        if (textId == Name) {
+            availableTextWidth -= firstColumnInc;
+        }
+
+        if (requiredWidth > availableTextWidth) {
+            text = option.fontMetrics.elidedText(text, Qt::ElideRight, availableTextWidth);
+            requiredWidth = option.fontMetrics.width(text);
+        }
+
+        m_text[textId].setText(text);
+        m_textPos[textId] = QPointF(x + columnMargin, y);
         x += columnWidth;
 
         switch (textId) {
index 09b9bf08fbff8b7e832ce809857c3db7a98effdb..f9b976369f8b648a9f17372a25488797a92af81a 100644 (file)
@@ -337,7 +337,7 @@ bool KItemListHeader::isAboveRoleGrip(const QPointF& pos, int roleIndex) const
 qreal KItemListHeader::minimumRoleWidth() const
 {
     QFontMetricsF fontMetrics(font());
-    return fontMetrics.averageCharWidth() * 5;
+    return fontMetrics.averageCharWidth() * 8;
 }
 
 #include "kitemlistheader_p.moc"
index 83008518e2257f7c4286972254cab8dea4e29934..612b6fd6536677e9dd61011382019a1039c69cd7 100644 (file)
@@ -227,16 +227,17 @@ void KItemListView::setVisibleRoles(const QList<QByteArray>& roles)
 
     m_sizeHintResolver->clearCache();
     m_layouter->markAsDirty();
-    onVisibleRolesChanged(roles, previousRoles);
-
-    updateVisibleRolesSizes();
-    updateLayout();
 
     if (m_header) {
         m_header->setVisibleRoles(roles);
         m_header->setVisibleRolesWidths(headerRolesWidths());
         m_useHeaderWidths = false;
     }
+
+    updateVisibleRolesSizes();
+    updateLayout();
+
+    onVisibleRolesChanged(roles, previousRoles);
 }
 
 QList<QByteArray> KItemListView::visibleRoles() const