Esempio n. 1
0
class Beam(QGraphicsLineItem):
    """Class representing the neutron beam."""
    def __init__(self, fromObj, toObj, parent=None, scene=None):
        self._start = fromObj
        self._end = toObj
        QGraphicsLineItem.__init__(self, parent)
        self.setPen(QPen(QColor('white'), 4))
        self._beam = QGraphicsLineItem(parent)
        self._beam.setPen(QPen(QColor('blue'), 1))
        if not parent and scene:
            scene.addItem(self)
            scene.addItem(self._beam)
        self.update()
        self.setZValue(50)
        self._beam.setZValue(51)

    def paint(self, painter, options, widget):
        self.setLine(QLineF(self._start.scenePos(), self._end.scenePos()))
        QGraphicsLineItem.paint(self, painter, options, widget)

    def setLine(self, line):
        self._beam.setLine(line)
        QGraphicsLineItem.setLine(self, line)

    def boundingRect(self):
        # This refreshes the bounding rect
        self.setLine(QLineF(self._start.scenePos(), self._end.scenePos()))
        return QGraphicsLineItem.boundingRect(self)
Esempio n. 2
0
 def setLine(self, line):
     self._beam.setLine(line)
     QGraphicsLineItem.setLine(self, line)