From a29f58c023b8497929058ab4272639c8e016a7c1 Mon Sep 17 00:00:00 2001 From: Vxrtrauter <101264710+Vxrtrauter@users.noreply.github.com> Date: Wed, 8 Apr 2026 01:52:08 +0200 Subject: [PATCH] Add fast layout update for image overlay Introduce _apply_layout_fast to update the image overlay quickly on window resize using the cached QImage and FastTransformation. Called from the Resize event handler before the resize timer, it handles wallpaper mode (fast scale, center-crop to parent) and non-wallpaper mode (positioning by state.image_position and state.image_offset) to provide immediate visual feedback without running the heavier _apply_layout. --- src/interface/dialogs/image.py | 36 ++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/interface/dialogs/image.py b/src/interface/dialogs/image.py index 922ce46..408f880 100644 --- a/src/interface/dialogs/image.py +++ b/src/interface/dialogs/image.py @@ -35,6 +35,7 @@ class Image(QObject): def eventFilter(self, obj, event): if obj == self.application and event.type() == QEvent.Type.Resize: if self._current_image_path: + self._apply_layout_fast() self._resize_timer.start() return False @@ -141,6 +142,41 @@ class Image(QObject): self._apply_layout() + def _apply_layout_fast(self): + if self._cached_qimage is None or not state.image_enabled: + return + + parent = self.application + image = self._cached_qimage + + if getattr(state, "image_as_wallpaper", False): + scaled = image.scaled( + parent.size(), + Qt.AspectRatioMode.KeepAspectRatioByExpanding, + Qt.TransformationMode.FastTransformation + ) + cx = (scaled.width() - parent.width()) // 2 + cy = (scaled.height() - parent.height()) // 2 + cropped = scaled.copy(cx, cy, parent.width(), parent.height()) + self.overlay_label.setPixmap(QPixmap.fromImage(cropped)) + self.overlay_label.setGeometry(0, 0, parent.width(), parent.height()) + else: + w = self.overlay_label.width() + h = self.overlay_label.height() + pos = state.image_position + off = int(state.image_offset) + if pos == "top-left": + x, y = off, off + elif pos == "top-right": + x, y = parent.width() - w - off, off + elif pos == "bottom-left": + x, y = off, parent.height() - h - off + elif pos == "center": + x, y = (parent.width() - w) // 2, (parent.height() - h) // 2 + else: + x, y = parent.width() - w - off, parent.height() - h - off + self.overlay_label.move(x, y) + def _apply_layout(self): if self._cached_qimage is None or not state.image_enabled: self.overlay_label.hide()