Skip to content

Commit

Permalink
fix: optimize filename display height in icon view
Browse files Browse the repository at this point in the history
- Limit filename display height to normal height (2 lines) when item is not
  selected or not a single selection target
- Update Chinese comments to English for better code readability
- Keep maximum height display for the last item when it's single selected
  to ensure proper scrollbar appearance

Log: optimize filename display
Bug: https://pms.uniontech.com/bug-view-298351.html
  • Loading branch information
Lighto-Ku authored and deepin-bot[bot] committed Jan 2, 2025
1 parent 0b173f7 commit e2f7120
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,15 @@ void IconItemDelegate::paintItemFileName(QPainter *painter, QRectF iconRect, QPa
layout->setAttribute(ElideTextLayout::kBackgroundRadius, kIconModeRectRadius);
}

// If the filename is very long, sizeHint() will set the height of the last item to maximum
// to make the scrollbar appear on the right side.
// However, when the last item is not a single selection target,
// we don't need to draw the filename at maximum height
if (!isSelected || !singleSelected) {
qreal normalHeight = lineHeight * 2;
labelRect.setHeight(labelRect.height() > normalHeight ? normalHeight : labelRect.height());
}

layout->layout(labelRect, opt.textElideMode, painter, background);
}

Expand All @@ -671,7 +680,8 @@ QSize IconItemDelegate::sizeHint(const QStyleOptionViewItem &, const QModelIndex
int lineHeight = UniversalUtils::getTextLineHeight(index, parent()->parent()->fontMetrics());
size.setHeight(size.height() + 2 * lineHeight);

// 如果有一个选中,名称显示很长时,最后一个index时设置item的高度为最多,右边才会出现滑动块
// If there is one selection and the name is very long,
// set the item height to maximum for the last index to make the scrollbar appear on the right side
if (index.isValid() && parent()->isLastIndex(index) && d->expandedItem
&& d->expandedIndex.isValid() && d->expandedItem->isVisible()) {
d->expandedItem->setIconHeight(parent()->parent()->iconSize().height());
Expand Down

0 comments on commit e2f7120

Please sign in to comment.