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

Method _update_draw_ghost

SLiCAP/schematic/canvas.py:836–882  ·  view source on GitHub ↗
(self, scene_pos: QPointF)

Source from the content-addressed store, hash-verified

834 self.placing_cancelled.emit()
835
836 def _update_draw_ghost(self, scene_pos: QPointF) -> None:
837 from .shape_item import ShapeItem
838 from . import config as cfg
839 color = "#000000"
840 lw = 1.5
841
842 if self._mode == _Mode.DRAWING_LINE:
843 pts = self._draw_pts + [scene_pos]
844 if len(pts) < 2:
845 if self._draw_ghost and self._draw_ghost.scene():
846 self.removeItem(self._draw_ghost)
847 self._draw_ghost = None
848 return
849 anchor = pts[0]
850 rel = [QPointF(p.x() - anchor.x(), p.y() - anchor.y()) for p in pts]
851 kind_g = "line"
852
853 elif self._mode == _Mode.DRAWING_RECT:
854 if self._draw_anchor is None:
855 return
856 anchor = self._draw_anchor
857 rel = [QPointF(0, 0),
858 QPointF(scene_pos.x() - anchor.x(),
859 scene_pos.y() - anchor.y())]
860 kind_g = "rect"
861
862 elif self._mode == _Mode.DRAWING_CIRCLE:
863 if self._draw_anchor is None:
864 return
865 anchor = self._draw_anchor
866 rel = [QPointF(0, 0),
867 QPointF(scene_pos.x() - anchor.x(),
868 scene_pos.y() - anchor.y())]
869 kind_g = "circle"
870 else:
871 return
872
873 if self._draw_ghost and self._draw_ghost.scene():
874 self.removeItem(self._draw_ghost)
875 ghost = ShapeItem(kind_g, rel, stroke_color=color, line_width=lw,
876 pos=anchor)
877 ghost.setOpacity(0.45)
878 ghost.setFlag(QGraphicsItem.ItemIsSelectable, False)
879 ghost.setFlag(QGraphicsItem.ItemIsMovable, False)
880 ghost.setAcceptedMouseButtons(Qt.NoButton)
881 self._draw_ghost = ghost
882 self.addItem(ghost)
883
884 def _commit_shape(self, scene_pos: QPointF) -> None:
885 """Finalise the current shape and add it to the scene."""

Callers 1

mouseMoveEventMethod · 0.95

Calls 1

ShapeItemClass · 0.85

Tested by

no test coverage detected