Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions TeXmacs/misc/themes/liii-night.css
Original file line number Diff line number Diff line change
Expand Up @@ -1126,3 +1126,17 @@ QPushButton#startup-tab-secondary-btn {
QPushButton#startup-tab-secondary-btn:hover {
background-color: rgba(39, 145, 173, 0.2);
}

/* 模板使用按钮 - Template Use Button */
QPushButton#template-use-btn {
background-color: #4CAF50;
color: white;
padding: 8px 24px;
border-radius: 4px;
font-weight: bold;
border: none;
}

QPushButton#template-use-btn:hover {
background-color: #45a049;
}
14 changes: 14 additions & 0 deletions TeXmacs/misc/themes/liii.css
Original file line number Diff line number Diff line change
Expand Up @@ -1099,3 +1099,17 @@ QPushButton#startup-tab-secondary-btn {
QPushButton#startup-tab-secondary-btn:hover {
background-color: #e8f4f6;
}

/* 模板使用按钮 - Template Use Button */
QPushButton#template-use-btn {
background-color: #4CAF50;
color: white;
padding: 8px 24px;
border-radius: 4px;
font-weight: bold;
border: none;
}

QPushButton#template-use-btn:hover {
background-color: #45a049;
}
45 changes: 45 additions & 0 deletions TeXmacs/templates/categories.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; MODULE : categories.scm
;; DESCRIPTION : Template categories for Liii STEM/Mogan Template Center
;; COPYRIGHT : (C) 2026 Yuki Lu
;;
;; This software falls under the GNU general public license version 3 or later.
;; It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
;; in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(texmacs-module (templates categories))

(tm-define template-default-categories
'(((id . "university-thesis")
(name . "University Thesis")
(icon . "🎓")
(order . 1))

((id . "lab-report")
(name . "Lab Report")
(icon . "📊")
(order . 2))

((id . "math-modeling")
(name . "Math Modeling")
(icon . "🧪")
(order . 3))))

(tm-define (template-get-category-name category-id)
(:synopsis "Get the display name for a category")
(let ((cat (list-find template-default-categories
(lambda (c) (equal? (assoc-ref c 'id) category-id)))))
(if cat
(assoc-ref cat 'name)
category-id)))

(tm-define (template-get-categories)
(:synopsis "Get list of all template categories, sorted by order")
(sort template-default-categories
(lambda (a b)
(< (assoc-ref a 'order)
(assoc-ref b 'order)))))
34 changes: 34 additions & 0 deletions TeXmacs/templates/metadata.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; MODULE : metadata.scm
;; DESCRIPTION : Local template metadata for bundled templates
;; COPYRIGHT : (C) 2026 Yuki Lu
;;
;; This software falls under the GNU general public license version 3 or later.
;; It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
;; in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(texmacs-module (templates metadata))

(tm-define bundled-templates
;; Local templates bundled with Mogan
;; Remote templates will be loaded from Gitee Releases
'())

(tm-define (template-get-bundled-templates)
(:synopsis "Get list of bundled template metadata")
bundled-templates)

(tm-define (template-exists? template-id)
(:synopsis "Check if a template exists in bundled set")
(assoc template-id bundled-templates))

(tm-define (template-get-metadata template-id)
(:synopsis "Get metadata for a specific template")
(let ((tmpl (assoc template-id bundled-templates)))
(if tmpl
(cdr tmpl)
#f)))
130 changes: 130 additions & 0 deletions devel/216_3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
# 216_3 模板中心展示与下载

## 如何测试
1. 编译时先输入 `xmake config -vD --startup_tab=true`
2. 启动 Mogan STEM,点击 "Mogan STEM" 标签页
3. 点击左侧导航栏 **Template**,切换到模板页面
4. 测试分类栏:
- **All**: 显示所有模板
- **Thesis/Lab Report/Math Modeling**: 按分类过滤模板
5. 点击任意模板卡片,弹出预览对话框:
- 显示模板名称、描述、作者、版本
- 预览区域显示 PDF/图片预览
- **Cancel**: 关闭对话框
- **Use Template**: 下载并使用模板
6. 如果模板未下载,显示下载进度对话框
7. 下载完成后自动打开模板文件

## 2026/04/08 模板中心展示与下载

### What
实现模板中心的 UI 展示、分类过滤、预览和下载功能。采用 liiistem.cn API 获取模板数据,支持从远程服务器下载模板文件。

#### 新增文件:

**src/Plugins/Qt/qt_template_page.hpp** (新增)
- 模板页面主类 `QTTemplatePage`
- 信号:`templateOpened(const QString& filePath)`
- 方法:`initialize()`, `setupUI()`, `setupCategoryBar()`, `refreshTemplateGrid()`, `createTemplateCard()`, `showTemplatePreview()`, `downloadAndUseTemplate()`

**src/Plugins/Qt/qt_template_page.cpp** (新增)
- 模板页面实现:标题 + 分类栏 + 模板网格
- 分类按钮动态生成(从 TemplateManager 获取)
- 模板卡片:缩略图 + 名称 + 作者/版本
- 预览对话框:PDF/图片预览 + 模板信息 + Use/Cancel 按钮
- 下载进度对话框

**src/Plugins/Qt/qt_pdf_preview_widget.hpp/cpp** (新增)
- 通用 PDF 预览组件 `QTPdfPreviewWidget`
- 支持从 URL 加载 PDF
- 支持设置 QPixmap 图片预览

**src/Mogan/TemplateCenter/template_types.hpp** (新增)
- 共享类型定义:`TemplateMetadata`, `TemplateCategory`
- 使用 `TemplateMetadataPtr = QSharedPointer<TemplateMetadata>`

**src/Mogan/TemplateCenter/template_api.hpp/cpp** (新增)
- API 客户端 `TemplateAPI`
- 支持 liiistem.cn API 格式(嵌套 categories[].templates[])
- 元数据获取、模板下载、进度反馈

**src/Mogan/TemplateCenter/template_manager.hpp/cpp** (新增)
- 模板管理器单例 `TemplateManager`
- 本地缓存与远程数据合并
- Scheme 配置加载:`loadCategoriesFromScheme()`

**src/Mogan/TemplateCenter/template_cache.hpp/cpp** (新增)
- 本地缓存管理 `TemplateCache`
- 元数据缓存、模板文件缓存

**TeXmacs/templates/categories.scm** (新增)
- 分类配置 Scheme 文件
- 定义 `(template-get-categories)` 函数返回分类列表
- 默认分类:University Thesis、Lab Report、Math Modeling

**TeXmacs/templates/metadata.scm** (新增)
- 本地模板元数据配置 Scheme 文件
- 定义 `(template-get-bundled-templates)` 函数返回捆绑模板列表
- 支持 `(template-get-metadata template-id)` 获取指定模板元数据

#### 修改文件:

**src/Plugins/Qt/qt_startup_tab_widget.cpp** (修改)
- 集成 `QTTemplatePage` 到启动标签页
- Template 导航按钮切换到模板页面

### Why
PR-01.5 只实现了文件入口功能,需要在 216_3 中:
1. 实现模板数据层(API + 缓存)
2. 实现模板展示 UI(分类、网格、预览)
3. 实现下载功能,支持从 liiistem.cn 获取模板
4. 提供良好的用户体验(预览、进度、错误处理)

### How

**1. 数据层架构**:
```
TemplateAPI (网络请求)
TemplateManager (数据合并与业务逻辑)
TemplateCache (本地缓存)
```

**2. API 格式** (liiistem.cn):
```json
{
"categories": [
{
"id": "thesis",
"name": "Thesis",
"templates": [
{"id": "tsinghua-thesis", "name": "清华大学本科毕业论文", ...}
]
}
]
}
```

**3. UI 布局**:
- 分类栏:水平排列的分类按钮(All + 动态分类)
- 模板网格:3列自适应,卡片包含缩略图、名称、作者/版本
- 预览对话框:模态对话框,左侧信息 + 右侧预览

**4. 下载流程**:
```
点击卡片 → showTemplatePreview() → 点击 Use Template
→ downloadAndUseTemplate() → TemplateManager::downloadTemplate()
→ TemplateAPI::downloadTemplate() → QNetworkAccessManager
→ onDownloadCompleted() → emit templateOpened()
```

**5. 缓存策略**:
- 元数据缓存:JSON 格式,有效期 1 小时
- 模板文件缓存:存储在 AppData/template_cache/templates/
- 离线时自动使用缓存数据

**6. Scheme 集成**:
- 分类配置从 `TeXmacs/templates/categories.scm` 加载
- 使用 S7 Scheme 解释器解析配置
- 失败时回退到硬编码默认分类
Loading
Loading