A clickable hyperlink on the schematic canvas. Displayed as styled text (colour + optional underline) read from Preferences. In SVG/PDF export the label is wrapped in an element so it is clickable in browsers and PDF viewers.
| 9 | |
| 10 | |
| 11 | class HyperlinkItem(QGraphicsSimpleTextItem): |
| 12 | """ |
| 13 | A clickable hyperlink on the schematic canvas. |
| 14 | |
| 15 | Displayed as styled text (colour + optional underline) read from |
| 16 | Preferences. In SVG/PDF export the label is wrapped in an <a href> |
| 17 | element so it is clickable in browsers and PDF viewers. |
| 18 | """ |
| 19 | |
| 20 | def __init__(self, url: str, label: str, pos: QPointF = QPointF(0, 0)): |
| 21 | super().__init__(label or url) |
| 22 | self.url = url |
| 23 | self.label = label |
| 24 | self._apply_style() |
| 25 | self.setPos(pos) |
| 26 | self.setFlag(QGraphicsItem.ItemIsSelectable) |
| 27 | self.setFlag(QGraphicsItem.ItemIsMovable) |
| 28 | self.setFlag(QGraphicsItem.ItemSendsGeometryChanges) |
| 29 | |
| 30 | def _apply_style(self) -> None: |
| 31 | font = QFont(HYPERLINK_FONT_FAMILY, HYPERLINK_FONT_SIZE) |
| 32 | font.setUnderline(HYPERLINK_UNDERLINE) |
| 33 | self.setFont(font) |
| 34 | self.setBrush(QBrush(HYPERLINK_COLOR)) |
| 35 | |
| 36 | def itemChange(self, change, value): |
| 37 | if change == QGraphicsItem.ItemPositionChange: |
| 38 | return snap(value) |
| 39 | return super().itemChange(change, value) |
no outgoing calls
no test coverage detected