Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -658,10 +658,10 @@ void ListItemDelegate::paintFileName(QPainter *painter, const QStyleOptionViewIt
QString ListItemDelegate::getCorrectDisplayName(QPainter *painter, const QModelIndex &index, const QStyleOptionViewItem &option,
const QUrl &url, const int &role, const int &textLineHeight, const QRectF &rect) const
{
QScopedPointer<ElideTextLayout> layout(ItemDelegateHelper::createTextLayout("", QTextOption::WrapAtWordBoundaryOrAnywhere,
textLineHeight, index.data(Qt::TextAlignmentRole).toInt(),
painter));
QString displayName { "" };

// 获取完整的显示名称,不进行省略处理
// 省略处理将由 ElideTextLayout::layout 统一完成,以确保高亮功能正常工作
if (Q_LIKELY(!FileUtils::isDesktopFileSuffix(url))) {
do {
if (role != kItemNameRole && role != kItemFileDisplayNameRole)
Expand All @@ -679,33 +679,18 @@ QString ListItemDelegate::getCorrectDisplayName(QPainter *painter, const QModelI
if (suffix == ".")
break;

QStringList textList {};
layout->setText(index.data(kItemFileBaseNameRole).toString().remove('\n'));
QRectF baseNameRect = rect;
baseNameRect.adjust(0, 0, -option.fontMetrics.horizontalAdvance(suffix), 0);
layout->layout(baseNameRect, Qt::ElideRight, nullptr, Qt::NoBrush, &textList);

displayName = textList.join('\n');

auto tmpFileName = displayName;
// get error suffix, so show the file displayname
if (tmpFileName.append(suffix) != itemFileDisplayName.toString()) {
displayName = itemFileDisplayName.toString();
break;
}
// 获取基础名称(不含后缀)
displayName = index.data(kItemFileBaseNameRole).toString().remove('\n');

// 根据设置决定是否显示后缀
bool showSuffix { Application::instance()->genericAttribute(Application::kShowedFileSuffix).toBool() };
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: Suffix display logic is now more direct, but may miss error handling for mismatched display names.

Consider whether removing the display name check could cause issues for files with unusual names or encodings, as the new logic may not always produce the intended display name.

if (showSuffix)
displayName.append(suffix);
} while (false);
}

if (displayName.isEmpty()) {
QStringList textList {};
layout->setText(index.data(role).toString().remove('\n'));
layout->layout(rect, Qt::ElideRight, nullptr, Qt::NoBrush, &textList);

displayName = textList.join('\n');
displayName = index.data(role).toString().remove('\n');
}

return displayName;
Expand Down
Loading