-
Notifications
You must be signed in to change notification settings - Fork 60
fix(viewing): replace font metrics with document renderer #422
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Upgrade the height computation mechanism to utilize QTextDocument instead of QFontMetrics. This change accommodates HTML formatting in the license display and adjusts minimum dimensions to improve visual proportions across different content volumes. log: replace font metrics with document renderer pms: BUG-314073
Reviewer's guide (collapsed on small PRs)Reviewer's GuideReplaces font-metrics-based height calculation with a QTextDocument-based HTML-aware content height computation and adjusts scroll area minimum height bounds to better fit varying content lengths. Sequence diagram for updated window height calculationsequenceDiagram
actor User
participant LicenseDialog
participant Content
participant QTextDocument
participant QScrollArea
User->>LicenseDialog: open()
LicenseDialog->>Content: updateWindowHeight()
Content->>QTextDocument: construct()
Content->>QTextDocument: setHtml(m_source.text())
Content->>QTextDocument: setTextWidth(m_scrollArea.width() - 40)
QTextDocument-->>Content: size().height()
Content->>QScrollArea: setMinimumHeight(qBound(100, contentHeight, 491))
Class diagram for Content height computation updateclassDiagram
class Content {
- QWidget m_source
- QScrollArea m_scrollArea
+ updateWindowHeight()
}
class QTextDocument {
+ setHtml(html)
+ setTextWidth(width)
+ size()
}
Content ..> QTextDocument : uses
Content ..> QWidget : reads_text
Content ..> QScrollArea : sets_minimumHeight
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
deepin pr auto review这份代码修改主要是为了优化 1. 语法逻辑审查现状:
潜在问题:
2. 代码质量审查优点:
改进建议:
3. 代码性能审查潜在问题:
改进建议:
4. 代码安全审查潜在问题:
改进建议:
5. 其他改进建议
优化后的代码示例void Content::updateWindowHeight()
{
static QString lastText;
static int lastWidth = 0;
static int cachedHeight = 0;
QString currentText = m_source->text();
const int kTextMargin = 40;
int availableWidth = m_scrollArea->width() - kTextMargin;
if (availableWidth <= 0) {
availableWidth = 100; // 默认宽度
}
if (currentText != lastText || availableWidth != lastWidth) {
QTextDocument doc;
doc.setHtml(currentText); // 或 setPlainText,根据实际需求
doc.setTextWidth(availableWidth);
cachedHeight = static_cast<int>(doc.size().height());
lastText = currentText;
lastWidth = availableWidth;
}
int minHeight = qBound(100, cachedHeight, 491);
m_scrollArea->setMinimumHeight(minHeight);
}总结新代码在逻辑上是正确的,但可以通过以下方式进一步优化:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey - I've left some high level feedback:
- Using
m_scrollArea->width()as the layout width may be fragile if this is called before the scroll area is laid out (width could be 0 or stale); consider basing it onm_source’s available width or ensuring this is only invoked after layout is finalized or on resize. - The bounds for
minHeighthave changed from[300, 491]to[100, 491], which can significantly reduce the dialog’s minimum height; double-check whether this is intentional for all license contents or whether a higher lower-bound (or content-dependent heuristic) would keep the layout more consistent.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Using `m_scrollArea->width()` as the layout width may be fragile if this is called before the scroll area is laid out (width could be 0 or stale); consider basing it on `m_source`’s available width or ensuring this is only invoked after layout is finalized or on resize.
- The bounds for `minHeight` have changed from `[300, 491]` to `[100, 491]`, which can significantly reduce the dialog’s minimum height; double-check whether this is intentional for all license contents or whether a higher lower-bound (or content-dependent heuristic) would keep the layout more consistent.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: add-uos, caixr23 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 |
|
/merge |
Upgrade the height computation mechanism to utilize QTextDocument instead of QFontMetrics. This change accommodates HTML formatting in the license display and adjusts minimum dimensions to improve visual proportions across different content volumes.
log: replace font metrics with document renderer
pms: BUG-314073
Summary by Sourcery
Update license dialog content height calculation to use rich-text document rendering instead of font metrics for better handling of HTML content and proportional sizing.
Bug Fixes:
Enhancements: