Bounding rect sized to the text content (used when there is no renderer).
(self)
| 80 | return path |
| 81 | |
| 82 | def _natural_text_rect(self) -> QRectF: |
| 83 | """Bounding rect sized to the text content (used when there is no renderer).""" |
| 84 | hdr_font = QFont(COMP_REFDES_FONT_FAMILY) |
| 85 | hdr_font.setBold(True) |
| 86 | hdr_font.setPointSizeF(COMP_LABEL_FONT_SIZE) |
| 87 | body_font = QFont(COMP_REFDES_FONT_FAMILY) |
| 88 | body_font.setPointSizeF(COMP_LABEL_FONT_SIZE) |
| 89 | |
| 90 | fm_h = QFontMetricsF(hdr_font) |
| 91 | fm_b = QFontMetricsF(body_font) |
| 92 | |
| 93 | lines = self._text_display_lines() |
| 94 | pad = fm_b.height() * 0.3 |
| 95 | line_h = fm_b.height() * _LINE_SPACING |
| 96 | |
| 97 | widths = [fm_h.horizontalAdvance(lines[0])] + [ |
| 98 | fm_b.horizontalAdvance(l) for l in lines[1:] |
| 99 | ] |
| 100 | max_w = max(widths) if widths else 10.0 |
| 101 | |
| 102 | total_w = max_w + 2 * pad |
| 103 | total_h = pad + fm_h.height() + len(lines[1:]) * line_h + pad |
| 104 | |
| 105 | return QRectF(0, 0, max(1.0, total_w), max(1.0, total_h)) |
| 106 | |
| 107 | # ── paint ───────────────────────────────────────────────────────────────── |
| 108 |
no test coverage detected