]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/kitemviews/kstandarditemlistwidget.cpp
Add some missing const qualifiers
[dolphin.git] / src / kitemviews / kstandarditemlistwidget.cpp
index c963b719664ee3fd85c034dcd965de71a362e334..41e9287c1628c24cf963cec9af13479c623c6f13 100644 (file)
@@ -113,8 +113,8 @@ QString KStandardItemListWidgetInformant::itemText(int index, const KItemListVie
 
 bool KStandardItemListWidgetInformant::itemIsLink(int index, const KItemListView* view) const
 {
-    Q_UNUSED(index);
-    Q_UNUSED(view);
+    Q_UNUSED(index)
+    Q_UNUSED(view)
     return false;
 }
 
@@ -600,7 +600,7 @@ void KStandardItemListWidget::refreshCache()
 
 bool KStandardItemListWidget::isRoleRightAligned(const QByteArray& role) const
 {
-    Q_UNUSED(role);
+    Q_UNUSED(role)
     return false;
 }
 
@@ -665,7 +665,7 @@ QString KStandardItemListWidget::roleText(const QByteArray& role,
 void KStandardItemListWidget::dataChanged(const QHash<QByteArray, QVariant>& current,
                                           const QSet<QByteArray>& roles)
 {
-    Q_UNUSED(current);
+    Q_UNUSED(current)
 
     m_dirtyContent = true;
 
@@ -697,7 +697,7 @@ void KStandardItemListWidget::dataChanged(const QHash<QByteArray, QVariant>& cur
 void KStandardItemListWidget::visibleRolesChanged(const QList<QByteArray>& current,
                                               const QList<QByteArray>& previous)
 {
-    Q_UNUSED(previous);
+    Q_UNUSED(previous)
     m_sortedVisibleRoles = current;
     m_dirtyLayout = true;
 }
@@ -706,38 +706,38 @@ void KStandardItemListWidget::columnWidthChanged(const QByteArray& role,
                                              qreal current,
                                              qreal previous)
 {
-    Q_UNUSED(role);
-    Q_UNUSED(current);
-    Q_UNUSED(previous);
+    Q_UNUSED(role)
+    Q_UNUSED(current)
+    Q_UNUSED(previous)
     m_dirtyLayout = true;
 }
 
 void KStandardItemListWidget::styleOptionChanged(const KItemListStyleOption& current,
                                              const KItemListStyleOption& previous)
 {
-    Q_UNUSED(current);
-    Q_UNUSED(previous);
+    Q_UNUSED(current)
+    Q_UNUSED(previous)
     updateAdditionalInfoTextColor();
     m_dirtyLayout = true;
 }
 
 void KStandardItemListWidget::hoveredChanged(bool hovered)
 {
-    Q_UNUSED(hovered);
+    Q_UNUSED(hovered)
     m_dirtyLayout = true;
 }
 
 void KStandardItemListWidget::selectedChanged(bool selected)
 {
-    Q_UNUSED(selected);
+    Q_UNUSED(selected)
     updateAdditionalInfoTextColor();
     m_dirtyContent = true;
 }
 
 void KStandardItemListWidget::siblingsInformationChanged(const QBitArray& current, const QBitArray& previous)
 {
-    Q_UNUSED(current);
-    Q_UNUSED(previous);
+    Q_UNUSED(current)
+    Q_UNUSED(previous)
     m_dirtyLayout = true;
 }
 
@@ -748,7 +748,7 @@ int KStandardItemListWidget::selectionLength(const QString& text) const
 
 void KStandardItemListWidget::editedRoleChanged(const QByteArray& current, const QByteArray& previous)
 {
-    Q_UNUSED(previous);
+    Q_UNUSED(previous)
 
     QGraphicsView* parent = scene()->views()[0];
     if (current.isEmpty() || !parent || current != "text") {
@@ -1113,6 +1113,26 @@ void KStandardItemListWidget::updateTextsCache()
     }
 }
 
+QString KStandardItemListWidget::elideRightKeepExtension(const QString &text, int elidingWidth) const
+{
+    const auto extensionIndex = text.lastIndexOf('.');
+    if (extensionIndex != -1) {
+        // has file extension
+        const auto extensionLength = text.length() - extensionIndex;
+        const auto extensionWidth = m_customizedFontMetrics.width(text.right(extensionLength));
+        if (elidingWidth > extensionWidth && extensionLength < 6 && (float(extensionWidth) / float(elidingWidth)) < 0.3) {
+            // if we have room to display the file extension and the extension is not too long
+            QString ret = m_customizedFontMetrics.elidedText(text.chopped(extensionLength),
+                                                             Qt::ElideRight,
+                                                             elidingWidth - extensionWidth);
+            ret.append(text.right(extensionLength));
+            return ret;
+        }
+    }
+    return m_customizedFontMetrics.elidedText(text,Qt::ElideRight,
+                                              elidingWidth);
+}
+
 void KStandardItemListWidget::updateIconsLayoutTextCache()
 {
     //      +------+
@@ -1164,9 +1184,7 @@ void KStandardItemListWidget::updateIconsLayoutTextCache()
                 qreal lastLineWidth;
                 do {
                     QString lastTextLine = nameText.mid(line.textStart());
-                    lastTextLine = m_customizedFontMetrics.elidedText(lastTextLine,
-                                                                      Qt::ElideMiddle,
-                                                                      elidingWidth);
+                    lastTextLine = elideRightKeepExtension(lastTextLine, elidingWidth);
                     const QString elidedText = nameText.left(line.textStart()) + lastTextLine;
                     nameTextInfo->staticText.setText(elidedText);
 
@@ -1221,7 +1239,7 @@ void KStandardItemListWidget::updateIconsLayoutTextCache()
             textLine.setLineWidth(maxWidth);
             requiredWidth = textLine.naturalTextWidth();
             if (requiredWidth > maxWidth) {
-                const QString elidedText = m_customizedFontMetrics.elidedText(text, Qt::ElideMiddle, maxWidth);
+                const QString elidedText = elideRightKeepExtension(text, maxWidth);
                 textInfo->staticText.setText(elidedText);
                 requiredWidth = m_customizedFontMetrics.width(elidedText);
             } else if (role == "rating") {
@@ -1270,7 +1288,7 @@ void KStandardItemListWidget::updateCompactLayoutTextCache()
         qreal requiredWidth = m_customizedFontMetrics.width(text);
         if (requiredWidth > maxWidth) {
             requiredWidth = maxWidth;
-            const QString elidedText = m_customizedFontMetrics.elidedText(text, Qt::ElideMiddle, maxWidth);
+            const QString elidedText = elideRightKeepExtension(text, maxWidth);
             textInfo->staticText.setText(elidedText);
         }
 
@@ -1327,7 +1345,7 @@ void KStandardItemListWidget::updateDetailsLayoutTextCache()
         }
 
         if (requiredWidth > availableTextWidth) {
-            text = m_customizedFontMetrics.elidedText(text, Qt::ElideMiddle, availableTextWidth);
+            text = elideRightKeepExtension(text, availableTextWidth);
             requiredWidth = m_customizedFontMetrics.width(text);
         }