fix: changesMade bool now binding for robustness

This commit is contained in:
2026-09-30 14:26:59 +02:00
parent 62e19b5261
commit a22022e969
2 changed files with 41 additions and 19 deletions
+40 -18
View File
@@ -16,8 +16,20 @@ Item {
readonly property var currentScreen: screens.length > selectedScreenIndex ? screens[selectedScreenIndex] : null readonly property var currentScreen: screens.length > selectedScreenIndex ? screens[selectedScreenIndex] : null
readonly property real maxZoom: 5.0 readonly property real maxZoom: 5.0
readonly property bool changesMade: {
cropRevision;
const r = cropRectLoader.item;
if (!r || !currentScreen || scaledImg.status !== Image.Ready)
return false;
const t = r.savedTarget();
return Math.abs(r.x - t.x) > 0.5 || Math.abs(r.y - t.y) > 0.5 || Math.abs(r.zoom - t.zoom) > 0.001;
}
property int cropRevision: 0
property int buttonRowHeight: Tokens.padding.large * 3 property int buttonRowHeight: Tokens.padding.large * 3
property bool changesMade: false
property var screens: [] property var screens: []
property int selectedScreenIndex: 0 property int selectedScreenIndex: 0
property bool shouldBeActive: true property bool shouldBeActive: true
@@ -42,6 +54,7 @@ Item {
const cropHeightPercent = cropRect.height / cropRect.imageH; const cropHeightPercent = cropRect.height / cropRect.imageH;
Wallpapers.setCrop(currentScreen.name, Qt.rect(cropXPercent, cropYPercent, cropWidthPercent, cropHeightPercent), cropRect.zoom); Wallpapers.setCrop(currentScreen.name, Qt.rect(cropXPercent, cropYPercent, cropWidthPercent, cropHeightPercent), cropRect.zoom);
cropRevision++;
} }
function refreshScreens(): void { function refreshScreens(): void {
@@ -161,8 +174,6 @@ Item {
onInteraction: value => { onInteraction: value => {
wrapper.zoomClipRect(wrapper.zoomFromSlider(value)); wrapper.zoomClipRect(wrapper.zoomFromSlider(value));
} }
onPosChanged: wrapper.changesMade = true
} }
ButtonRow { ButtonRow {
@@ -181,7 +192,6 @@ Item {
onClicked: { onClicked: {
wrapper.syncCropToScreen(); wrapper.syncCropToScreen();
wrapper.changesMade = false;
} }
} }
@@ -198,7 +208,6 @@ Item {
onClicked: { onClicked: {
wrapper.applyCrop(); wrapper.applyCrop();
wrapper.changesMade = false;
} }
} }
} }
@@ -318,19 +327,33 @@ Item {
y = Math.max(imageY, Math.min(y, imageY + imageH - height)); y = Math.max(imageY, Math.min(y, imageY + imageH - height));
} }
// Where the rect should be according to saved data (same rules as a restore).
function savedTarget() {
const data = Wallpapers.getCrop(wrapper.currentScreen.name);
const hasCrop = data && (Math.abs(data.x) > 0.001 || Math.abs(data.y) > 0.001 || Math.abs(data.width - 1.0) > 0.001 || Math.abs(data.height - 1.0) > 0.001);
const z = hasCrop && data.zoom > 0 ? data.zoom : 1.0;
const w = Math.round(baseWidth / z);
const h = Math.round(baseHeight / z);
let tx = hasCrop ? Math.round(imageX + data.x * imageW) : Math.round(imageX + (imageW - w) / 2);
let ty = hasCrop ? Math.round(imageY + data.y * imageH) : Math.round(imageY + (imageH - h) / 2);
tx = Math.max(imageX, Math.min(tx, imageX + imageW - w));
ty = Math.max(imageY, Math.min(ty, imageY + imageH - h));
return {
x: tx,
y: ty,
zoom: z
};
}
function restoreFromData() { function restoreFromData() {
let data = Wallpapers.getCrop(wrapper.currentScreen.name); const t = savedTarget();
zoom = t.zoom;
if (data && (Math.abs(data.x) > 0.001 || Math.abs(data.y) > 0.001 || Math.abs(data.width - 1.0) > 0.001 || Math.abs(data.height - 1.0) > 0.001)) { x = t.x;
zoom = data.zoom > 0 ? data.zoom : 1.0; y = t.y;
x = Math.round(imageX + (data.x * imageW));
y = Math.round(imageY + (data.y * imageH));
clampToBounds();
} else {
zoom = 1.0;
centerInImage();
}
} }
height: Math.round(baseHeight / zoom) height: Math.round(baseHeight / zoom)
@@ -424,7 +447,6 @@ Item {
onPositionChanged: mouse => { onPositionChanged: mouse => {
if (pressed) { if (pressed) {
updateCrop(mouse.x, mouse.y); updateCrop(mouse.x, mouse.y);
wrapper.changesMade = true;
} }
} }
onPressed: mouse => { onPressed: mouse => {
+1 -1
View File
@@ -3,7 +3,7 @@
// @ pragma DefaultEnv QSG_RHI_BACKEND=vulkan // @ pragma DefaultEnv QSG_RHI_BACKEND=vulkan
//@ pragma DefaultEnv QSG_NO_VSYNC=1 //@ pragma DefaultEnv QSG_NO_VSYNC=1
//@ pragma DefaultEnv QS_NO_RELOAD_POPUP=1 //@ pragma DefaultEnv QS_NO_RELOAD_POPUP=1
// @ pragma DefaultEnv QT_SCALE_FACTOR_ROUNDING_POLICY=Round //@ pragma DefaultEnv QT_SCALE_FACTOR_ROUNDING_POLICY=Round
//@ pragma DefaultEnv QT_QUICK_FLICKABLE_WHEEL_DECELERATION=10000 //@ pragma DefaultEnv QT_QUICK_FLICKABLE_WHEEL_DECELERATION=10000
//@ pragma DropExpensiveFonts //@ pragma DropExpensiveFonts
import Quickshell import Quickshell