fix: show a single line in ProjectItem's desc. when there's no more space

Signed-off-by: flow <flowlnlnln@gmail.com>
This commit is contained in:
flow 2022-10-20 14:51:09 -03:00
parent b46c4a81e0
commit 5d27633821
No known key found for this signature in database
GPG Key ID: 8D0F221F0A59F469

View File

@ -89,7 +89,12 @@ void ProjectItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& o
auto num_lines = 1;
// Get second line, elided if needed
if (cut_text.size() > 1 && rect.height() - title_height > opt.fontMetrics.height() * 2) {
if (cut_text.size() > 1) {
// 2.5x so because there should be some margin left from the 2x so things don't get too squishy.
if (rect.height() - title_height <= 2.5 * opt.fontMetrics.height()) {
// If there's not enough space, show only a single line, elided.
description = opt.fontMetrics.elidedText(description, opt.textElideMode, cut_text.at(0).first);
} else {
if (cut_text.size() > 2) {
description += opt.fontMetrics.elidedText(cut_text.at(1).second, opt.textElideMode, cut_text.at(1).first);
} else {
@ -97,6 +102,7 @@ void ProjectItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& o
}
num_lines += 1;
}
}
int description_x = rect.x();