fix(annotation): use text layout positions for ruled lines in note editor#262
Merged
deepin-bot[bot] merged 1 commit intolinuxdeepin:masterfrom Apr 22, 2026
Conversation
472e10a to
0290251
Compare
…itor Use QTextDocument's actual layout (QTextBlock/QTextLine) instead of fixed font metrics height to draw ruled lines, preventing accumulated drift that causes text/line overlap after 10+ lines. 使用QTextDocument实际布局信息绘制注释编辑框横线, 替代固定字体度量的等差递增方式,修复多行文字与行线重叠问题。 Log: 修复注释编辑框多行文字与横线重叠 PMS: BUG-338065 Influence: 注释编辑框输入超过10行时,横线与文字不再错位重叠。
0290251 to
941ab59
Compare
lzwind
approved these changes
Apr 22, 2026
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: lzwind, pengfeixx 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 |
deepin pr auto review这段代码主要重写了 1. 语法逻辑
2. 代码质量
3. 代码性能
4. 代码安全
总结与改进建议这段代码修改是正向的,它修复了横线与文本对齐不准的问题,并提升了代码的可读性。 进一步优化的建议:
修改后的代码片段示例(针对性能优化的建议): // ... 前面的代码保持不变 ...
// Draw ruled lines aligned with actual text layout
pen.setWidth(normalLineHeight);
painter.setPen(pen);
// 用于存储最后一行可见线的坐标,以便在循环外统一处理粗线
QPointF lastVisibleLinePos;
bool hasLastVisibleLine = false;
QTextDocument *doc = this->document();
QTextBlock block = doc->begin();
while (block.isValid()) {
QTextLayout *layout = block.layout();
if (layout) {
QPointF blockPos = layout->position();
for (int i = 0; i < layout->lineCount(); ++i) {
QTextLine textLine = layout->lineAt(i);
qreal lineY = blockPos.y() + textLine.position().y() + textLine.height() - scrollY;
if (lineY < topY)
continue;
if (lineY > viewportHeight)
break;
// 绘制线条
painter.drawLine(QPointF(leftMargin, lineY), QPointF(viewWidth - rightMargin, lineY));
// 记录当前绘制的线条作为“最后一个可见线条”的候选
// 只有当真正滚动到底部且该行接近视口底部时,才需要加粗
if (atBottom && lineY + textLine.height() > viewportHeight) {
lastVisibleLinePos = QPointF(leftMargin, lineY);
hasLastVisibleLine = true;
}
}
}
block = block.next();
}
// 循环结束后,如果需要加粗最后一行,则重绘最后一条线
if (hasLastVisibleLine) {
pen.setWidth(topLineHeight);
painter.setPen(pen);
// 重新绘制最后一条线,覆盖原来的细线
painter.drawLine(lastVisibleLinePos, QPointF(viewWidth - rightMargin, lastVisibleLinePos.y()));
}这个优化减少了 |
Contributor
Author
|
/merge |
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.
Use QTextDocument's actual layout (QTextBlock/QTextLine) instead of fixed font metrics height to draw ruled lines, preventing accumulated drift that causes text/line overlap after 10+ lines.
使用QTextDocument实际布局信息绘制注释编辑框横线,
替代固定字体度量的等差递增方式,修复多行文字与行线重叠问题。
Log: 修复注释编辑框多行文字与横线重叠
PMS: BUG-338065
Influence: 注释编辑框输入超过10行时,横线与文字不再错位重叠。