(self, event)
| 2839 | # ── keyboard ───────────────────────────────────────────────────────────── |
| 2840 | |
| 2841 | def keyPressEvent(self, event): |
| 2842 | scene = self.scene() |
| 2843 | |
| 2844 | # While a text item is actively being edited, let Qt dispatch |
| 2845 | # the event normally — don't intercept Backspace, R, Ctrl+C/V, etc. |
| 2846 | focused = scene.focusItem() |
| 2847 | from PySide6.QtWidgets import QGraphicsTextItem |
| 2848 | if (isinstance(focused, QGraphicsTextItem) |
| 2849 | and focused.textInteractionFlags() != Qt.NoTextInteraction): |
| 2850 | super().keyPressEvent(event) |
| 2851 | return |
| 2852 | |
| 2853 | key = event.key() |
| 2854 | mods = event.modifiers() |
| 2855 | |
| 2856 | if key == Qt.Key_Escape: |
| 2857 | if scene._mode == _Mode.DRAWING_LINE: |
| 2858 | # Commit if we have a valid line; otherwise just cancel |
| 2859 | if len(scene._draw_pts) >= 2: |
| 2860 | scene._commit_shape(scene._draw_pts[-1]) |
| 2861 | else: |
| 2862 | scene._cancel_draw() |
| 2863 | elif scene._mode in (_Mode.DRAWING_RECT, _Mode.DRAWING_CIRCLE): |
| 2864 | scene._cancel_draw() |
| 2865 | elif scene._mode == _Mode.WIRING: |
| 2866 | scene.finish_wire() |
| 2867 | else: |
| 2868 | scene.cancel_placement() |
| 2869 | elif key in (Qt.Key_Return, Qt.Key_Enter): |
| 2870 | if scene._mode == _Mode.DRAWING_LINE and len(scene._draw_pts) >= 2: |
| 2871 | scene._commit_shape(scene._draw_pts[-1]) |
| 2872 | else: |
| 2873 | scene.finish_wire() |
| 2874 | elif key == Qt.Key_Slash: |
| 2875 | scene.toggle_elbow() |
| 2876 | elif key == Qt.Key_Z and mods & Qt.ControlModifier: |
| 2877 | if mods & Qt.ShiftModifier: |
| 2878 | scene.redo() |
| 2879 | else: |
| 2880 | scene.undo() |
| 2881 | elif key == Qt.Key_Y and mods & Qt.ControlModifier: |
| 2882 | scene.redo() |
| 2883 | elif key == Qt.Key_R: |
| 2884 | if scene.selectedItems(): |
| 2885 | scene._push_undo() |
| 2886 | for item in scene.selectedItems(): |
| 2887 | item.setRotation(item.rotation() + 90) |
| 2888 | elif key == Qt.Key_M: |
| 2889 | sel = [i for i in scene.selectedItems() if isinstance(i, ComponentItem)] |
| 2890 | if sel: |
| 2891 | scene._push_undo() |
| 2892 | for item in sel: |
| 2893 | item.h_flip = not item.h_flip |
| 2894 | item.apply_transform() |
| 2895 | scene._sync_junctions() |
| 2896 | elif key in (Qt.Key_Delete, Qt.Key_Backspace): |
| 2897 | if scene.selectedItems(): |
| 2898 | scene._push_undo() |
nothing calls this directly
no test coverage detected