Skip to content

Commit a15d4a5

Browse files
committed
#187 Resolved graphics quality issues
1 parent d352923 commit a15d4a5

File tree

2 files changed

+22
-21
lines changed

2 files changed

+22
-21
lines changed

src/graphics/canvas.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ class Canvas(QGraphicsView):
1313
def __init__(self, background_colour: Qt.GlobalColor):
1414
super().__init__(None)
1515
self._background_colour = background_colour
16-
self._width = self.geometry().width() - 2
17-
self._height = self.geometry().height() - 2
16+
self._width = self.geometry().width() - 5
17+
self._height = self.geometry().height() - 5
1818
self._recreate_scene()
1919

2020
def paintEvent(self, event):
21-
new_width = self.geometry().width() - 2
22-
new_height = self.geometry().height() - 2
21+
new_width = self.geometry().width() - 5
22+
new_height = self.geometry().height() - 5
2323
if self._width != new_width or self._height != new_height:
2424
self._width = new_width
2525
self._height = new_height
@@ -32,7 +32,7 @@ def _recreate_scene(self):
3232
pixmap.fill(self._background_colour)
3333
painter = QPainter(pixmap)
3434
painter.setRenderHint(QPainter.RenderHint.Antialiasing)
35-
self._paint(painter)
35+
self._paint(painter, self._width, self._height)
3636
painter.end()
3737

3838
scene = QGraphicsScene(0, 0, self._width, self._height)
@@ -42,7 +42,7 @@ def _recreate_scene(self):
4242
self.setScene(scene)
4343

4444
@abstractmethod
45-
def _paint(self, painter: QPainter):
45+
def _paint(self, painter: QPainter, width: int, height: int):
4646
pass
4747

4848
@abstractmethod

src/graphics/track_analysis_canvas.py

+16-15
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from abc import ABC
55

66
from graphics.canvas import Canvas
7-
from PyQt6.QtWidgets import QAbstractGraphicsShapeItem
7+
from PyQt6.QtWidgets import QAbstractGraphicsShapeItem, QGraphicsLineItem, QGraphicsItem
88
from PyQt6.QtGui import QPen, QPainter, QBrush, QColor, QFont, QPainterPath
99
from PyQt6.QtCore import Qt
1010

@@ -70,7 +70,7 @@ def reset_to_blank(self):
7070
def set_track_area(self, track_area: TrackArea):
7171
self._track_area = track_area
7272

73-
def _get_current_scale(self):
73+
def _get_current_scale(self, width: int, height: int):
7474
min_x = self._track_area.min_x
7575
min_y = self._track_area.min_y
7676
max_x = self._track_area.max_x
@@ -79,8 +79,8 @@ def _get_current_scale(self):
7979
x_size = max_x - min_x
8080
y_size = max_y - min_y
8181

82-
x_scale = self.geometry().width() / x_size
83-
y_scale = self.geometry().height() / y_size
82+
x_scale = width / x_size
83+
y_scale = height / y_size
8484

8585
scale = min(x_scale, y_scale)
8686

@@ -89,21 +89,22 @@ def _get_current_scale(self):
8989

9090
return Scale(min_x - x_border, max_y + y_border, scale)
9191

92-
def _paint(self, painter: QPainter):
93-
scale = self._get_current_scale()
92+
def _paint(self, painter: QPainter, width: int, height: int):
93+
scale = self._get_current_scale(width, height)
9494
for f in self._fixed_shapes:
9595
f.paint(painter, scale)
9696

97-
def _get_scene_items(self) -> list[QAbstractGraphicsShapeItem]:
98-
# rect = QGraphicsRectItem(0, 0, self._width / 20, self._height / 20)
99-
# rect.setPos(self._width / 10, self._height / 10)
100-
# brush = QBrush(Qt.GlobalColor.red)
101-
# rect.setBrush(brush)
97+
def _get_scene_items(self) -> list[QGraphicsItem]:
10298
# pen = QPen(Qt.GlobalColor.cyan)
103-
# pen.setWidth(10)
104-
# rect.setPen(pen)
99+
# pen.setWidth(0)
100+
# result = []
101+
# for i in range(0, 200):
102+
# line = QGraphicsLineItem(i * 2, 0, i * 2, 200)
103+
# line.setPos(0, 0)
104+
# line.setPen(pen)
105+
# result.append(line)
105106
#
106-
# return [rect]
107+
# return result
107108
return []
108109

109110
def add_fixed_shape(self, item: FixedShape):
@@ -126,7 +127,7 @@ def paint(self, painter: QPainter, scale: Scale):
126127
painter.setPen(self._pen)
127128
painter.setBrush(self._brush)
128129
radius = self._diameter / 2
129-
if self._diameter >= 3:
130+
if self._diameter >= 2:
130131
painter.drawEllipse(round(x - radius), round(y - radius), self._diameter, self._diameter)
131132
else:
132133
painter.drawPoint(round(x), round(y))

0 commit comments

Comments
 (0)