From 50bbf2aacce0e525b8af8956aeffe0fdecd44b5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20R=C3=BCth?= Date: Tue, 18 Oct 2022 15:14:00 +0200 Subject: [PATCH 1/4] fix text clipping MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Sebastian Rüth --- launcher/ui/widgets/ProjectItem.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/launcher/ui/widgets/ProjectItem.cpp b/launcher/ui/widgets/ProjectItem.cpp index 01be88d9..93d3fca1 100644 --- a/launcher/ui/widgets/ProjectItem.cpp +++ b/launcher/ui/widgets/ProjectItem.cpp @@ -91,8 +91,8 @@ void ProjectItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& o } // On the bottom, aligned to the left after the icon, and featuring at most two lines of text (with some margin space to spare) - painter->drawText(rect.x(), rect.y() + rect.height() - 2.2 * opt.fontMetrics.height(), remaining_width, - 2 * opt.fontMetrics.height(), Qt::TextWordWrap, description); + painter->drawText(rect.x(), rect.y() + rect.height() - 2.0 * opt.fontMetrics.height(), remaining_width, + 4 * opt.fontMetrics.height(), Qt::TextWordWrap, description); } painter->restore(); From d6479e133d340dcd5ed265b49149627d8cb4fe5b Mon Sep 17 00:00:00 2001 From: flow Date: Tue, 18 Oct 2022 15:13:02 -0300 Subject: [PATCH 2/4] fix: properly center project descriptions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In particular, this takes into account the space used by the title, so (hopefully) there won't be problems with custom themes with that. Signed-off-by: flow Signed-off-by: Sefa Eyeoglu Signed-off-by: Sebastian Rüth --- launcher/ui/widgets/ProjectItem.cpp | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/launcher/ui/widgets/ProjectItem.cpp b/launcher/ui/widgets/ProjectItem.cpp index 93d3fca1..1011d6e4 100644 --- a/launcher/ui/widgets/ProjectItem.cpp +++ b/launcher/ui/widgets/ProjectItem.cpp @@ -51,6 +51,8 @@ void ProjectItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& o auto remaining_width = rect.width() - icon_width - 2 * icon_x_margin; rect.setRect(rect.x() + icon_width + 2 * icon_x_margin, rect.y(), remaining_width, rect.height()); + int title_height = 0; + { // Title painting auto title = index.data(UserDataTypes::TITLE).toString(); @@ -66,8 +68,10 @@ void ProjectItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& o font.setPointSize(font.pointSize() + 2); painter->setFont(font); + title_height = QFontMetrics(font).height(); + // On the top, aligned to the left after the icon - painter->drawText(rect.x(), rect.y() + QFontMetrics(font).height(), title); + painter->drawText(rect.x(), rect.y() + title_height, title); painter->restore(); } @@ -90,9 +94,19 @@ void ProjectItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& o description += cut_text.at(1).second; } + int description_x = rect.x(); + + // 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. + int description_y = rect.y() + title_height + (rect.height() - title_height) / 2; + if (cut_text.size() == 1) + description_y -= opt.fontMetrics.height() / 2; + else + description_y -= opt.fontMetrics.height(); + // On the bottom, aligned to the left after the icon, and featuring at most two lines of text (with some margin space to spare) - painter->drawText(rect.x(), rect.y() + rect.height() - 2.0 * opt.fontMetrics.height(), remaining_width, - 4 * opt.fontMetrics.height(), Qt::TextWordWrap, description); + painter->drawText(description_x, description_y, remaining_width, + cut_text.size() * opt.fontMetrics.height(), Qt::TextWordWrap, description); } painter->restore(); From b46c4a81e0355189d90f33567b21ac07872fc2a4 Mon Sep 17 00:00:00 2001 From: Sebastian Rueth Date: Thu, 20 Oct 2022 08:02:05 +0200 Subject: [PATCH 3/4] 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 --- launcher/ui/widgets/ProjectItem.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/launcher/ui/widgets/ProjectItem.cpp b/launcher/ui/widgets/ProjectItem.cpp index 1011d6e4..49baf3e8 100644 --- a/launcher/ui/widgets/ProjectItem.cpp +++ b/launcher/ui/widgets/ProjectItem.cpp @@ -86,20 +86,25 @@ void ProjectItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& o // Get first line unconditionally description = cut_text.first().second; + auto num_lines = 1; + // Get second line, elided if needed - if (cut_text.size() > 1) { - if (cut_text.size() > 2) + if (cut_text.size() > 1 && rect.height() - title_height > opt.fontMetrics.height() * 2) { + if (cut_text.size() > 2) { description += opt.fontMetrics.elidedText(cut_text.at(1).second, opt.textElideMode, cut_text.at(1).first); - else + } else { description += cut_text.at(1).second; + } + num_lines += 1; } int description_x = rect.x(); + // 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. 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; else description_y -= opt.fontMetrics.height(); From 5d2763382128fb6ddbdc34ca803dc1b0f582d318 Mon Sep 17 00:00:00 2001 From: flow Date: Thu, 20 Oct 2022 14:51:09 -0300 Subject: [PATCH 4/4] fix: show a single line in ProjectItem's desc. when there's no more space Signed-off-by: flow --- launcher/ui/widgets/ProjectItem.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/launcher/ui/widgets/ProjectItem.cpp b/launcher/ui/widgets/ProjectItem.cpp index 49baf3e8..d1ff9dbc 100644 --- a/launcher/ui/widgets/ProjectItem.cpp +++ b/launcher/ui/widgets/ProjectItem.cpp @@ -89,13 +89,19 @@ 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() > 2) { - description += opt.fontMetrics.elidedText(cut_text.at(1).second, opt.textElideMode, cut_text.at(1).first); + 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 { - description += cut_text.at(1).second; + if (cut_text.size() > 2) { + description += opt.fontMetrics.elidedText(cut_text.at(1).second, opt.textElideMode, cut_text.at(1).first); + } else { + description += cut_text.at(1).second; + } + num_lines += 1; } - num_lines += 1; } int description_x = rect.x();