Skip to content

sync: from linuxdeepin/dde-session-shell - #538

Open
deepin-ci-robot wants to merge 1 commit into
masterfrom
sync-pr-89-nosync
Open

deepin-ci-robot wants to merge 1 commit into
masterfrom
sync-pr-89-nosync

Conversation

@deepin-ci-robot

@deepin-ci-robot deepin-ci-robot commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Synchronize source files from linuxdeepin/dde-session-shell.

Source-pull-request: linuxdeepin/dde-session-shell#89

Summary by Sourcery

Improve password placeholder rendering so text is sized and displayed within the available space alongside embedded controls.

Bug Fixes:

  • Prevent password placeholder text from overlapping embedded icons by sizing and eliding it within the line edit’s actual usable text area.

Enhancements:

  • Account for text and layout margins when sizing and rendering placeholder text in extended line edits.

@deepin-ci-robot

Copy link
Copy Markdown
Contributor Author

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: deepin-ci-robot

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 14, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Synchronizes placeholder rendering with the upstream implementation by calculating an icon-safe text region from QLineEdit margins before eliding and painting the placeholder, preventing overlap with trailing icons while preserving truncation tooltips.

Flow diagram for icon-safe placeholder rendering

flowchart TD
    A[Placeholder paint event] --> B[Read QLineEdit geometry and textMargins]
    B --> C[Calculate icon-safe textRect]
    C --> D[Elide placeholder to textRect width]
    D --> E[Paint placeholder in textRect]
    E --> F{Text was elided}
    F -->|Yes| G[Show full placeholder in tooltip]
    F -->|No| H[Finish rendering]
Loading

File-Level Changes

Change Details Files
Adjust placeholder rendering to respect the embedded line edit’s text margins and avoid overlap with trailing status/action icons.
  • Derive the effective placeholder text rectangle from the line edit geometry and left/right text margins.
  • Use the reduced rectangle width for right-side elision and draw centered single-line placeholder text within it.
  • Retain tooltip behavior when the placeholder is truncated.
src/widgets/dlineeditex.cpp

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 found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="src/widgets/dlineeditex.cpp" line_range="167-169" />
<code_context>
+        // 避免占位文本与右侧图标(大写状态、密码显示、密码提示等)重叠
+        QRect leRect = lineEdit()->geometry();
+        QMargins textMargins = lineEdit()->textMargins();
+        QRect textRect(leRect.x() + textMargins.left(), rect().y(),
+                       leRect.width() - textMargins.left() - textMargins.right(),
+                       rect().height());
+        QString elidedText = fm.elidedText(placeholderText, Qt::ElideRight, textRect.width());
+        pa.drawText(textRect, Qt::AlignCenter | Qt::TextSingleLine, elidedText);
</code_context>
<issue_to_address>
**issue (bug_risk):** The effective placeholder rectangle does not reserve the full space occupied by the embedded controls. In `AuthPassword`, the left text margin is set only to the caps-lock label width while the child layout also has a 10-pixel left content margin, so a sufficiently long centered placeholder extends into the caps-lock icon area.

**Triggers:** When the caps-lock indicator is visible and the placeholder is wide enough to reach the left side of the calculated text rectangle.

**Suggested fix:** Calculate the text rectangle from the actual embedded-control bounds, including the child layout's contents margins and spacing, or include those values in the line edit's text margins.
</issue_to_address>

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

Comment thread src/widgets/dlineeditex.cpp Outdated
Comment on lines +167 to +169
QRect textRect(leRect.x() + textMargins.left(), rect().y(),
leRect.width() - textMargins.left() - textMargins.right(),
rect().height());

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): The effective placeholder rectangle does not reserve the full space occupied by the embedded controls. In AuthPassword, the left text margin is set only to the caps-lock label width while the child layout also has a 10-pixel left content margin, so a sufficiently long centered placeholder extends into the caps-lock icon area.

Triggers: When the caps-lock indicator is visible and the placeholder is wide enough to reach the left side of the calculated text rectangle.

Suggested fix: Calculate the text rectangle from the actual embedded-control bounds, including the child layout's contents margins and spacing, or include those values in the line edit's text margins.

@deepin-bot

deepin-bot Bot commented Sep 22, 2026

Copy link
Copy Markdown

TAG Bot

New tag: 6.0.68
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #548

Synchronize source files from linuxdeepin/dde-session-shell.

Source-pull-request: linuxdeepin/dde-session-shell#89
@deepin-ci-robot

Copy link
Copy Markdown
Contributor Author

deepin pr auto review

🤖 AI 代码审查报告

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

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 代码变更修复了 DLineEditEx 中占位文本字体大小计算和绘制时的边距计算问题,逻辑正确,注释完善,无安全漏洞。OCR 审查确认了 2 处边界条件处理建议。存在少量代码重复可优化空间。代码变更为从上游仓库同步,目的是改善占位文本与图标的重叠问题。

🔍 详细分析

1. 语法逻辑 ✅

评价: 良好 ✅ 通过

潜在问题:

  1. src/widgets/dlineeditex.cpp:91 - availWidth 在控件极窄且边距较大时可能为 0 或负值,此时 while 循环条件恒为 true(文本宽度始终 > 负数),可能导致字体缩到极小。此问题为既有代码模式的延伸,TODO 注释已提及此风险,setPointSize 在参数为负数时不生效提供了自然退出机制。[OCR 确认:bug · medium]
  2. src/widgets/dlineeditex.cpp:178 - textRect.width() 在 leRect.width() 小于边距总和时可能为 0 或负值,Qt 的 elidedText 会返回空字符串,导致占位文本不显示。[OCR 确认:bug · low]

建议: 1. 在 setPlaceholderTextFont 中添加防护:if (availWidth <= 0) { setFont(fontTmp); return; }
2. 在 paintEvent 中添加防护:if (textRect.width() <= 0) return;


2. 代码质量 ✅

评价: 良好 ✅ 通过

潜在问题:

  1. src/widgets/dlineeditex.cpp:83-88, 171-176 - textMargins 和 layoutMargins 的计算逻辑在 setPlaceholderTextFont 和 paintEvent 两个函数中重复出现,包括 QMargins 初始化、layout 空指针检查、contentsMargins 获取等步骤,违反 DRY 原则,建议提取为私有辅助函数。

建议: 建议将边距计算逻辑提取为私有辅助函数 effectiveTextMargins()


3. 代码性能 ✅

评价: 优秀 ✅ 通过

潜在问题:

  1. src/widgets/dlineeditex.cpp:91 - QFontMetrics 在 while 循环内重复构造(既有代码,非本次引入),每次迭代都创建新的 QFontMetrics 对象。

建议: 可将 QFontMetrics 构造移至循环外。此为既有问题,非本次变更引入。


4. 代码安全 🔒

评价: 优秀 ✅ 通过

🔐 发现 0 个安全漏洞

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

建议: 本次变更不涉及安全敏感操作,无需安全加固。


💡 改进建议代码示例

// 1. setPlaceholderTextFont 中添加 availWidth 防护
int availWidth = width() - textMargins.left() - textMargins.right()
               - layoutMargins.left() - layoutMargins.right();
if (availWidth <= 0) {
    setFont(fontTmp);
    return;
}
while (QFontMetrics(fontTmp).boundingRect(text).width() > availWidth) {
    // ...
}

// 2. paintEvent 中添加 textRect.width() 防护
QRect textRect(leRect.x() + leftOffset, rect().y(),
               leRect.width() - leftOffset - rightOffset,
               rect().height());
if (textRect.width() <= 0)
    return;
QString elidedText = fm.elidedText(placeholderText, Qt::ElideRight, textRect.width());

// 3. 提取公共边距计算辅助函数
QMargins DLineEditEx::effectiveTextMargins() const
{
    QMargins textMargins = lineEdit()->textMargins();
    QMargins layoutMargins(0, 0, 0, 0);
    if (auto *layout = lineEdit()->layout()) {
        layoutMargins = layout->contentsMargins();
    }
    return QMargins(
        textMargins.left() + layoutMargins.left(),
        textMargins.top() + layoutMargins.top(),
        textMargins.right() + layoutMargins.right(),
        textMargins.bottom() + layoutMargins.bottom()
    );
}

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

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.

1 participant