Skip to content

Conversation

@add-uos
Copy link
Contributor

@add-uos add-uos commented Jan 20, 2026

set white background for print rendering

log: set white background for print rendering
bug: https://pms.uniontech.com/bug-view-338245.html

Summary by Sourcery

Bug Fixes:

  • Force print rendering to use a white background when generating the page image for the print dialog.

set white background for print rendering

log: set white background for print rendering
bug: https://pms.uniontech.com/bug-view-338245.html
@sourcery-ai
Copy link

sourcery-ai bot commented Jan 20, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Updates print dialog invocation so that page rendering uses a white background when generating the preview/print image.

Sequence diagram for updated print rendering with white background

sequenceDiagram
    actor User
    participant TopTilte
    participant DrawApp
    participant DrawBoard
    participant Page
    participant PageContext
    participant CPrintManager

    User->>TopTilte: clickPrintAction()
    TopTilte->>DrawApp: drawBoard()
    DrawApp-->>TopTilte: DrawBoard
    TopTilte->>DrawBoard: currentPage()
    DrawBoard-->>TopTilte: Page
    TopTilte->>Page: context()
    Page-->>TopTilte: PageContext
    TopTilte->>PageContext: renderToImage(Qt_white)
    PageContext-->>TopTilte: renderedImage
    TopTilte->>CPrintManager: CPrintManager(topMainWindowWidget)
    TopTilte->>CPrintManager: showPrintDialog(renderedImage, topMainWindowWidget, pageName)
    CPrintManager-->>User: displayPrintDialogWithWhiteBackground
Loading

Updated class diagram for print rendering interaction

classDiagram
    class TopTilte {
        +initMenu() void
    }

    class DrawApp {
        +topMainWindowWidget() QWidget
        +drawBoard() DrawBoard
    }

    class DrawBoard {
        +currentPage() Page
    }

    class Page {
        +name() QString
        +context() PageContext
    }

    class PageContext {
        +renderToImage(backgroundColor QtColor) QImage
    }

    class CPrintManager {
        +CPrintManager(parent QWidget)
        +showPrintDialog(image QImage, parent QWidget, title QString) void
    }

    TopTilte --> DrawApp
    DrawApp --> DrawBoard
    DrawBoard --> Page
    Page --> PageContext
    TopTilte --> CPrintManager
    TopTilte ..> PageContext : uses_renderToImage
    TopTilte ..> CPrintManager : uses_showPrintDialog
Loading

File-Level Changes

Change Details Files
Ensure printed/previewed page is rendered with a white background instead of inheriting a potentially non-white background.
  • Change renderToImage call to pass Qt::white as the background parameter when preparing the page image for printing.
  • Keep the print dialog wiring and page/context null checks unchanged, only modifying the rendering behavior.
src/frame/toptoolbar.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

Copy link

@sourcery-ai sourcery-ai bot left a 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:

  • Forcing a white background in renderToImage(Qt::white) may override documents that intentionally use a different page/background color; consider deriving the background from the page context or making the print background color configurable rather than hard-coded.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Forcing a white background in `renderToImage(Qt::white)` may override documents that intentionally use a different page/background color; consider deriving the background from the page context or making the print background color configurable rather than hard-coded.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@deepin-ci-robot
Copy link

deepin pr auto review

这段代码修改主要是在调用 renderToImage() 函数时增加了一个参数 Qt::white。以下是对此修改的详细审查和改进意见:

1. 语法逻辑

  • 审查结果:语法正确。
  • 分析:修改后的代码 page->context()->renderToImage(Qt::white) 符合 Qt 的函数调用规范。假设 renderToImage 是一个重载函数,接受一个 Qt::GlobalColor 类型的参数来指定背景色,这在逻辑上是合理的。

2. 代码质量

  • 审查结果:良好,但存在潜在风险。
  • 分析
    • 优点:显式指定背景色为白色,使得打印输出的背景颜色明确,避免了默认透明背景在某些打印场景下可能出现的问题(例如黑色背景或看不清内容)。
    • 风险:使用了魔法值(Magic Value)Qt::white。如果将来需求变更,需要支持用户自定义背景色,或者需要根据主题动态调整背景色,硬编码 Qt::white 会导致修改点分散。

3. 代码性能

  • 审查结果:影响微乎其微。
  • 分析
    • 传入 Qt::white 参数通常只会影响渲染时的填充操作,对于大多数图形渲染引擎来说,填充纯色背景的性能开销极小,可以忽略不计。
    • 如果 renderToImage 内部实现非常复杂,且背景填充是性能瓶颈,可以考虑优化,但通常不需要担心。

4. 代码安全

  • 审查结果:安全。
  • 分析
    • Qt::white 是 Qt 框架提供的枚举值,类型安全,不存在类型转换风险。
    • 不会引入内存泄漏、越界访问等安全隐患。

改进建议

  1. 避免硬编码(提高可维护性)
    如果背景色可能随需求变化,建议将其定义为常量或配置项,例如:

    // 在类定义或配置文件中
    static const Qt::GlobalColor DEFAULT_PRINT_BG_COLOR = Qt::white;
    
    // 使用时
    manager.showPrintDialog(page->context()->renderToImage(DEFAULT_PRINT_BG_COLOR), ...);
  2. 增加空指针检查(健壮性)
    虽然代码中已有 page != nullptr && page->context() != nullptr 的检查,但建议进一步确认 renderToImage 的返回值是否有效:

    auto image = page->context()->renderToImage(Qt::white);
    if (!image.isNull()) {
        manager.showPrintDialog(image, drawApp->topMainWindowWidget(), page->name());
    }
  3. 注释说明(可读性)
    建议添加注释说明为什么指定白色背景,例如:

    // 指定白色背景以避免打印时出现透明或黑色背景问题
    manager.showPrintDialog(page->context()->renderToImage(Qt::white), ...);
  4. 考虑国际化(扩展性)
    如果打印功能涉及国际化(如纸张大小、单位等),建议检查 showPrintDialog 是否已正确处理。


总结

当前修改是合理的,解决了打印时的背景色问题,但可以通过避免硬编码和增加注释来提高代码的可维护性和可读性。如果背景色可能动态变化,建议进一步抽象为配置项。

@github-actions
Copy link

  • 敏感词检查失败, 检测到1个文件存在敏感词
详情
{
    "src/frame/toptoolbar.cpp": [
        {
            "line": "    dApp->setApplicationAcknowledgementPage(\"https://www.deepin.org/acknowledgments/deepin-draw/\");",
            "line_number": 235,
            "rule": "S35",
            "reason": "Url link | a2d44da975"
        }
    ]
}

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: add-uos, lzwind

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

@add-uos
Copy link
Contributor Author

add-uos commented Jan 20, 2026

/merge

@deepin-bot deepin-bot bot merged commit 09100c3 into linuxdeepin:develop/snipe Jan 20, 2026
18 checks passed
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.

3 participants