From 0fd527cd78a65de740ba54a9028aab6bf7deabbc Mon Sep 17 00:00:00 2001 From: lm Date: Sun, 19 Oct 2025 20:05:11 +0200 Subject: [PATCH] Render exclusion outlines on overlay preview --- app/qt/main_window.py | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/app/qt/main_window.py b/app/qt/main_window.py index b7c1547..6fe4959 100644 --- a/app/qt/main_window.py +++ b/app/qt/main_window.py @@ -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