diff src/gui/widgets/elided_label.cc @ 273:f31305b9f60a

*: various code safety changes this also makes the code build on Qt 5.7. I can't test it though because I don't have it working... FAIL!
author Paper <paper@paper.us.eu.org>
date Thu, 18 Apr 2024 16:53:17 -0400
parents 862d0d8619f6
children 6b0768158dcd
line wrap: on
line diff
--- a/src/gui/widgets/elided_label.cc	Thu Apr 18 16:51:35 2024 -0400
+++ b/src/gui/widgets/elided_label.cc	Thu Apr 18 16:53:17 2024 -0400
@@ -49,32 +49,30 @@
 	QFrame::paintEvent(event);
 
 	QPainter painter(this);
-	QFontMetrics fontMetrics = painter.fontMetrics();
+	QFontMetrics metrics = painter.fontMetrics();
 
-	int line_spacing = fontMetrics.lineSpacing();
+	const int line_spacing = metrics.lineSpacing();
 	int y = 0;
 
-	QTextLayout textLayout(content, painter.font());
-	textLayout.beginLayout();
+	QTextLayout text_layout(content, painter.font());
+	text_layout.beginLayout();
 	for (;;) {
-		QTextLine line = textLayout.createLine();
-
+		QTextLine line = text_layout.createLine();
 		if (!line.isValid())
 			break;
 
 		line.setLineWidth(width());
-		int nextLineY = y + line_spacing;
 
-		if (height() >= nextLineY + line_spacing) {
+		if (height() >= y + (2 * line_spacing)) {
 			line.draw(&painter, QPoint(0, y));
-			y = nextLineY;
+			y += line_spacing;
 		} else {
 			QString last_line = content.mid(line.textStart());
-			QString elided_last_line = fontMetrics.elidedText(last_line, Qt::ElideRight, width());
-			painter.drawText(QPoint(0, y + fontMetrics.ascent()), elided_last_line);
-			line = textLayout.createLine();
+			QString elided_last_line = metrics.elidedText(last_line, Qt::ElideRight, width());
+			painter.drawText(QPoint(0, y + metrics.ascent()), elided_last_line);
+			line = text_layout.createLine();
 			break;
 		}
 	}
-	textLayout.endLayout();
+	text_layout.endLayout();
 }