feat: finally a working super simple pattern
This commit is contained in:
@@ -9,17 +9,29 @@ from PySide6.QtWidgets import (
|
||||
|
||||
|
||||
class SphereGraphicsItem(QGraphicsEllipseItem):
|
||||
"""Single sphere of a static size."""
|
||||
|
||||
SPHERE_WIDTH = 30
|
||||
|
||||
def __init__(self, x_pos: int, y_pos: int) -> None:
|
||||
"""Create a sphere
|
||||
|
||||
Args:
|
||||
x_pos (int): x coordinate of the center
|
||||
y_pos (int): y coordinate of the center
|
||||
"""
|
||||
super().__init__(
|
||||
self.SPHERE_WIDTH / 2,
|
||||
self.SPHERE_WIDTH / 2,
|
||||
x_pos - self.SPHERE_WIDTH / 2,
|
||||
y_pos - self.SPHERE_WIDTH / 2,
|
||||
self.SPHERE_WIDTH,
|
||||
self.SPHERE_WIDTH,
|
||||
)
|
||||
print(f"sphere at {x_pos}:{y_pos}")
|
||||
self.setPos(x_pos, y_pos)
|
||||
self.x_pos = x_pos - self.SPHERE_WIDTH / 2
|
||||
self.y_pos = y_pos - self.SPHERE_WIDTH / 2
|
||||
print(f"sphere at {self.x_pos}:{self.y_pos}")
|
||||
|
||||
# self.setPos(self.x_pos - self.SPHERE_WIDTH/2, self.y_pos - self.SPHERE_WIDTH/2)
|
||||
# super().moveBy(x_pos - center.x(), y_pos - center.y())
|
||||
brush = QBrush(Qt.GlobalColor.darkBlue)
|
||||
self.setBrush(brush)
|
||||
pen = QPen(Qt.GlobalColor.blue)
|
||||
@@ -27,8 +39,13 @@ class SphereGraphicsItem(QGraphicsEllipseItem):
|
||||
self.setPen(pen)
|
||||
self.show()
|
||||
|
||||
def boundingRect(self) -> QRectF:
|
||||
return QRectF(self.x_pos, self.y_pos, self.SPHERE_WIDTH, self.SPHERE_WIDTH)
|
||||
|
||||
|
||||
class ArcGraphicsItem(QGraphicsItem):
|
||||
"""Circle arc."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
x_pos: int,
|
||||
@@ -38,13 +55,25 @@ class ArcGraphicsItem(QGraphicsItem):
|
||||
angle_end: int,
|
||||
parent: QGraphicsItem | None = ...,
|
||||
):
|
||||
"""Construct a circle arc.
|
||||
|
||||
Args:
|
||||
x_pos (int): x center of the circle
|
||||
y_pos (int): y center of the circle
|
||||
width (int): width of the circle
|
||||
angle_start (int): Angle start in human degree
|
||||
angle_end (int): Angle end in human degree
|
||||
parent (QGraphicsItem | None, optional): _description_. Defaults to ....
|
||||
"""
|
||||
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
|
||||
self.width = width
|
||||
self.angle_start = angle_start
|
||||
self.angle_end = angle_end
|
||||
self.draw_angle_start = int(angle_start / 16)
|
||||
self.draw_angle_end = int(angle_end * 16)
|
||||
print(
|
||||
f"arc from {self.x_pos}:{self.y_pos} of {self.width} {self.angle_start}° {self.angle_end}°"
|
||||
)
|
||||
@@ -60,12 +89,12 @@ class ArcGraphicsItem(QGraphicsItem):
|
||||
self.y_pos,
|
||||
self.width,
|
||||
self.width,
|
||||
self.angle_start,
|
||||
self.angle_end,
|
||||
self.draw_angle_start,
|
||||
self.draw_angle_end,
|
||||
)
|
||||
|
||||
def boundingRect(self) -> QRectF:
|
||||
return QRectF(0, 0, self.x_pos, self.y_pos)
|
||||
return QRectF(self.x_pos, self.y_pos, self.width, self.width)
|
||||
|
||||
|
||||
class LineGraphicsItem(QGraphicsItem):
|
||||
|
||||
Reference in New Issue
Block a user