]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Display newline in filename as Unicode line break
authorYifan Zhu <fanzhuyifan@gmail.com>
Sun, 22 Oct 2023 18:54:51 +0000 (11:54 -0700)
committerYifan Zhu <fanzhuyifan@gmail.com>
Mon, 23 Oct 2023 17:09:22 +0000 (10:09 -0700)
BUG: 422998
CCBUG: 444747

src/kitemviews/kstandarditemlistwidget.cpp
src/kitemviews/kstandarditemlistwidget.h

index 01b135038d3d1707f3a6f1f9c896f832c0cc6be4..0088e4116b34e2ab732e95d588de393b3b001a52 100644 (file)
@@ -1205,6 +1205,16 @@ QString KStandardItemListWidget::elideRightKeepExtension(const QString &text, in
     return m_customizedFontMetrics.elidedText(text, Qt::ElideRight, elidingWidth);
 }
 
+QString KStandardItemListWidget::escapeString(const QString &text) const
+{
+    QString escaped(text);
+
+    const QChar returnSymbol(0x21b5);
+    escaped.replace('\n', returnSymbol);
+
+    return escaped;
+}
+
 void KStandardItemListWidget::updateIconsLayoutTextCache()
 {
     //      +------+
@@ -1227,7 +1237,7 @@ void KStandardItemListWidget::updateIconsLayoutTextCache()
     // Initialize properties for the "text" role. It will be used as anchor
     // for initializing the position of the other roles.
     TextInfo *nameTextInfo = m_textInfo.value("text");
-    const QString nameText = KStringHandler::preProcessWrap(values["text"].toString());
+    const QString nameText = KStringHandler::preProcessWrap(escapeString(values["text"].toString()));
     nameTextInfo->staticText.setText(nameText);
 
     // Calculate the number of lines required for the name and the required width
@@ -1348,7 +1358,7 @@ void KStandardItemListWidget::updateCompactLayoutTextCache()
     qreal y = qRound((widgetHeight - textLinesHeight) / 2);
     const qreal maxWidth = size().width() - x - option.padding;
     for (const QByteArray &role : qAsConst(m_sortedVisibleRoles)) {
-        const QString text = roleText(role, values);
+        const QString text = escapeString(roleText(role, values));
         TextInfo *textInfo = m_textInfo.value(role);
         textInfo->staticText.setText(text);
 
@@ -1407,6 +1417,7 @@ void KStandardItemListWidget::updateDetailsLayoutTextCache()
 
         const bool isTextRole = (role == "text");
         if (isTextRole) {
+            text = escapeString(text);
             availableTextWidth -= firstColumnInc - sidePadding();
         }
 
index c4f80af1ddbdc1b35f1211d87c24e748254128f4..52cde1423851b16bba9682a39715cff163f53aca 100644 (file)
@@ -208,6 +208,13 @@ private:
 
     QString elideRightKeepExtension(const QString &text, int elidingWidth) const;
 
+    /**
+     * Escapes text for display purposes.
+     *
+     * Replaces '\n' with Unicode line break (U+21B5).
+     */
+    QString escapeString(const QString &text) const;
+
     /**
      * Closes the role editor and returns the focus back
      * to the KItemListContainer.