fix(shot): dynamically calculate size tips dimensions based on font size#828
Merged
deepin-bot[bot] merged 1 commit intoApr 20, 2026
Merged
Conversation
Use fontMetrics() to compute width and height instead of hardcoded setFixedSize(90, 30), ensuring size tips display correctly on different font sizes and screen scaling ratios (e.g., 125% scale with font size 20). bug: https://pms.uniontech.com/bug-view-346697.html
lzwind
approved these changes
Apr 20, 2026
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: dengzhongyuan365-dev, lzwind 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. 代码安全
改进建议代码// 在类定义中添加常量
// static constexpr int kStandardWidth = 1920;
// static constexpr int kStandardHeight = 1080;
void TopTips::setContent(const QSize &size)
{
// 防御性编程:检查尺寸有效性
if (size.width() <= 0 || size.height() <= 0) {
qCWarning(dsrApp) << "Invalid size provided to TopTips:" << size;
return;
}
QString text = tr("Recording area: %1x%2").arg(size.width()).arg(size.height());
QString displayText;
if (m_showRecorderTips && size.width() * size.height() > kStandardWidth * kStandardHeight &&
size.width() != m_width && size.height() != m_height) {
// 建议:如果目标是保持 16:9,可以直接计算
// int w = qMin(size.width(), kStandardWidth);
// int h = w * 9 / 16;
// 或者保留原逻辑,但使用常量
int h = static_cast<int>(sqrt(static_cast<double>(kStandardWidth) * kStandardHeight * size.height() / size.width()));
int w = static_cast<int>(sqrt(static_cast<double>(kStandardWidth) * kStandardHeight * size.width() / size.height()));
QString recorderTips = tr(" Adjust the recording area within %1*%2 to get better video effect");
qCDebug(dsrApp) << "Setting content with recording area adjustment tip:" << w << "x" << h;
displayText = text + recorderTips.arg(w).arg(h);
} else {
qCDebug(dsrApp) << "Setting content size:" << size;
displayText = text;
}
setText(displayText);
// 统一设置大小,减少重复代码
// 使用 boundingRect 的 width() 可能比 horizontalAdvance 更准确处理换行,但单行文本 horizontalAdvance 性能更好
// 这里增加一点 padding (例如 10px) 防止文字贴边
int textWidth = fontMetrics().horizontalAdvance(displayText);
int textHeight = fontMetrics().boundingRect(displayText).height();
setFixedSize(textWidth + 10, textHeight);
}总结该 diff 成功地将固定尺寸改为动态计算尺寸,是一个正向的改进。主要建议是:消除魔法数字、增加除零检查、以及提取重复的逻辑以优化代码结构。 |
Member
Author
|
/merge |
Contributor
|
This pr cannot be merged! (status: unstable) |
Member
Author
|
/forcemerge |
Contributor
|
This pr force merged! (status: unstable) |
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 fontMetrics() to compute width and height instead of hardcoded setFixedSize(90, 30), ensuring size tips display correctly on different font sizes and screen scaling ratios (e.g., 125% scale with font size 20).
bug: https://pms.uniontech.com/bug-view-346697.html