diff options
| author | Nate Graham <[email protected]> | 2025-01-03 12:45:27 -0700 |
|---|---|---|
| committer | Felix Ernst <[email protected]> | 2025-01-07 01:46:12 +0000 |
| commit | f42e81fb5d71ffa23948c4edea9bb3f86c84e8c7 (patch) | |
| tree | 5f94ec7cbda6a0b00895b1d9119c9801f5047e1a | |
| parent | cd583c410996f28ca54168156505992f146f4cad (diff) | |
Elide file names in the middle again
In ye olden days, filenames were elided on the right. This prevented
seeing the filename extension and any suffix style text the user
included in the filename (e.g. "myfile 1", "myfile 2" and so on).
In 97f49347482519b9ad53b7596d7462e68b7c2e14, this was changed to elide
in the middle, fixing both problems and bringing Dolphin into Jakobs'
Law style consistency with MacOS Finder and Windows Explorer, and
possibly other file managers too.
However it worsened the situation for users who name their files such
that most of the information was on the left. After some complaints, it
was changed in 99cf24c03def1c0722ba8dbd86a27b9dbc521f43 to right-elide
again, but excluding the filename extension.
Unfortunately user complaints have continued. At this point it's clear
that nothing will satisfy everyone due to diversity of file naming
styles. In such a situation, Jakobs' Law consistency with the rest of
the industry is the best solution short of making it configurable,
which has its own drawbacks.
Accordingly, return to middle-elision.
BUG: 497664
CCBUG: 404955
FIXED-IN: 25.04.0
| -rw-r--r-- | src/kitemviews/kstandarditemlistwidget.cpp | 25 | ||||
| -rw-r--r-- | src/kitemviews/kstandarditemlistwidget.h | 2 |
2 files changed, 4 insertions, 23 deletions
diff --git a/src/kitemviews/kstandarditemlistwidget.cpp b/src/kitemviews/kstandarditemlistwidget.cpp index 05628d391..a30a1bcd2 100644 --- a/src/kitemviews/kstandarditemlistwidget.cpp +++ b/src/kitemviews/kstandarditemlistwidget.cpp @@ -1285,23 +1285,6 @@ 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.horizontalAdvance(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(QStringView(text).right(extensionLength)); - return ret; - } - } - return m_customizedFontMetrics.elidedText(text, Qt::ElideRight, elidingWidth); -} - QString KStandardItemListWidget::escapeString(const QString &text) const { QString escaped(text); @@ -1362,7 +1345,7 @@ void KStandardItemListWidget::updateIconsLayoutTextCache() qreal lastLineWidth; do { QString lastTextLine = nameText.mid(line.textStart()); - lastTextLine = elideRightKeepExtension(lastTextLine, elidingWidth); + lastTextLine = m_customizedFontMetrics.elidedText(lastTextLine, Qt::ElideMiddle, elidingWidth); const QString elidedText = nameText.left(line.textStart()) + lastTextLine; nameTextInfo->staticText.setText(elidedText); @@ -1410,7 +1393,7 @@ void KStandardItemListWidget::updateIconsLayoutTextCache() textLine.setLineWidth(maxWidth); requiredWidth = textLine.naturalTextWidth(); if (requiredWidth > maxWidth) { - const QString elidedText = elideRightKeepExtension(text, maxWidth); + const QString elidedText = m_customizedFontMetrics.elidedText(text, Qt::ElideMiddle, maxWidth); textInfo->staticText.setText(elidedText); requiredWidth = m_customizedFontMetrics.horizontalAdvance(elidedText); } else if (role == "rating") { @@ -1462,7 +1445,7 @@ void KStandardItemListWidget::updateCompactLayoutTextCache() qreal requiredWidth = m_customizedFontMetrics.horizontalAdvance(text); if (requiredWidth > maxWidth) { requiredWidth = maxWidth; - const QString elidedText = elideRightKeepExtension(text, maxWidth); + const QString elidedText = m_customizedFontMetrics.elidedText(text, Qt::ElideMiddle, maxWidth); textInfo->staticText.setText(elidedText); } @@ -1522,7 +1505,7 @@ void KStandardItemListWidget::updateDetailsLayoutTextCache() } if (requiredWidth > availableTextWidth) { - text = elideRightKeepExtension(text, availableTextWidth); + text = m_customizedFontMetrics.elidedText(text, Qt::ElideMiddle, availableTextWidth); requiredWidth = m_customizedFontMetrics.horizontalAdvance(text); } diff --git a/src/kitemviews/kstandarditemlistwidget.h b/src/kitemviews/kstandarditemlistwidget.h index 7ff97a126..d4a4f1231 100644 --- a/src/kitemviews/kstandarditemlistwidget.h +++ b/src/kitemviews/kstandarditemlistwidget.h @@ -218,8 +218,6 @@ private: QRectF roleEditingRect(const QByteArray &role) const; - QString elideRightKeepExtension(const QString &text, int elidingWidth) const; - /** * Escapes text for display purposes. * |
