+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);
+#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
+ ret.append(text.rightRef(extensionLength));
+#else
+ ret.append(QStringView(text).right(extensionLength));
+#endif
+ return ret;
+ }
+ }
+ 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;
+}
+