better wallpaper preview positioning

This commit is contained in:
2026-05-21 17:55:31 +02:00
parent 80683800eb
commit 4663c7d683
+16 -18
View File
@@ -38,15 +38,13 @@ RowLayout {
property var displayData property var displayData
readonly property real imageRatio: scaledImg.sourceSize.width / scaledImg.sourceSize.height readonly property real imageRatio: scaledImg.sourceSize.width / scaledImg.sourceSize.height
property real monitorScale: 1.0 property real monitorScale: 1.0
readonly property real scaleDownX: scaledImg.width / scaledImg.sourceSize.width readonly property real scaleDownX: scaledImg.paintedWidth / scaledImg.sourceSize.width
readonly property real scaleDownY: scaledImg.height / scaledImg.sourceSize.height readonly property real scaleDownY: scaledImg.paintedHeight / scaledImg.sourceSize.height
readonly property real scaleX: (scaledImg.sourceSize.width * monitorScale) / scaledImg.width readonly property real scaleX: (scaledImg.sourceSize.width * monitorScale) / scaledImg.paintedWidth
readonly property real scaleY: (scaledImg.sourceSize.height * monitorScale) / scaledImg.height readonly property real scaleY: (scaledImg.sourceSize.height * monitorScale) / scaledImg.paintedHeight
anchors.left: parent.left anchors.fill: parent
anchors.right: parent.right fillMode: Image.PreserveAspectFit
anchors.verticalCenter: parent.verticalCenter
height: width / imageRatio
source: Wallpapers.current source: Wallpapers.current
onPaintedWidthChanged: { onPaintedWidthChanged: {
@@ -74,23 +72,23 @@ RowLayout {
property real aspectRatio: delegate.modelData.width / delegate.modelData.height property real aspectRatio: delegate.modelData.width / delegate.modelData.height
readonly property real baseHeight: baseWidth / aspectRatio readonly property real baseHeight: baseWidth / aspectRatio
readonly property real baseWidth: { readonly property real baseWidth: {
let fittedHeight = scaledImg.height; let fittedHeight = scaledImg.paintedHeight;
let fittedWidth = fittedHeight * aspectRatio; let fittedWidth = fittedHeight * aspectRatio;
if (fittedWidth > scaledImg.width) { if (fittedWidth > scaledImg.paintedWidth) {
fittedWidth = scaledImg.width; fittedWidth = scaledImg.paintedWidth;
fittedHeight = fittedWidth / aspectRatio; fittedHeight = fittedWidth / aspectRatio;
} }
return fittedWidth; return fittedWidth;
} }
readonly property real imageX: (scaledImg.width - scaledImg.width) / 2 readonly property real imageX: (scaledImg.width - scaledImg.paintedWidth) / 2
readonly property real imageY: (scaledImg.height - scaledImg.height) / 2 readonly property real imageY: (scaledImg.height - scaledImg.paintedHeight) / 2
property real zoom: scaledImg.displayData.zoom property real zoom: scaledImg.displayData.zoom
function centerInImage() { function centerInImage() {
x = imageX + (scaledImg.width - width) / 2; x = imageX + (scaledImg.paintedWidth - width) / 2;
y = imageY + (scaledImg.height - height) / 2; y = imageY + (scaledImg.paintedHeight - height) / 2;
} }
function clampToBounds() { function clampToBounds() {
@@ -129,9 +127,9 @@ RowLayout {
let nx = mouseX - cropRect.width * 0.5; let nx = mouseX - cropRect.width * 0.5;
let ny = mouseY - cropRect.height * 0.5; let ny = mouseY - cropRect.height * 0.5;
nx = Math.max(cropRect.imageX, Math.min(nx, cropRect.imageX + scaledImg.width - cropRect.width)); nx = Math.max(cropRect.imageX, Math.min(nx, cropRect.imageX + scaledImg.paintedWidth - cropRect.width));
ny = Math.max(cropRect.imageY, Math.min(ny, cropRect.imageY + scaledImg.height - cropRect.height)); ny = Math.max(cropRect.imageY, Math.min(ny, cropRect.imageY + scaledImg.paintedHeight - cropRect.height));
cropRect.x = nx; cropRect.x = nx;
cropRect.y = ny; cropRect.y = ny;
@@ -150,7 +148,7 @@ RowLayout {
} }
onReleased: { onReleased: {
const croprect = cropRect.mapToItem(scaledImg, 0, 0, cropRect.width, cropRect.height); const croprect = cropRect.mapToItem(scaledImg, 0, 0, cropRect.width, cropRect.height);
const upscaledRect = Qt.rect(croprect.x / scaledImg.width, croprect.y / scaledImg.height, croprect.width / scaledImg.width, croprect.height / scaledImg.height); const upscaledRect = Qt.rect((croprect.x - cropRect.imageX) / scaledImg.paintedWidth, (croprect.y - cropRect.imageY) / scaledImg.paintedHeight, croprect.width / scaledImg.paintedWidth, croprect.height / scaledImg.paintedHeight);
Wallpapers.setCrop(delegate.modelData.name, upscaledRect, croprect, cropRect.zoom); Wallpapers.setCrop(delegate.modelData.name, upscaledRect, croprect, cropRect.zoom);
} }
onWheel: wheel => { onWheel: wheel => {