Skip to content

fix(shot): clamp resized capture area to annotations - #929

Closed
dengzhongyuan365-dev wants to merge 2 commits into
linuxdeepin:masterfrom
dengzhongyuan365-dev:regonadjust
Closed

dengzhongyuan365-dev wants to merge 2 commits into
linuxdeepin:masterfrom
dengzhongyuan365-dev:regonadjust

Conversation

@dengzhongyuan365-dev

@dengzhongyuan365-dev dengzhongyuan365-dev commented Sep 9, 2026 •

Copy link
Copy Markdown
Member

Clamp screenshot selection resizing by existing annotation bounds.

根据已有标注外接矩形限制截图选区缩放范围。

Log: 修复编辑后缩放选区裁剪标注
PMS: TASK-393987
Influence: 截图编辑后缩小选区时,边界不会越过已有标注外接矩形,避免保存结果裁剪标注内容。

Summary by Sourcery

Keep edited annotations fully included when resizing and saving screenshot selections.

Bug Fixes:

  • Prevent resized screenshot selections from crossing existing annotation bounds, avoiding cropped annotations in saved captures.
  • Preserve annotation positioning and rendering when resizing selections, including correct capture-region handling in Treeland mode.

Enhancements:

  • Improve screenshot editing event handling, cursor behavior, annotation geometry tracking, and selection synchronization across drawing, moving, resizing, rotating, and text editing.

Tests:

  • Add coverage for expanding selections around annotations and preserving annotation screen positions during left-side expansion.

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: dengzhongyuan365-dev

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

@sourcery-ai

sourcery-ai Bot commented Sep 9, 2026

Copy link
Copy Markdown

Reviewer's Guide

The PR adds end-to-end annotation-aware selection resizing: it derives padded bounds from all visible shape content, enforces those bounds during mouse-driven resizing, preserves annotation screen positions as the selection moves, and applies coordinate-correct annotation compositing when saving cropped screenshots, including Treeland handling.

Sequence diagram for annotation-aware selection resizing

sequenceDiagram
    participant User
    participant MainWindow
    participant ShapesWidget

    User->>MainWindow: mousePressEF(mouseEvent)
    MainWindow->>MainWindow: getAction(mouseEvent)
    MainWindow->>ShapesWidget: shapesContentBoundingRectInWindow()
    MainWindow->>MainWindow: constrainSelectionToShapes()
    User->>MainWindow: mouseMoveEF(mouseEvent)
    MainWindow->>MainWindow: resizeLeft/resizeRight/resizeTop/resizeBottom(mouseEvent)
    MainWindow->>MainWindow: constrainSelectionToShapes()
    MainWindow->>ShapesWidget: translateContents(offset)
    MainWindow->>MainWindow: updateSelectionRelatedWidgets()
    User->>MainWindow: mouseReleaseEF(mouseEvent)
    MainWindow->>MainWindow: constrainSelectionToShapes()
    MainWindow->>ShapesWidget: translateContents(offset)
    MainWindow->>MainWindow: updateSelectionRelatedWidgets()
Loading

File-Level Changes

Change Details Files
Adds annotation-aware screenshot selection resizing that prevents existing content from being clipped.
  • Computes annotation bounds, including in-progress and selected/hovered shapes, with drawing safety padding.
  • Constrains all edge and corner resize paths to annotation bounds, minimum sizes, and the capture background.
  • Locks bounds during a resize and translates local annotation coordinates when the selection’s top or left edge moves.
  • Synchronizes the shape widget, toolbar/sidebar, size tips, and repaint state after resizing.
src/main_window.cpp
src/main_window.h
src/widgets/shapeswidget.cpp
src/widgets/shapeswidget.h
Reworks event routing and coordinate handling for edit-mode selection resizing, including Treeland compatibility.
  • Installs a ShapesWidget event filter and routes relevant mouse events through MainWindow while preserving normal widget events and text-editing behavior.
  • Uses window coordinates consistently for cursor hit testing, drag initiation, resizing, and cursor selection.
  • Avoids Treeland capture-region initialization when an editable ShapesWidget exists.
src/main_window.cpp
src/main_window.h
Corrects annotation compositing when saving cropped screenshots.
  • Calculates the saved image origin and crop intersection against the Treeland source region.
  • Paints annotations with the correct offset and scale relative to the cropped image.
  • Separates content rendering from selection/hover editing controls during image export.
src/main_window.cpp
src/widgets/shapeswidget.cpp
src/widgets/shapeswidget.h

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 reviewed your changes and they look great!


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

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

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

Fail


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 代码修复了截图编辑后缩小选区裁剪标注的问题,实现逻辑清晰,边界处理完善,无安全漏洞。代码结构良好,注释充分,测试覆盖合理。

🔍 详细分析

1. 语法逻辑 ✅

评价: 优秀 ✅ 通过

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

建议: 检查语法错误和逻辑一致性


2. 代码质量 ✅

评价: 优秀 ✅ 通过

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

建议: 遵循代码规范和最佳实践


3. 代码性能 ✅

评价: 优秀 ✅ 通过

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

建议: 优化算法复杂度和资源使用


4. 代码安全 🔒

评价: 优秀 ✅ 通过

🔐 发现 0 个安全漏洞

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

建议: 修复安全漏洞,加强输入验证


💡 改进建议代码示例

// 暂无代码示例

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

Clamp screenshot selection resizing by existing annotation bounds.

根据已有标注外接矩形限制截图选区缩放范围。

Log: 修复编辑后缩放选区裁剪标注
PMS: TASK-393987
Influence: 截图编辑后缩小选区时,边界不会越过已有标注外接矩形,避免保存结果裁剪标注内容。
Clamp shape dragging by its painted bounds and keep resize cursor stable.

拖动标注时按外接矩形限制屏幕边界,并稳定拉伸光标状态。

Log: 修复全屏下标注拖动越界和拉伸光标异常
PMS: TASK-393987
Influence: 全屏截图编辑时标注不会在拖动后越出屏幕,拉伸标注时光标状态正确;未满屏时仍可扩张选区。
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