Skip to content

fix: resolve content area spacing and alignment issues - #437

Draft
GongHeng2017 wants to merge 1 commit into
linuxdeepin:masterfrom
GongHeng2017:agent/agent/7a3a0020c848
Draft

GongHeng2017 wants to merge 1 commit into
linuxdeepin:masterfrom
GongHeng2017:agent/agent/7a3a0020c848

Conversation

@GongHeng2017

@GongHeng2017 GongHeng2017 commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Root Cause Analysis

The document viewer (deepin-reader) has two UI layout issues: (1) the content area has zero vertical gap with the titlebar because CentralDocPage sets setContentsMargins(0, 0, 0, 0) in its layout, and the entire layout chain (MainWindow → Central → CentralDocPage) propagates zero margins; (2) the content area is not horizontally centered because SheetBrowser (a QGraphicsView) does not set an explicit alignment, and the scene's centering is based on maxWidth (widest page) rather than viewport width. Pixel analysis of the bug screenshot confirms: y=122 is white (255,255,255), y=123 is content color (230,238,237) — zero gap; left margin 40px ≠ right margin 90px.

Fix Approach

  1. CentralDocPage.cpp:110: Change setContentsMargins(0, 0, 0, 0) to setContentsMargins(0, 10, 0, 0) to add a 10px top margin between the titlebar and content area.
  2. SheetBrowser.cpp:65: Add setAlignment(Qt::AlignHCenter | Qt::AlignTop) in the constructor to ensure the scene content is horizontally centered in the viewport.

Change Safety Assessment

Code Safety

  • Risk Level: Low
  • Both changes are UI layout parameter adjustments — no function signatures, public members, or core rendering logic are affected.
  • Target lines originate from initial 2020 code (5d71add4), not from any historical bug fix. No historical fix is reverted.
  • No external callers depend on these layout parameter values; references list is empty.

Business Impact Scope

Affected module: document viewer layout display. The changes affect how PDF/document pages are positioned in the application window — vertical spacing between titlebar and content, and horizontal centering of content within the viewport. No core functionality (parsing, rendering, search, annotation) is affected.

Verification Suggestion

Test opening PDFs of various page sizes to verify correct spacing and centering. Test window resize and multi-page navigation to ensure layout consistency.


根因分析

文档查看器(deepin-reader)存在两个 UI 布局问题:(1)内容区与标题栏之间无垂直间距,因为 CentralDocPage 在布局中设置了 setContentsMargins(0, 0, 0, 0),整条布局链(MainWindow → Central → CentralDocPage)均传播零边距;(2)内容区水平未居中,因为 SheetBrowser(QGraphicsView)未设置显式对齐方式,且场景居中基于 maxWidth(最宽页面)而非视口宽度。Bug 截图像素分析确认:y=122 为白色 (255,255,255),y=123 为内容色 (230,238,237)——零间距;左边距 40px ≠ 右边距 90px。

修复方案

  1. CentralDocPage.cpp:110:将 setContentsMargins(0, 0, 0, 0) 改为 setContentsMargins(0, 10, 0, 0),在标题栏与内容区之间添加 10px 上边距。
  2. SheetBrowser.cpp:65:在构造函数中添加 setAlignment(Qt::AlignHCenter | Qt::AlignTop),确保场景内容在视口中水平居中。

改动安全评估

代码安全评估

  • 风险等级: 低风险
  • 两处改动均为 UI 布局参数调整——不涉及函数签名、公开成员或核心渲染逻辑。
  • 目标行源自 2020 年初始代码(5d71add4),非历史 bug 修复产物,不撤销任何已有修复。
  • 无外部调用者依赖这些布局参数值;引用列表为空。

业务影响范围

受影响模块:文档查看器布局显示。改动影响 PDF/文档页面在应用窗口中的定位——标题栏与内容区的垂直间距、内容区在视口中的水平居中。不涉及核心功能(解析、渲染、搜索、注释)。

验证建议

测试打开不同页面尺寸的 PDF,验证间距和居中效果。测试窗口缩放和多页翻页,确保布局一致性。

Summary by Sourcery

Bug Fixes:

  • Correct document viewer layout by adding spacing below the title bar and centering page content horizontally within the viewport.

1. Root cause: layout chain sets zero margins (setContentsMargins(0,0,0,0))
   at CentralDocPage, leaving no gap between titlebar and content area;
   SheetBrowser lacks explicit alignment, causing horizontal asymmetry
2. Fix: set top margin to 10px in CentralDocPage layout and add
   setAlignment(Qt::AlignHCenter | Qt::AlignTop) in SheetBrowser
3. Impact: only UI layout parameters changed, no function signatures or
   core rendering logic affected

Log: fix content area zero vertical gap with titlebar and horizontal misalignment

Influence:
1. Test PDF opening with different page sizes for correct spacing and centering
2. Test window resize to verify alignment persists
3. Test multi-page navigation to ensure layout consistency

fix: 修复内容区间距缺失和水平未居中问题

1. 根因:布局链中 CentralDocPage 设置零边距(setContentsMargins(0,0,0,0)),
   标题栏与内容区之间无垂直间距;SheetBrowser 未设置对齐方式,内容区
   在视口中水平未居中
2. 方案:CentralDocPage 布局上边距设为 10px,SheetBrowser 构造函数中
   添加 setAlignment(Qt::AlignHCenter | Qt::AlignTop) 确保水平居中
3. 影响:仅修改 UI 布局参数,不涉及函数签名或核心渲染逻辑

Log: 修复内容区与标题栏零间距及水平未居中问题

Influence:
1. 测试不同页面尺寸的 PDF 打开后的间距和居中效果
2. 测试窗口缩放后对齐是否保持
3. 测试多页翻页后布局一致性

PMS: BUG-193233
@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: GongHeng2017

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@GongHeng2017
GongHeng2017 marked this pull request as draft October 29, 2026 20:41
@sourcery-ai

sourcery-ai Bot commented Oct 29, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Fixes document viewer layout positioning with a 10px gap below the titlebar and explicit horizontal centering of page content, without changing rendering or document-processing behavior.

File-Level Changes

Change Details Files
Adds a fixed top inset to separate document content from the titlebar.
  • Changes the central document layout’s top content margin from 0 to 10 pixels while preserving zero margins on other sides and zero layout spacing.
reader/uiframe/CentralDocPage.cpp
Explicitly centers document scenes horizontally within the graphics viewport.
  • Configures the sheet browser to use horizontal-center and top alignment during construction.
reader/browser/SheetBrowser.cpp

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants