Repository navigation
Conversation
1. Root cause: DrawBoard::addPage(Page*) does not call adjustViewScaleRatio() after setCurrentPage(), leaving canvas at 100% scale which overflows the viewport area 2. Fix: add page->adjustViewScaleRatio() after setCurrentPage(page) to auto-fit canvas to viewport, matching image-loading path 3. Impact: new blank page canvas now fits viewport; image loading path unaffected due to idempotent nature of the call Log: fix canvas displayed too large when creating new blank page Influence: 1. Test creating new blank canvas at different resolutions and DPR 2. Verify image loading canvas display has no regression 3. Verify canvas margins are even and not touching screen edges fix: 修复画板新建空白页时画布显示偏大 1. 根因:DrawBoard::addPage(Page*) 在 setCurrentPage() 后未调用 adjustViewScaleRatio(),画布以 100% 比例显示时溢出 viewport 2. 方案:在 setCurrentPage(page) 后补调 adjustViewScaleRatio(), 使空白页自动适配 viewport 缩放,与加载图片路径行为一致 3. 影响:新建空白页画布将自动适配窗口可视区域;加载图片路径 不受影响(调用幂等,无副作用) Log: 修复画板新建空白页时画布显示尺寸偏大的问题 Influence: 1. 测试不同分辨率和 DPR 下新建空白画板的显示效果 2. 验证加载图片时画布显示无回归 3. 验证画布留白均匀、上下不贴边 PMS: BUG-287301
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: lzwind The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Reviewer's GuideUses of the APIFit a newly selected blank page to the viewport by calling its existing scale-adjustment method.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 3 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="src/frame/ccentralwidget.cpp" line_range="881" />
<code_context>
setCurrentPage(page);
+
+ page->adjustViewScaleRatio();
}
</code_context>
<issue_to_address>
**Page construction crashes**
When a `Page` is constructed with a non-null `DrawBoard*` before its context is set, `Page` registers with the board before its context exists, so `adjustViewScaleRatio()` reaches `scene()` with no scene and dereferences the null result, crashing construction.
Ensure the page has a context and scene before invoking `adjustViewScaleRatio()`, or defer the adjustment until they exist.
</issue_to_address>
### Comment 2
<location path="src/frame/ccentralwidget.cpp" line_range="881" />
<code_context>
setCurrentPage(page);
+
+ page->adjustViewScaleRatio();
}
</code_context>
<issue_to_address>
**Imported images appear too small**
When an image is loaded through a path that creates a blank page before replacing its scene rect with the image bounds, `addPage()` scales the default screen-sized scene before the image dimensions are installed, and the later `adjustViewScaleRatio()` does not reset that scale; it either compounds the zoom-out or skips fitting when the image scene fits the viewport, leaving the imported image smaller than intended.
Fit the view after installing the image scene rect, setting the scale from the desired fit instead of retaining or compounding the blank page's scale.
</issue_to_address>
### Comment 3
<location path="src/frame/ccentralwidget.cpp" line_range="881" />
<code_context>
setCurrentPage(page);
+
+ page->adjustViewScaleRatio();
}
</code_context>
<issue_to_address>
**Hidden pages stay undersized**
When a page is added before its window has been shown or its layout has established nonzero viewport dimensions, `adjustViewScaleRatio()` reads the not-yet-laid-out viewport dimensions, computes a zero ratio, and passes it to `PageView::scale()`, which clamps the scale to 0.1. The later resize and show handlers do not fit the page again, so the canvas stays at 10% instead of fitting the viewport.
Defer fitting until the viewport has valid dimensions, and retry the fit after the page is shown or resized.
</issue_to_address>|
|
||
| setCurrentPage(page); | ||
|
|
||
| page->adjustViewScaleRatio(); |
There was a problem hiding this comment.
🟠 High · Page construction crashes
When a Page is constructed with a non-null DrawBoard* before its context is set, Page registers with the board before its context exists, so adjustViewScaleRatio() reaches scene() with no scene and dereferences the null result, crashing construction.
Ensure the page has a context and scene before invoking adjustViewScaleRatio(), or defer the adjustment until they exist.
Prompt for AI agents
In `src/frame/ccentralwidget.cpp` at line 881:
**Page construction crashes**
When a `Page` is constructed with a non-null `DrawBoard*` before its context is set, `Page` registers with the board before its context exists, so `adjustViewScaleRatio()` reaches `scene()` with no scene and dereferences the null result, crashing construction.
Ensure the page has a context and scene before invoking `adjustViewScaleRatio()`, or defer the adjustment until they exist.|
|
||
| setCurrentPage(page); | ||
|
|
||
| page->adjustViewScaleRatio(); |
There was a problem hiding this comment.
🟠 High · Imported images appear too small
When an image is loaded through a path that creates a blank page before replacing its scene rect with the image bounds, addPage() scales the default screen-sized scene before the image dimensions are installed, and the later adjustViewScaleRatio() does not reset that scale; it either compounds the zoom-out or skips fitting when the image scene fits the viewport, leaving the imported image smaller than intended.
Fit the view after installing the image scene rect, setting the scale from the desired fit instead of retaining or compounding the blank page's scale.
Prompt for AI agents
In `src/frame/ccentralwidget.cpp` at line 881:
**Imported images appear too small**
When an image is loaded through a path that creates a blank page before replacing its scene rect with the image bounds, `addPage()` scales the default screen-sized scene before the image dimensions are installed, and the later `adjustViewScaleRatio()` does not reset that scale; it either compounds the zoom-out or skips fitting when the image scene fits the viewport, leaving the imported image smaller than intended.
Fit the view after installing the image scene rect, setting the scale from the desired fit instead of retaining or compounding the blank page's scale.|
|
||
| setCurrentPage(page); | ||
|
|
||
| page->adjustViewScaleRatio(); |
There was a problem hiding this comment.
🟡 Medium · Hidden pages stay undersized
When a page is added before its window has been shown or its layout has established nonzero viewport dimensions, adjustViewScaleRatio() reads the not-yet-laid-out viewport dimensions, computes a zero ratio, and passes it to PageView::scale(), which clamps the scale to 0.1. The later resize and show handlers do not fit the page again, so the canvas stays at 10% instead of fitting the viewport.
Defer fitting until the viewport has valid dimensions, and retry the fit after the page is shown or resized.
Prompt for AI agents
In `src/frame/ccentralwidget.cpp` at line 881:
**Hidden pages stay undersized**
When a page is added before its window has been shown or its layout has established nonzero viewport dimensions, `adjustViewScaleRatio()` reads the not-yet-laid-out viewport dimensions, computes a zero ratio, and passes it to `PageView::scale()`, which clamps the scale to 0.1. The later resize and show handlers do not fit the page again, so the canvas stays at 10% instead of fitting the viewport.
Defer fitting until the viewport has valid dimensions, and retry the fit after the page is shown or resized.
Root Cause Analysis
When deepin-draw creates a new blank page,
DrawBoard::addPage(Page*)(src/frame/ccentralwidget.cpp:871) callssetCurrentPage(page)but does not calladjustViewScaleRatio()to fit the canvas to the viewport. The canvas scene rect is set to screen resolution × DPR inPageContextconstructor, whilePageView's initial scale is 1.0 (100%). Since the viewport is always smaller than the full screen resolution (due to window chrome — title bar, toolbar, side panels), the canvas overflows the viewport at 100% scale, causing the canvas to touch screen edges with uneven margins. The image-loading path (ccentralwidget.cpp:1208) already callsadjustViewScaleRatio()after page creation, but the blank-page creation path does not, creating an inconsistency.Fix
Add
page->adjustViewScaleRatio()aftersetCurrentPage(page)inDrawBoard::addPage(Page*)(src/frame/ccentralwidget.cpp:881), making the blank-page creation path consistent with the image-loading path. The method checks if the canvas is larger than the viewport and adjusts the scale ratio accordingly.Change Safety Assessment
Code Safety
DrawBoard::addPage) was introduced in commitbdcb567b(2021-07-21, architecture refactoring) and is not a product of any historical bug fix — this change does not revert any previous fixadjustViewScaleRatio()is an existing method already called at line 1208 (image-loading path); it has internal null checks and is idempotent (second call is a no-op when canvas already fits viewport)Business Impact Scope
The fix affects canvas display behavior when creating new blank pages in deepin-draw. Users will see the canvas properly fitted within the viewport at 100% scale, instead of overflowing with uneven margins. The image-loading path is unaffected due to the idempotent nature of the additional call. No other modules or features are impacted.
Verification Suggestion
Test creating new blank canvas at different screen resolutions and DPR settings — verify the canvas fits within the viewport with even margins. Also verify image loading canvas display has no regression.
根因分析
deepin-draw 创建新空白页时,
DrawBoard::addPage(Page*)(src/frame/ccentralwidget.cpp:871)调用setCurrentPage(page)后未调用adjustViewScaleRatio()进行缩放适配。画布 scene rect 在PageContext构造函数中被设置为屏幕分辨率 × DPR,而PageView初始缩放比例为 1.0(100%)。由于窗口标题栏、工具栏等 chrome 占用导致 viewport 始终小于全屏分辨率,画布在 100% 比例下溢出 viewport,表现为画板上下贴边、左右留白不均。加载图片路径(ccentralwidget.cpp:1208)已调用adjustViewScaleRatio(),但空白页创建路径未调用,导致两条路径行为不一致。修复方案
在
DrawBoard::addPage(Page*)的setCurrentPage(page)之后添加page->adjustViewScaleRatio()调用(src/frame/ccentralwidget.cpp:881),使空白页创建路径与加载图片路径行为一致。该方法在画布大于 viewport 时自动计算并调整缩放比例。改动安全评估
代码安全评估
DrawBoard::addPage)由 commitbdcb567b(2021-07-21,架构重构)引入,非历史 bug 修复产物——本次改动不撤销任何已有修复adjustViewScaleRatio()是已有方法,在加载图片路径(line 1208)已被稳定调用;内部有 null check,且操作幂等(画布已适配时第二次调用为空操作)业务影响范围
本次修复影响 deepin-draw 新建空白页时的画布显示行为。用户将看到画布在 100% 比例下正确适配窗口可视区域,不再溢出且留白均匀。加载图片路径因调用幂等性不受影响。不影响其他模块或功能。
验证建议
在不同屏幕分辨率和 DPR 设置下测试新建空白画板——验证画布在窗口内正确显示、留白均匀。同时验证加载图片时画布显示无回归。
Summary by Sourcery
Bug Fixes: