def shape(self): path = QPainterPath() w = self._width + 2 r = QRectF(0, 0, 600 + w, 50 + w) r.translate(-w / 2, -w / 2) path.addRect(r) return path
def shape(self): path = QPainterPath() path.addRect(QRectF(0, 0, 600, 50)) rect = QRectF(0, 0, 10, 10) rect.translate(-10, 20) path.addRect(rect) return path
def __init__(self, x, y, r, start, span, parent=None): self.circle = QRectF(x - r, y - r, 2 * r, 2 * r) self.startAngle = start self.spanAngle = span w = 10 self.boundingRectTemp = self.circle.adjusted(-w, -w, w, w) QGraphicsItem.__init__(self) self._color = QColor('blue')
def __init__(self, r=762, span=48, parent=None): self.radius1 = r - 329 self.radius2 = r + 58 self.circle1 = QRectF(-self.radius1, -self.radius1, 2 * self.radius1, 2 * self.radius1) self.circle2 = QRectF(-self.radius2, -self.radius2, 2 * self.radius2, 2 * self.radius2) self.startAngle = 180 - span self.spanAngle = span w = 10 self.boundingRectTemp = self.circle1.adjusted(-w, -w, w, w) QGraphicsPathItem.__init__(self, parent=parent)
class ArcGraphicsItem(QGraphicsItem): def __init__(self, x, y, r, start, span, parent=None): self.circle = QRectF(x - r, y - r, 2 * r, 2 * r) self.startAngle = start self.spanAngle = span w = 10 self.boundingRectTemp = self.circle.adjusted(-w, -w, w, w) QGraphicsItem.__init__(self) self._color = QColor('blue') def boundingRect(self): # outer most edges return self.boundingRectTemp def paint(self, painter, option, widget): painter.setRenderHint(QPainter.Antialiasing) # Draw arc painter.setBrush(Qt.NoBrush) painter.drawPath(self.shape()) def shape(self): path = QPainterPath() path.arcMoveTo(self.circle, self.startAngle) path.arcTo(self.circle, self.startAngle, self.spanAngle) return path
def __init__(self, x, y, size=60, width=10, parent=None, scene=None): self._width = width s = size + width / 2 QGraphicsEllipseItem.__init__(self, QRectF(-QPoint(s, s), QSizeF(2 * s, 2 * s)), parent) self.setBrush(QBrush(statuscolor[status.OK])) if not parent and scene: scene.addItem(self) self.setPos(x, y) self.setState(status.OK)
def __init__(self, x, y, size=20, parent=None, scene=None): TableBase.__init__(self, x, y, size, parent, scene) self._halowidth = max(size / 4, 10) self._halo = Halo(x, y, size, self._halowidth, self, scene) self._tuberadius = size / 5 p = QPointF(self._tuberadius, self._tuberadius) s = QSizeF(2 * self._tuberadius, 2 * self._tuberadius) self._tube = QGraphicsEllipseItem(QRectF(-p, s), self) self._tube.setPen(QPen(QColor('black'), 3)) self._tube.setBrush(QBrush(QColor('white'))) self._tube.setZValue(20)
def __init__(self, x, y, size=40, parent=None, scene=None): self._origin = QPoint(x, y) self._size = size self._radius = size / 2 if not self._color: self._color = QColor('white') QGraphicsEllipseItem.__init__(self, QRectF(-QPoint(size, size), QSizeF(2 * size, 2 * size)), parent) if not parent and scene: scene.addItem(self) self.setPos(x, y) self.setBrush(QBrush(self._color))
class DetectorBox(QGraphicsPathItem): def __init__(self, r=762, span=48, parent=None): self.radius1 = r - 329 self.radius2 = r + 58 self.circle1 = QRectF(-self.radius1, -self.radius1, 2 * self.radius1, 2 * self.radius1) self.circle2 = QRectF(-self.radius2, -self.radius2, 2 * self.radius2, 2 * self.radius2) self.startAngle = 180 - span self.spanAngle = span w = 10 self.boundingRectTemp = self.circle1.adjusted(-w, -w, w, w) QGraphicsPathItem.__init__(self, parent=parent) def paint(self, painter, options, widget): painter.setRenderHint(QPainter.Antialiasing) painter.setBrush(Qt.NoBrush) painter.drawPath(self.shape()) def shape(self): aoffs = 5 # additional angle for the inner arc path = QPainterPath() # draw inner circle of the detector box path.arcMoveTo(self.circle1, self.startAngle - aoffs) path.arcTo(self.circle1, self.startAngle - aoffs, self.spanAngle + 2 * aoffs) # draw outer circle of the detector box path.arcMoveTo(self.circle2, self.startAngle) path.arcTo(self.circle2, self.startAngle, self.spanAngle) # calculate left inner point of the box tmpLine = QLineF(QPointF(0, 0), QPointF(-self.radius1, 0)) tmpLine.setAngle(tmpLine.angle() + aoffs) # draw left line path.addPolygon(QPolygonF([tmpLine.p2(), QPointF(-self.radius2, 0)])) # calculate right inner point of the box tmpLine = QLineF(QPointF(0, 0), QPointF(-self.radius1, 0)) tmpLine.setAngle(self.startAngle - aoffs) # calculate right outer point of the box line2 = QLineF(QPointF(0, 0), QPointF(-self.radius2, 0)) line2.setAngle(self.startAngle) # draw right line of the box path.addPolygon(QPolygonF([tmpLine.p2(), line2.p2()])) return path
def __init__(self, width, parent=None, scene=None): w = width + 2 if parent and isinstance(parent, QGraphicsRectItem): rect = parent.rect() size = rect.size() size += QSizeF(w, w) rect.setSize(size) else: rect = QRectF() QGraphicsRectItem.__init__(self, rect, parent) transform = QTransform() transform.translate(-w / 2, -w / 2) self.setTransform(transform) self.setBrush(QBrush(statuscolor[status.OK])) self.setPen(QPen(statuscolor[status.OK], width))
def __init__(self, x, y, size=20, parent=None, scene=None): if parent: self._color = parent._color TableBase.__init__(self, x, y, size, parent, scene) if not self._pencolor: self._pencolor = QColor('#666666') self._pen = QPen(self._pencolor, 1) self._pen.setBrush(QBrush(self._pencolor)) sz = size / 3 self._polygon = QGraphicsRectItem( QRectF(-QPointF(sz, sz), QPointF(sz, sz)), self) self._polygon.setBrush(QBrush(self._pencolor)) self._l1 = QGraphicsLineItem(-size, 0, size, 0, self) self._l1.setPen(self._pen) self._l2 = QGraphicsLineItem(0, -size, 0, size, self) self._l2.setPen(self._pen)
def __init__(self, point1=QPointF(0, 0), point2=QPointF(0, 1), point3=QPointF(1, 1)): lineBC = QLineF(point2, point3) lineAC = QLineF(point1, point3) lineBA = QLineF(point2, point1) rad = abs(lineBC.length() / (2 * sin(radians(lineAC.angleTo(lineBA))))) bisectorBC = QLineF(lineBC.pointAt(0.5), lineBC.p2()) bisectorBC.setAngle(lineBC.normalVector().angle()) bisectorBA = QLineF(lineBA.pointAt(0.5), lineBA.p2()) bisectorBA.setAngle(lineBA.normalVector().angle()) center = QPointF() bisectorBA.intersect(bisectorBC, center) self.circle = QRectF(center.x() - rad, center.y() - rad, 2 * rad, 2 * rad) lineOA = QLineF(center, point1) lineOB = QLineF(center, point2) lineOC = QLineF(center, point2) startAngle = lineOA.angle() spanAngle = lineOA.angleTo(lineOC) # Make sure that the span angle covers all three points with the second # point in the middle if abs(spanAngle) < abs(lineOA.angleTo(lineOB)) or \ abs(spanAngle) < abs(lineOB.angleTo(lineOC)): # swap the end point and invert the spanAngle startAngle = lineOC.angle() spanAngle = 360 - self.spanAngle ArcGraphicsItem.__init__(self, center.x(), center.y(), rad, startAngle, spanAngle)