from PySide6.QtCore import QRectF, Qt from PySide6.QtGui import QBrush, QPainter, QPen from PySide6.QtWidgets import QGraphicsEllipseItem, QGraphicsItem, QStyleOptionGraphicsItem, QWidget class SphereGraphicsItem(QGraphicsEllipseItem): SPHERE_WIDTH = 30 def __init__(self, x_pos: int, y_pos: int) -> None: super().__init__(self.SPHERE_WIDTH/2, self.SPHERE_WIDTH/2, self.SPHERE_WIDTH, self.SPHERE_WIDTH) print(f"sphere at {x_pos}:{y_pos}") self.setPos(x_pos, y_pos) brush = QBrush(Qt.GlobalColor.darkBlue) self.setBrush(brush) pen = QPen(Qt.GlobalColor.blue) pen.setWidth(3) self.setPen(pen) self.show() class ArcGraphicsItem(QGraphicsItem): def __init__(self, x_pos: int, y_pos: int, width: int, angle_start: int, angle_end: int, parent: QGraphicsItem | None = ...): super().__init__(parent) shift = int(width/2) self.x_pos = x_pos-shift self.y_pos = y_pos-shift self.width = width*2 self.angle_start = angle_start*16 self.angle_end = angle_end*16 print(f"arc from {self.x_pos}:{self.y_pos} of {self.width} {self.angle_start}° {self.angle_end}°") def paint(self, painter: QPainter, option: QStyleOptionGraphicsItem, widget: QWidget | None = ...) -> None: painter.drawArc(self.x_pos, self.y_pos, self.width, self.width, self.angle_start, self.angle_end) def boundingRect(self) -> QRectF: return QRectF(0, 0, self.x_pos, self.y_pos) class LineGraphicsItem(QGraphicsItem): def __init__(self, begin_x: int, begin_y: int, end_x: int, end_y: int, parent: QGraphicsItem | None = ...) -> None: super().__init__(parent) print(f"line from {begin_x}:{begin_y} to {end_x}:{end_y}") self.begin_x = begin_x self.begin_y = begin_y self.end_x = end_x self.end_y = end_y def paint(self, painter: QPainter, option: QStyleOptionGraphicsItem, widget: QWidget | None = ...) -> None: painter.drawLine(self.begin_x, self.begin_y, self.end_x, self.end_y) def boundingRect(self) -> QRectF: return QRectF(self.begin_x, self.begin_y, self.end_x, self.end_y)