Render exclusion outlines on overlay preview
This commit is contained in:
parent
b882e5d751
commit
0fd527cd78
|
|
@ -929,7 +929,8 @@ class MainWindow(QtWidgets.QMainWindow, I18nMixin):
|
|||
self.image_view.set_pixmap(preview_pix)
|
||||
self.image_view.set_shapes(self.processor.exclude_shapes.copy())
|
||||
self.overlay_view.setText("")
|
||||
self.overlay_view.setPixmap(overlay_pix)
|
||||
overlay_pix = self._overlay_with_outlines(overlay_pix)
|
||||
self.overlay_view.setPixmap(overlay_pix)
|
||||
if self._current_image_path and self.processor.preview_img:
|
||||
width, height = self.processor.preview_img.size
|
||||
total = len(self.processor.preview_paths)
|
||||
|
|
@ -952,9 +953,39 @@ class MainWindow(QtWidgets.QMainWindow, I18nMixin):
|
|||
self.overlay_view.setPixmap(QtGui.QPixmap())
|
||||
else:
|
||||
self.overlay_view.setText("")
|
||||
self.overlay_view.setPixmap(pix)
|
||||
self.overlay_view.setPixmap(self._overlay_with_outlines(pix))
|
||||
self.ratio_label.setText(self.processor.stats.summary(self._t))
|
||||
|
||||
def _on_shapes_changed(self, shapes: list[dict[str, object]]) -> None:
|
||||
self.processor.set_exclusions(shapes)
|
||||
self._refresh_overlay_only()
|
||||
|
||||
def _overlay_with_outlines(self, pixmap: QtGui.QPixmap) -> QtGui.QPixmap:
|
||||
if pixmap.isNull() or not self.processor.exclude_shapes:
|
||||
return pixmap
|
||||
result = QtGui.QPixmap(pixmap)
|
||||
painter = QtGui.QPainter(result)
|
||||
colour = QtGui.QColor(THEMES[self.current_theme]["highlight"])
|
||||
pen = QtGui.QPen(colour)
|
||||
pen.setWidth(3)
|
||||
pen.setCosmetic(True)
|
||||
pen.setCapStyle(QtCore.Qt.RoundCap)
|
||||
pen.setJoinStyle(QtCore.Qt.RoundJoin)
|
||||
painter.setPen(pen)
|
||||
for shape in self.processor.exclude_shapes:
|
||||
kind = shape.get("kind")
|
||||
if kind == "rect":
|
||||
x0, y0, x1, y1 = shape["coords"] # type: ignore[index]
|
||||
painter.drawRect(QtCore.QRectF(x0, y0, x1 - x0, y1 - y0))
|
||||
elif kind == "polygon":
|
||||
points = shape.get("points", [])
|
||||
if len(points) >= 2:
|
||||
path = QtGui.QPainterPath()
|
||||
first = QtCore.QPointF(*points[0])
|
||||
path.moveTo(first)
|
||||
for px, py in points[1:]:
|
||||
path.lineTo(px, py)
|
||||
path.closeSubpath()
|
||||
painter.drawPath(path)
|
||||
painter.end()
|
||||
return result
|
||||
|
|
|
|||
Loading…
Reference in New Issue