fix(shot): align size tips with actual saved image dimensions#826
fix(shot): align size tips with actual saved image dimensions#826lzwind merged 1 commit intolinuxdeepin:masterfrom
Conversation
The selection size tooltip displayed recordWidth×DPR × recordHeight×DPR, but the actual crop applies -2 width and -1 height adjustments to avoid capturing the dashed selection border, causing a few pixels discrepancy between the displayed size and the saved image file info. bug: https://pms.uniontech.com/bug-view-353039.html
deepin pr auto review这段代码修改主要涉及了在处理高DPI(设备像素比)屏幕时,对提示框尺寸计算的调整。以下是对该代码修改的审查意见,包括语法逻辑、代码质量、代码性能和代码安全方面的分析: 1. 语法逻辑分析优点:
潜在问题与建议:
2. 代码质量分析优点:
改进建议:
3. 代码性能分析
4. 代码安全分析
5. 综合改进后的代码示例结合以上分析,改进后的代码可能如下: void TopTips::updateTips(QPoint pos, const QSize &size)
{
// 检查尺寸有效性
if (size.width() <= 2 || size.height() <= 1) {
return; // 或设置默认尺寸
}
QPoint startPoint = pos;
qreal pixelRatio = qApp->primaryScreen()->devicePixelRatio();
// 检查 pixelRatio 有效性
if (pixelRatio <= 0) {
pixelRatio = 1.0;
}
// 定义边距常量
constexpr int BORDER_MARGIN_X = 2;
constexpr int BORDER_MARGIN_Y = 1;
// 计算尺寸,使用 qRound 四舍五入
int tipWidth = qMax(qRound((size.width() - BORDER_MARGIN_X) * pixelRatio), 0);
int tipHeight = qMax(qRound((size.height() - BORDER_MARGIN_Y) * pixelRatio), 0);
QSize s = QSize(tipWidth, tipHeight);
setContent(s);
startPoint.setX(pos.x());
}总结该代码修改在逻辑上是合理的,主要是为了与截图裁剪逻辑保持一致,并通过
|
|
[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 |
The selection size tooltip displayed recordWidth×DPR × recordHeight×DPR, but the actual crop applies -2 width and -1 height adjustments to avoid capturing the dashed selection border, causing a few pixels discrepancy between the displayed size and the saved image file info.
bug: https://pms.uniontech.com/bug-view-353039.html