This commit is contained in:
@@ -1,13 +1,23 @@
|
||||
from PySide6.QtCore import QRectF, Qt
|
||||
from PySide6.QtGui import QBrush, QPainter, QPen
|
||||
from PySide6.QtWidgets import QGraphicsEllipseItem, QGraphicsItem, QStyleOptionGraphicsItem, QWidget
|
||||
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)
|
||||
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)
|
||||
@@ -17,36 +27,69 @@ class SphereGraphicsItem(QGraphicsEllipseItem):
|
||||
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 = ...):
|
||||
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}°")
|
||||
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 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:
|
||||
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:
|
||||
|
||||
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:
|
||||
|
||||
Reference in New Issue
Block a user