Multi-line text input dialog for placing/editing a text annotation.
| 6 | |
| 7 | |
| 8 | class TextDialog(QDialog): |
| 9 | """Multi-line text input dialog for placing/editing a text annotation.""" |
| 10 | |
| 11 | def __init__(self, text: str = "", parent=None): |
| 12 | super().__init__(parent, Qt.Window) |
| 13 | self.setWindowTitle("Text") |
| 14 | self.setMinimumWidth(360) |
| 15 | |
| 16 | from .config import TEXT_FONT_FAMILY, TEXT_FONT_SIZE, TEXT_COLOR |
| 17 | |
| 18 | outer = QVBoxLayout() |
| 19 | outer.setSizeConstraint(QLayout.SetMinimumSize) |
| 20 | self.setLayout(outer) |
| 21 | |
| 22 | # Info line showing current Preferences settings (non-editable). |
| 23 | info = QLabel( |
| 24 | f"Font: {TEXT_FONT_FAMILY}, {TEXT_FONT_SIZE} pt, " |
| 25 | f"colour: {TEXT_COLOR.name()}" |
| 26 | ) |
| 27 | info.setStyleSheet("color: grey; font-size: 8pt;") |
| 28 | outer.addWidget(info) |
| 29 | |
| 30 | self._edit = QPlainTextEdit() |
| 31 | self._edit.setMinimumHeight(100) |
| 32 | self._edit.setPlainText(text) |
| 33 | outer.addWidget(self._edit) |
| 34 | |
| 35 | buttons = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) |
| 36 | buttons.accepted.connect(self.accept) |
| 37 | buttons.rejected.connect(self.reject) |
| 38 | outer.addWidget(buttons) |
| 39 | |
| 40 | self._edit.setFocus() |
| 41 | # Select all so user can immediately replace existing text. |
| 42 | self._edit.selectAll() |
| 43 | |
| 44 | def text(self) -> str: |
| 45 | return self._edit.toPlainText() |
no outgoing calls
no test coverage detected