def boundingRect(self): if not self.source or not self.dest: return QtCore.QRectF() extra = (self.penWidth + self.arrowSize) / 2.0 extra = max(extra, self.fontHeight) return QtCore.QRectF( self.sourcePoint, QtCore.QSizeF(self.destPoint.x() - self.sourcePoint.x(), self.destPoint.y() - self.sourcePoint.y())).normalized().adjusted( -extra, -extra, extra, extra)
def boundingRect(self): if not self.source or not self.dest: return QtCore.QRectF() penWidth = 2.0 # extra padding for edge text #if self._beingHovered: # extra = (penWidth + 10.0) / 2.0 #else: extra = (penWidth + 30.0) / 2.0 # http://lists.trolltech.com/qt-interest/2000-08/thread00439-0.html # bound = QRect(QPoint(min(p0.x(),p1.x(),p2.x(),p3.x()), # min(p0.y(),p1.y(),p2.y(),p3.y())), # QPoint(max(p0.x(),p1.x(),p2.x(),p3.x()), # mxa(p0.y(),p1.y(),p2.y(),p3.y()))); return QtCore.QRectF( self.sourcePoint, QtCore.QSizeF(self.destPoint.x() - self.sourcePoint.x(), self.destPoint.y() - self.sourcePoint.y())).normalized().adjusted( -extra, -extra, extra, extra)
def mousePressEvent(self, event): # CANVAS SCENE printMouseEvent(self, event) modifiers = getKeyboardModifiers() # allow graphics view panning if self.graph._panning: event.ignore() return # if its not a port, then don't draw a line modmidbutton_event = (event.button() == QtCore.Qt.LeftButton and modifiers == QtCore.Qt.AltModifier) if ((event.button() == QtCore.Qt.LeftButton) or (event.button() == QtCore.Qt.MidButton) or modmidbutton_event) \ and isinstance(self.itemAt(event.scenePos()), Port): event.accept() self.startLineDraw(event) # rubber band select # elif ((event.button() == QtCore.Qt.MidButton) or modmidbutton_event): elif ((event.button() == QtCore.Qt.LeftButton) \ and not isinstance(self.itemAt(event.scenePos()), Node) \ and not isinstance(self.itemAt(event.scenePos()), PortEdge)): event.accept() self.unselectAllItems() # reset select before making another self.origin = event.scenePos() self.rubberBand = QtGui.QGraphicsRectItem( QtCore.QRectF(self.origin, QtCore.QSizeF())) self.rubberBand.setPen( QtGui.QPen(QtCore.Qt.gray, 0, QtCore.Qt.SolidLine)) self.rubberBand.setBrush(QtGui.QBrush(QtCore.Qt.lightGray)) self.rubberBand.setZValue(0) self.addItem(self.rubberBand) else: QtGui.QApplication.restoreOverrideCursor() event.ignore() super(CanvasScene, self).mousePressEvent(event)