Skip to content

fix(viewer): optimize image scaling behavior for selection states - #183

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:develop/eaglefrom
add-uos:pick-pr173-develop-eagle
Nov 17, 2026
Merged

deepin-bot[bot] merged 1 commit into
linuxdeepin:develop/eaglefrom
add-uos:pick-pr173-develop-eagle

Conversation

@add-uos

@add-uos add-uos commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Pick #173 to develop/eagle

  • 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
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:

  • Correct image positioning during scaled rendering to keep thumbnails centered across selection states.

Enhancements:

  • Use aspect-ratio-preserving scaling for selected images and fill-based scaling for unselected images to provide consistent thumbnail presentation.

@sourcery-ai

sourcery-ai Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

UI

Update image painting to use selection-dependent scaling and center the source rectangle when drawing.

  • libimageviewer/viewpanel/contents/imgviewdelegate.cpp L1, L168-181

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨

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);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚪ 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.

@add-uos
add-uos force-pushed the pick-pr173-develop-eagle branch 2 times, most recently from 961cf38 to 4f49f01 Compare November 17, 2026 09:11
 - 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
@add-uos
add-uos force-pushed the pick-pr173-develop-eagle branch from 4f49f01 to 26445c3 Compare November 17, 2026 09:22
@deepin-ci-robot

Copy link
Copy Markdown

[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.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

总体评分: 98 分 (通过阈值: 70分)

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 本次提交修复了图片查看器在不同选中状态下的缩放行为,逻辑清晰正确。选中状态使用 KeepAspectRatio 保持宽高比,未选中状态使用 KeepAspectRatioByExpanding 填充区域; 同时修正了居中显示时的源矩形偏移量计算。代码语法正确、逻辑合理、性能无明显影响、 无安全漏洞。仅存在少量注释措辞和空行格式上的轻微问题。

🔍 详细分析

1. 语法逻辑 ✅

评价: 语法正确,逻辑清晰 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: []


2. 代码质量 ✅

评价: 代码结构清晰,注释完整 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: ['建议将注释 "负责旋转时计算" 修改为更清晰的表达,如 "修正垂直方向的居中偏移"', '建议清理多余的空白行']


3. 代码性能 ✅

评价: 性能良好,资源使用合理 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: []


4. 代码安全 🔒

评价: 存在0个安全漏洞 ✅ 通过

🔐 发现 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 代码审查工具自动生成

@add-uos

add-uos commented Nov 17, 2026

Copy link
Copy Markdown
Contributor Author

/merge

@deepin-bot
deepin-bot Bot merged commit e586bf4 into linuxdeepin:develop/eagle Nov 17, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants