Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: mhduiy 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 GuideUpdates DLineEditEx placeholder painting to account for QLineEdit text margins, preventing long placeholder text from overlapping right-side icons while preserving existing elision and tooltip behavior. Sequence diagram for margin-aware placeholder paintingsequenceDiagram
participant PaintSystem
participant DLineEditEx
participant QLineEdit
PaintSystem->>DLineEditEx: paintEvent(event)
DLineEditEx->>QLineEdit: placeholderText()
DLineEditEx->>QLineEdit: geometry()
DLineEditEx->>QLineEdit: textMargins()
DLineEditEx->>DLineEditEx: elidedText(placeholderText, Qt::ElideRight, textRect.width())
DLineEditEx->>DLineEditEx: drawText(textRect, Qt::AlignCenter | Qt::TextSingleLine, elidedText)
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
1. Root cause: first fix (BUG-351887) read textMargins but missed the passwordLayout contentsMargins(10,0,10,0) set in AuthPassword::initUI, leaving ~10px gap on the right where text still overlapped icons 2. Fix: in paintEvent(), combine textMargins + layout()->contentsMargins() to compute the effective text rect; in setPlaceholderTextFont(), use the same effective width as the font-shrink threshold 3. Impact: only affects placeholder text rendering when input is empty and focused; normal text input/display unaffected Log: 修复占位文本省略宽度未包含 layout contentsMargins 导致仍与图标重叠 Influence: 1. 测试输入错误密码后密码框清空时占位提示文本不与图标重叠 2. 验证大写状态、密码显示、密码提示图标区域无文本覆盖 3. 测试无图标的 DLineEditEx 占位文本正常居中显示 PMS: BUG-351887
e2e3c43 to
1dac660
Compare
Synchronize source files from linuxdeepin/dde-session-shell. Source-pull-request: linuxdeepin/dde-session-shell#89
deepin pr auto review🤖 AI 代码审查报告📊 总体评价
🔍 详细分析1. 语法逻辑 ✓(22/25分)评价: 语法正确,逻辑清晰 ✓ 通过 潜在问题:
建议: int availWidth = width() - textMargins.left() - textMargins.right()
- layoutMargins.left() - layoutMargins.right();
if (availWidth <= 0) {
qWarning() << "DLineEditEx available width is non-positive:" << availWidth;
return;
}
while (QFontMetrics(fontTmp).boundingRect(text).width() > availWidth) {2. 代码质量 ✓(20/25分)评价: 代码结构清晰,注释完整 ✓ 通过 潜在问题:
建议: // 抽取公共计算逻辑为辅助方法
int DLineEditEx::effectiveTextWidth() const
{
QMargins textMargins = lineEdit()->textMargins();
QMargins layoutMargins(0, 0, 0, 0);
if (auto *layout = lineEdit()->layout()) {
layoutMargins = layout->contentsMargins();
}
return width() - textMargins.left() - textMargins.right()
- layoutMargins.left() - layoutMargins.right();
}
// 修复 qDebug 日志
qDebug() << "Password line edit placeholder text width : "
<< QFontMetrics(fontTmp).boundingRect(text).width()
<< " available width : " << availWidth;3. 代码性能 ✓(20/20分)评价: 性能良好,资源使用合理 ✓ 通过 潜在问题: 新增的 4. 代码安全 ✓(30/30分)评价: 存在0个安全漏洞 ✓ 通过
安全漏洞详情: 漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个 📝 代码变更概述本次 PR 修复了 BUG-351887,解决 修改点 1:
修改点 2:
审查结论: 本报告由 AI 代码审查工具自动生成 |
|
已创建替代 PR #99(https://github.com/linuxdeepin/dde-session-shell/pull/99),使用主仓库分支而非 fork 分支,解决 cppcheck CI 因 fork PR 安全限制无法运行的问题。请在新 PR 上审核合并。 |
Root Cause Analysis
DLineEditEx::paintEvent()usesrect().width()(the full widget width) as the elision width when drawing placeholder text, ignoring thetextMarginsthatAuthPassword::updatePasswordTextMargins()has already set on the internalQLineEditto account for right-side icons (capslock status, password visibility toggle, password hint). This causes the elided placeholder text to extend into the icon area and visually overlap with the icons. Key evidence:dlineeditex.cpp:163usesrect().width()whileauth_password.cpp:972-991correctly setstextMargins— butpaintEventnever reads them.Fix
Read
lineEdit()->geometry()andlineEdit()->textMargins()inpaintEvent()to compute the effective text rect (subtracting icon-occupied margins), then usetextRect.width()for elision and draw withintextRect. This dynamically adapts to any icon configuration. The implementation matches the analysis report's fix suggestion with no deviation.Change Safety Assessment
Code Safety
2c6d4497to fix BUG-322639 (long placeholder text wrapping/abnormal display). This fix does NOT revert that behavior — it only corrects the width parameter passed toelidedText, keeping the elision and tooltip logic intact.paintEventis a Qt virtual override invoked by the paint system.Business Impact Scope
Affected module: Lock screen / Login password field — placeholder text rendering when the password field is empty and focused (e.g., error prompts like "Verification failed, 4 chances left"). The fix ensures the placeholder text is elided and drawn within the area that excludes the right-side icon buttons, preventing visual overlap.
Verification Suggestion
Test the lock screen / login password field: enter a wrong password, then verify the error placeholder text (after the field clears) does not overlap with the capslock, password visibility, or password hint icons. Also verify that
DLineEditExwithout icons still displays placeholder text correctly centered.根因分析
DLineEditEx::paintEvent()在绘制占位文本时使用rect().width()(控件全宽)作为省略宽度,忽略了AuthPassword::updatePasswordTextMargins()已在内部QLineEdit上设置的textMargins(用于为右侧图标——大写状态、密码显示、密码提示——预留空间)。这导致省略后的占位文本延伸到图标区域,与右侧图标视觉重叠。关键证据:dlineeditex.cpp:163使用rect().width(),而auth_password.cpp:972-991已正确设置textMargins,但paintEvent从未读取它。修复方案
在
paintEvent()中读取lineEdit()->geometry()和lineEdit()->textMargins(),计算扣除图标占用边距后的有效文本 rect,用textRect.width()做省略并在textRect内居中绘制。此方案动态适应任意图标配置,与分析报告的修复建议一致,无偏离。改动安全评估
代码安全评估
2c6d4497引入以修复 BUG-322639(长占位文本换行/显示异常)。本次修复不会撤销该行为——仅修正传入elidedText的宽度参数,保留省略和 ToolTip 逻辑不变。paintEvent为 Qt 虚函数重写,由绘制系统调用。业务影响范围
受影响模块:锁屏/登录密码框——密码框为空且有焦点时的占位文本绘制(如"Verification failed, 4 chances left"错误提示)。修复确保占位文本在扣除右侧图标按钮区域后进行省略和绘制,避免视觉重叠。
验证建议
测试锁屏/登录密码框:输入错误密码后验证密码框清空时错误提示占位文本不与大写状态、密码显示、密码提示图标重叠;同时验证无图标的
DLineEditEx占位文本仍正常居中显示。PMS: BUG-351887
Summary by Sourcery
Keep DLineEditEx placeholder text within the usable field area when margins or embedded controls reduce the available width.
Bug Fixes:
Enhancements: