From 77d91d6625b03b6695b8cb05fd8e82aafa12697b Mon Sep 17 00:00:00 2001 From: lzwind Date: Sun, 15 Nov 2026 13:20:36 +0800 Subject: [PATCH] fix: reserve viewport margin in adjustViewScaleRatio MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. Root cause: adjustViewScaleRatio() used full viewport dimensions to compute scale ratio without reserving any margin 2. Fix: subtract 40px (20px per side) from viewport width and height before computing the scale ratio 3. Impact: both crop and non-crop modes now keep >=20px margin on all sides; no API change, only local variable adjustment Log: canvas now keeps 20px margin on all sides of viewport Influence: 1. Test image loading with various canvas sizes 2. Test crop mode entry/exit with different viewport sizes 3. Verify no regression on manual zoom and page switch fix: 缩放计算预留画布边距 1. 根因:adjustViewScaleRatio() 使用 viewport 全量尺寸计算缩放比, 未预留任何边距 2. 方案:计算缩放比前从 viewport 尺寸中减去 40px(每侧 20px) 3. 影响:裁剪与非裁剪模式均保证四边至少 20px 间距;无接口变更 Log: 画布四边预留 20px 边距,修复裁剪时贴边问题 Influence: 1. 测试不同画布尺寸下的图像加载 2. 测试不同 viewport 尺寸下裁剪模式进出 3. 验证手动缩放和页面切换无回归 PMS: BUG-287307 --- src/frame/ccentralwidget.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/frame/ccentralwidget.cpp b/src/frame/ccentralwidget.cpp index f21cd8be4..3c297fe74 100644 --- a/src/frame/ccentralwidget.cpp +++ b/src/frame/ccentralwidget.cpp @@ -714,8 +714,9 @@ void Page::closeEvent(QCloseEvent *event) void Page::adjustViewScaleRatio() { if (nullptr != view()) { - int viewportWidth = view()->viewport()->width(); - int viewportHeight = view()->viewport()->height(); + const int margin = 20; + int viewportWidth = view()->viewport()->width() - margin * 2; + int viewportHeight = view()->viewport()->height() - margin * 2; qreal sceneWidth = scene()->width(); qreal sceneHeight = scene()->height(); if (viewportWidth < sceneWidth || viewportHeight < sceneHeight) {