Conversation
Reviewer's GuideFix focused, empty password-field placeholder rendering by including internal layout contentsMargins alongside textMargins, keeping long error text from overlapping right-side icons and aligning font-size reduction with the elided drawing width. Sequence diagram for corrected password placeholder renderingsequenceDiagram
participant DLineEditEx
participant QLineEdit
participant Layout
participant QFontMetrics
participant QPainter
DLineEditEx->>QLineEdit: textMargins()
DLineEditEx->>QLineEdit: layout()
QLineEdit-->>DLineEditEx: Layout
DLineEditEx->>Layout: contentsMargins()
Layout-->>DLineEditEx: layoutMargins
DLineEditEx->>QFontMetrics: elidedText(placeholderText, ElideRight, textRect.width())
QFontMetrics-->>DLineEditEx: elidedText
DLineEditEx->>QPainter: drawText(textRect, elidedText)
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
…cal centering 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. Additional fix: textRect y/height now uses leRect.y()/leRect.height() instead of rect().y()/rect().height(), so placeholder text is vertically centered within the actual QLineEdit geometry, matching user input text 4. Impact: only affects placeholder text rendering when input is empty and focused; normal text input/display unaffected Log: 修复占位文本省略宽度未包含 layout contentsMargins 及垂直方向未使用 QLineEdit 几何导致与图标重叠及上下不居中 Influence: 1. 测试输入错误密码后密码框清空时占位提示文本不与图标重叠 2. 验证大写状态、密码显示、密码提示图标区域无文本覆盖 3. 测试无图标的 DLineEditEx 占位文本正常居中显示 4. 验证占位文本垂直居中与实际输入文本位置一致 PMS: BUG-351887
1dac660 to
e3c5a9f
Compare
Synchronize source files from linuxdeepin/dde-session-shell. Source-pull-request: linuxdeepin/dde-session-shell#99
deepin pr auto review🤖 AI 代码审查报告📊 总体评价
🔍 详细分析1. 语法逻辑 ✅评价: 良好 ✅ 通过 潜在问题:
建议: 建议在 availWidth 和 textRect.width() 计算后增加下限保护,如 availWidth = qMax(availWidth, 0),避免极端边距场景下的异常行为 2. 代码质量 ✅评价: 良好 ✅ 通过 潜在问题:
建议: 建议将 textMargins + layoutMargins 的计算逻辑提取为私有辅助方法(如 QPair<QMargins, QMargins> getMargins() const 或 int effectiveTextWidth() const),减少代码重复,提高可维护性 3. 代码性能 ✅评价: 优秀 ✅ 通过 潜在问题: 建议: 性能良好,资源使用合理。margin 计算为 O(1) 常量时间操作,对渲染性能无可感知影响 4. 代码安全 🔒评价: 优秀 ✅ 通过
安全漏洞详情: 建议: 安全合规,无安全风险。代码仅涉及 Qt 控件渲染逻辑,无用户输入处理、无外部数据交互、无文件/网络/命令操作 💡 改进建议代码示例// 建议提取辅助方法,减少重复代码并增加边界保护
// 在 DLineEditEx 类中添加私有辅助方法
QPair<int, int> DLineEditEx::getHorizontalMargins() const
{
QMargins textMargins = lineEdit()->textMargins();
QMargins layoutMargins(0, 0, 0, 0);
if (auto *layout = lineEdit()->layout()) {
layoutMargins = layout->contentsMargins();
}
int left = textMargins.left() + layoutMargins.left();
int right = textMargins.right() + layoutMargins.right();
return {left, right};
}
// setPlaceholderTextFont() 中使用
void DLineEditEx::setPlaceholderTextFont(const QFont &font)
{
const QString &text = lineEdit()->placeholderText();
QFont fontTmp = font;
auto [left, right] = getHorizontalMargins();
int availWidth = qMax(width() - left - right, 0); // 增加下限保护
while (QFontMetrics(fontTmp).boundingRect(text).width() > availWidth) {
if (fontTmp.pointSize() <= 1) {
qWarning() << "Password line edit font size" << font.pointSize() << fontTmp.pointSize();
return;
}
fontTmp.setPointSize(fontTmp.pointSize() - 1);
}
setFont(fontTmp);
}
// paintEvent() 中使用
void DLineEditEx::paintEvent(QPaintEvent *event)
{
// ...
QRect leRect = lineEdit()->geometry();
auto [leftOffset, rightOffset] = getHorizontalMargins();
int textWidth = qMax(leRect.width() - leftOffset - rightOffset, 0); // 增加下限保护
QRect textRect(leRect.x() + leftOffset, leRect.y(), textWidth, leRect.height());
QString elidedText = fm.elidedText(placeholderText, Qt::ElideRight, textWidth);
pa.drawText(textRect, Qt::AlignCenter | Qt::TextSingleLine, elidedText);
// ...
}本报告由 AI 代码审查工具自动生成 |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: mhduiy, yixinshark 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 |
修复 PMS BUG-351887
问题
锁屏密码框错误提示文案过长使用省略形式时,仍与大写图标、加密图标、提示图标等重叠。
根因
DLineEditEx::paintEvent()自定义绘制占位文本时,首次修复仅读取了textMargins,但未包含AuthPassword::initUI()中passwordLayout的contentsMargins(10, 0, 10, 0),导致右侧仍残留约 10px 区域使文本与图标重叠。修复方案
paintEvent()中,合并textMargins+layout()->contentsMargins()计算有效文本区域setPlaceholderTextFont()中,使用相同的有效宽度作为字体缩小阈值影响范围
关联
Summary by Sourcery
Ensure password-field placeholder text respects both text and layout margins when sizing and eliding content.
Bug Fixes:
Enhancements: