fix: DCrumbEdit crumb 自适应容器宽度,修复缩小溢出与放大留白 - #767
Draft
18202781743 wants to merge 3 commits into
Draft
Conversation
drawObject 中带 tagColor 的 crumb 文字由 AlignRight 改为 AlignLeft, 消除放大时色块与文字间的空白;并依据 doc->textWidth() 收缩绘制矩形、 对超长文字做 elidedText 省略,避免缩小侧边栏时标记信息溢出框外。 无 tagColor 分支与 intrinsicSize 保持不变。 新增 ut_dcrumbedit 用例 tagCrumbElidedAndNoOverflowWhenContainerNarrow, 验证容器宽度小于 crumb 宽度时文字省略、不溢出。 Log: 修复预览侧边栏标记在放大/缩小时不自适应的问题 Bug: https://pms.uniontech.com/bug-view-346439.html
Contributor
|
Skipping CI for Draft Pull Request. |
Contributor
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: 18202781743 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 |
Reviewer's GuideAdjusts DCrumbEdit crumb drawing to respect the document’s available width and improve alignment for tagged crumbs, and adds a regression test that verifies text is elided and does not overflow when the container is narrow. Flow diagram for updated CrumbObjectInterface::drawObject rendering logicflowchart TD
A[drawObject called with painter, rect, doc, format] --> B[Compute new_rect from rect margins]
B --> C[Create DCrumbTextFormat crumb_format]
C --> D[Compute QFontMetricsF font_metrics and radius]
D --> E{crumb_format.tagColor is valid?}
E -->|No| F[Draw background with backgroundBrush]
F --> G[Set pen to textColor]
G --> H[drawText new_rect with AlignCenter]
E -->|Yes| I[Check doc->textWidth and right edge]
I --> J{Need shrink?}
J -->|Yes| K[Adjust new_rect.setRight based on doc->textWidth]
K --> L[Draw background with backgroundBrush]
L --> M[save painter and setClipRect new_rect]
M --> N[Compute tag_rect and draw tag_path]
N --> O[Compute textRect from new_rect]
O --> P[Compute displayText via font_metrics.elidedText]
P --> Q[drawText textRect with displayText AlignVCenter|AlignLeft]
Q --> R[restore painter]
J -->|No| S[Draw background with backgroundBrush]
S --> T[Compute tag_rect and draw tag_path]
T --> U[Compute textRect from new_rect]
U --> V[Compute displayText via font_metrics.elidedText]
V --> W[drawText textRect with displayText AlignVCenter|AlignLeft]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
采纳代码审核建议 A(非阻塞优化):带 tagColor 分支中,elidedText 仅在容器宽度不足(shrink=true)时调用,常规宽度直接绘制原文。 行为等价(常规宽度下 elidedText 本就返回原文),但意图更清晰、 省去常规路径的无谓省略计算,并避免将来口径微调导致意外省略号回归。 Log: 优化 DCrumbEdit drawObject 省略逻辑 Bug: https://pms.uniontech.com/bug-view-346439.html
intrinsicSize 带 tagColor 分支将固有宽度限制在文档可用内容宽度内 (doc->textWidth() - 2*documentMargin()),超宽时收缩到 avail, 避免单个超宽 crumb 撑开文档导致水平滚动条。 drawObject 相应简化:删除原 shrink 矩形收缩块(已成死代码), 省略条件改为文字宽度 > 可用宽度时才 elidedText,setClipRect 改为 无条件 save/restore 兜底。 UT 补 EXPECT_LE(doc->idealWidth(), narrowWidth) 断言锁定根因。 Log: 修复单个超宽标记撑开容器出现水平滚动条的问题 Bug: https://pms.uniontech.com/bug-view-346439.html
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.
问题描述
预览侧边栏放大/缩小时,图片标记(DCrumbEdit crumb)自适应不好:
PMS 单:https://pms.uniontech.com/bug-view-346439.html
修复方案
修改
src/widgets/dcrumbedit.cpp中CrumbObjectInterface::drawObject绘制逻辑(intrinsicSize与公开 API 不变,二进制兼容):修改点 A — 文字对齐:带
tagColor的 crumb 文字由Qt::AlignRight改为Qt::AlignLeft,文字紧贴色块右侧,消除放大时色块与文字之间的空白。无tagColor分支(Qt::AlignCenter)保持不变。修改点 B — 文字省略 / 收缩:
drawObject收到的rect始终是intrinsicSize返回的固有宽度,不随容器收窄,因此原elidedText不会真正截断。本次依据doc->textWidth()在绘制阶段收缩绘制矩形(仅当 crumb 右边缘超出文档可用宽度时),收缩后对超长文字做elidedText省略,避免缩小侧边栏时标记信息溢出框外;同时setClipRect兜底防止背景越界。intrinsicSize未动(拿不到可靠视口宽度)。改动文件
src/widgets/dcrumbedit.cppCrumbObjectInterface::drawObject绘制逻辑(+30 −4)tests/testcases/widgets/ut_dcrumbedit.cpptagCrumbElidedAndNoOverflowWhenContainerNarrow用例(+65)单测结果
dtkwidget(DTK6 / Qt 6.8.0)构建并运行
ut_dcrumbedit:ut_DCrumbedit.createMimeDataFromSelection— 既有用例,通过(无回归)ut_DCrumbedit.tagCrumbElidedAndNoOverflowWhenContainerNarrow— 本次新增用例,通过目标用例 2/2 通过;全量回归 433/437 通过(4 项失败均为 offscreen 环境下既有像素/字体对比用例,与本次改动无关)。本次改动关键路径(shrink 收缩、elidedText 省略、AlignLeft 对齐、setClipRect 兜底)均被覆盖。
Summary by Sourcery
Adjust DCrumbEdit crumb rendering to better adapt to the container width and avoid overflow or excessive spacing.
Bug Fixes:
Enhancements:
Tests: