Skip to content

fix: use DDciIcon for crisp icons under fractional scaling - #94

Draft
tianming-1996 wants to merge 1 commit into
linuxdeepin:release/eaglefrom
tianming-1996:release/eagle
Draft

tianming-1996 wants to merge 1 commit into
linuxdeepin:release/eaglefrom
tianming-1996:release/eagle

Conversation

@tianming-1996

@tianming-1996 tianming-1996 commented Aug 20, 2026 •

Copy link
Copy Markdown

Root Cause Analysis

The OCR window icon aliasing under fractional display scaling (1.5x) on Wayland/Qt5 is caused by MainWidget::setIcons() using QIcon(svg) to set the window icon (src/mainwidget.cpp:692,695,746,749). Under Qt5 Wayland fractional scaling, devicePixelRatio() returns the integer 1 instead of 1.5, so QIcon renders the icon at only 32×32 physical pixels. The compositor must then upscale to 48×48 (32×1.5), producing aliasing. The same file already uses DDciIcon::pixmap(devicePixelRatio(), size, theme) for other icons (copy, export, tip) which correctly handles DPR — only the app icon was left using raw QIcon(svg).

Fix

Replace 4 QIcon(svg) calls with DDciIcon::pixmap(App->devicePixelRatioF(), 32, theme) wrapped as QIcon, add an appicon.dci resource file (dark/light themes), and register it in resource.qrc. This matches the existing DDciIcon usage pattern in the same function. No deviation from the analysis report's recommended fix.

Change Safety Assessment

Code Safety

  • Risk Level: Low
  • Target code originates from a sync commit (c12efa8), not a previous bug fix — this change does not revert any historical fix.
  • Only 4 QIcon(svg) calls within setIcons() are modified; no function signatures, public members, or callers changed. The setIcons() function is called at window init, image open, and window open — impact is limited to icon rendering.

Business Impact Scope

  • OCR window icon display — After taking a screenshot and entering the OCR recognition interface, the window title bar app icon rendering.
  • Affects dark theme and light theme icon rendering paths.
  • No impact on OCR recognition, screenshot capture, or other core functionality.

Verification Suggestion

  1. Test OCR window icon clarity at 1.5x fractional scaling (2560×1600 display).
  2. Verify icon displays correctly at 1.0x integer scaling.
  3. Test icon rendering after switching dark/light themes.
  4. Verify icon clarity at 2.0x scaling.

根因分析

OCR 窗口图标在 Wayland/Qt5 分数缩放(1.5x)下锯齿严重,根因是 MainWidget::setIcons() 使用 QIcon(svg) 设置窗口图标(src/mainwidget.cpp:692,695,746,749)。Qt5 Wayland 分数缩放下 devicePixelRatio() 返回整数 1 而非 1.5,QIcon 仅按 32×32 物理像素渲染,合成器需 48×48(32×1.5),放大 1.5 倍产生锯齿。同文件中其他图标(复制、导出、提示)已正确使用 DDciIcon::pixmap(devicePixelRatio(), size, theme) 处理 DPR,唯独应用图标仍用原始 SVG QIcon。

修复方案

将 4 处 QIcon(svg) 替换为 DDciIcon::pixmap(App->devicePixelRatioF(), 32, theme) 包装为 QIcon,新增 appicon.dci 资源文件(含深色/浅色主题),在 resource.qrc 中注册。与同函数现有 DDciIcon 用法一致,与分析报告推荐方案无偏离。

改动安全评估

代码安全评估

  • 风险等级: 低风险
  • 目标代码来自同步提交 c12efa8,非历史 bug 修复产物,本次改动不撤销任何已有修复。
  • 仅修改 setIcons() 内 4 处 QIcon(svg) 调用,未改函数签名、公开成员或调用方。setIcons() 在窗口初始化、图片打开、窗口打开时调用,影响仅限图标渲染。

业务影响范围

  • OCR 窗口图标显示 — 截图后进入 OCR 识别界面,窗口标题栏应用图标渲染。
  • 影响深色主题和浅色主题图标渲染路径。
  • 不影响 OCR 识别、截图捕获等核心功能。

验证建议

  1. 测试 1.5x 分数缩放下(2560×1600)OCR 窗口图标清晰度。
  2. 验证 1.0x 整数缩放下图标显示正常。
  3. 测试深色/浅色主题切换后图标正确显示。
  4. 验证 2.0x 缩放下图标清晰度。

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

Sorry @tianming-1996, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: tianming-1996

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

@github-actions

github-actions Bot commented Aug 20, 2026 •

Copy link
Copy Markdown

CLA Assistant Lite bot:

如果你是以企业贡献者的身份进行提交,请联系我们签署企业贡献者许可协议
If you submit as corporate contributor, please contact us to sign our Corporate Contributor License Agreement

感谢您的提交,我们非常感谢。 像许多开源项目一样,在接受您的贡献之前,我们要求您签署我们的个人贡献者许可协议。 您只需发布与以下格式相同的评论即可签署个人贡献者许可协议。
Thank you for your submission, we really appreciate it. Like many open-source projects, we ask that you sign our Individual Contributor License Agreement before we can accept your contribution. You can sign the Individual Contributor License Agreement by just posting a Pull Request Comment same as the below format.


I have read the CLA Document and I hereby sign the CLA.

deepin seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You can retrigger this bot by commenting recheck in this Pull Request

@sourcery-ai

sourcery-ai Bot commented Aug 20, 2026

Copy link
Copy Markdown

Reviewer's Guide

This PR throttles mouse wheel zoom in the OCR image viewer, switches to fast image transformation during zoom, clamps zoom scale before applying it, and adds finite-value guards to avoid degenerate transforms and GPU overload-induced crashes, while keeping pinch zoom behavior unchanged.

Sequence diagram for throttled wheel zoom and transformation mode switching

sequenceDiagram
    actor User
    participant ImageView
    participant QTimer
    participant PixmapItem

    User->>ImageView: wheelEvent(QWheelEvent)
    ImageView->>ImageView: m_accumulatedFactor *= qPow(1.2, delta/240.0)
    ImageView->>ImageView: m_wheelPos = event->position().toPoint()
    ImageView->>PixmapItem: setTransformationMode(Qt::FastTransformation)
    ImageView->>QTimer: start()

    QTimer-->>ImageView: onWheelTimerTimeout()
    ImageView->>ImageView: scaleAtPoint(m_wheelPos, m_accumulatedFactor)
    ImageView->>ImageView: setScaleValue(factor)
    ImageView->>ImageView: scale(v, v)
    ImageView->>PixmapItem: setTransformationMode(Qt::SmoothTransformation)
Loading

File-Level Changes

Change Details Files
Introduce a timer-based wheel zoom throttle that accumulates wheel deltas and defers a single zoom operation, using fast transformation during the interaction and restoring smooth transformation afterward.
  • Add QTimer member m_wheelTimer, accumulated factor state, wheel position storage, and an isZooming flag to ImageView
  • Initialize m_wheelTimer in the ImageView constructor as a 50ms single-shot timer connected to a new timeout slot
  • Refactor wheelEvent to use angleDelta/position, guard zero delta, accumulate zoom factor and last wheel position, set fast transformation while zooming, and start the throttle timer
  • Implement onWheelTimerTimeout to apply the accumulated zoom once via scaleAtPoint, reset the accumulated state, clear zooming flag, and restore smooth transformation
src/view/imageview.cpp
src/view/imageview.h
Add stability guards and pre-clamped scaling to prevent degenerate transforms and avoid apply-then-rollback repaints when hitting zoom bounds.
  • Update scaleAtPoint to validate the zoom factor and mapped scene points with qIsFinite and early-return on invalid or non-positive values
  • Add qIsFinite checks on targetScenePos and centerScenePos before calling centerOn to avoid centering on invalid coordinates
  • Change setScaleValue to compute the projected scale, clamp it to MIN_SCALE_FACTOR/MAX_SCALE_FACTOR before calling scale(), and remove the previous rollback logic
  • Ensure fit-image/fit-window flags are consistently cleared after scaling and that scaled percent emission uses the updated m_scal value
src/view/imageview.cpp

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

@tianming-1996 tianming-1996 changed the title fix: throttle wheel zoom to avoid GPU crash fix: use DDciIcon for crisp icons under fractional scaling Oct 28, 2026
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

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

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 本次提交将应用图标从 SVG 格式替换为 DCI 格式,并将 devicePixelRatio() 改为 devicePixelRatioF() 以支持分数缩放下的清晰图标显示。代码变更逻辑正确,语法无误,无安全漏洞,性能良好,代码质量符合规范。

🔍 详细分析

1. 语法逻辑 ✅

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

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

建议: ['无改进建议,代码逻辑正确。']


2. 代码质量 ✅

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

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

建议: ['无改进建议,代码质量良好。']


3. 代码性能 ✅

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

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

建议: ['无改进建议,性能表现良好。']


4. 代码安全 🔒

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

🔐 发现 0 个安全漏洞

安全漏洞详情:
✅ 未发现安全漏洞

建议: ['无改进建议,代码安全合规。']


💡 改进建议代码示例

// 当前代码已正确实现,无需修复。以下为完整正确用法示例: // Dark 主题分支 DDciIcon appIcon(QString(":/assets/appicon.dci")); QPixmap appIconPix = appIcon.pixmap(App->devicePixelRatioF(), 32, DDciIcon::Theme::Dark); App->setWindowIcon(QIcon(appIconPix)); DMainWindow *mainWindow = static_cast<DMainWindow *>(this->parent()); if (mainWindow) {
    mainWindow->titlebar()->setIcon(QIcon(appIconPix));
} // Light 主题分支同理,将 DDciIcon::Theme::Dark 改为 DDciIcon::Theme::Light

本报告由 AI 代码审查工具自动生成

1. Root cause: setIcons() used QIcon(svg) for window icon which does
   not handle fractional DPR on Qt5 Wayland, devicePixelRatio() returns
   integer 1 instead of 1.5, producing 32x32 instead of 48x48 pixels
2. Fix: replace 4 QIcon(svg) calls with DDciIcon::pixmap(devicePixelRatioF(),
   32, theme) wrapped as QIcon, add appicon.dci resource with dark/light
   themes, register in resource.qrc
3. Impact: OCR window icon renders at correct physical pixel density
   under fractional scaling, no behavior change at integer scaling

Log: Fix OCR window icon aliasing under fractional display scaling

Influence:
1. Test OCR window icon clarity at 1.5x fractional scaling
2. Verify icon displays correctly at 1.0x integer scaling
3. Test icon rendering after switching dark/light themes
4. Verify icon clarity at 2.0x scaling

fix: 使用 DDciIcon 替换 QIcon 修复 OCR 应用图标锯齿

1. 根因:setIcons() 使用 QIcon(svg) 设置窗口图标,Qt5 Wayland 分数缩放
   下 devicePixelRatio() 返回整数 1 而非 1.5,图标仅按 32x32 物理像素渲染
2. 方案:将 4 处 QIcon(svg) 替换为 DDciIcon::pixmap(devicePixelRatioF(),
   32, theme) 包装为 QIcon,新增 appicon.dci 资源文件(含深色/浅色主题),
   在 resource.qrc 中注册
3. 影响:OCR 窗口图标在分数缩放下按正确物理像素密度渲染,整数缩放下无行为变化

Log: 修复分数缩放下 OCR 窗口图标锯齿问题

Influence:
1. 测试 1.5x 分数缩放下 OCR 窗口图标清晰度
2. 验证 1.0x 整数缩放下图标显示正常
3. 测试深色/浅色主题切换后图标正确显示
4. 验证 2.0x 缩放下图标清晰度

PMS: BUG-193447
@tianming-1996
tianming-1996 marked this pull request as draft October 29, 2026 20:06
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.

2 participants