Skip to content

[0120] 在 Mogan STEM 中实现 PDF 阅读功能#3351

Merged
da-liii merged 16 commits into
mainfrom
da/0120/pdf
May 15, 2026
Merged

[0120] 在 Mogan STEM 中实现 PDF 阅读功能#3351
da-liii merged 16 commits into
mainfrom
da/0120/pdf

Conversation

@da-liii
Copy link
Copy Markdown
Contributor

@da-liii da-liii commented May 14, 2026

Summary

在 Mogan STEM 中实现基础 PDF 阅读功能,使打开 PDF 文件时直接在应用内以标签页形式展示。

Changes

  • C++ 基础设施

    • 新增 is_pdf_tab_file() 工具函数(通过后缀检测 PDF)
    • 新增 PDFReaderWidget:基于 QScrollArea 的连续滚动 PDF 阅读器
    • qt_tm_widget_rep 集成 PDFReaderWidget,支持编辑器/启动页/PDF 三种模式切换
    • QTPdfPreviewWidget 保持原样,继续用于模板预览
  • Scheme 层

    • 新增 load-pdf-buffer 函数,用原始 PDF 路径直接创建 buffer
    • load-buffer-mainload-browse-bufferload-document 入口拦截 PDF
    • 打开过的 PDF 自动加入最近文档列表
  • UI

    • File -> Open 对话框默认支持 *.pdf
    • PDF 渲染区域外背景使用 QPalette::Mid,与编辑器外围颜色一致
    • 支持方向键和鼠标滚轮上下滑动浏览
  • 测试

    • 新增 qt_pdf_tab_utils_test:验证 is_pdf_tab_file() 后缀检测

Test Plan

  • 通过 File -> Open 打开 PDF,验证在标签页内打开
  • 验证 PDF 可以正常翻页/滚动阅读
  • 验证窗口大小调整时 PDF 页面自适应重新渲染
  • 验证 PDF 标签页和普通文档标签页可以正常切换
  • 验证打开过的 PDF 出现在最近文档列表中
  • 验证启动页和正常文档打开不受影响

🤖 Generated with Claude Code

@da-liii da-liii marked this pull request as draft May 14, 2026 06:11
da-liii and others added 12 commits May 15, 2026 10:01
- 新增 is_pdf_tab_file() 工具函数,通过后缀检测 PDF 文件
- qt_tm_widget_rep 集成 QTPdfPreviewWidget,支持编辑器/启动页/PDF 三种模式切换
- Scheme 层新增 load-pdf-buffer,在 load-buffer-main/load-browse-buffer/load-document 入口拦截 PDF
- File -> Open 对话框默认支持 *.pdf 文件
- PDF 渲染区域外背景使用 QPalette::Mid,与编辑器外围颜色一致
- 添加 C++ 单元测试:qt_pdf_tab_utils_test、qt_pdf_preview_widget_test
- 打开过的 PDF 自动加入最近文档列表

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- 新增 PDFReaderWidget:基于 QScrollArea 的连续滚动 PDF 阅读器
- 支持方向键和鼠标滚轮上下滑动浏览
- 页面垂直排列,自适应窗口宽度重新渲染
- qt_tm_widget 改用 PDFReaderWidget,QTPdfPreviewWidget 保持原样
- 代码格式化

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
QTPdfPreviewWidget 保持原样,PDF 阅读功能由新新增的 PDFReaderWidget 提供。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- 重写 keyPressEvent,空格键向下滚动 90% 视口高度
- loadFromFile 末尾调用 adjustSize 确保布局即时更新
- 新增 qt_pdf_reader_widget_test 覆盖创建、加载和空格键滚动

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
将 preview-file 从 open-url 改为 load-pdf-buffer,
使预览 PDF 时在 Mogan 内部新标签页打开,而不是调用外部程序。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- 重写 keyPressEvent 处理回车复制和 Escape 取消选择
- 解决焦点在 PDFReaderWidget 上时键盘事件未被捕获的问题
- 添加单元测试验证回车复制和 Escape 取消行为

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- 将 tm-files.scm 中的 load-pdf-buffer 由 define 改为 tm-define,
  使其可被 tm-print.scm 中的 preview-file 正常调用
- 格式化 Qt PDF 阅读器相关代码

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@da-liii da-liii marked this pull request as ready for review May 15, 2026 03:07
矩形选框功能存在已知问题,计划在后续版本中重新实现。
本次提交先行移除相关代码以便合并主干。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@da-liii da-liii merged commit b64c6f9 into main May 15, 2026
5 checks passed
@da-liii da-liii deleted the da/0120/pdf branch May 15, 2026 04:11
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