def ellipse_path(center, a, b, rotation=0): if not isinstance(center, QPointF): center = QPointF(*center) brect = QRectF(-a, -b, 2 * a, 2 * b) path = QPainterPath() path.addEllipse(brect) if rotation != 0: transform = QTransform().rotate(rotation) path = transform.map(path) path.translate(center) return path
def paint (self, painter, style, widget=None): assert isinstance(painter, QPainter) if self.isSelected(): brush = QBrush(Qt.green) else: brush = QBrush(Qt.white) pen = QPen(Qt.black) circle_path = QPainterPath() circle_path.addEllipse(self.boundingRect()) painter.fillPath(circle_path, brush) painter.strokePath(circle_path, pen) text_path = QPainterPath() text_path.addText(0, 0, QFont(), str(self.node)) box = text_path.boundingRect() text_path.translate(-box.center()) painter.fillPath(text_path, QBrush(Qt.black))
def overlay_for(pt1, pt2, frequency): # Construct the line-geometry, we'll use this to construct the ellipsoid line = QLineF(pt1, pt2) # Determine the radius for the ellipsoid radius = fresnel_radius(line.length(), frequency) # Draw the ellipsoid zone = QPainterPath() zone.addEllipse(QPointF(0., 0.), line.length() / 2, radius) # Rotate the ellipsoid - same angle as the line transform = QTransform() transform.rotate(-line.angle()) zone = transform.map(zone) # Center the zone over the line lc = QRectF(pt1, pt2).center() zc = zone.boundingRect().center() zone.translate(lc.x() - zc.x(), lc.y() - zc.y()) return line, zone