graphics_edge_item.py 1.1 KB

12345678910111213141516171819202122232425262728293031
  1. """
  2. Edge representation for Qt: Same as a LineItem, but stores items it is connected to
  3. as well as the modelverse edge id.
  4. """
  5. from PyQt5.QtWidgets import QGraphicsItem, QGraphicsLineItem
  6. from sketchUI.graphics_node_item import GraphicsNodeItem
  7. class GraphicsEdgeItem(QGraphicsLineItem):
  8. def __init__(self, from_item, to_item, edge_id=None):
  9. #type: (GraphicsNodeItem, GraphicsNodeItem) -> None
  10. QGraphicsLineItem.__init__(self)
  11. self.from_item = from_item
  12. self.to_item = to_item
  13. self.edge_id = edge_id
  14. self.setFlag(QGraphicsItem.ItemIsMovable, False)
  15. self.setFlag(QGraphicsItem.ItemIsSelectable, True)
  16. self.setZValue(-1.0)
  17. def redraw(self):
  18. from_pos = self.from_item.scenePos()
  19. from_brect = self.from_item.boundingRect()
  20. to_pos = self.to_item.scenePos()
  21. to_brec = self.to_item.boundingRect()
  22. self.setLine(from_pos.x() + int(from_brect.width()/2.0),
  23. from_pos.y() + int(from_brect.height()/2.0),
  24. to_pos.x() + int(to_brec.width()/2.0),
  25. to_pos.y() + int(to_brec.height()/2.0))