MCPcopy Create free account
hub / github.com/SLiCAP/SLiCAP_python / _natural_text_rect

Method _natural_text_rect

SLiCAP/schematic/parameter_item.py:82–105  ·  view source on GitHub ↗

Bounding rect sized to the text content (used when there is no renderer).

(self)

Source from the content-addressed store, hash-verified

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

Callers 1

boundingRectMethod · 0.95

Calls 1

_text_display_linesMethod · 0.95

Tested by

no test coverage detected