Repository navigation
fix(reader): align search result content with count text - #431
GongHeng2017 wants to merge 1 commit into
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: GongHeng2017 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 guide (collapsed on small PRs)Reviewer's GuideThis low-risk UI layout fix updates the search result delegate’s paint calculations so content text, count text, and the bottom separator share the same right boundary, improving alignment across sidebar widths. Flow diagram for aligned search result renderingflowchart LR
A["SearchResDelegate.paint"] --> B["Draw count text to option.rect.right() - 20"]
A --> C["Draw content text within contentSize.width"]
A --> D["Draw bottom separator to option.rect.right() - 20"]
B --> E["Shared right boundary"]
C --> E
D --> E
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
1. drawPageContenttext used option.rect.right() as right boundary while drawSearchCount used option.rect.right() - 20, causing a 20px misalignment 2. Adjust contentSize width to use option.rect.right() - textStartX - 20 3. Adjust drawBottomLine endpoint to use option.rect.right() - 20 4. Update SPDX-FileCopyrightText year from 2023 to 2023-2026 Log: Search result content text now right-aligns with search count text in sidebar Influence: 1. Verify search result count text and content text are right-aligned 2. Verify bottom separator line length matches content text width 3. Test with different window widths and search result counts fix(reader): 搜索结果内容文字与数量文字右对齐 1. drawPageContenttext 使用 option.rect.right() 作为右边界,而 drawSearchCount 使用 option.rect.right() - 20,导致两者相差 20px 未居右对齐 2. 将 contentSize 宽度调整为 option.rect.right() - textStartX - 20 3. 将 drawBottomLine 终点调整为 option.rect.right() - 20 4. 更新 SPDX-FileCopyrightText 版权年份从 2023 为 2023-2026 Log: 搜索结果内容文字与搜索数量文字在侧边栏中右对齐 Influence: 1. 验证搜索结果数量文字与内容文字右边界对齐 2. 验证底部分割线长度与内容文字宽度一致 3. 测试不同窗口宽度和搜索结果数量下的对齐效果 PMS: BUG-193245
f091022 to
14536db
Compare
deepin pr auto review🤖 AI 代码审查报告📊 总体评价
🔍 详细分析1. 语法逻辑 ✅评价: 语法正确,逻辑清晰 ✅ 通过 潜在问题: 建议: [] 2. 代码质量 ✅评价: 代码结构清晰,注释完整 ✅ 通过 潜在问题: 建议: ['建议将魔法数字 20 提取为命名常量(如 3. 代码性能 ✅评价: 性能良好,资源使用合理 ✅ 通过 潜在问题: 建议: ['将魔法数字20提取为命名常量 4. 代码安全 🔒评价: 存在0个安全漏洞 ✅ 通过
安全漏洞详情: 建议: [] 💡 改进建议代码示例// 在 paint 方法开头添加命名常量
void SearchResDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
// ... 前置代码 ...
const int rightMargin = 20; // 右边距,与计数文本对齐
// 内容区域宽度计算
QSize contentSize(option.rect.right() - textStartX - rightMargin,
option.rect.height() - pagetextHeight - 2 * margin);
const QString &elidedContentText = Utils::getElidedText(
painter->fontMetrics(), contentSize, contentText, contentOption.alignment());
painter->drawText(QRect(textStartX, option.rect.y() + margin + pagetextHeight,
contentSize.width(), contentSize.height()),
elidedContentText, contentOption);
painter->restore();
// 底部分隔线
painter->save();
int bottomlineHeight = 1;
painter->setPen(QPen(DTK_NAMESPACE::Gui::DGuiApplicationHelper::instance()
->applicationPalette().frameBorder().color(), bottomlineHeight));
painter->drawLine(textStartX, option.rect.bottom() - bottomlineHeight,
option.rect.right() - rightMargin,
option.rect.bottom() - bottomlineHeight);
painter->restore();
}本报告由 AI 代码审查工具自动生成 |
Root Cause Analysis
In
reader/sidebar/SearchResDelegate.cpp, thepaint()method draws search count text with a right boundary atoption.rect.right() - 20(line 81), but the search content text (drawPageContenttext) usesoption.rect.right()as its right boundary (line 97), and the bottom separator line also extends tooption.rect.right()(line 106). This 20px discrepancy causes the search result count text and content text to appear misaligned — the count text has a 20px right margin while the content text extends to the edge.Fix Approach
Adjust the content text width calculation and bottom line endpoint to use
option.rect.right() - 20, matching the search count text's right boundary. Two lines changed inSearchResDelegate.cpp:contentSizewidth:option.rect.right() - textStartX→option.rect.right() - textStartX - 20drawBottomLineendpoint:option.rect.right()→option.rect.right() - 20Change Safety Assessment
Code Safety
paint()methodBusiness Impact Scope
Affects the search results sidebar in the document reader. The search result list items' content text and bottom separator line will now align with the search count text's right boundary. Users will see properly right-aligned search result content.
Verification Suggestion
Verify search result count text, content text, and bottom separator line are all right-aligned in the sidebar search results list. Test with various window widths.
根因分析
在
reader/sidebar/SearchResDelegate.cpp的paint()方法中,搜索数量文字的右边界为option.rect.right() - 20(第 81 行),而搜索内容文字(drawPageContenttext)的右边界为option.rect.right()(第 97 行),底部分割线终点也是option.rect.right()(第 106 行)。这 20px 的差异导致搜索结果数量文字和内容文字未居右对齐。修复方案
将内容文字宽度计算和底线终点的右边界统一调整为
option.rect.right() - 20,与搜索数量文字的右边界一致。SearchResDelegate.cpp改动两处:contentSize宽度:option.rect.right() - textStartX→option.rect.right() - textStartX - 20drawBottomLine终点:option.rect.right()→option.rect.right() - 20改动安全评估
代码安全评估
paint()方法内部业务影响范围
影响文档查看器的搜索结果侧边栏。搜索结果列表项的内容文字和底部分割线将与搜索数量文字的右边界对齐。用户将看到正确右对齐的搜索结果内容。
验证建议
验证侧边栏搜索结果列表中搜索数量文字、内容文字和底部分割线右边界对齐。测试不同窗口宽度下的效果。
Summary by Sourcery
Align reader search result content and separators with the search count boundary.
Bug Fixes:
Chores: