check space requirements of project description

if there isn't enough space for 2 lines of project description, only
draw one

Signed-off-by: Sebastian Rueth <sebastian.rueth@protonmail.com>
This commit is contained in:
Sebastian Rueth 2022-10-20 08:02:05 +02:00
parent d6479e133d
commit b46c4a81e0
No known key found for this signature in database
GPG Key ID: 4138F52C43DEA038

View File

@ -86,20 +86,25 @@ void ProjectItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& o
// Get first line unconditionally // Get first line unconditionally
description = cut_text.first().second; description = cut_text.first().second;
auto num_lines = 1;
// Get second line, elided if needed // Get second line, elided if needed
if (cut_text.size() > 1) { if (cut_text.size() > 1 && rect.height() - title_height > opt.fontMetrics.height() * 2) {
if (cut_text.size() > 2) if (cut_text.size() > 2) {
description += opt.fontMetrics.elidedText(cut_text.at(1).second, opt.textElideMode, cut_text.at(1).first); description += opt.fontMetrics.elidedText(cut_text.at(1).second, opt.textElideMode, cut_text.at(1).first);
else } else {
description += cut_text.at(1).second; description += cut_text.at(1).second;
} }
num_lines += 1;
}
int description_x = rect.x(); int description_x = rect.x();
// Have the y-value be set based on the number of lines in the description, to centralize the // Have the y-value be set based on the number of lines in the description, to centralize the
// description text with the space between the base and the title. // description text with the space between the base and the title.
int description_y = rect.y() + title_height + (rect.height() - title_height) / 2; int description_y = rect.y() + title_height + (rect.height() - title_height) / 2;
if (cut_text.size() == 1) if (num_lines == 1)
description_y -= opt.fontMetrics.height() / 2; description_y -= opt.fontMetrics.height() / 2;
else else
description_y -= opt.fontMetrics.height(); description_y -= opt.fontMetrics.height();