Repository navigation
fix(viewer): optimize image scaling behavior for selection states - #183
Conversation
Reviewer's GuideUIUpdate image painting to use selection-dependent scaling and center the source rectangle when drawing.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="libimageviewer/viewpanel/contents/imgviewdelegate.cpp" line_range="180" />
<code_context>
- painter->drawImage(pixmapRect,_pixmap,_pixmap.rect().adjusted(adjustx / 2, -adjusty / 2, -adjustx / 2, adjusty / 2));
+
+ // 修复:居中显示时,偏移量应该是正值,负责旋转时计算
+ QRect sourceRect = _pixmap.rect().adjusted(adjustx / 2, adjusty / 2, -adjustx / 2, -adjusty / 2);
+ painter->drawImage(pixmapRect, _pixmap, sourceRect);
</code_context>
<issue_to_address>
**Odd crop sizes distort thumbnails**
When the scaled image's width or height differs from `pixmapRect` by an odd number of pixels, when the scaled image differs from the target by an odd number of pixels, converting the half-deltas to `QRect::adjusted` integer arguments truncates them on both sides. The resulting source rectangle is one pixel off, so `drawImage` slightly rescales the image and the crop is not exactly centered.
Use a floating-point source rectangle or distribute odd-pixel crop margins asymmetrically so the source rectangle matches the target dimensions exactly.
</issue_to_address>| painter->drawImage(pixmapRect,_pixmap,_pixmap.rect().adjusted(adjustx / 2, -adjusty / 2, -adjustx / 2, adjusty / 2)); | ||
|
|
||
| // 修复:居中显示时,偏移量应该是正值,负责旋转时计算 | ||
| QRect sourceRect = _pixmap.rect().adjusted(adjustx / 2, adjusty / 2, -adjustx / 2, -adjusty / 2); |
There was a problem hiding this comment.
⚪ Low · Odd crop sizes distort thumbnails
When the scaled image's width or height differs from pixmapRect by an odd number of pixels, when the scaled image differs from the target by an odd number of pixels, converting the half-deltas to QRect::adjusted integer arguments truncates them on both sides. The resulting source rectangle is one pixel off, so drawImage slightly rescales the image and the crop is not exactly centered.
Use a floating-point source rectangle or distribute odd-pixel crop margins asymmetrically so the source rectangle matches the target dimensions exactly.
Prompt for AI agents
In `libimageviewer/viewpanel/contents/imgviewdelegate.cpp` at line 180:
**Odd crop sizes distort thumbnails**
When the scaled image's width or height differs from `pixmapRect` by an odd number of pixels, when the scaled image differs from the target by an odd number of pixels, converting the half-deltas to `QRect::adjusted` integer arguments truncates them on both sides. The resulting source rectangle is one pixel off, so `drawImage` slightly rescales the image and the crop is not exactly centered.
Use a floating-point source rectangle or distribute odd-pixel crop margins asymmetrically so the source rectangle matches the target dimensions exactly.961cf38 to
4f49f01
Compare
- Selected state: Keep aspect ratio scaling without cropping - Unselected state: Expand to fill while maintaining aspect ratio - Ensures consistent visual presentation across different selection states Log: use different scaling modes based on selection state PMS: BUG-346079
4f49f01 to
26445c3
Compare
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: add-uos, 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 |
deepin pr auto review🤖 AI 代码审查报告📊 总体评价
🔍 详细分析1. 语法逻辑 ✅评价: 语法正确,逻辑清晰 ✅ 通过 潜在问题: 建议: [] 2. 代码质量 ✅评价: 代码结构清晰,注释完整 ✅ 通过 潜在问题: 建议: ['建议将注释 "负责旋转时计算" 修改为更清晰的表达,如 "修正垂直方向的居中偏移"', '建议清理多余的空白行'] 3. 代码性能 ✅评价: 性能良好,资源使用合理 ✅ 通过 潜在问题: 建议: [] 4. 代码安全 🔒评价: 存在0个安全漏洞 ✅ 通过
安全漏洞详情: 建议: [] 💡 改进建议代码示例// 建议的注释措辞修正
// 根据选中状态使用不同的缩放模式
if (backgroundRect.width() != LibImgViewListView::ITEM_NORMAL_WIDTH) {
// 选中状态:保持宽高比
_pixmap = _pixmap.scaled(pixmapRect.size(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
} else {
// 未选中状态:填充整个区域
_pixmap = _pixmap.scaled(pixmapRect.size(), Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation);
}
qreal adjustx = _pixmap.width() - pixmapRect.width();
qreal adjusty = _pixmap.height() - pixmapRect.height();
// 修正垂直方向的居中偏移,对称裁剪上下边
QRect sourceRect = _pixmap.rect().adjusted(adjustx / 2, adjusty / 2, -adjustx / 2, -adjusty / 2);
painter->drawImage(pixmapRect, _pixmap, sourceRect);本报告由 AI 代码审查工具自动生成 |
|
/merge |
Pick #173 to
develop/eaglelog: use different scaling modes based on selection state
bug: https://pms.uniontech.com/bug-view-346079.html
Summary by Sourcery
Adjust image scaling and centering based on selection state to improve thumbnail rendering.
Bug Fixes:
Enhancements: