Repository navigation
fix(shot): clamp resized capture area to annotations - #942
Open
dengzhongyuan365-dev wants to merge 2 commits into
Open
dengzhongyuan365-dev wants to merge 2 commits into
dengzhongyuan365-dev wants to merge 2 commits into
Conversation
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: 全屏截图编辑时标注不会在拖动后越出屏幕,拉伸标注时光标状态正确;未满屏时仍可扩张选区。
Reviewer's GuideThe PR reworks screenshot edit-mode event routing and geometry synchronization so capture-area resizing cannot clip existing annotations, while annotation edits can expand the selection within screen limits. It also adjusts annotation export offsets/scaling for Treeland and adds focused regression tests for expansion and coordinate preservation. Sequence diagram for annotation-aware capture-area resizingsequenceDiagram
participant User
participant MainWindow
participant ShapesWidget
User->>MainWindow: MouseButtonPress
MainWindow->>MainWindow: getAction
MainWindow->>MainWindow: shapesContentBoundingRectInWindow
MainWindow->>MainWindow: constrainSelectionToShapes
User->>MainWindow: MouseMove
MainWindow->>MainWindow: resizeTop/resizeBottom/resizeLeft/resizeRight
MainWindow->>MainWindow: constrainSelectionToShapes
MainWindow->>MainWindow: translateShapesForSelectionResize
MainWindow->>ShapesWidget: translateContents
MainWindow->>MainWindow: updateSelectionRelatedWidgets
User->>MainWindow: MouseButtonRelease
MainWindow->>MainWindow: constrainSelectionToShapes
MainWindow->>MainWindow: updateSelectionRelatedWidgets
Sequence diagram for annotation edits expanding the capture areasequenceDiagram
participant User
participant ShapesWidget
participant MainWindow
User->>ShapesWidget: MouseMove
ShapesWidget->>ShapesWidget: handleDrag
ShapesWidget-->>MainWindow: contentsGeometryChanged
MainWindow->>MainWindow: expandSelectionToContents
MainWindow->>MainWindow: shapesContentBoundingRectInWindow
MainWindow->>ShapesWidget: translateContents
MainWindow->>MainWindow: updateSelectionRelatedWidgets
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
[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. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
There was a problem hiding this comment.
Hey - I've found 4 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="src/main_window.cpp" line_range="7601-7608" />
<code_context>
+ const QRect sourceRegion = context->captureRegion().toRect();
+ imageTopLeftInWindow = sourceRegion.topLeft();
+ const QRect currentRegion(recordX, recordY, recordWidth, recordHeight);
+ QRect cropRectInWindow = currentRegion.intersected(sourceRegion);
+ if (!cropRectInWindow.isEmpty()) {
+ imageTopLeftInWindow = cropRectInWindow.topLeft();
+ QRect cropRect = cropRectInWindow;
+ cropRect.translate(-sourceRegion.topLeft());
+ cropRect = cropRect.intersected(QRect(QPoint(0, 0), backgroundImage.size()));
+ if (!cropRect.isEmpty()) {
+ saveImage = backgroundImage.copy(cropRect);
+ }
+ }
</code_context>
<issue_to_address>
**Saved images clip annotation content**
When a selection or annotation extends beyond Treeland’s original capture region, `paintImage` crops to the intersection with the original `captureRegion`, so content outside that region is omitted from the saved image.
Extend or refresh the source capture region before cropping so it covers the full selection and its annotations.
Also at `src/widgets/shapeswidget.cpp:1350-1361`.
</issue_to_address>
### Comment 2
<location path="src/main_window.cpp" line_range="5183-5185" />
<code_context>
return DWidget::eventFilter(obj,event);
bool needRepaint = false;
+ if (isShapesWidgetObject && !isMouseEvent) {
+ return false;
+ }
#undef KeyPress
</code_context>
<issue_to_address>
**Shift resizing stops working**
When the ShapesWidget has focus and the user holds Shift while drawing or resizing an annotation, `eventFilter` returns before calling `keyPressEF` for ShapesWidget events, so `m_isShiftPressed` is never updated and ShapesWidget's key handler does not handle Shift; users cannot draw or resize annotations proportionally while holding Shift.
Keep routing Shift press and release events through the MainWindow handlers before allowing unhandled key events to reach ShapesWidget.
</issue_to_address>
### Comment 3
<location path="src/main_window.cpp" line_range="5304-5305" />
<code_context>
+ return;
+ }
+
+ m_shapesWidget->setFixedSize(qMax(recordWidth - 4, 1), qMax(recordHeight - 4, 1));
+ m_shapesWidget->move(recordX + 2, recordY + 2);
+
+ QRect t_rect(recordX, recordY, recordWidth, recordHeight);
</code_context>
<issue_to_address>
**Annotations shift during Treeland resizing**
When selection geometry is updated in Treeland mode after annotations have been created, `updateShapesWidgetGeometry` moves the ShapesWidget to `recordX + 2, recordY + 2`, although Treeland initially places it at the capture region’s exact origin. Existing annotation coordinates therefore shift relative to the captured content.
Preserve the widget’s original coordinate origin when updating its geometry, or compensate for the initial offset.
</issue_to_address>
### Comment 4
<location path="src/widgets/shapeswidget.cpp" line_range="307-311" />
<code_context>
+ bottom = qMax(bottom, point.y());
+ };
+
+ if (hasMainPoint) {
+ for (const QPointF &point : shape.mainPoints) {
+ unitePoint(point);
+ }
+ }
+ for (const QPointF &point : shape.points) {
</code_context>
<issue_to_address>
**Old annotation positions constrain later edits**
When an arrow or line is dragged from its original position, `handleDrag` moves `points` but leaves `mainPoints` unchanged, while `shapePointRect` and `shapeContentBoundingRect` include both. The stale points keep the old location in the bounds, constraining later dragging and selection resizing.
Make arrow and line bounds follow their moved geometry instead of retaining the old `mainPoints` locations.
Also at `src/widgets/shapeswidget.cpp:1349-1351`, `src/widgets/shapeswidget.cpp:1364-1369`.
</issue_to_address>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix(shot): keep annotations inside screen while dragging
fix(shot): clamp resized capture area to annotations
Summary by Sourcery
Keep screenshot selections and annotations aligned by constraining selection resizing, expanding selections around edited content, and correcting annotation rendering offsets.
New Features:
Bug Fixes:
Enhancements:
Tests: