Compare commits
2 Commits
555371a4e0
...
c749d642cf
| Author | SHA1 | Date | |
|---|---|---|---|
| c749d642cf | |||
| 9bafa71667 |
@@ -30,3 +30,45 @@ if(GO_EXECUTABLE)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
add_subdirectory(client)
|
add_subdirectory(client)
|
||||||
|
|
||||||
|
install(FILES README.md DESTINATION .)
|
||||||
|
install(FILES client/3rd/ElaWidgetTools/LICENSE
|
||||||
|
DESTINATION licenses RENAME ElaWidgetTools-LICENSE)
|
||||||
|
install(FILES client/3rd/tomlplusplus/LICENSE
|
||||||
|
DESTINATION licenses RENAME tomlplusplus-LICENSE)
|
||||||
|
|
||||||
|
if(WIN32)
|
||||||
|
if(NOT SCHEDULE_WINDEPLOYQT)
|
||||||
|
message(FATAL_ERROR "windeployqt was not configured; check the Qt/MinGW preset paths")
|
||||||
|
endif()
|
||||||
|
set(_compiler_runtime_arg "")
|
||||||
|
if(MSVC)
|
||||||
|
set(_compiler_runtime_arg "--compiler-runtime")
|
||||||
|
endif()
|
||||||
|
install(CODE "
|
||||||
|
set(_stage \"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}\")
|
||||||
|
execute_process(
|
||||||
|
COMMAND \"${SCHEDULE_WINDEPLOYQT}\" ${_compiler_runtime_arg} --dir \"\${_stage}\" \"\${_stage}/Schedule.exe\"
|
||||||
|
RESULT_VARIABLE _deploy_result
|
||||||
|
)
|
||||||
|
if(NOT _deploy_result EQUAL 0)
|
||||||
|
message(FATAL_ERROR \"windeployqt failed during install: \${_deploy_result}\")
|
||||||
|
endif()
|
||||||
|
")
|
||||||
|
|
||||||
|
set(CPACK_GENERATOR "NSIS")
|
||||||
|
set(CPACK_PACKAGE_NAME "Schedule")
|
||||||
|
set(CPACK_PACKAGE_VENDOR "Misaki")
|
||||||
|
set(CPACK_PACKAGE_VERSION "${PROJECT_VERSION}")
|
||||||
|
set(CPACK_PACKAGE_INSTALL_DIRECTORY "Schedule")
|
||||||
|
set(CPACK_PACKAGE_EXECUTABLES "Schedule;AI 日程")
|
||||||
|
set(CPACK_CREATE_DESKTOP_LINKS "Schedule")
|
||||||
|
set(CPACK_NSIS_DISPLAY_NAME "AI 日程")
|
||||||
|
set(CPACK_NSIS_PACKAGE_NAME "AI 日程")
|
||||||
|
set(CPACK_NSIS_ENABLE_UNINSTALL_BEFORE_INSTALL ON)
|
||||||
|
set(CPACK_NSIS_MODIFY_PATH OFF)
|
||||||
|
set(CPACK_NSIS_INSTALLED_ICON_NAME "Schedule.exe")
|
||||||
|
set(CPACK_NSIS_MUI_FINISHPAGE_RUN "Schedule.exe")
|
||||||
|
set(CPACK_RESOURCE_FILE_README "${CMAKE_SOURCE_DIR}/README.md")
|
||||||
|
include(CPack)
|
||||||
|
endif()
|
||||||
|
|||||||
@@ -65,6 +65,18 @@
|
|||||||
"deprecated": false
|
"deprecated": false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "windows-mingw-release",
|
||||||
|
"displayName": "Windows MinGW-w64 Release",
|
||||||
|
"inherits": "windows-mingw",
|
||||||
|
"binaryDir": "${sourceDir}/build/windows-mingw-release",
|
||||||
|
"cacheVariables": {
|
||||||
|
"CMAKE_BUILD_TYPE": "Release"
|
||||||
|
},
|
||||||
|
"warnings": {
|
||||||
|
"deprecated": false
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "macos-clang",
|
"name": "macos-clang",
|
||||||
"displayName": "macOS Clang (edit Qt path in preset)",
|
"displayName": "macOS Clang (edit Qt path in preset)",
|
||||||
@@ -96,6 +108,10 @@
|
|||||||
"name": "windows-mingw",
|
"name": "windows-mingw",
|
||||||
"configurePreset": "windows-mingw"
|
"configurePreset": "windows-mingw"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "windows-mingw-release",
|
||||||
|
"configurePreset": "windows-mingw-release"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "macos-clang",
|
"name": "macos-clang",
|
||||||
"configurePreset": "macos-clang"
|
"configurePreset": "macos-clang"
|
||||||
@@ -143,6 +159,11 @@
|
|||||||
"QT_QPA_PLATFORM": "offscreen",
|
"QT_QPA_PLATFORM": "offscreen",
|
||||||
"PATH": "C:/Qt/6.6.3/mingw_64/bin;C:/Qt/Tools/mingw1120_64/bin;$penv{PATH}"
|
"PATH": "C:/Qt/6.6.3/mingw_64/bin;C:/Qt/Tools/mingw1120_64/bin;$penv{PATH}"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "windows-mingw-release",
|
||||||
|
"inherits": "windows-mingw",
|
||||||
|
"configurePreset": "windows-mingw-release"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
细粒度个人日程 + AI 自然语言排程 + 自部署多设备同步。
|
细粒度个人日程 + AI 自然语言排程 + 自部署多设备同步。
|
||||||
|
|
||||||
当前进度:**阶段 0 + 阶段 1 + 界面重构 + TOML 配置 + AI 日程闭环 + AI 增强(更新/删除/涟漪/拆分)+ 多设备同步**。
|
当前进度:**阶段 0–4 + 搜索 / 重复日程 / Windows 安装包 / 界面动画**。
|
||||||
本地模型 50 条指令回归已完成:完整 49/50(98%),失败项 #42 单独复测通过。
|
本地模型 50 条指令回归已完成:完整 49/50(98%),失败项 #42 单独复测通过。
|
||||||
详细计划见 [`docs/PLAN.md`](docs/PLAN.md),验证记录见 [`docs/validation/`](docs/validation/)。
|
详细计划见 [`docs/PLAN.md`](docs/PLAN.md),验证记录见 [`docs/validation/`](docs/validation/)。
|
||||||
|
|
||||||
@@ -11,6 +11,9 @@
|
|||||||
- **紧凑主窗口**(默认启动):AI 助手 + 今日任务,顶部可打开详细日程或设置。
|
- **紧凑主窗口**(默认启动):AI 助手 + 今日任务,顶部可打开详细日程或设置。
|
||||||
- **详细日程窗口**:日 / 月 / 年三种视图、选中日期任务面板、新建/编辑/删除、设置;顶部房屋按钮或关闭窗口回到紧凑窗口。
|
- **详细日程窗口**:日 / 月 / 年三种视图、选中日期任务面板、新建/编辑/删除、设置;顶部房屋按钮或关闭窗口回到紧凑窗口。
|
||||||
- **系统托盘**:关闭紧凑窗口时最小化到托盘;托盘可显示主窗口、新建日程、退出。
|
- **系统托盘**:关闭紧凑窗口时最小化到托盘;托盘可显示主窗口、新建日程、退出。
|
||||||
|
- **智能增强**:今日任务面板显示主动建议;日视图绘制幽灵时间;提供每日复盘对话框。
|
||||||
|
- **搜索与重复**:详细日程支持标题/说明搜索(`Ctrl+F`);新建日程可设置每天/每周/每月重复。
|
||||||
|
- **轻量动画**:窗口淡入、视图切换淡入、任务列表刷新与 Diff 卡片淡入。
|
||||||
- **设置**:主题(跟随系统/浅色/深色)、ElaMica 云母效果、AI 接口地址/模型/API Key、同步服务地址/开关。
|
- **设置**:主题(跟随系统/浅色/深色)、ElaMica 云母效果、AI 接口地址/模型/API Key、同步服务地址/开关。
|
||||||
|
|
||||||
> 云母效果使用 ElaWidgetTools 的 `ElaMica` 跨平台模拟背景(内置模糊基底图),
|
> 云母效果使用 ElaWidgetTools 的 `ElaMica` 跨平台模拟背景(内置模糊基底图),
|
||||||
@@ -35,10 +38,57 @@
|
|||||||
- Word:docx 需要 `unzip`,doc 需要 `catdoc`
|
- Word:docx 需要 `unzip`,doc 需要 `catdoc`
|
||||||
- 图片:以 data URL 发送,需要模型支持视觉输入
|
- 图片:以 data URL 发送,需要模型支持视觉输入
|
||||||
|
|
||||||
排程由本地确定性 `SchedulerEngine` 完成:避开已确认日程、优先用户指定时间、回退到 08:00–22:00、按 15 分钟粒度、遵守 deadline。
|
排程由本地确定性 `SchedulerEngine` 完成:避开已确认日程、优先用户指定时间、回退到 08:00–22:00、按 15 分钟粒度、遵守 deadline,并按学习到的精力曲线约束高精力任务。
|
||||||
|
|
||||||
> 隐私提示:拖入文件的文本/图片会发送到你配置的 AI 服务。若需完全离线,请配置本地 OpenAI 兼容模型。
|
> 隐私提示:拖入文件的文本/图片会发送到你配置的 AI 服务。若需完全离线,请配置本地 OpenAI 兼容模型。
|
||||||
|
|
||||||
|
## 精力、幽灵时间与复盘
|
||||||
|
|
||||||
|
- 客户端从**已完成且带 `energy_req` 的日程**学习 7×24 精力档案(0 低 / 1 中 / 2 高);撤销完成后会回退。
|
||||||
|
- AI 收到精力高峰摘要;`SchedulerEngine` 会为高精力任务寻找高精力时段,而不是只找最早空档。
|
||||||
|
- **幽灵时间**:日视图以半透明虚线块显示 08:00–22:00 内的可用空档;复盘对话框列出当天所有 30 分钟以上空档。
|
||||||
|
- **主动建议**:今日任务面板顶部显示「处理超时日程 / 发现幽灵时间 / 做一次今日复盘」等确定性建议。
|
||||||
|
- **每日复盘**:点击今日任务标题旁的复盘按钮或按 `Ctrl+R`,查看完成率、专注时长、精力高峰、待办与幽灵时间。
|
||||||
|
|
||||||
|
精力档案按设备本地保存,不参与多设备变更流;不同设备的作息差异不会互相覆盖。
|
||||||
|
|
||||||
|
## 搜索与重复日程
|
||||||
|
|
||||||
|
### 搜索
|
||||||
|
|
||||||
|
- 详细日程顶部搜索框输入标题或说明,回车打开结果;`Ctrl+F` 从任何窗口打开。
|
||||||
|
- 查询覆盖任务标题、说明和来源引用;结果按离当前时间最近排序,最多 100 条。
|
||||||
|
- 点击或回车选择结果会跳到对应日期并定位到日程块。
|
||||||
|
|
||||||
|
### 重复日程
|
||||||
|
|
||||||
|
- 新建日程时可选择每天、每周或每月重复,并设置重复结束日期。
|
||||||
|
- 重复会物化为共享同一任务的时间块,最多 1 年 / 200 次;与现有日程冲突的日期会自动跳过。
|
||||||
|
- 重复规则元数据保存在本机 `recurrence` 表;具体时间块照常参与多设备同步。其他设备能看到所有已物化的日程。
|
||||||
|
- 编辑某个重复日程的标题会修改共享任务标题(影响该系列);删除单个块只删除该次。
|
||||||
|
|
||||||
|
## 同步冲突行为
|
||||||
|
|
||||||
|
同步是后台无感进行的:不弹冲突对话框,失败自动重试,状态只显示在顶部标签。
|
||||||
|
|
||||||
|
- **同一任务/时间块在不同设备同时编辑**:按 `updated_at` 做 LWW,时间戳更新的版本获胜;删除墓碑在等时间戳时优先。
|
||||||
|
- **不同日程被安排在同一时间**:它们是两个独立实体,都会保留,日视图以重叠列展示;系统不会自动移动或删除任何一方。
|
||||||
|
- **重复日程**:物化后的时间块按普通日程同步;重复规则本身不参与变更流。
|
||||||
|
- **服务端**只保存有序变更流,不做语义合并;最终一致性由客户端 LWW 保证。
|
||||||
|
- 如果希望“同一时间只保留一个日程”,需要后续在客户端增加冲突策略或自动涟漪;当前策略是保留双方、避免静默丢数据。
|
||||||
|
|
||||||
|
### 本地模型
|
||||||
|
|
||||||
|
本地模型通过 **OpenAI 兼容端点**接入,与云端使用同一套 Provider:
|
||||||
|
|
||||||
|
| 服务 | 接口地址示例 | API Key |
|
||||||
|
|---|---|---|
|
||||||
|
| Ollama | `http://127.0.0.1:11434/v1` | 留空 |
|
||||||
|
| LM Studio | `http://127.0.0.1:1234/v1` | 留空 |
|
||||||
|
| vLLM / llama.cpp / 其他 | 对应 `/v1` 地址 | 按服务要求 |
|
||||||
|
|
||||||
|
在设置中填写接口地址和模型名即可;本地服务不要求 API Key 时留空。模型需要支持流式 SSE 和 OpenAI Chat Completions 格式。
|
||||||
|
|
||||||
### Linux 中文输入法(fcitx5)
|
### Linux 中文输入法(fcitx5)
|
||||||
|
|
||||||
自定义 Qt 安装通常不带 fcitx5 的 Qt6 platform input context 插件;系统包
|
自定义 Qt 安装通常不带 fcitx5 的 Qt6 platform input context 插件;系统包
|
||||||
@@ -143,6 +193,22 @@ cmake --build --preset linux-gcc
|
|||||||
`windows-msvc` 与 `macos-clang` 也采用相同的做法:在对应 preset 中直接填写
|
`windows-msvc` 与 `macos-clang` 也采用相同的做法:在对应 preset 中直接填写
|
||||||
`CMAKE_PREFIX_PATH`,不使用环境变量或自动搜索。
|
`CMAKE_PREFIX_PATH`,不使用环境变量或自动搜索。
|
||||||
|
|
||||||
|
### Windows 安装包
|
||||||
|
|
||||||
|
安装 [NSIS](https://nsis.sourceforge.io/) 并将 `makensis.exe` 加入 `PATH` 后,在仓库根目录运行:
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
.\scripts\package-windows.ps1
|
||||||
|
```
|
||||||
|
|
||||||
|
脚本会使用 `windows-mingw-release` preset 构建 Release、运行测试,然后执行 CPack:
|
||||||
|
|
||||||
|
- 安装 `build/windows-mingw-release/Schedule-0.1.0-win64.exe`;
|
||||||
|
- 安装过程会自动运行 `windeployqt`,收集 Qt DLL、插件和 MinGW 运行时;
|
||||||
|
- 未安装 NSIS 时会退化为 `Schedule-*.zip` 便携包。
|
||||||
|
|
||||||
|
安装包包含开始菜单项与桌面快捷方式,卸载信息写入 Windows 应用列表。
|
||||||
|
|
||||||
### Windows 多设备联调
|
### Windows 多设备联调
|
||||||
|
|
||||||
1. 在服务端机器启动 `go run ./cmd/server`(或 Docker),设置随机 `SYNC_TOKEN_PEPPER`。
|
1. 在服务端机器启动 `go run ./cmd/server`(或 Docker),设置随机 `SYNC_TOKEN_PEPPER`。
|
||||||
@@ -162,9 +228,9 @@ cmake --build --preset linux-gcc
|
|||||||
ctest --preset linux-gcc
|
ctest --preset linux-gcc
|
||||||
```
|
```
|
||||||
|
|
||||||
当前自动化测试(11 组):存储/服务、网格与详细窗口、紧凑窗口、TOML 配置、SchedulerEngine、
|
当前自动化测试(12 组):存储/服务、网格与详细窗口、紧凑窗口、TOML 配置、SchedulerEngine、
|
||||||
AI 编排(15 个用例:流式、修复、更新/删除、涟漪、拆分、冲突保护、多轮历史、文件、删除兜底、无 diff 重试)、
|
精力档案 / 幽灵时间 / 每日复盘、搜索 / 重复日程、AI 编排(15 个用例:流式、修复、更新/删除、涟漪、拆分、冲突保护、多轮历史、文件、删除兜底、无 diff 重试)、
|
||||||
OpenAI 兼容 Provider(本地假 SSE 服务)、AI 对话到接受落库的 UI 全链路、Go 服务端单元/接口/并发测试、双客户端同步集成(含离线重连)。
|
OpenAI 兼容 Provider(本地假 SSE 服务,含无 API Key 的本地模型)、AI 对话到接受落库的 UI 全链路、Go 服务端单元/接口/并发测试、双客户端同步集成(含离线重连)。
|
||||||
|
|
||||||
本地模型回归(50 条真实中文指令):
|
本地模型回归(50 条真实中文指令):
|
||||||
|
|
||||||
@@ -178,7 +244,7 @@ cmake --build --preset linux-gcc --target ai_regression
|
|||||||
|
|
||||||
## 数据与配置
|
## 数据与配置
|
||||||
|
|
||||||
- 数据库:`~/.local/share/Misaki/Schedule/schedule.db`(SQLite WAL)。
|
- 数据库:`~/.local/share/Misaki/Schedule/schedule.db`(SQLite WAL,包含精力档案;精力档案不参与同步)。
|
||||||
- 配置文件:`~/.config/Misaki/Schedule/config.toml`(TOML,权限 0600)。
|
- 配置文件:`~/.config/Misaki/Schedule/config.toml`(TOML,权限 0600)。
|
||||||
- 旧版 `~/.config/Misaki/Schedule.conf` 会在首次启动时自动迁移,原文件保留作备份。
|
- 旧版 `~/.config/Misaki/Schedule.conf` 会在首次启动时自动迁移,原文件保留作备份。
|
||||||
|
|
||||||
@@ -210,6 +276,8 @@ AI 接口地址、模型、API Key 与同步服务地址/开关可直接在设
|
|||||||
|---|---|
|
|---|---|
|
||||||
| `Ctrl+O` | 打开详细日程 |
|
| `Ctrl+O` | 打开详细日程 |
|
||||||
| `Ctrl+,` | 打开设置 |
|
| `Ctrl+,` | 打开设置 |
|
||||||
|
| `Ctrl+R` | 今日复盘 |
|
||||||
|
| `Ctrl+F` | 打开搜索 |
|
||||||
|
|
||||||
### 详细日程窗口
|
### 详细日程窗口
|
||||||
|
|
||||||
@@ -221,6 +289,8 @@ AI 接口地址、模型、API Key 与同步服务地址/开关可直接在设
|
|||||||
| `Alt+←/→` | 上一段 / 下一段(日/月/年自适应) |
|
| `Alt+←/→` | 上一段 / 下一段(日/月/年自适应) |
|
||||||
| `Ctrl+T` | 回到今天 |
|
| `Ctrl+T` | 回到今天 |
|
||||||
| `Ctrl+,` | 打开设置 |
|
| `Ctrl+,` | 打开设置 |
|
||||||
|
| `Ctrl+R` | 今日复盘 |
|
||||||
|
| `Ctrl+F` | 搜索日程 |
|
||||||
| `Ctrl` + 滚轮 | 时间轴缩放(日视图) |
|
| `Ctrl` + 滚轮 | 时间轴缩放(日视图) |
|
||||||
| `Delete` | 删除选中日程(日视图) |
|
| `Delete` | 删除选中日程(日视图) |
|
||||||
| `Enter` | 编辑选中日程(日视图) |
|
| `Enter` | 编辑选中日程(日视图) |
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
当前本地时间:{CURRENT_TIME}
|
当前本地时间:{CURRENT_TIME}
|
||||||
今天星期:{WEEKDAY}
|
今天星期:{WEEKDAY}
|
||||||
用户默认可用时间:{WORK_START}–{WORK_END}
|
用户默认可用时间:{WORK_START}–{WORK_END}
|
||||||
|
用户精力高峰(用于安排高精力任务):{ENERGY_PROFILE}
|
||||||
用户现有日程(每行开头的 [bN] 是引用编号,只能用于 update/delete):
|
用户现有日程(每行开头的 [bN] 是引用编号,只能用于 update/delete):
|
||||||
{EXISTING_SCHEDULE}
|
{EXISTING_SCHEDULE}
|
||||||
|
|
||||||
@@ -29,6 +30,7 @@
|
|||||||
15. 现有日程摘要中带“(会议)”标记的条目属于会议类;用户要求删除“所有会议”时,逐个 delete 所有带该标记的条目。
|
15. 现有日程摘要中带“(会议)”标记的条目属于会议类;用户要求删除“所有会议”时,逐个 delete 所有带该标记的条目。
|
||||||
16. 示例:现有 [b2] 团队同步(会议)、[b4] 项目会议(会议)。用户说“删除明天所有会议”时,输出 {"operations":[{"type":"delete","target_ref":"b2"},{"type":"delete","target_ref":"b4"}]}。
|
16. 示例:现有 [b2] 团队同步(会议)、[b4] 项目会议(会议)。用户说“删除明天所有会议”时,输出 {"operations":[{"type":"delete","target_ref":"b2"},{"type":"delete","target_ref":"b4"}]}。
|
||||||
17. 示例:用户说“明天之前找时间做两小时长任务,可以拆开”,输出 create 并设置 "splittable":true;不要拆成两个独立任务。
|
17. 示例:用户说“明天之前找时间做两小时长任务,可以拆开”,输出 create 并设置 "splittable":true;不要拆成两个独立任务。
|
||||||
|
18. energy_req 取值:0=低精力杂务,1=一般沟通/会议,2=高专注深度工作、学习或创作;不确定时填 1。高精力任务应优先放在用户的精力高峰时段。
|
||||||
|
|
||||||
补充信息:
|
补充信息:
|
||||||
{EXTRA_CONTEXT}
|
{EXTRA_CONTEXT}
|
||||||
|
|||||||
@@ -1,7 +1,12 @@
|
|||||||
add_library(schedule_core STATIC
|
add_library(schedule_core STATIC
|
||||||
core/DateTimeUtils.cpp
|
core/DateTimeUtils.cpp
|
||||||
core/DateTimeUtils.h
|
core/DateTimeUtils.h
|
||||||
|
core/DailyInsights.cpp
|
||||||
|
core/DailyInsights.h
|
||||||
|
core/EnergyProfile.cpp
|
||||||
|
core/EnergyProfile.h
|
||||||
core/ProposedDiff.h
|
core/ProposedDiff.h
|
||||||
|
core/Recurrence.h
|
||||||
core/SchedulerEngine.cpp
|
core/SchedulerEngine.cpp
|
||||||
core/SchedulerEngine.h
|
core/SchedulerEngine.h
|
||||||
core/ScheduleItem.h
|
core/ScheduleItem.h
|
||||||
@@ -77,6 +82,10 @@ add_library(schedule_ui STATIC
|
|||||||
ui/MainWindow.h
|
ui/MainWindow.h
|
||||||
ui/dialogs/BlockEditDialog.cpp
|
ui/dialogs/BlockEditDialog.cpp
|
||||||
ui/dialogs/BlockEditDialog.h
|
ui/dialogs/BlockEditDialog.h
|
||||||
|
ui/dialogs/DailyReviewDialog.cpp
|
||||||
|
ui/dialogs/DailyReviewDialog.h
|
||||||
|
ui/dialogs/SearchDialog.cpp
|
||||||
|
ui/dialogs/SearchDialog.h
|
||||||
ui/dialogs/SettingsDialog.cpp
|
ui/dialogs/SettingsDialog.cpp
|
||||||
ui/dialogs/SettingsDialog.h
|
ui/dialogs/SettingsDialog.h
|
||||||
ui/panels/ChatPanel.cpp
|
ui/panels/ChatPanel.cpp
|
||||||
@@ -87,6 +96,8 @@ add_library(schedule_ui STATIC
|
|||||||
ui/panels/TodayItemCard.h
|
ui/panels/TodayItemCard.h
|
||||||
ui/panels/TodayPanel.cpp
|
ui/panels/TodayPanel.cpp
|
||||||
ui/panels/TodayPanel.h
|
ui/panels/TodayPanel.h
|
||||||
|
ui/theme/AnimationUtils.cpp
|
||||||
|
ui/theme/AnimationUtils.h
|
||||||
ui/theme/ThemeManager.cpp
|
ui/theme/ThemeManager.cpp
|
||||||
ui/theme/ThemeManager.h
|
ui/theme/ThemeManager.h
|
||||||
ui/theme/ThemeTokens.h
|
ui/theme/ThemeTokens.h
|
||||||
@@ -118,3 +129,19 @@ target_link_libraries(Schedule PRIVATE schedule_ui schedule_sync)
|
|||||||
if(WIN32)
|
if(WIN32)
|
||||||
schedule_deploy_qt_runtime(Schedule)
|
schedule_deploy_qt_runtime(Schedule)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
install(TARGETS Schedule
|
||||||
|
RUNTIME DESTINATION .
|
||||||
|
BUNDLE DESTINATION .
|
||||||
|
)
|
||||||
|
if(WIN32 AND MINGW)
|
||||||
|
get_filename_component(_mingw_bin_dir "${CMAKE_CXX_COMPILER}" DIRECTORY)
|
||||||
|
file(GLOB _mingw_runtime
|
||||||
|
"${_mingw_bin_dir}/libgcc_s_*.dll"
|
||||||
|
"${_mingw_bin_dir}/libstdc++-6.dll"
|
||||||
|
"${_mingw_bin_dir}/libwinpthread-1.dll"
|
||||||
|
)
|
||||||
|
if(_mingw_runtime)
|
||||||
|
install(FILES ${_mingw_runtime} DESTINATION .)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|||||||
@@ -476,6 +476,8 @@ QString AIService::buildSystemPrompt()
|
|||||||
prompt.replace(QStringLiteral("{WEEKDAY}"), weekdayLabel(now.date()));
|
prompt.replace(QStringLiteral("{WEEKDAY}"), weekdayLabel(now.date()));
|
||||||
prompt.replace(QStringLiteral("{WORK_START}"), QStringLiteral("08:00"));
|
prompt.replace(QStringLiteral("{WORK_START}"), QStringLiteral("08:00"));
|
||||||
prompt.replace(QStringLiteral("{WORK_END}"), QStringLiteral("22:00"));
|
prompt.replace(QStringLiteral("{WORK_END}"), QStringLiteral("22:00"));
|
||||||
|
prompt.replace(QStringLiteral("{ENERGY_PROFILE}"),
|
||||||
|
m_scheduleService.dailyReview(now.date()).energySummary);
|
||||||
prompt.replace(QStringLiteral("{EXISTING_SCHEDULE}"), scheduleSummary());
|
prompt.replace(QStringLiteral("{EXISTING_SCHEDULE}"), scheduleSummary());
|
||||||
prompt.replace(QStringLiteral("{EXTRA_CONTEXT}"),
|
prompt.replace(QStringLiteral("{EXTRA_CONTEXT}"),
|
||||||
m_filePaths.isEmpty()
|
m_filePaths.isEmpty()
|
||||||
@@ -922,6 +924,9 @@ void AIService::buildProposalFromOperations(const QJsonArray& operations, const
|
|||||||
}
|
}
|
||||||
scheduler::Options options;
|
scheduler::Options options;
|
||||||
options.granularityMinutes = 15;
|
options.granularityMinutes = 15;
|
||||||
|
options.energyAt = [this](scheduler::SysTime value) {
|
||||||
|
return m_scheduleService.energyLevelFor(fromSysTime(value));
|
||||||
|
};
|
||||||
|
|
||||||
struct Busy
|
struct Busy
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,273 @@
|
|||||||
|
#include "DailyInsights.h"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
|
#include "core/DateTimeUtils.h"
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
bool isActiveStatus(const QString& status)
|
||||||
|
{
|
||||||
|
return status == QStringLiteral("scheduled") || status == QStringLiteral("in_progress");
|
||||||
|
}
|
||||||
|
|
||||||
|
bool occupiesTime(const QString& status)
|
||||||
|
{
|
||||||
|
return status != QStringLiteral("dropped") && status != QStringLiteral("missed");
|
||||||
|
}
|
||||||
|
|
||||||
|
QDateTime dayBoundary(const QDate& date, int hour)
|
||||||
|
{
|
||||||
|
if (hour >= 24)
|
||||||
|
{
|
||||||
|
return QDateTime(date.addDays(1), QTime(0, 0), Qt::LocalTime);
|
||||||
|
}
|
||||||
|
return QDateTime(date, QTime(std::max(0, hour), 0), Qt::LocalTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
QString formatWindow(const FreeWindow& window)
|
||||||
|
{
|
||||||
|
return QStringLiteral("%1–%2").arg(window.start.toString(QStringLiteral("HH:mm")),
|
||||||
|
window.end.toString(QStringLiteral("HH:mm")));
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
QVector<FreeWindow> findFreeWindows(const QVector<ScheduleItem>& items,
|
||||||
|
const QDate& date,
|
||||||
|
const QDateTime& from,
|
||||||
|
int workStartHour,
|
||||||
|
int workEndHour,
|
||||||
|
int minMinutes)
|
||||||
|
{
|
||||||
|
QVector<FreeWindow> result;
|
||||||
|
if (!date.isValid())
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
QDateTime rangeStart = dayBoundary(date, workStartHour);
|
||||||
|
const QDateTime rangeEnd = dayBoundary(date, workEndHour);
|
||||||
|
if (from.isValid() && from > rangeStart)
|
||||||
|
{
|
||||||
|
rangeStart = from;
|
||||||
|
}
|
||||||
|
if (rangeStart >= rangeEnd || minMinutes <= 0)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
QVector<QPair<QDateTime, QDateTime>> busy;
|
||||||
|
for (const ScheduleItem& item : items)
|
||||||
|
{
|
||||||
|
if (!occupiesTime(item.block.status))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const QDateTime start = std::max(item.block.startAt, rangeStart);
|
||||||
|
const QDateTime end = std::min(item.block.endAt, rangeEnd);
|
||||||
|
if (start < end)
|
||||||
|
{
|
||||||
|
busy.append({start, end});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
std::sort(busy.begin(), busy.end(), [](const auto& a, const auto& b) {
|
||||||
|
return a.first < b.first;
|
||||||
|
});
|
||||||
|
|
||||||
|
QDateTime cursor = rangeStart;
|
||||||
|
for (const auto& interval : busy)
|
||||||
|
{
|
||||||
|
if (interval.second <= cursor)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (interval.first > cursor)
|
||||||
|
{
|
||||||
|
const int minutes = DateTimeUtils::minutesBetween(cursor, interval.first);
|
||||||
|
if (minutes >= minMinutes)
|
||||||
|
{
|
||||||
|
result.append({cursor, interval.first, minutes});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cursor = std::max(cursor, interval.second);
|
||||||
|
}
|
||||||
|
if (cursor < rangeEnd)
|
||||||
|
{
|
||||||
|
const int minutes = DateTimeUtils::minutesBetween(cursor, rangeEnd);
|
||||||
|
if (minutes >= minMinutes)
|
||||||
|
{
|
||||||
|
result.append({cursor, rangeEnd, minutes});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
QVector<FreeWindow> findFreeWindows(const QVector<ScheduleItem>& items,
|
||||||
|
const QDate& date,
|
||||||
|
int workStartHour,
|
||||||
|
int workEndHour,
|
||||||
|
int minMinutes)
|
||||||
|
{
|
||||||
|
return findFreeWindows(items, date, dayBoundary(date, workStartHour), workStartHour, workEndHour, minMinutes);
|
||||||
|
}
|
||||||
|
|
||||||
|
DailyReview buildDailyReview(const QVector<ScheduleItem>& items,
|
||||||
|
const QDate& date,
|
||||||
|
const QDateTime& now)
|
||||||
|
{
|
||||||
|
DailyReview review;
|
||||||
|
review.date = date;
|
||||||
|
review.total = items.size();
|
||||||
|
for (const ScheduleItem& item : items)
|
||||||
|
{
|
||||||
|
const QString& status = item.block.status;
|
||||||
|
if (status == QStringLiteral("done"))
|
||||||
|
{
|
||||||
|
++review.done;
|
||||||
|
review.focusedMinutes +=
|
||||||
|
std::max(0, DateTimeUtils::minutesBetween(item.block.startAt, item.block.endAt));
|
||||||
|
}
|
||||||
|
else if (isActiveStatus(status))
|
||||||
|
{
|
||||||
|
++review.active;
|
||||||
|
if (item.block.endAt < now)
|
||||||
|
{
|
||||||
|
++review.overdue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (status == QStringLiteral("missed"))
|
||||||
|
{
|
||||||
|
++review.missed;
|
||||||
|
}
|
||||||
|
else if (status == QStringLiteral("dropped"))
|
||||||
|
{
|
||||||
|
++review.dropped;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
review.completionPercent =
|
||||||
|
review.total > 0 ? static_cast<int>(std::lround(review.done * 100.0 / review.total)) : 0;
|
||||||
|
|
||||||
|
const QDateTime reviewFrom = date < now.date() ? dayBoundary(date, 8) : now;
|
||||||
|
review.ghostWindows = findFreeWindows(items, date, reviewFrom, 8, 22, 30);
|
||||||
|
|
||||||
|
if (review.total == 0)
|
||||||
|
{
|
||||||
|
review.summary = QStringLiteral("今天还没有安排;可以先留出一段专注时间。");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
review.summary = QStringLiteral("完成 %1/%2 项(%3%),累计专注 %4。")
|
||||||
|
.arg(review.done)
|
||||||
|
.arg(review.total)
|
||||||
|
.arg(review.completionPercent)
|
||||||
|
.arg(DateTimeUtils::formatDuration(review.focusedMinutes));
|
||||||
|
}
|
||||||
|
if (review.overdue > 0)
|
||||||
|
{
|
||||||
|
review.highlights.append(QStringLiteral("%1 项日程已超时").arg(review.overdue));
|
||||||
|
}
|
||||||
|
if (review.active > 0)
|
||||||
|
{
|
||||||
|
review.highlights.append(QStringLiteral("还有 %1 项待办").arg(review.active));
|
||||||
|
}
|
||||||
|
if (review.missed > 0 || review.dropped > 0)
|
||||||
|
{
|
||||||
|
review.highlights.append(
|
||||||
|
QStringLiteral("错过 %1 项,放弃 %2 项").arg(review.missed).arg(review.dropped));
|
||||||
|
}
|
||||||
|
if (review.done > 0)
|
||||||
|
{
|
||||||
|
review.highlights.append(QStringLiteral("今日专注 %1 分钟").arg(review.focusedMinutes));
|
||||||
|
}
|
||||||
|
if (review.ghostWindows.isEmpty())
|
||||||
|
{
|
||||||
|
review.highlights.append(QStringLiteral("今天没有 30 分钟以上的幽灵时间"));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
review.highlights.append(
|
||||||
|
QStringLiteral("幽灵时间最早一段:%1").arg(formatWindow(review.ghostWindows.first())));
|
||||||
|
}
|
||||||
|
return review;
|
||||||
|
}
|
||||||
|
|
||||||
|
QVector<Suggestion> buildSuggestions(const QVector<ScheduleItem>& items,
|
||||||
|
const QDateTime& now,
|
||||||
|
int maxCount)
|
||||||
|
{
|
||||||
|
QVector<Suggestion> result;
|
||||||
|
if (maxCount <= 0)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
QVector<ScheduleItem> overdue;
|
||||||
|
for (const ScheduleItem& item : items)
|
||||||
|
{
|
||||||
|
if (isActiveStatus(item.block.status) && item.block.endAt < now)
|
||||||
|
{
|
||||||
|
overdue.append(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!overdue.isEmpty())
|
||||||
|
{
|
||||||
|
Suggestion suggestion;
|
||||||
|
suggestion.kind = Suggestion::Kind::Overdue;
|
||||||
|
suggestion.title = QStringLiteral("处理超时日程");
|
||||||
|
suggestion.detail = QStringLiteral("「%1」%2已超时,建议重新安排或标记完成。")
|
||||||
|
.arg(overdue.first().task.title)
|
||||||
|
.arg(overdue.size() > 1
|
||||||
|
? QStringLiteral("等 %1 项").arg(overdue.size())
|
||||||
|
: QString());
|
||||||
|
result.append(suggestion);
|
||||||
|
}
|
||||||
|
if (result.size() >= maxCount)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QVector<FreeWindow> ghost =
|
||||||
|
findFreeWindows(items, now.date(), now, 8, 22, 30);
|
||||||
|
if (!ghost.isEmpty())
|
||||||
|
{
|
||||||
|
Suggestion suggestion;
|
||||||
|
suggestion.kind = Suggestion::Kind::GhostTime;
|
||||||
|
suggestion.title = QStringLiteral("发现幽灵时间");
|
||||||
|
const FreeWindow& window = ghost.first();
|
||||||
|
suggestion.detail = QStringLiteral("%1 空出 %2,可安排一件重要的事。")
|
||||||
|
.arg(formatWindow(window), DateTimeUtils::formatDuration(window.minutes));
|
||||||
|
suggestion.start = window.start;
|
||||||
|
suggestion.end = window.end;
|
||||||
|
result.append(suggestion);
|
||||||
|
}
|
||||||
|
if (result.size() >= maxCount)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
int doneCount = 0;
|
||||||
|
int activeCount = 0;
|
||||||
|
for (const ScheduleItem& item : items)
|
||||||
|
{
|
||||||
|
if (item.block.status == QStringLiteral("done"))
|
||||||
|
{
|
||||||
|
++doneCount;
|
||||||
|
}
|
||||||
|
else if (isActiveStatus(item.block.status))
|
||||||
|
{
|
||||||
|
++activeCount;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (now.time().hour() >= 18 && (doneCount > 0 || activeCount > 0))
|
||||||
|
{
|
||||||
|
Suggestion suggestion;
|
||||||
|
suggestion.kind = Suggestion::Kind::Review;
|
||||||
|
suggestion.title = QStringLiteral("做一次今日复盘");
|
||||||
|
suggestion.detail = QStringLiteral("今天完成 %1 项,还有 %2 项待办,花 2 分钟回顾一下。")
|
||||||
|
.arg(doneCount)
|
||||||
|
.arg(activeCount);
|
||||||
|
result.append(suggestion);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
@@ -0,0 +1,71 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QDate>
|
||||||
|
#include <QDateTime>
|
||||||
|
#include <QString>
|
||||||
|
#include <QStringList>
|
||||||
|
#include <QVector>
|
||||||
|
|
||||||
|
#include "core/ScheduleItem.h"
|
||||||
|
|
||||||
|
struct FreeWindow
|
||||||
|
{
|
||||||
|
QDateTime start;
|
||||||
|
QDateTime end;
|
||||||
|
int minutes = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct DailyReview
|
||||||
|
{
|
||||||
|
QDate date;
|
||||||
|
int total = 0;
|
||||||
|
int done = 0;
|
||||||
|
int active = 0;
|
||||||
|
int missed = 0;
|
||||||
|
int dropped = 0;
|
||||||
|
int overdue = 0;
|
||||||
|
int focusedMinutes = 0;
|
||||||
|
int completionPercent = 0;
|
||||||
|
QVector<FreeWindow> ghostWindows;
|
||||||
|
QStringList highlights;
|
||||||
|
QString summary;
|
||||||
|
QString energySummary;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Suggestion
|
||||||
|
{
|
||||||
|
enum class Kind
|
||||||
|
{
|
||||||
|
Overdue,
|
||||||
|
GhostTime,
|
||||||
|
Review,
|
||||||
|
Energy,
|
||||||
|
};
|
||||||
|
|
||||||
|
Kind kind = Kind::Review;
|
||||||
|
QString title;
|
||||||
|
QString detail;
|
||||||
|
QDateTime start;
|
||||||
|
QDateTime end;
|
||||||
|
};
|
||||||
|
|
||||||
|
QVector<FreeWindow> findFreeWindows(const QVector<ScheduleItem>& items,
|
||||||
|
const QDate& date,
|
||||||
|
const QDateTime& from,
|
||||||
|
int workStartHour = 8,
|
||||||
|
int workEndHour = 22,
|
||||||
|
int minMinutes = 30);
|
||||||
|
|
||||||
|
QVector<FreeWindow> findFreeWindows(const QVector<ScheduleItem>& items,
|
||||||
|
const QDate& date,
|
||||||
|
int workStartHour = 8,
|
||||||
|
int workEndHour = 22,
|
||||||
|
int minMinutes = 30);
|
||||||
|
|
||||||
|
DailyReview buildDailyReview(const QVector<ScheduleItem>& items,
|
||||||
|
const QDate& date,
|
||||||
|
const QDateTime& now = QDateTime::currentDateTime());
|
||||||
|
|
||||||
|
QVector<Suggestion> buildSuggestions(const QVector<ScheduleItem>& items,
|
||||||
|
const QDateTime& now,
|
||||||
|
int maxCount = 3);
|
||||||
@@ -0,0 +1,147 @@
|
|||||||
|
#include "EnergyProfile.h"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
int clampedLevel(int level)
|
||||||
|
{
|
||||||
|
return std::clamp(level, 0, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
int clampedWeekday(int weekday)
|
||||||
|
{
|
||||||
|
return std::clamp(weekday, 1, 7);
|
||||||
|
}
|
||||||
|
|
||||||
|
int clampedHour(int hour)
|
||||||
|
{
|
||||||
|
return std::clamp(hour, 0, 23);
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
EnergyProfile EnergyProfile::defaults()
|
||||||
|
{
|
||||||
|
EnergyProfile profile;
|
||||||
|
for (int weekday = 1; weekday <= 7; ++weekday)
|
||||||
|
{
|
||||||
|
for (int hour = 0; hour < 24; ++hour)
|
||||||
|
{
|
||||||
|
int level = 0;
|
||||||
|
if (weekday <= 5)
|
||||||
|
{
|
||||||
|
if (hour >= 9 && hour <= 11)
|
||||||
|
{
|
||||||
|
level = 2;
|
||||||
|
}
|
||||||
|
else if (hour == 8 || hour == 12 || hour == 14 || (hour >= 15 && hour <= 18))
|
||||||
|
{
|
||||||
|
level = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if ((hour >= 10 && hour <= 11) || (hour >= 14 && hour <= 17))
|
||||||
|
{
|
||||||
|
level = 1;
|
||||||
|
}
|
||||||
|
profile.m_levels[weekday][hour] = level;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return profile;
|
||||||
|
}
|
||||||
|
|
||||||
|
EnergyProfile EnergyProfile::fromLevels(const QVector<EnergyLevel>& levels)
|
||||||
|
{
|
||||||
|
EnergyProfile profile = defaults();
|
||||||
|
for (const EnergyLevel& level : levels)
|
||||||
|
{
|
||||||
|
profile.m_levels[clampedWeekday(level.weekday)][clampedHour(level.hour)] =
|
||||||
|
clampedLevel(level.level);
|
||||||
|
}
|
||||||
|
return profile;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString EnergyProfile::label(int level)
|
||||||
|
{
|
||||||
|
switch (clampedLevel(level))
|
||||||
|
{
|
||||||
|
case 2:
|
||||||
|
return QStringLiteral("高");
|
||||||
|
case 1:
|
||||||
|
return QStringLiteral("中");
|
||||||
|
default:
|
||||||
|
return QStringLiteral("低");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int EnergyProfile::level(int weekday, int hour) const
|
||||||
|
{
|
||||||
|
if (weekday < 1 || weekday > 7 || hour < 0 || hour > 23)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return m_levels[weekday][hour];
|
||||||
|
}
|
||||||
|
|
||||||
|
int EnergyProfile::level(const QDateTime& localDateTime) const
|
||||||
|
{
|
||||||
|
if (!localDateTime.isValid())
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return level(localDateTime.date().dayOfWeek(), localDateTime.time().hour());
|
||||||
|
}
|
||||||
|
|
||||||
|
bool EnergyProfile::setLevel(int weekday, int hour, int levelValue)
|
||||||
|
{
|
||||||
|
if (weekday < 1 || weekday > 7 || hour < 0 || hour > 23)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
m_levels[weekday][hour] = clampedLevel(levelValue);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
QVector<EnergyLevel> EnergyProfile::levels() const
|
||||||
|
{
|
||||||
|
QVector<EnergyLevel> result;
|
||||||
|
result.reserve(7 * 24);
|
||||||
|
for (int weekday = 1; weekday <= 7; ++weekday)
|
||||||
|
{
|
||||||
|
for (int hour = 0; hour < 24; ++hour)
|
||||||
|
{
|
||||||
|
result.append({weekday, hour, m_levels[weekday][hour]});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void EnergyProfile::learn(const QVector<EnergySample>& samples)
|
||||||
|
{
|
||||||
|
std::array<std::array<int, 24>, 8> sums{};
|
||||||
|
std::array<std::array<int, 24>, 8> counts{};
|
||||||
|
for (const EnergySample& sample : samples)
|
||||||
|
{
|
||||||
|
if (sample.weekday < 1 || sample.weekday > 7 || sample.hour < 0 || sample.hour > 23)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
sums[sample.weekday][sample.hour] += clampedLevel(sample.level);
|
||||||
|
++counts[sample.weekday][sample.hour];
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int weekday = 1; weekday <= 7; ++weekday)
|
||||||
|
{
|
||||||
|
for (int hour = 0; hour < 24; ++hour)
|
||||||
|
{
|
||||||
|
if (counts[weekday][hour] == 0)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const double average =
|
||||||
|
static_cast<double>(sums[weekday][hour]) / counts[weekday][hour];
|
||||||
|
m_levels[weekday][hour] =
|
||||||
|
std::clamp(static_cast<int>(std::lround(average)), 0, 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QDateTime>
|
||||||
|
#include <QString>
|
||||||
|
#include <QVector>
|
||||||
|
|
||||||
|
#include <array>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 类名: EnergyProfile
|
||||||
|
* 功能: 按星期与小时保存精力水平(0 低 / 1 中 / 2 高),并从完成记录学习
|
||||||
|
* 线程安全: 否(值类型)
|
||||||
|
*/
|
||||||
|
struct EnergyLevel
|
||||||
|
{
|
||||||
|
int weekday = 1;
|
||||||
|
int hour = 0;
|
||||||
|
int level = 1;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct EnergySample
|
||||||
|
{
|
||||||
|
int weekday = 1;
|
||||||
|
int hour = 0;
|
||||||
|
int level = 1;
|
||||||
|
};
|
||||||
|
|
||||||
|
class EnergyProfile
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static EnergyProfile defaults();
|
||||||
|
static EnergyProfile fromLevels(const QVector<EnergyLevel>& levels);
|
||||||
|
static QString label(int level);
|
||||||
|
|
||||||
|
int level(int weekday, int hour) const;
|
||||||
|
int level(const QDateTime& localDateTime) const;
|
||||||
|
bool setLevel(int weekday, int hour, int level);
|
||||||
|
QVector<EnergyLevel> levels() const;
|
||||||
|
void learn(const QVector<EnergySample>& samples);
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::array<std::array<int, 24>, 8> m_levels{};
|
||||||
|
};
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QDate>
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
|
enum class RecurrenceFrequency
|
||||||
|
{
|
||||||
|
None = 0,
|
||||||
|
Daily,
|
||||||
|
Weekly,
|
||||||
|
Monthly,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct RecurrenceSpec
|
||||||
|
{
|
||||||
|
RecurrenceFrequency frequency = RecurrenceFrequency::None;
|
||||||
|
QDate until;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Recurrence
|
||||||
|
{
|
||||||
|
QString id;
|
||||||
|
QString taskId;
|
||||||
|
QString rule;
|
||||||
|
std::optional<QDate> until;
|
||||||
|
};
|
||||||
@@ -65,47 +65,62 @@ std::optional<TimeRange> findSlot(const std::vector<TimeRange>& windows,
|
|||||||
SysTime rangeStart,
|
SysTime rangeStart,
|
||||||
std::optional<SysTime> deadline,
|
std::optional<SysTime> deadline,
|
||||||
std::chrono::seconds duration,
|
std::chrono::seconds duration,
|
||||||
int granularityMinutes)
|
int granularityMinutes,
|
||||||
|
int energyRequired,
|
||||||
|
const Options& options)
|
||||||
{
|
{
|
||||||
|
const auto energySatisfied = [&](SysTime start) {
|
||||||
|
if (energyRequired < 0 || !options.energyAt)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
const int level = options.energyAt(start);
|
||||||
|
return level < 0 || level >= energyRequired;
|
||||||
|
};
|
||||||
|
const auto nextGrid = [granularityMinutes](SysTime value) {
|
||||||
|
return ceilToGranularity(value + std::chrono::seconds{std::max(1, granularityMinutes) * 60},
|
||||||
|
granularityMinutes);
|
||||||
|
};
|
||||||
|
|
||||||
for (const TimeRange& window : windows)
|
for (const TimeRange& window : windows)
|
||||||
{
|
{
|
||||||
SysTime cursor = ceilToGranularity(std::max(window.start, rangeStart), granularityMinutes);
|
SysTime cursor = ceilToGranularity(std::max(window.start, rangeStart), granularityMinutes);
|
||||||
if (cursor >= window.end)
|
while (cursor + duration <= window.end)
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const TimeRange& occupied : busy)
|
|
||||||
{
|
|
||||||
if (occupied.end <= cursor)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (occupied.start >= cursor + duration)
|
|
||||||
{
|
|
||||||
if (deadline && cursor + duration > *deadline)
|
|
||||||
{
|
|
||||||
return std::nullopt;
|
|
||||||
}
|
|
||||||
return TimeRange{cursor, cursor + duration};
|
|
||||||
}
|
|
||||||
if (occupied.end > cursor)
|
|
||||||
{
|
|
||||||
cursor = ceilToGranularity(occupied.end, granularityMinutes);
|
|
||||||
if (cursor >= window.end)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cursor + duration <= window.end)
|
|
||||||
{
|
{
|
||||||
if (deadline && cursor + duration > *deadline)
|
if (deadline && cursor + duration > *deadline)
|
||||||
{
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
SysTime occupiedUntil = cursor;
|
||||||
|
bool conflict = false;
|
||||||
|
for (const TimeRange& occupied : busy)
|
||||||
|
{
|
||||||
|
if (occupied.end <= cursor)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (occupied.start >= cursor + duration)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (occupied.start < cursor + duration && occupied.end > cursor)
|
||||||
|
{
|
||||||
|
occupiedUntil = std::max(occupiedUntil, occupied.end);
|
||||||
|
conflict = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (conflict)
|
||||||
|
{
|
||||||
|
cursor = ceilToGranularity(occupiedUntil, granularityMinutes);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
return TimeRange{cursor, cursor + duration};
|
if (energySatisfied(cursor))
|
||||||
|
{
|
||||||
|
return TimeRange{cursor, cursor + duration};
|
||||||
|
}
|
||||||
|
cursor = nextGrid(cursor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
@@ -212,7 +227,9 @@ Result schedule(const std::vector<TaskInput>& tasks,
|
|||||||
rangeStart,
|
rangeStart,
|
||||||
deadline,
|
deadline,
|
||||||
duration,
|
duration,
|
||||||
options.granularityMinutes);
|
options.granularityMinutes,
|
||||||
|
task.energyRequired,
|
||||||
|
options);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -220,7 +237,14 @@ Result schedule(const std::vector<TaskInput>& tasks,
|
|||||||
{
|
{
|
||||||
const SysTime upper = deadline.value_or(rangeEnd);
|
const SysTime upper = deadline.value_or(rangeEnd);
|
||||||
const std::vector<TimeRange> generalWindows = intersect(windows, rangeStart, upper);
|
const std::vector<TimeRange> generalWindows = intersect(windows, rangeStart, upper);
|
||||||
slot = findSlot(generalWindows, busy, rangeStart, deadline, duration, options.granularityMinutes);
|
slot = findSlot(generalWindows,
|
||||||
|
busy,
|
||||||
|
rangeStart,
|
||||||
|
deadline,
|
||||||
|
duration,
|
||||||
|
options.granularityMinutes,
|
||||||
|
task.energyRequired,
|
||||||
|
options);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!slot.has_value())
|
if (!slot.has_value())
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
#include <functional>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@@ -50,6 +51,8 @@ struct Failure
|
|||||||
struct Options
|
struct Options
|
||||||
{
|
{
|
||||||
int granularityMinutes = 15;
|
int granularityMinutes = 15;
|
||||||
|
// 返回某个开始时刻的精力水平(0 低 / 1 中 / 2 高);返回 -1 表示未知。
|
||||||
|
std::function<int(SysTime)> energyAt;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Result
|
struct Result
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
|
#include "core/DailyInsights.h"
|
||||||
#include "core/DateTimeUtils.h"
|
#include "core/DateTimeUtils.h"
|
||||||
#include "storage/SqliteStore.h"
|
#include "storage/SqliteStore.h"
|
||||||
|
|
||||||
@@ -21,6 +22,36 @@ QDateTime truncateToMinute(const QDateTime& value)
|
|||||||
{
|
{
|
||||||
return QDateTime(value.date(), QTime(value.time().hour(), value.time().minute()), value.timeSpec());
|
return QDateTime(value.date(), QTime(value.time().hour(), value.time().minute()), value.timeSpec());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString energySummaryForDate(const EnergyProfile& profile, const QDate& date)
|
||||||
|
{
|
||||||
|
if (!date.isValid())
|
||||||
|
{
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
QStringList windows;
|
||||||
|
int runStart = -1;
|
||||||
|
for (int hour = 0; hour <= 24; ++hour)
|
||||||
|
{
|
||||||
|
const bool high = hour < 24 && profile.level(date.dayOfWeek(), hour) == 2;
|
||||||
|
if (high && runStart < 0)
|
||||||
|
{
|
||||||
|
runStart = hour;
|
||||||
|
}
|
||||||
|
else if (!high && runStart >= 0)
|
||||||
|
{
|
||||||
|
windows.append(QStringLiteral("%1:00–%2:00")
|
||||||
|
.arg(runStart, 2, 10, QLatin1Char('0'))
|
||||||
|
.arg(hour, 2, 10, QLatin1Char('0')));
|
||||||
|
runStart = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (windows.isEmpty())
|
||||||
|
{
|
||||||
|
return QStringLiteral("今天没有明显的高精力时段");
|
||||||
|
}
|
||||||
|
return QStringLiteral("精力高峰:%1").arg(windows.join(QStringLiteral("、")));
|
||||||
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
ScheduleService::ScheduleService(SqliteStore& store, QString deviceId, QObject* parent)
|
ScheduleService::ScheduleService(SqliteStore& store, QString deviceId, QObject* parent)
|
||||||
@@ -28,6 +59,7 @@ ScheduleService::ScheduleService(SqliteStore& store, QString deviceId, QObject*
|
|||||||
, m_store(store)
|
, m_store(store)
|
||||||
, m_deviceId(std::move(deviceId))
|
, m_deviceId(std::move(deviceId))
|
||||||
{
|
{
|
||||||
|
rebuildEnergyProfile();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ScheduleService::validateRange(const QDateTime& start, const QDateTime& end, QString* error)
|
bool ScheduleService::validateRange(const QDateTime& start, const QDateTime& end, QString* error)
|
||||||
@@ -154,6 +186,216 @@ bool ScheduleService::createBlock(const QString& title,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ScheduleService::createRecurringBlock(const QString& title,
|
||||||
|
const QDateTime& start,
|
||||||
|
const QDateTime& end,
|
||||||
|
RecurrenceFrequency frequency,
|
||||||
|
const QDate& until,
|
||||||
|
int* createdCount,
|
||||||
|
QString* error)
|
||||||
|
{
|
||||||
|
if (createdCount)
|
||||||
|
{
|
||||||
|
*createdCount = 0;
|
||||||
|
}
|
||||||
|
if (frequency == RecurrenceFrequency::None)
|
||||||
|
{
|
||||||
|
return createBlock(title, start, end, error);
|
||||||
|
}
|
||||||
|
|
||||||
|
const QDateTime normalizedStart = truncateToMinute(start);
|
||||||
|
const QDateTime normalizedEnd = truncateToMinute(end);
|
||||||
|
if (!validateRange(normalizedStart, normalizedEnd, error))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!until.isValid() || until < normalizedStart.date())
|
||||||
|
{
|
||||||
|
m_lastError = QStringLiteral("重复结束日期必须不早于开始日期");
|
||||||
|
if (error)
|
||||||
|
{
|
||||||
|
*error = m_lastError;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QDate firstDate = normalizedStart.date();
|
||||||
|
const QDate horizon = firstDate.addDays(366);
|
||||||
|
const QDate effectiveUntil = std::min(until, horizon);
|
||||||
|
const int durationSeconds = DateTimeUtils::minutesBetween(normalizedStart, normalizedEnd) * 60;
|
||||||
|
|
||||||
|
QVector<QDateTime> candidates;
|
||||||
|
candidates.reserve(64);
|
||||||
|
for (int index = 0; index < 200; ++index)
|
||||||
|
{
|
||||||
|
QDate date;
|
||||||
|
switch (frequency)
|
||||||
|
{
|
||||||
|
case RecurrenceFrequency::Daily:
|
||||||
|
date = firstDate.addDays(index);
|
||||||
|
break;
|
||||||
|
case RecurrenceFrequency::Weekly:
|
||||||
|
date = firstDate.addDays(index * 7);
|
||||||
|
break;
|
||||||
|
case RecurrenceFrequency::Monthly:
|
||||||
|
date = firstDate.addMonths(index);
|
||||||
|
break;
|
||||||
|
case RecurrenceFrequency::None:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (!date.isValid() || date > effectiveUntil)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
candidates.append(QDateTime(date, normalizedStart.time(), normalizedStart.timeSpec()));
|
||||||
|
}
|
||||||
|
if (candidates.isEmpty())
|
||||||
|
{
|
||||||
|
m_lastError = QStringLiteral("没有生成有效的重复日期");
|
||||||
|
if (error)
|
||||||
|
{
|
||||||
|
*error = m_lastError;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QDateTime lastEnd = candidates.last().addSecs(durationSeconds);
|
||||||
|
const QVector<ScheduleItem> existing =
|
||||||
|
m_store.blocksInRange(DateTimeUtils::localDayStartUtc(firstDate),
|
||||||
|
DateTimeUtils::localDayEndUtc(lastEnd.date()));
|
||||||
|
QVector<QPair<QDateTime, QDateTime>> busy;
|
||||||
|
for (const ScheduleItem& item : existing)
|
||||||
|
{
|
||||||
|
if (item.block.status == QStringLiteral("dropped") ||
|
||||||
|
item.block.status == QStringLiteral("missed"))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
busy.append({item.block.startAt, item.block.endAt});
|
||||||
|
}
|
||||||
|
|
||||||
|
QVector<QDateTime> accepted;
|
||||||
|
for (const QDateTime& occurrence : candidates)
|
||||||
|
{
|
||||||
|
const QDateTime occurrenceEnd = occurrence.addSecs(durationSeconds);
|
||||||
|
const bool conflict = std::any_of(busy.cbegin(), busy.cend(), [&](const auto& interval) {
|
||||||
|
return occurrence < interval.second && occurrenceEnd > interval.first;
|
||||||
|
});
|
||||||
|
if (conflict)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
accepted.append(occurrence);
|
||||||
|
busy.append({occurrence, occurrenceEnd});
|
||||||
|
}
|
||||||
|
if (accepted.isEmpty())
|
||||||
|
{
|
||||||
|
m_lastError = QStringLiteral("重复日程的时段均已被占用");
|
||||||
|
if (error)
|
||||||
|
{
|
||||||
|
*error = m_lastError;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QDateTime now = QDateTime::currentDateTime();
|
||||||
|
Task task;
|
||||||
|
task.id = newId();
|
||||||
|
task.title = title.trimmed().isEmpty() ? QStringLiteral("未命名日程") : title.trimmed();
|
||||||
|
task.source = QStringLiteral("manual");
|
||||||
|
task.estimatedMin = durationSeconds / 60;
|
||||||
|
task.createdAt = now;
|
||||||
|
task.updatedAt = now;
|
||||||
|
task.version = 0;
|
||||||
|
task.deviceId = m_deviceId;
|
||||||
|
|
||||||
|
QVector<TimeBlock> blocks;
|
||||||
|
blocks.reserve(accepted.size());
|
||||||
|
for (const QDateTime& occurrence : accepted)
|
||||||
|
{
|
||||||
|
TimeBlock block;
|
||||||
|
block.id = newId();
|
||||||
|
block.taskId = task.id;
|
||||||
|
block.startAt = occurrence;
|
||||||
|
block.endAt = occurrence.addSecs(durationSeconds);
|
||||||
|
block.createdAt = now;
|
||||||
|
block.updatedAt = now;
|
||||||
|
block.version = 0;
|
||||||
|
block.deviceId = m_deviceId;
|
||||||
|
blocks.append(block);
|
||||||
|
}
|
||||||
|
|
||||||
|
Recurrence recurrence;
|
||||||
|
recurrence.id = newId();
|
||||||
|
recurrence.taskId = task.id;
|
||||||
|
recurrence.rule = frequency == RecurrenceFrequency::Daily
|
||||||
|
? QStringLiteral("FREQ=DAILY")
|
||||||
|
: (frequency == RecurrenceFrequency::Weekly ? QStringLiteral("FREQ=WEEKLY")
|
||||||
|
: QStringLiteral("FREQ=MONTHLY"));
|
||||||
|
recurrence.until = effectiveUntil;
|
||||||
|
|
||||||
|
if (!m_store.beginTransaction())
|
||||||
|
{
|
||||||
|
m_lastError = m_store.lastError();
|
||||||
|
if (error)
|
||||||
|
{
|
||||||
|
*error = m_lastError;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!m_store.insertTask(task))
|
||||||
|
{
|
||||||
|
m_store.rollback();
|
||||||
|
m_lastError = m_store.lastError();
|
||||||
|
if (error)
|
||||||
|
{
|
||||||
|
*error = m_lastError;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
for (const TimeBlock& block : blocks)
|
||||||
|
{
|
||||||
|
if (!m_store.insertTimeBlock(block))
|
||||||
|
{
|
||||||
|
m_store.rollback();
|
||||||
|
m_lastError = m_store.lastError();
|
||||||
|
if (error)
|
||||||
|
{
|
||||||
|
*error = m_lastError;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!m_store.insertRecurrence(recurrence))
|
||||||
|
{
|
||||||
|
m_store.rollback();
|
||||||
|
m_lastError = m_store.lastError();
|
||||||
|
if (error)
|
||||||
|
{
|
||||||
|
*error = m_lastError;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!m_store.commit())
|
||||||
|
{
|
||||||
|
m_store.rollback();
|
||||||
|
m_lastError = m_store.lastError();
|
||||||
|
if (error)
|
||||||
|
{
|
||||||
|
*error = m_lastError;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (createdCount)
|
||||||
|
{
|
||||||
|
*createdCount = accepted.size();
|
||||||
|
}
|
||||||
|
m_lastError.clear();
|
||||||
|
Q_EMIT dataChanged();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool ScheduleService::updateBlock(const QString& blockId,
|
bool ScheduleService::updateBlock(const QString& blockId,
|
||||||
const QString& title,
|
const QString& title,
|
||||||
const QDateTime& start,
|
const QDateTime& start,
|
||||||
@@ -315,6 +557,7 @@ bool ScheduleService::setBlockStatus(const QString& blockId, const QString& stat
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
m_lastError.clear();
|
m_lastError.clear();
|
||||||
|
rebuildEnergyProfile();
|
||||||
Q_EMIT dataChanged();
|
Q_EMIT dataChanged();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -404,6 +647,7 @@ bool ScheduleService::deleteBlock(const QString& blockId, QString* error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
m_lastError.clear();
|
m_lastError.clear();
|
||||||
|
rebuildEnergyProfile();
|
||||||
Q_EMIT dataChanged();
|
Q_EMIT dataChanged();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -889,6 +1133,7 @@ bool ScheduleService::applyProposedDiff(const ProposedDiff& diff,
|
|||||||
}
|
}
|
||||||
|
|
||||||
m_lastError.clear();
|
m_lastError.clear();
|
||||||
|
rebuildEnergyProfile();
|
||||||
Q_EMIT dataChanged();
|
Q_EMIT dataChanged();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -941,6 +1186,11 @@ QVector<ScheduleItem> ScheduleService::overdueItems(const QDateTime& now) const
|
|||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QVector<ScheduleItem> ScheduleService::search(const QString& query, int limit) const
|
||||||
|
{
|
||||||
|
return m_store.search(query, limit);
|
||||||
|
}
|
||||||
|
|
||||||
QString ScheduleService::lastError() const
|
QString ScheduleService::lastError() const
|
||||||
{
|
{
|
||||||
return m_lastError;
|
return m_lastError;
|
||||||
@@ -948,5 +1198,42 @@ QString ScheduleService::lastError() const
|
|||||||
|
|
||||||
void ScheduleService::notifyDataChanged()
|
void ScheduleService::notifyDataChanged()
|
||||||
{
|
{
|
||||||
|
rebuildEnergyProfile();
|
||||||
Q_EMIT dataChanged();
|
Q_EMIT dataChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const EnergyProfile& ScheduleService::energyProfile() const
|
||||||
|
{
|
||||||
|
return m_energyProfile;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ScheduleService::energyLevelFor(const QDateTime& localDateTime) const
|
||||||
|
{
|
||||||
|
return m_energyProfile.level(localDateTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
DailyReview ScheduleService::dailyReview(const QDate& date) const
|
||||||
|
{
|
||||||
|
QDateTime now = QDateTime::currentDateTime();
|
||||||
|
if (date != now.date())
|
||||||
|
{
|
||||||
|
now = date < now.date() ? QDateTime(date, QTime(23, 59), Qt::LocalTime)
|
||||||
|
: QDateTime(date, QTime(0, 0), Qt::LocalTime);
|
||||||
|
}
|
||||||
|
DailyReview review = buildDailyReview(itemsForDay(date), date, now);
|
||||||
|
review.energySummary = energySummaryForDate(m_energyProfile, date);
|
||||||
|
return review;
|
||||||
|
}
|
||||||
|
|
||||||
|
QVector<Suggestion> ScheduleService::suggestions(const QDateTime& now) const
|
||||||
|
{
|
||||||
|
return buildSuggestions(itemsForDay(now.date()), now);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScheduleService::rebuildEnergyProfile()
|
||||||
|
{
|
||||||
|
EnergyProfile profile = EnergyProfile::defaults();
|
||||||
|
profile.learn(m_store.completedEnergySamples());
|
||||||
|
m_energyProfile = profile;
|
||||||
|
m_store.replaceEnergyLevels(m_energyProfile.levels());
|
||||||
|
}
|
||||||
|
|||||||
@@ -5,7 +5,10 @@
|
|||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
|
|
||||||
|
#include "core/DailyInsights.h"
|
||||||
|
#include "core/EnergyProfile.h"
|
||||||
#include "core/ProposedDiff.h"
|
#include "core/ProposedDiff.h"
|
||||||
|
#include "core/Recurrence.h"
|
||||||
#include "core/ScheduleItem.h"
|
#include "core/ScheduleItem.h"
|
||||||
|
|
||||||
class SqliteStore;
|
class SqliteStore;
|
||||||
@@ -26,6 +29,13 @@ public:
|
|||||||
const QDateTime& start,
|
const QDateTime& start,
|
||||||
const QDateTime& end,
|
const QDateTime& end,
|
||||||
QString* error = nullptr);
|
QString* error = nullptr);
|
||||||
|
bool createRecurringBlock(const QString& title,
|
||||||
|
const QDateTime& start,
|
||||||
|
const QDateTime& end,
|
||||||
|
RecurrenceFrequency frequency,
|
||||||
|
const QDate& until,
|
||||||
|
int* createdCount = nullptr,
|
||||||
|
QString* error = nullptr);
|
||||||
bool updateBlock(const QString& blockId,
|
bool updateBlock(const QString& blockId,
|
||||||
const QString& title,
|
const QString& title,
|
||||||
const QDateTime& start,
|
const QDateTime& start,
|
||||||
@@ -51,7 +61,16 @@ public:
|
|||||||
// 返回 [from, to] 闭区间内的所有日程,按开始时间升序。
|
// 返回 [from, to] 闭区间内的所有日程,按开始时间升序。
|
||||||
QVector<ScheduleItem> itemsForRange(const QDate& from, const QDate& to) const;
|
QVector<ScheduleItem> itemsForRange(const QDate& from, const QDate& to) const;
|
||||||
QVector<ScheduleItem> overdueItems(const QDateTime& now = QDateTime::currentDateTime()) const;
|
QVector<ScheduleItem> overdueItems(const QDateTime& now = QDateTime::currentDateTime()) const;
|
||||||
|
QVector<ScheduleItem> search(const QString& query, int limit = 100) const;
|
||||||
QString lastError() const;
|
QString lastError() const;
|
||||||
|
|
||||||
|
const EnergyProfile& energyProfile() const;
|
||||||
|
int energyLevelFor(const QDateTime& localDateTime) const;
|
||||||
|
void rebuildEnergyProfile();
|
||||||
|
|
||||||
|
DailyReview dailyReview(const QDate& date) const;
|
||||||
|
QVector<Suggestion> suggestions(const QDateTime& now = QDateTime::currentDateTime()) const;
|
||||||
|
|
||||||
// 供同步层在外部写入后通知 UI 刷新。
|
// 供同步层在外部写入后通知 UI 刷新。
|
||||||
void notifyDataChanged();
|
void notifyDataChanged();
|
||||||
|
|
||||||
@@ -67,4 +86,5 @@ private:
|
|||||||
SqliteStore& m_store;
|
SqliteStore& m_store;
|
||||||
QString m_deviceId;
|
QString m_deviceId;
|
||||||
QString m_lastError;
|
QString m_lastError;
|
||||||
|
EnergyProfile m_energyProfile;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
#include "SqliteStore.h"
|
#include "SqliteStore.h"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
@@ -1053,6 +1055,205 @@ bool SqliteStore::applyRemoteChange(const RemoteChange& change, QString* error)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool SqliteStore::insertRecurrence(const Recurrence& recurrence)
|
||||||
|
{
|
||||||
|
m_lastError.clear();
|
||||||
|
if (!isOpenInternal())
|
||||||
|
{
|
||||||
|
return setError(QStringLiteral("数据库未打开"));
|
||||||
|
}
|
||||||
|
QSqlQuery query(m_database);
|
||||||
|
query.prepare(QStringLiteral(
|
||||||
|
"INSERT INTO recurrence(id, task_id, rrule, until) VALUES(:id, :task_id, :rrule, :until)"));
|
||||||
|
query.bindValue(QStringLiteral(":id"), recurrence.id);
|
||||||
|
query.bindValue(QStringLiteral(":task_id"), recurrence.taskId);
|
||||||
|
query.bindValue(QStringLiteral(":rrule"), recurrence.rule);
|
||||||
|
query.bindValue(QStringLiteral(":until"),
|
||||||
|
recurrence.until.has_value() ? QVariant(recurrence.until->toString(Qt::ISODate))
|
||||||
|
: QVariant());
|
||||||
|
if (!query.exec())
|
||||||
|
{
|
||||||
|
return setError(QStringLiteral("写入重复规则失败: %1").arg(query.lastError().text()));
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::optional<Recurrence> SqliteStore::recurrenceForTask(const QString& taskId) const
|
||||||
|
{
|
||||||
|
m_lastError.clear();
|
||||||
|
if (!isOpenInternal())
|
||||||
|
{
|
||||||
|
setError(QStringLiteral("数据库未打开"));
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
QSqlQuery query(m_database);
|
||||||
|
query.prepare(QStringLiteral("SELECT id, task_id, rrule, until FROM recurrence WHERE task_id = :task_id"));
|
||||||
|
query.bindValue(QStringLiteral(":task_id"), taskId);
|
||||||
|
if (!query.exec())
|
||||||
|
{
|
||||||
|
setError(QStringLiteral("查询重复规则失败: %1").arg(query.lastError().text()));
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
if (!query.next())
|
||||||
|
{
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
Recurrence recurrence;
|
||||||
|
recurrence.id = query.value(0).toString();
|
||||||
|
recurrence.taskId = query.value(1).toString();
|
||||||
|
recurrence.rule = query.value(2).toString();
|
||||||
|
const QString until = query.value(3).toString();
|
||||||
|
if (!until.isEmpty())
|
||||||
|
{
|
||||||
|
recurrence.until = QDate::fromString(until, Qt::ISODate);
|
||||||
|
}
|
||||||
|
return recurrence;
|
||||||
|
}
|
||||||
|
|
||||||
|
QVector<ScheduleItem> SqliteStore::search(const QString& query, int limit) const
|
||||||
|
{
|
||||||
|
m_lastError.clear();
|
||||||
|
QVector<ScheduleItem> items;
|
||||||
|
if (!isOpenInternal())
|
||||||
|
{
|
||||||
|
setError(QStringLiteral("数据库未打开"));
|
||||||
|
return items;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString escaped = query.trimmed();
|
||||||
|
escaped.replace(QLatin1Char('\\'), QStringLiteral("\\\\"));
|
||||||
|
escaped.replace(QLatin1Char('%'), QStringLiteral("\\%"));
|
||||||
|
escaped.replace(QLatin1Char('_'), QStringLiteral("\\_"));
|
||||||
|
const QString pattern = QStringLiteral("%%1%").arg(escaped);
|
||||||
|
|
||||||
|
const QString sql =
|
||||||
|
QStringLiteral("SELECT ") + QLatin1String(kTaskColumns) + QStringLiteral(", ") +
|
||||||
|
QLatin1String(kBlockColumns) +
|
||||||
|
QStringLiteral(" FROM task t JOIN timeblock b ON b.task_id = t.id "
|
||||||
|
"WHERE t.title LIKE :q ESCAPE '\\' "
|
||||||
|
"OR IFNULL(t.description, '') LIKE :q ESCAPE '\\' "
|
||||||
|
"OR IFNULL(t.source_ref, '') LIKE :q ESCAPE '\\' "
|
||||||
|
"ORDER BY ABS(julianday(b.start_at) - julianday('now')) ASC, b.start_at ASC "
|
||||||
|
"LIMIT :limit");
|
||||||
|
QSqlQuery statement(m_database);
|
||||||
|
statement.prepare(sql);
|
||||||
|
statement.bindValue(QStringLiteral(":q"), pattern);
|
||||||
|
statement.bindValue(QStringLiteral(":limit"), qBound(1, limit, 500));
|
||||||
|
if (!statement.exec())
|
||||||
|
{
|
||||||
|
setError(QStringLiteral("搜索日程失败: %1").arg(statement.lastError().text()));
|
||||||
|
return items;
|
||||||
|
}
|
||||||
|
while (statement.next())
|
||||||
|
{
|
||||||
|
ScheduleItem item;
|
||||||
|
item.task = mapTask(statement, 0);
|
||||||
|
item.block = mapTimeBlock(statement, 14);
|
||||||
|
items.append(item);
|
||||||
|
}
|
||||||
|
return items;
|
||||||
|
}
|
||||||
|
|
||||||
|
QVector<EnergyLevel> SqliteStore::energyLevels() const
|
||||||
|
{
|
||||||
|
m_lastError.clear();
|
||||||
|
QVector<EnergyLevel> levels;
|
||||||
|
if (!isOpenInternal())
|
||||||
|
{
|
||||||
|
setError(QStringLiteral("数据库未打开"));
|
||||||
|
return levels;
|
||||||
|
}
|
||||||
|
QSqlQuery query(m_database);
|
||||||
|
if (!query.exec(QStringLiteral(
|
||||||
|
"SELECT weekday, hour_slot, level FROM energy_profile ORDER BY weekday, hour_slot")))
|
||||||
|
{
|
||||||
|
setError(QStringLiteral("查询精力档案失败: %1").arg(query.lastError().text()));
|
||||||
|
return levels;
|
||||||
|
}
|
||||||
|
while (query.next())
|
||||||
|
{
|
||||||
|
levels.append({query.value(0).toInt(), query.value(1).toInt(), query.value(2).toInt()});
|
||||||
|
}
|
||||||
|
return levels;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SqliteStore::replaceEnergyLevels(const QVector<EnergyLevel>& levels)
|
||||||
|
{
|
||||||
|
m_lastError.clear();
|
||||||
|
if (!isOpenInternal())
|
||||||
|
{
|
||||||
|
return setError(QStringLiteral("数据库未打开"));
|
||||||
|
}
|
||||||
|
if (!m_database.transaction())
|
||||||
|
{
|
||||||
|
return setError(QStringLiteral("开启精力档案事务失败: %1").arg(m_database.lastError().text()));
|
||||||
|
}
|
||||||
|
QSqlQuery clear(m_database);
|
||||||
|
if (!clear.exec(QStringLiteral("DELETE FROM energy_profile")))
|
||||||
|
{
|
||||||
|
m_database.rollback();
|
||||||
|
return setError(QStringLiteral("清理精力档案失败: %1").arg(clear.lastError().text()));
|
||||||
|
}
|
||||||
|
QSqlQuery insert(m_database);
|
||||||
|
insert.prepare(QStringLiteral(
|
||||||
|
"INSERT OR REPLACE INTO energy_profile(id, weekday, hour_slot, level) "
|
||||||
|
"VALUES (:id, :weekday, :hour_slot, :level)"));
|
||||||
|
for (const EnergyLevel& level : levels)
|
||||||
|
{
|
||||||
|
insert.bindValue(QStringLiteral(":id"),
|
||||||
|
QStringLiteral("%1-%2").arg(level.weekday).arg(level.hour));
|
||||||
|
insert.bindValue(QStringLiteral(":weekday"), level.weekday);
|
||||||
|
insert.bindValue(QStringLiteral(":hour_slot"), level.hour);
|
||||||
|
insert.bindValue(QStringLiteral(":level"), std::clamp(level.level, 0, 2));
|
||||||
|
if (!insert.exec())
|
||||||
|
{
|
||||||
|
m_database.rollback();
|
||||||
|
return setError(QStringLiteral("写入精力档案失败: %1").arg(insert.lastError().text()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!m_database.commit())
|
||||||
|
{
|
||||||
|
m_database.rollback();
|
||||||
|
return setError(QStringLiteral("提交精力档案失败: %1").arg(m_database.lastError().text()));
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
QVector<EnergySample> SqliteStore::completedEnergySamples() const
|
||||||
|
{
|
||||||
|
m_lastError.clear();
|
||||||
|
QVector<EnergySample> samples;
|
||||||
|
if (!isOpenInternal())
|
||||||
|
{
|
||||||
|
setError(QStringLiteral("数据库未打开"));
|
||||||
|
return samples;
|
||||||
|
}
|
||||||
|
QSqlQuery query(m_database);
|
||||||
|
if (!query.exec(QStringLiteral(
|
||||||
|
"SELECT t.energy_req, b.start_at, b.end_at FROM timeblock b "
|
||||||
|
"JOIN task t ON t.id = b.task_id "
|
||||||
|
"WHERE b.status = 'done' AND t.energy_req IS NOT NULL")))
|
||||||
|
{
|
||||||
|
setError(QStringLiteral("查询精力样本失败: %1").arg(query.lastError().text()));
|
||||||
|
return samples;
|
||||||
|
}
|
||||||
|
while (query.next())
|
||||||
|
{
|
||||||
|
const int level = std::clamp(query.value(0).toInt(), 0, 2);
|
||||||
|
const QDateTime start = DateTimeUtils::fromDb(query.value(1).toString());
|
||||||
|
const QDateTime end = DateTimeUtils::fromDb(query.value(2).toString());
|
||||||
|
if (!start.isValid() || !end.isValid() || start >= end)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
for (QDateTime cursor = start; cursor < end; cursor = cursor.addSecs(3600))
|
||||||
|
{
|
||||||
|
samples.append({cursor.date().dayOfWeek(), cursor.time().hour(), level});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return samples;
|
||||||
|
}
|
||||||
|
|
||||||
qint64 SqliteStore::syncCursor(const QString& deviceId, QString* error) const
|
qint64 SqliteStore::syncCursor(const QString& deviceId, QString* error) const
|
||||||
{
|
{
|
||||||
m_lastError.clear();
|
m_lastError.clear();
|
||||||
|
|||||||
@@ -7,7 +7,9 @@
|
|||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
|
||||||
|
#include "core/EnergyProfile.h"
|
||||||
#include "core/ProposedDiff.h"
|
#include "core/ProposedDiff.h"
|
||||||
|
#include "core/Recurrence.h"
|
||||||
#include "core/SyncTypes.h"
|
#include "core/SyncTypes.h"
|
||||||
#include "core/ScheduleItem.h"
|
#include "core/ScheduleItem.h"
|
||||||
|
|
||||||
@@ -41,6 +43,8 @@ public:
|
|||||||
std::optional<Task> taskById(const QString& id);
|
std::optional<Task> taskById(const QString& id);
|
||||||
bool deleteTask(const QString& id);
|
bool deleteTask(const QString& id);
|
||||||
bool hasBlocksForTask(const QString& taskId);
|
bool hasBlocksForTask(const QString& taskId);
|
||||||
|
bool insertRecurrence(const Recurrence& recurrence);
|
||||||
|
std::optional<Recurrence> recurrenceForTask(const QString& taskId) const;
|
||||||
|
|
||||||
bool insertTimeBlock(const TimeBlock& block);
|
bool insertTimeBlock(const TimeBlock& block);
|
||||||
bool updateTimeBlock(const TimeBlock& block);
|
bool updateTimeBlock(const TimeBlock& block);
|
||||||
@@ -55,6 +59,7 @@ public:
|
|||||||
QVector<ScheduleItem> blocksInRange(const QDateTime& fromUtc, const QDateTime& toUtc) const;
|
QVector<ScheduleItem> blocksInRange(const QDateTime& fromUtc, const QDateTime& toUtc) const;
|
||||||
// 已结束但仍未完成、且结束时间在最近 windowDays 内的块。
|
// 已结束但仍未完成、且结束时间在最近 windowDays 内的块。
|
||||||
QVector<ScheduleItem> overdueBefore(const QDateTime& nowUtc, int windowDays = 30) const;
|
QVector<ScheduleItem> overdueBefore(const QDateTime& nowUtc, int windowDays = 30) const;
|
||||||
|
QVector<ScheduleItem> search(const QString& query, int limit = 100) const;
|
||||||
|
|
||||||
QVector<SyncOutboxItem> outboxBatch(int limit, QString* error = nullptr) const;
|
QVector<SyncOutboxItem> outboxBatch(int limit, QString* error = nullptr) const;
|
||||||
int outboxCount(QString* error = nullptr) const;
|
int outboxCount(QString* error = nullptr) const;
|
||||||
@@ -64,6 +69,10 @@ public:
|
|||||||
qint64 syncCursor(const QString& deviceId, QString* error = nullptr) const;
|
qint64 syncCursor(const QString& deviceId, QString* error = nullptr) const;
|
||||||
bool setSyncCursor(const QString& deviceId, qint64 seq, QString* error = nullptr);
|
bool setSyncCursor(const QString& deviceId, qint64 seq, QString* error = nullptr);
|
||||||
|
|
||||||
|
QVector<EnergyLevel> energyLevels() const;
|
||||||
|
bool replaceEnergyLevels(const QVector<EnergyLevel>& levels);
|
||||||
|
QVector<EnergySample> completedEnergySamples() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool openDatabase(QString* error);
|
bool openDatabase(QString* error);
|
||||||
bool configureConnection(QString* error);
|
bool configureConnection(QString* error);
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QShortcut>
|
#include <QShortcut>
|
||||||
|
#include <QShowEvent>
|
||||||
#include <QSplitter>
|
#include <QSplitter>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
@@ -28,9 +29,11 @@
|
|||||||
#include "sync/SyncService.h"
|
#include "sync/SyncService.h"
|
||||||
#include "ui/MainWindow.h"
|
#include "ui/MainWindow.h"
|
||||||
#include "ui/dialogs/BlockEditDialog.h"
|
#include "ui/dialogs/BlockEditDialog.h"
|
||||||
|
#include "ui/dialogs/DailyReviewDialog.h"
|
||||||
#include "ui/dialogs/SettingsDialog.h"
|
#include "ui/dialogs/SettingsDialog.h"
|
||||||
#include "ui/panels/ChatPanel.h"
|
#include "ui/panels/ChatPanel.h"
|
||||||
#include "ui/panels/TodayPanel.h"
|
#include "ui/panels/TodayPanel.h"
|
||||||
|
#include "ui/theme/AnimationUtils.h"
|
||||||
#include "ui/theme/ThemeManager.h"
|
#include "ui/theme/ThemeManager.h"
|
||||||
#include "ui/theme/WindowEffects.h"
|
#include "ui/theme/WindowEffects.h"
|
||||||
#include "utils/AppSettings.h"
|
#include "utils/AppSettings.h"
|
||||||
@@ -175,6 +178,16 @@ void CompactWindow::buildUi()
|
|||||||
connect(openShortcut, &QShortcut::activated, this, &CompactWindow::openSchedule);
|
connect(openShortcut, &QShortcut::activated, this, &CompactWindow::openSchedule);
|
||||||
auto* settingsShortcut = new QShortcut(QKeySequence(QStringLiteral("Ctrl+,")), this);
|
auto* settingsShortcut = new QShortcut(QKeySequence(QStringLiteral("Ctrl+,")), this);
|
||||||
connect(settingsShortcut, &QShortcut::activated, this, &CompactWindow::openSettings);
|
connect(settingsShortcut, &QShortcut::activated, this, &CompactWindow::openSettings);
|
||||||
|
auto* reviewShortcut = new QShortcut(QKeySequence(QStringLiteral("Ctrl+R")), this);
|
||||||
|
connect(reviewShortcut, &QShortcut::activated, this, &CompactWindow::openDailyReview);
|
||||||
|
auto* searchShortcut = new QShortcut(QKeySequence::Find, this);
|
||||||
|
connect(searchShortcut, &QShortcut::activated, this, [this]() {
|
||||||
|
openSchedule();
|
||||||
|
if (m_scheduleWindow)
|
||||||
|
{
|
||||||
|
m_scheduleWindow->openSearch();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void CompactWindow::setupTray()
|
void CompactWindow::setupTray()
|
||||||
@@ -244,6 +257,7 @@ void CompactWindow::connectSignals()
|
|||||||
m_scheduleWindow->focusBlock(QDate::currentDate(), id);
|
m_scheduleWindow->focusBlock(QDate::currentDate(), id);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
connect(m_todayPanel, &TodayPanel::reviewRequested, this, &CompactWindow::openDailyReview);
|
||||||
|
|
||||||
connect(&m_notificationService,
|
connect(&m_notificationService,
|
||||||
&NotificationService::overdueListChanged,
|
&NotificationService::overdueListChanged,
|
||||||
@@ -332,8 +346,13 @@ void CompactWindow::reloadToday()
|
|||||||
.arg(today.day())
|
.arg(today.day())
|
||||||
.arg(weekdayLabel(today)));
|
.arg(weekdayLabel(today)));
|
||||||
m_todayItems = m_scheduleService.itemsForDay(today);
|
m_todayItems = m_scheduleService.itemsForDay(today);
|
||||||
|
const QDateTime now = QDateTime::currentDateTime();
|
||||||
m_todayPanel->setDate(today);
|
m_todayPanel->setDate(today);
|
||||||
m_todayPanel->setItems(m_todayItems, QDateTime::currentDateTime());
|
m_todayPanel->setItems(m_todayItems, now);
|
||||||
|
const QVector<Suggestion> suggestions = m_scheduleService.suggestions(now);
|
||||||
|
m_todayPanel->setInsightText(
|
||||||
|
suggestions.isEmpty() ? QString()
|
||||||
|
: QStringLiteral("建议:%1").arg(suggestions.first().detail));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CompactWindow::openSchedule()
|
void CompactWindow::openSchedule()
|
||||||
@@ -362,6 +381,13 @@ void CompactWindow::openSettings()
|
|||||||
dialog.exec();
|
dialog.exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CompactWindow::openDailyReview()
|
||||||
|
{
|
||||||
|
DailyReviewDialog dialog(m_scheduleService.dailyReview(QDate::currentDate()), m_tokens, this);
|
||||||
|
dialog.moveToCenter();
|
||||||
|
dialog.exec();
|
||||||
|
}
|
||||||
|
|
||||||
void CompactWindow::updateSyncStatus(const QString& status)
|
void CompactWindow::updateSyncStatus(const QString& status)
|
||||||
{
|
{
|
||||||
if (!m_syncLabel)
|
if (!m_syncLabel)
|
||||||
@@ -452,6 +478,16 @@ void CompactWindow::showAndRaise()
|
|||||||
reloadToday();
|
reloadToday();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CompactWindow::showEvent(QShowEvent* event)
|
||||||
|
{
|
||||||
|
ElaWindow::showEvent(event);
|
||||||
|
if (!m_firstShowAnimated)
|
||||||
|
{
|
||||||
|
m_firstShowAnimated = true;
|
||||||
|
QTimer::singleShot(0, this, [this]() { AnimationUtils::fadeWindow(this); });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void CompactWindow::paintEvent(QPaintEvent* event)
|
void CompactWindow::paintEvent(QPaintEvent* event)
|
||||||
{
|
{
|
||||||
ElaWindow::paintEvent(event);
|
ElaWindow::paintEvent(event);
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ class TodayPanel;
|
|||||||
class QCloseEvent;
|
class QCloseEvent;
|
||||||
class QLabel;
|
class QLabel;
|
||||||
class QPaintEvent;
|
class QPaintEvent;
|
||||||
|
class QShowEvent;
|
||||||
class QSplitter;
|
class QSplitter;
|
||||||
class QTimer;
|
class QTimer;
|
||||||
|
|
||||||
@@ -50,6 +51,7 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
void closeEvent(QCloseEvent* event) override;
|
void closeEvent(QCloseEvent* event) override;
|
||||||
void paintEvent(QPaintEvent* event) override;
|
void paintEvent(QPaintEvent* event) override;
|
||||||
|
void showEvent(QShowEvent* event) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void buildUi();
|
void buildUi();
|
||||||
@@ -62,6 +64,7 @@ private:
|
|||||||
void reloadToday();
|
void reloadToday();
|
||||||
void openSchedule();
|
void openSchedule();
|
||||||
void openSettings();
|
void openSettings();
|
||||||
|
void openDailyReview();
|
||||||
void openEditDialog(const QString& blockId);
|
void openEditDialog(const QString& blockId);
|
||||||
void showError(const QString& title, const QString& message);
|
void showError(const QString& title, const QString& message);
|
||||||
void updateSyncStatus(const QString& status);
|
void updateSyncStatus(const QString& status);
|
||||||
@@ -89,4 +92,5 @@ private:
|
|||||||
QTimer* m_refreshTimer = nullptr;
|
QTimer* m_refreshTimer = nullptr;
|
||||||
|
|
||||||
bool m_quitting = false;
|
bool m_quitting = false;
|
||||||
|
bool m_firstShowAnimated = false;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -34,8 +34,11 @@
|
|||||||
#include "services/ScheduleService.h"
|
#include "services/ScheduleService.h"
|
||||||
#include "sync/SyncService.h"
|
#include "sync/SyncService.h"
|
||||||
#include "ui/dialogs/BlockEditDialog.h"
|
#include "ui/dialogs/BlockEditDialog.h"
|
||||||
|
#include "ui/dialogs/DailyReviewDialog.h"
|
||||||
|
#include "ui/dialogs/SearchDialog.h"
|
||||||
#include "ui/dialogs/SettingsDialog.h"
|
#include "ui/dialogs/SettingsDialog.h"
|
||||||
#include "ui/panels/TodayPanel.h"
|
#include "ui/panels/TodayPanel.h"
|
||||||
|
#include "ui/theme/AnimationUtils.h"
|
||||||
#include "ui/theme/ThemeManager.h"
|
#include "ui/theme/ThemeManager.h"
|
||||||
#include "ui/theme/WindowEffects.h"
|
#include "ui/theme/WindowEffects.h"
|
||||||
#include "ui/views/MonthView.h"
|
#include "ui/views/MonthView.h"
|
||||||
@@ -144,10 +147,10 @@ void MainWindow::buildUi()
|
|||||||
m_newButton->setToolTip(QStringLiteral("新建日程 (Ctrl+N)"));
|
m_newButton->setToolTip(QStringLiteral("新建日程 (Ctrl+N)"));
|
||||||
|
|
||||||
m_searchEdit = new ElaLineEdit(m_toolbar);
|
m_searchEdit = new ElaLineEdit(m_toolbar);
|
||||||
m_searchEdit->setPlaceholderText(QStringLiteral("搜索(阶段 4)"));
|
m_searchEdit->setPlaceholderText(QStringLiteral("搜索日程 (Ctrl+F)"));
|
||||||
m_searchEdit->setFixedSize(140, 30);
|
m_searchEdit->setFixedSize(160, 30);
|
||||||
m_searchEdit->setEnabled(false);
|
m_searchEdit->setClearButtonEnabled(true);
|
||||||
m_searchEdit->setToolTip(QStringLiteral("搜索将在阶段 4 接入"));
|
m_searchEdit->setToolTip(QStringLiteral("搜索标题或说明,回车打开结果"));
|
||||||
|
|
||||||
m_snapCombo = new ElaComboBox(m_toolbar);
|
m_snapCombo = new ElaComboBox(m_toolbar);
|
||||||
m_snapCombo->addItems({QStringLiteral("吸附 15 分"),
|
m_snapCombo->addItems({QStringLiteral("吸附 15 分"),
|
||||||
@@ -252,6 +255,7 @@ void MainWindow::buildUi()
|
|||||||
connect(m_newButton, &ElaPushButton::clicked, this, &MainWindow::openCreateDialogForNew);
|
connect(m_newButton, &ElaPushButton::clicked, this, &MainWindow::openCreateDialogForNew);
|
||||||
connect(m_themeButton, &ElaToolButton::clicked, this, [this]() { m_themeManager.cyclePreference(); });
|
connect(m_themeButton, &ElaToolButton::clicked, this, [this]() { m_themeManager.cyclePreference(); });
|
||||||
connect(m_settingsButton, &ElaToolButton::clicked, this, &MainWindow::openSettings);
|
connect(m_settingsButton, &ElaToolButton::clicked, this, &MainWindow::openSettings);
|
||||||
|
connect(m_searchEdit, &ElaLineEdit::returnPressed, this, &MainWindow::openSearch);
|
||||||
if (m_syncService)
|
if (m_syncService)
|
||||||
{
|
{
|
||||||
connect(m_syncService, &SyncService::statusChanged, this, &MainWindow::updateSyncStatus);
|
connect(m_syncService, &SyncService::statusChanged, this, &MainWindow::updateSyncStatus);
|
||||||
@@ -310,6 +314,19 @@ void MainWindow::buildUi()
|
|||||||
auto* settingsShortcut = new QShortcut(QKeySequence(QStringLiteral("Ctrl+,")), this);
|
auto* settingsShortcut = new QShortcut(QKeySequence(QStringLiteral("Ctrl+,")), this);
|
||||||
connect(settingsShortcut, &QShortcut::activated, this, &MainWindow::openSettings);
|
connect(settingsShortcut, &QShortcut::activated, this, &MainWindow::openSettings);
|
||||||
|
|
||||||
|
auto* reviewShortcut = new QShortcut(QKeySequence(QStringLiteral("Ctrl+R")), this);
|
||||||
|
connect(reviewShortcut, &QShortcut::activated, this, &MainWindow::openDailyReview);
|
||||||
|
|
||||||
|
auto* searchShortcut = new QShortcut(QKeySequence::Find, this);
|
||||||
|
connect(searchShortcut, &QShortcut::activated, this, [this]() {
|
||||||
|
if (m_searchEdit)
|
||||||
|
{
|
||||||
|
m_searchEdit->setFocus();
|
||||||
|
m_searchEdit->selectAll();
|
||||||
|
}
|
||||||
|
openSearch();
|
||||||
|
});
|
||||||
|
|
||||||
auto* compactShortcut = new QShortcut(QKeySequence(QStringLiteral("Ctrl+W")), this);
|
auto* compactShortcut = new QShortcut(QKeySequence(QStringLiteral("Ctrl+W")), this);
|
||||||
connect(compactShortcut, &QShortcut::activated, this, &MainWindow::close);
|
connect(compactShortcut, &QShortcut::activated, this, &MainWindow::close);
|
||||||
}
|
}
|
||||||
@@ -405,6 +422,7 @@ void MainWindow::connectSignals()
|
|||||||
m_grid->scrollToBlock(id);
|
m_grid->scrollToBlock(id);
|
||||||
m_grid->setFocus(Qt::OtherFocusReason);
|
m_grid->setFocus(Qt::OtherFocusReason);
|
||||||
});
|
});
|
||||||
|
connect(m_todayPanel, &TodayPanel::reviewRequested, this, &MainWindow::openDailyReview);
|
||||||
|
|
||||||
connect(&m_notificationService,
|
connect(&m_notificationService,
|
||||||
&NotificationService::overdueListChanged,
|
&NotificationService::overdueListChanged,
|
||||||
@@ -523,6 +541,7 @@ void MainWindow::setView(View view)
|
|||||||
{
|
{
|
||||||
m_currentView = view;
|
m_currentView = view;
|
||||||
const int index = static_cast<int>(view);
|
const int index = static_cast<int>(view);
|
||||||
|
const int previousIndex = m_viewStack ? m_viewStack->currentIndex() : -1;
|
||||||
if (m_viewStack)
|
if (m_viewStack)
|
||||||
{
|
{
|
||||||
m_viewStack->setCurrentIndex(index);
|
m_viewStack->setCurrentIndex(index);
|
||||||
@@ -538,6 +557,10 @@ void MainWindow::setView(View view)
|
|||||||
{
|
{
|
||||||
m_grid->scrollToCurrentTime();
|
m_grid->scrollToCurrentTime();
|
||||||
}
|
}
|
||||||
|
if (m_viewStack && previousIndex >= 0 && previousIndex != index)
|
||||||
|
{
|
||||||
|
AnimationUtils::fadeIn(m_viewStack, 160);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::View MainWindow::view() const
|
MainWindow::View MainWindow::view() const
|
||||||
@@ -590,8 +613,30 @@ void MainWindow::reloadCurrentView()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (m_currentView == View::Day)
|
||||||
|
{
|
||||||
|
const QDateTime ghostFrom =
|
||||||
|
m_currentDate == now.date() ? now : QDateTime(m_currentDate, QTime(8, 0), Qt::LocalTime);
|
||||||
|
m_grid->setGhostWindows(findFreeWindows(agendaItems, m_currentDate, ghostFrom, 8, 22, 30));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_grid->setGhostWindows({});
|
||||||
|
}
|
||||||
|
|
||||||
m_todayPanel->setDate(m_currentDate);
|
m_todayPanel->setDate(m_currentDate);
|
||||||
m_todayPanel->setItems(agendaItems, now);
|
m_todayPanel->setItems(agendaItems, now);
|
||||||
|
if (m_currentDate == QDate::currentDate())
|
||||||
|
{
|
||||||
|
const QVector<Suggestion> suggestions = m_scheduleService.suggestions(now);
|
||||||
|
m_todayPanel->setInsightText(
|
||||||
|
suggestions.isEmpty() ? QString()
|
||||||
|
: QStringLiteral("建议:%1").arg(suggestions.first().detail));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_todayPanel->setInsightText(QString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::navigateToDate(const QDate& date)
|
void MainWindow::navigateToDate(const QDate& date)
|
||||||
@@ -751,7 +796,17 @@ void MainWindow::openCreateDialog(const QDateTime& start, const QDateTime& end)
|
|||||||
}
|
}
|
||||||
|
|
||||||
QString error;
|
QString error;
|
||||||
if (!m_scheduleService.createBlock(dialog.titleValue(), dialog.startValue(), dialog.endValue(), &error))
|
const RecurrenceFrequency frequency = dialog.recurrenceFrequency();
|
||||||
|
const bool created = frequency == RecurrenceFrequency::None
|
||||||
|
? m_scheduleService.createBlock(dialog.titleValue(), dialog.startValue(), dialog.endValue(), &error)
|
||||||
|
: m_scheduleService.createRecurringBlock(dialog.titleValue(),
|
||||||
|
dialog.startValue(),
|
||||||
|
dialog.endValue(),
|
||||||
|
frequency,
|
||||||
|
dialog.recurrenceUntil(),
|
||||||
|
nullptr,
|
||||||
|
&error);
|
||||||
|
if (!created)
|
||||||
{
|
{
|
||||||
showError(QStringLiteral("创建日程失败"), error);
|
showError(QStringLiteral("创建日程失败"), error);
|
||||||
return;
|
return;
|
||||||
@@ -816,6 +871,33 @@ void MainWindow::openSettings()
|
|||||||
dialog.exec();
|
dialog.exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::openDailyReview()
|
||||||
|
{
|
||||||
|
DailyReviewDialog dialog(m_scheduleService.dailyReview(m_currentDate), m_tokens, this);
|
||||||
|
dialog.moveToCenter();
|
||||||
|
dialog.exec();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::openSearch()
|
||||||
|
{
|
||||||
|
SearchDialog dialog(m_scheduleService,
|
||||||
|
m_tokens,
|
||||||
|
m_searchEdit ? m_searchEdit->text() : QString(),
|
||||||
|
this);
|
||||||
|
connect(&dialog, &SearchDialog::blockSelected, this, [this](const QDate& date, const QString& blockId) {
|
||||||
|
if (m_searchEdit)
|
||||||
|
{
|
||||||
|
m_searchEdit->setText(QString());
|
||||||
|
}
|
||||||
|
m_currentDate = date;
|
||||||
|
setView(View::Day);
|
||||||
|
m_grid->scrollToBlock(blockId);
|
||||||
|
m_grid->setFocus(Qt::OtherFocusReason);
|
||||||
|
});
|
||||||
|
dialog.moveToCenter();
|
||||||
|
dialog.exec();
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::updateSyncStatus(const QString& status)
|
void MainWindow::updateSyncStatus(const QString& status)
|
||||||
{
|
{
|
||||||
if (!m_syncLabel)
|
if (!m_syncLabel)
|
||||||
@@ -937,6 +1019,7 @@ void MainWindow::showEvent(QShowEvent* event)
|
|||||||
{
|
{
|
||||||
m_firstShowHandled = true;
|
m_firstShowHandled = true;
|
||||||
QTimer::singleShot(0, this, [this]() {
|
QTimer::singleShot(0, this, [this]() {
|
||||||
|
AnimationUtils::fadeWindow(this);
|
||||||
if (m_grid && m_currentView == View::Day)
|
if (m_grid && m_currentView == View::Day)
|
||||||
{
|
{
|
||||||
m_grid->scrollToCurrentTime();
|
m_grid->scrollToCurrentTime();
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ public:
|
|||||||
|
|
||||||
void showAndRaise();
|
void showAndRaise();
|
||||||
void openNewBlock();
|
void openNewBlock();
|
||||||
|
void openSearch();
|
||||||
void focusBlock(const QDate& date, const QString& blockId);
|
void focusBlock(const QDate& date, const QString& blockId);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
@@ -89,6 +90,7 @@ private:
|
|||||||
void openCreateDialogForNew();
|
void openCreateDialogForNew();
|
||||||
void openEditDialog(const QString& blockId);
|
void openEditDialog(const QString& blockId);
|
||||||
void openSettings();
|
void openSettings();
|
||||||
|
void openDailyReview();
|
||||||
void updateOverdueBanner(const QVector<ScheduleItem>& items);
|
void updateOverdueBanner(const QVector<ScheduleItem>& items);
|
||||||
void showError(const QString& title, const QString& message);
|
void showError(const QString& title, const QString& message);
|
||||||
void updateSyncStatus(const QString& status);
|
void updateSyncStatus(const QString& status);
|
||||||
|
|||||||
@@ -1,14 +1,18 @@
|
|||||||
#include "BlockEditDialog.h"
|
#include "BlockEditDialog.h"
|
||||||
|
|
||||||
|
#include <QDateEdit>
|
||||||
#include <QDateTimeEdit>
|
#include <QDateTimeEdit>
|
||||||
#include <QFormLayout>
|
#include <QFormLayout>
|
||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
#include <QSignalBlocker>
|
#include <QSignalBlocker>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
|
#include "ElaComboBox.h"
|
||||||
#include "ElaLineEdit.h"
|
#include "ElaLineEdit.h"
|
||||||
#include "ElaPushButton.h"
|
#include "ElaPushButton.h"
|
||||||
#include "ElaText.h"
|
#include "ElaText.h"
|
||||||
|
#include "ui/theme/AnimationUtils.h"
|
||||||
|
|
||||||
BlockEditDialog::BlockEditDialog(const ThemeTokens& tokens, QWidget* parent)
|
BlockEditDialog::BlockEditDialog(const ThemeTokens& tokens, QWidget* parent)
|
||||||
: ElaDialog(parent)
|
: ElaDialog(parent)
|
||||||
@@ -17,7 +21,7 @@ BlockEditDialog::BlockEditDialog(const ThemeTokens& tokens, QWidget* parent)
|
|||||||
setWindowTitle(QStringLiteral("新建日程"));
|
setWindowTitle(QStringLiteral("新建日程"));
|
||||||
setWindowButtonFlags(ElaAppBarType::CloseButtonHint);
|
setWindowButtonFlags(ElaAppBarType::CloseButtonHint);
|
||||||
setMinimumWidth(440);
|
setMinimumWidth(440);
|
||||||
resize(440, 320);
|
resize(440, 430);
|
||||||
|
|
||||||
auto* root = new QVBoxLayout(this);
|
auto* root = new QVBoxLayout(this);
|
||||||
root->setContentsMargins(22, 8, 22, 18);
|
root->setContentsMargins(22, 8, 22, 18);
|
||||||
@@ -47,9 +51,26 @@ BlockEditDialog::BlockEditDialog(const ThemeTokens& tokens, QWidget* parent)
|
|||||||
m_endEdit->setDisplayFormat(QStringLiteral("yyyy-MM-dd HH:mm"));
|
m_endEdit->setDisplayFormat(QStringLiteral("yyyy-MM-dd HH:mm"));
|
||||||
m_endEdit->setMinimumHeight(34);
|
m_endEdit->setMinimumHeight(34);
|
||||||
|
|
||||||
|
m_repeatLabel = new ElaText(QStringLiteral("重复"), 13, this);
|
||||||
|
m_repeatCombo = new ElaComboBox(this);
|
||||||
|
m_repeatCombo->addItems({QStringLiteral("不重复"),
|
||||||
|
QStringLiteral("每天"),
|
||||||
|
QStringLiteral("每周"),
|
||||||
|
QStringLiteral("每月")});
|
||||||
|
m_repeatCombo->setMinimumHeight(34);
|
||||||
|
|
||||||
|
m_repeatUntilLabel = new ElaText(QStringLiteral("重复结束"), 13, this);
|
||||||
|
m_repeatUntilEdit = new QDateEdit(this);
|
||||||
|
m_repeatUntilEdit->setCalendarPopup(true);
|
||||||
|
m_repeatUntilEdit->setDisplayFormat(QStringLiteral("yyyy-MM-dd"));
|
||||||
|
m_repeatUntilEdit->setDate(QDate::currentDate().addMonths(3));
|
||||||
|
m_repeatUntilEdit->setMinimumHeight(34);
|
||||||
|
|
||||||
form->addRow(titleLabel, m_titleEdit);
|
form->addRow(titleLabel, m_titleEdit);
|
||||||
form->addRow(startLabel, m_startEdit);
|
form->addRow(startLabel, m_startEdit);
|
||||||
form->addRow(endLabel, m_endEdit);
|
form->addRow(endLabel, m_endEdit);
|
||||||
|
form->addRow(m_repeatLabel, m_repeatCombo);
|
||||||
|
form->addRow(m_repeatUntilLabel, m_repeatUntilEdit);
|
||||||
root->addLayout(form);
|
root->addLayout(form);
|
||||||
|
|
||||||
m_errorLabel = new ElaText(this);
|
m_errorLabel = new ElaText(this);
|
||||||
@@ -79,12 +100,42 @@ BlockEditDialog::BlockEditDialog(const ThemeTokens& tokens, QWidget* parent)
|
|||||||
const QSignalBlocker blocker(m_endEdit);
|
const QSignalBlocker blocker(m_endEdit);
|
||||||
m_endEdit->setDateTime(start.addSecs(60 * 60));
|
m_endEdit->setDateTime(start.addSecs(60 * 60));
|
||||||
}
|
}
|
||||||
|
if (m_repeatUntilEdit && start.isValid() && m_repeatUntilEdit->date() < start.date())
|
||||||
|
{
|
||||||
|
m_repeatUntilEdit->setDate(start.date().addMonths(3));
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
connect(m_repeatCombo, &ElaComboBox::currentIndexChanged, this, [this](int index) {
|
||||||
|
if (m_repeatUntilEdit)
|
||||||
|
{
|
||||||
|
m_repeatUntilEdit->setEnabled(index > 0);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
m_repeatUntilEdit->setEnabled(false);
|
||||||
|
QTimer::singleShot(0, this, [this]() { AnimationUtils::fadeWindow(this); });
|
||||||
}
|
}
|
||||||
|
|
||||||
void BlockEditDialog::setCreateMode(bool create)
|
void BlockEditDialog::setCreateMode(bool create)
|
||||||
{
|
{
|
||||||
|
m_createMode = create;
|
||||||
setWindowTitle(create ? QStringLiteral("新建日程") : QStringLiteral("编辑日程"));
|
setWindowTitle(create ? QStringLiteral("新建日程") : QStringLiteral("编辑日程"));
|
||||||
|
resize(width(), create ? 430 : 320);
|
||||||
|
if (m_repeatLabel)
|
||||||
|
{
|
||||||
|
m_repeatLabel->setVisible(create);
|
||||||
|
}
|
||||||
|
if (m_repeatCombo)
|
||||||
|
{
|
||||||
|
m_repeatCombo->setVisible(create);
|
||||||
|
}
|
||||||
|
if (m_repeatUntilLabel)
|
||||||
|
{
|
||||||
|
m_repeatUntilLabel->setVisible(create);
|
||||||
|
}
|
||||||
|
if (m_repeatUntilEdit)
|
||||||
|
{
|
||||||
|
m_repeatUntilEdit->setVisible(create);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BlockEditDialog::setValues(const QString& title, const QDateTime& start, const QDateTime& end)
|
void BlockEditDialog::setValues(const QString& title, const QDateTime& start, const QDateTime& end)
|
||||||
@@ -94,6 +145,10 @@ void BlockEditDialog::setValues(const QString& title, const QDateTime& start, co
|
|||||||
m_titleEdit->setText(title);
|
m_titleEdit->setText(title);
|
||||||
m_startEdit->setDateTime(start);
|
m_startEdit->setDateTime(start);
|
||||||
m_endEdit->setDateTime(end);
|
m_endEdit->setDateTime(end);
|
||||||
|
if (m_repeatUntilEdit && start.isValid())
|
||||||
|
{
|
||||||
|
m_repeatUntilEdit->setDate(start.date().addMonths(3));
|
||||||
|
}
|
||||||
m_titleEdit->setFocus();
|
m_titleEdit->setFocus();
|
||||||
m_titleEdit->selectAll();
|
m_titleEdit->selectAll();
|
||||||
}
|
}
|
||||||
@@ -113,6 +168,34 @@ QDateTime BlockEditDialog::endValue() const
|
|||||||
return m_endEdit->dateTime();
|
return m_endEdit->dateTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RecurrenceFrequency BlockEditDialog::recurrenceFrequency() const
|
||||||
|
{
|
||||||
|
if (!m_createMode || !m_repeatCombo)
|
||||||
|
{
|
||||||
|
return RecurrenceFrequency::None;
|
||||||
|
}
|
||||||
|
switch (m_repeatCombo->currentIndex())
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
return RecurrenceFrequency::Daily;
|
||||||
|
case 2:
|
||||||
|
return RecurrenceFrequency::Weekly;
|
||||||
|
case 3:
|
||||||
|
return RecurrenceFrequency::Monthly;
|
||||||
|
default:
|
||||||
|
return RecurrenceFrequency::None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QDate BlockEditDialog::recurrenceUntil() const
|
||||||
|
{
|
||||||
|
if (recurrenceFrequency() == RecurrenceFrequency::None || !m_repeatUntilEdit)
|
||||||
|
{
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
return m_repeatUntilEdit->date();
|
||||||
|
}
|
||||||
|
|
||||||
void BlockEditDialog::updateError(const QString& message)
|
void BlockEditDialog::updateError(const QString& message)
|
||||||
{
|
{
|
||||||
m_errorLabel->setText(message);
|
m_errorLabel->setText(message);
|
||||||
@@ -130,6 +213,12 @@ void BlockEditDialog::accept()
|
|||||||
updateError(QStringLiteral("日程时长至少为 5 分钟"));
|
updateError(QStringLiteral("日程时长至少为 5 分钟"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (recurrenceFrequency() != RecurrenceFrequency::None &&
|
||||||
|
recurrenceUntil() < startValue().date())
|
||||||
|
{
|
||||||
|
updateError(QStringLiteral("重复结束日期不能早于开始日期"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
updateError(QString());
|
updateError(QString());
|
||||||
QDialog::accept();
|
QDialog::accept();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,10 +4,13 @@
|
|||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
#include "ElaDialog.h"
|
#include "ElaDialog.h"
|
||||||
|
#include "core/Recurrence.h"
|
||||||
#include "ui/theme/ThemeTokens.h"
|
#include "ui/theme/ThemeTokens.h"
|
||||||
|
|
||||||
|
class ElaComboBox;
|
||||||
class ElaLineEdit;
|
class ElaLineEdit;
|
||||||
class ElaText;
|
class ElaText;
|
||||||
|
class QDateEdit;
|
||||||
class QDateTimeEdit;
|
class QDateTimeEdit;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -28,6 +31,8 @@ public:
|
|||||||
QString titleValue() const;
|
QString titleValue() const;
|
||||||
QDateTime startValue() const;
|
QDateTime startValue() const;
|
||||||
QDateTime endValue() const;
|
QDateTime endValue() const;
|
||||||
|
RecurrenceFrequency recurrenceFrequency() const;
|
||||||
|
QDate recurrenceUntil() const;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void accept() override;
|
void accept() override;
|
||||||
@@ -38,6 +43,11 @@ private:
|
|||||||
ElaLineEdit* m_titleEdit = nullptr;
|
ElaLineEdit* m_titleEdit = nullptr;
|
||||||
QDateTimeEdit* m_startEdit = nullptr;
|
QDateTimeEdit* m_startEdit = nullptr;
|
||||||
QDateTimeEdit* m_endEdit = nullptr;
|
QDateTimeEdit* m_endEdit = nullptr;
|
||||||
|
ElaText* m_repeatLabel = nullptr;
|
||||||
|
ElaComboBox* m_repeatCombo = nullptr;
|
||||||
|
ElaText* m_repeatUntilLabel = nullptr;
|
||||||
|
QDateEdit* m_repeatUntilEdit = nullptr;
|
||||||
ElaText* m_errorLabel = nullptr;
|
ElaText* m_errorLabel = nullptr;
|
||||||
QString m_errorColor;
|
QString m_errorColor;
|
||||||
|
bool m_createMode = true;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,149 @@
|
|||||||
|
#include "DailyReviewDialog.h"
|
||||||
|
|
||||||
|
#include <QGridLayout>
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <QHBoxLayout>
|
||||||
|
#include <QVBoxLayout>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
|
#include "ElaPushButton.h"
|
||||||
|
#include "ElaText.h"
|
||||||
|
#include "ui/theme/AnimationUtils.h"
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
QString formatWindow(const FreeWindow& window)
|
||||||
|
{
|
||||||
|
return QStringLiteral("%1–%2 · %3")
|
||||||
|
.arg(window.start.toString(QStringLiteral("HH:mm")),
|
||||||
|
window.end.toString(QStringLiteral("HH:mm")),
|
||||||
|
window.minutes >= 60
|
||||||
|
? QStringLiteral("%1 小时 %2 分").arg(window.minutes / 60).arg(window.minutes % 60)
|
||||||
|
: QStringLiteral("%1 分钟").arg(window.minutes));
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
DailyReviewDialog::DailyReviewDialog(const DailyReview& review,
|
||||||
|
const ThemeTokens& tokens,
|
||||||
|
QWidget* parent)
|
||||||
|
: ElaDialog(parent)
|
||||||
|
{
|
||||||
|
setWindowTitle(QStringLiteral("今日复盘"));
|
||||||
|
setWindowButtonFlags(ElaAppBarType::CloseButtonHint);
|
||||||
|
resize(520, 560);
|
||||||
|
setMinimumWidth(480);
|
||||||
|
|
||||||
|
auto* root = new QVBoxLayout(this);
|
||||||
|
root->setContentsMargins(24, 8, 24, 18);
|
||||||
|
root->setSpacing(10);
|
||||||
|
|
||||||
|
auto* title = new ElaText(QStringLiteral("%1月%2日 · %3复盘")
|
||||||
|
.arg(review.date.month())
|
||||||
|
.arg(review.date.day())
|
||||||
|
.arg(weekdayLabel(review.date)),
|
||||||
|
17,
|
||||||
|
this);
|
||||||
|
QFont titleFont = title->font();
|
||||||
|
titleFont.setWeight(QFont::DemiBold);
|
||||||
|
title->setFont(titleFont);
|
||||||
|
root->addWidget(title);
|
||||||
|
|
||||||
|
auto* summary = new ElaText(review.summary, 14, this);
|
||||||
|
summary->setWordWrap(true);
|
||||||
|
summary->setStyleSheet(QStringLiteral("color:%1;").arg(tokens.textPrimary.name()));
|
||||||
|
root->addWidget(summary);
|
||||||
|
|
||||||
|
auto* grid = new QGridLayout();
|
||||||
|
grid->setHorizontalSpacing(28);
|
||||||
|
grid->setVerticalSpacing(8);
|
||||||
|
const auto addStat = [this, grid](int row, int column, const QString& label, const QString& value) {
|
||||||
|
auto* labelText = new ElaText(label, 11, this);
|
||||||
|
labelText->setTextStyle(ElaTextType::Caption);
|
||||||
|
auto* valueText = new ElaText(value, 14, this);
|
||||||
|
QFont valueFont = valueText->font();
|
||||||
|
valueFont.setWeight(QFont::DemiBold);
|
||||||
|
valueText->setFont(valueFont);
|
||||||
|
grid->addWidget(labelText, row, column);
|
||||||
|
grid->addWidget(valueText, row + 1, column);
|
||||||
|
};
|
||||||
|
addStat(0, 0, QStringLiteral("完成"), QStringLiteral("%1 / %2").arg(review.done).arg(review.total));
|
||||||
|
addStat(0, 1, QStringLiteral("完成率"), QStringLiteral("%1%").arg(review.completionPercent));
|
||||||
|
addStat(0, 2, QStringLiteral("专注"), QStringLiteral("%1 分钟").arg(review.focusedMinutes));
|
||||||
|
addStat(2, 0, QStringLiteral("待办"), QString::number(review.active));
|
||||||
|
addStat(2, 1, QStringLiteral("超时"), QString::number(review.overdue));
|
||||||
|
addStat(2, 2, QStringLiteral("错过 / 放弃"),
|
||||||
|
QStringLiteral("%1 / %2").arg(review.missed).arg(review.dropped));
|
||||||
|
root->addLayout(grid);
|
||||||
|
|
||||||
|
if (!review.energySummary.isEmpty())
|
||||||
|
{
|
||||||
|
auto* energy = new ElaText(review.energySummary, 12, this);
|
||||||
|
energy->setWordWrap(true);
|
||||||
|
energy->setStyleSheet(QStringLiteral("color:%1;").arg(tokens.accent.name()));
|
||||||
|
root->addWidget(energy);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto* highlightsTitle = new ElaText(QStringLiteral("今日概览"), 13, this);
|
||||||
|
QFont sectionFont = highlightsTitle->font();
|
||||||
|
sectionFont.setWeight(QFont::DemiBold);
|
||||||
|
highlightsTitle->setFont(sectionFont);
|
||||||
|
root->addWidget(highlightsTitle);
|
||||||
|
for (const QString& highlight : review.highlights)
|
||||||
|
{
|
||||||
|
auto* line = new ElaText(QStringLiteral("· %1").arg(highlight), 12, this);
|
||||||
|
line->setWordWrap(true);
|
||||||
|
root->addWidget(line);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto* ghostTitle = new ElaText(QStringLiteral("幽灵时间"), 13, this);
|
||||||
|
ghostTitle->setFont(sectionFont);
|
||||||
|
root->addWidget(ghostTitle);
|
||||||
|
if (review.ghostWindows.isEmpty())
|
||||||
|
{
|
||||||
|
auto* empty = new ElaText(QStringLiteral("今天没有 30 分钟以上的空档。"), 12, this);
|
||||||
|
empty->setTextStyle(ElaTextType::Caption);
|
||||||
|
root->addWidget(empty);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
const qsizetype count = std::min<qsizetype>(5, review.ghostWindows.size());
|
||||||
|
for (int i = 0; i < count; ++i)
|
||||||
|
{
|
||||||
|
auto* line = new ElaText(QStringLiteral("· %1").arg(formatWindow(review.ghostWindows.at(i))),
|
||||||
|
12,
|
||||||
|
this);
|
||||||
|
root->addWidget(line);
|
||||||
|
}
|
||||||
|
if (review.ghostWindows.size() > count)
|
||||||
|
{
|
||||||
|
auto* more = new ElaText(QStringLiteral("还有 %1 段空档")
|
||||||
|
.arg(review.ghostWindows.size() - count),
|
||||||
|
11,
|
||||||
|
this);
|
||||||
|
more->setTextStyle(ElaTextType::Caption);
|
||||||
|
root->addWidget(more);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
root->addStretch(1);
|
||||||
|
auto* buttonRow = new QHBoxLayout();
|
||||||
|
buttonRow->addStretch(1);
|
||||||
|
auto* closeButton = new ElaPushButton(QStringLiteral("完成"), this);
|
||||||
|
closeButton->setFixedSize(88, 34);
|
||||||
|
closeButton->setDefault(true);
|
||||||
|
buttonRow->addWidget(closeButton);
|
||||||
|
root->addLayout(buttonRow);
|
||||||
|
connect(closeButton, &ElaPushButton::clicked, this, &DailyReviewDialog::accept);
|
||||||
|
QTimer::singleShot(0, this, [this]() { AnimationUtils::fadeWindow(this); });
|
||||||
|
}
|
||||||
|
|
||||||
|
QString DailyReviewDialog::weekdayLabel(const QDate& date) const
|
||||||
|
{
|
||||||
|
if (!date.isValid())
|
||||||
|
{
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
static const char* labels[] = {"周一", "周二", "周三", "周四", "周五", "周六", "周日"};
|
||||||
|
return QString::fromUtf8(labels[date.dayOfWeek() - 1]);
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "ElaDialog.h"
|
||||||
|
#include "core/DailyInsights.h"
|
||||||
|
#include "ui/theme/ThemeTokens.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 类名: DailyReviewDialog
|
||||||
|
* 功能: 展示每日完成情况、精力高峰与幽灵时间
|
||||||
|
* 线程安全: 否;UI 线程
|
||||||
|
*/
|
||||||
|
class DailyReviewDialog : public ElaDialog
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
DailyReviewDialog(const DailyReview& review, const ThemeTokens& tokens, QWidget* parent = nullptr);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString weekdayLabel(const QDate& date) const;
|
||||||
|
};
|
||||||
@@ -0,0 +1,156 @@
|
|||||||
|
#include "SearchDialog.h"
|
||||||
|
|
||||||
|
#include <QHBoxLayout>
|
||||||
|
#include <QListWidget>
|
||||||
|
#include <QTimer>
|
||||||
|
#include <QVBoxLayout>
|
||||||
|
|
||||||
|
#include "ElaLineEdit.h"
|
||||||
|
#include "ElaText.h"
|
||||||
|
#include "ui/theme/AnimationUtils.h"
|
||||||
|
#include "core/DateTimeUtils.h"
|
||||||
|
#include "services/ScheduleService.h"
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
QString statusLabel(const QString& status)
|
||||||
|
{
|
||||||
|
if (status == QStringLiteral("done"))
|
||||||
|
{
|
||||||
|
return QStringLiteral("已完成");
|
||||||
|
}
|
||||||
|
if (status == QStringLiteral("in_progress"))
|
||||||
|
{
|
||||||
|
return QStringLiteral("进行中");
|
||||||
|
}
|
||||||
|
if (status == QStringLiteral("dropped"))
|
||||||
|
{
|
||||||
|
return QStringLiteral("已放弃");
|
||||||
|
}
|
||||||
|
if (status == QStringLiteral("missed"))
|
||||||
|
{
|
||||||
|
return QStringLiteral("已错过");
|
||||||
|
}
|
||||||
|
return QStringLiteral("待办");
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
SearchDialog::SearchDialog(ScheduleService& scheduleService,
|
||||||
|
const ThemeTokens& tokens,
|
||||||
|
const QString& initialQuery,
|
||||||
|
QWidget* parent)
|
||||||
|
: ElaDialog(parent)
|
||||||
|
, m_scheduleService(scheduleService)
|
||||||
|
, m_tokens(tokens)
|
||||||
|
{
|
||||||
|
setWindowTitle(QStringLiteral("搜索日程"));
|
||||||
|
setWindowButtonFlags(ElaAppBarType::CloseButtonHint);
|
||||||
|
resize(620, 520);
|
||||||
|
setMinimumWidth(520);
|
||||||
|
|
||||||
|
auto* root = new QVBoxLayout(this);
|
||||||
|
root->setContentsMargins(22, 8, 22, 18);
|
||||||
|
root->setSpacing(10);
|
||||||
|
|
||||||
|
auto* searchRow = new QHBoxLayout();
|
||||||
|
searchRow->setSpacing(10);
|
||||||
|
m_searchEdit = new ElaLineEdit(this);
|
||||||
|
m_searchEdit->setPlaceholderText(QStringLiteral("输入标题或说明,回车打开第一条结果"));
|
||||||
|
m_searchEdit->setClearButtonEnabled(true);
|
||||||
|
m_searchEdit->setMinimumHeight(36);
|
||||||
|
m_searchEdit->setText(initialQuery);
|
||||||
|
m_countLabel = new ElaText(this);
|
||||||
|
m_countLabel->setTextPixelSize(11);
|
||||||
|
m_countLabel->setTextStyle(ElaTextType::Caption);
|
||||||
|
searchRow->addWidget(m_searchEdit, 1);
|
||||||
|
searchRow->addWidget(m_countLabel, 0, Qt::AlignVCenter);
|
||||||
|
root->addLayout(searchRow);
|
||||||
|
|
||||||
|
m_results = new QListWidget(this);
|
||||||
|
m_results->setFrameShape(QFrame::NoFrame);
|
||||||
|
m_results->setAlternatingRowColors(false);
|
||||||
|
m_results->setUniformItemSizes(false);
|
||||||
|
m_results->setWordWrap(true);
|
||||||
|
m_results->setSelectionMode(QAbstractItemView::SingleSelection);
|
||||||
|
m_results->setStyleSheet(
|
||||||
|
QStringLiteral("QListWidget{background:transparent;border:none;outline:none;}"
|
||||||
|
"QListWidget::item{padding:9px 10px;border-radius:8px;color:%1;}"
|
||||||
|
"QListWidget::item:selected{background:%2;color:%3;}")
|
||||||
|
.arg(tokens.textPrimary.name(), tokens.accent.name(), tokens.onAccent.name()));
|
||||||
|
root->addWidget(m_results, 1);
|
||||||
|
|
||||||
|
m_searchTimer = new QTimer(this);
|
||||||
|
m_searchTimer->setSingleShot(true);
|
||||||
|
m_searchTimer->setInterval(140);
|
||||||
|
connect(m_searchTimer, &QTimer::timeout, this, &SearchDialog::executeSearch);
|
||||||
|
connect(m_searchEdit, &ElaLineEdit::textChanged, this, &SearchDialog::scheduleSearch);
|
||||||
|
connect(m_searchEdit, &ElaLineEdit::returnPressed, this, &SearchDialog::selectCurrent);
|
||||||
|
connect(m_results, &QListWidget::itemActivated, this, [this](QListWidgetItem* item) {
|
||||||
|
if (!item)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Q_EMIT blockSelected(item->data(Qt::UserRole + 1).toDate(),
|
||||||
|
item->data(Qt::UserRole).toString());
|
||||||
|
accept();
|
||||||
|
});
|
||||||
|
connect(m_results, &QListWidget::itemDoubleClicked, this, [this](QListWidgetItem* item) {
|
||||||
|
if (!item)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Q_EMIT blockSelected(item->data(Qt::UserRole + 1).toDate(),
|
||||||
|
item->data(Qt::UserRole).toString());
|
||||||
|
accept();
|
||||||
|
});
|
||||||
|
|
||||||
|
m_searchEdit->setFocus();
|
||||||
|
m_searchEdit->selectAll();
|
||||||
|
executeSearch();
|
||||||
|
QTimer::singleShot(0, this, [this]() { AnimationUtils::fadeWindow(this); });
|
||||||
|
}
|
||||||
|
|
||||||
|
void SearchDialog::scheduleSearch()
|
||||||
|
{
|
||||||
|
m_searchTimer->start();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SearchDialog::executeSearch()
|
||||||
|
{
|
||||||
|
if (!m_results)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const QVector<ScheduleItem> items = m_scheduleService.search(m_searchEdit->text(), 100);
|
||||||
|
m_results->clear();
|
||||||
|
for (const ScheduleItem& item : items)
|
||||||
|
{
|
||||||
|
const QString text = QStringLiteral("%1 · %2 %3 · %4")
|
||||||
|
.arg(item.task.title,
|
||||||
|
item.block.startAt.date().toString(QStringLiteral("MM-dd")),
|
||||||
|
DateTimeUtils::formatTimeRange(item.block.startAt, item.block.endAt),
|
||||||
|
statusLabel(item.block.status));
|
||||||
|
auto* row = new QListWidgetItem(text, m_results);
|
||||||
|
row->setData(Qt::UserRole, item.block.id);
|
||||||
|
row->setData(Qt::UserRole + 1, item.block.startAt.date());
|
||||||
|
row->setSizeHint(QSize(0, 40));
|
||||||
|
}
|
||||||
|
m_countLabel->setText(items.isEmpty() ? QStringLiteral("无结果")
|
||||||
|
: QStringLiteral("%1 条结果").arg(items.size()));
|
||||||
|
if (!items.isEmpty())
|
||||||
|
{
|
||||||
|
m_results->setCurrentRow(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SearchDialog::selectCurrent()
|
||||||
|
{
|
||||||
|
QListWidgetItem* item = m_results->currentItem();
|
||||||
|
if (!item)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Q_EMIT blockSelected(item->data(Qt::UserRole + 1).toDate(),
|
||||||
|
item->data(Qt::UserRole).toString());
|
||||||
|
accept();
|
||||||
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QDate>
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
|
#include "ElaDialog.h"
|
||||||
|
#include "ui/theme/ThemeTokens.h"
|
||||||
|
|
||||||
|
class ElaLineEdit;
|
||||||
|
class ElaText;
|
||||||
|
class QListWidget;
|
||||||
|
class QTimer;
|
||||||
|
class ScheduleService;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 类名: SearchDialog
|
||||||
|
* 功能: 按标题/说明搜索日程,选择结果后跳转到对应日期
|
||||||
|
* 线程安全: 否;UI 线程
|
||||||
|
*/
|
||||||
|
class SearchDialog : public ElaDialog
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
SearchDialog(ScheduleService& scheduleService,
|
||||||
|
const ThemeTokens& tokens,
|
||||||
|
const QString& initialQuery = {},
|
||||||
|
QWidget* parent = nullptr);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void blockSelected(const QDate& date, const QString& blockId);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void scheduleSearch();
|
||||||
|
void executeSearch();
|
||||||
|
void selectCurrent();
|
||||||
|
|
||||||
|
ScheduleService& m_scheduleService;
|
||||||
|
ThemeTokens m_tokens;
|
||||||
|
ElaLineEdit* m_searchEdit = nullptr;
|
||||||
|
ElaText* m_countLabel = nullptr;
|
||||||
|
QListWidget* m_results = nullptr;
|
||||||
|
QTimer* m_searchTimer = nullptr;
|
||||||
|
};
|
||||||
@@ -5,6 +5,7 @@
|
|||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
#include <QLineEdit>
|
#include <QLineEdit>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
#include "ElaComboBox.h"
|
#include "ElaComboBox.h"
|
||||||
#include "ElaLineEdit.h"
|
#include "ElaLineEdit.h"
|
||||||
@@ -12,6 +13,7 @@
|
|||||||
#include "ElaText.h"
|
#include "ElaText.h"
|
||||||
#include "ElaToggleSwitch.h"
|
#include "ElaToggleSwitch.h"
|
||||||
#include "ElaToolButton.h"
|
#include "ElaToolButton.h"
|
||||||
|
#include "ui/theme/AnimationUtils.h"
|
||||||
#include "ui/theme/ThemeManager.h"
|
#include "ui/theme/ThemeManager.h"
|
||||||
#include "ui/theme/WindowEffects.h"
|
#include "ui/theme/WindowEffects.h"
|
||||||
#include "utils/AppSettings.h"
|
#include "utils/AppSettings.h"
|
||||||
@@ -247,6 +249,7 @@ SettingsDialog::SettingsDialog(ThemeManager& themeManager, AppSettings& settings
|
|||||||
saveAiConfig();
|
saveAiConfig();
|
||||||
saveSyncConfig();
|
saveSyncConfig();
|
||||||
});
|
});
|
||||||
|
QTimer::singleShot(0, this, [this]() { AnimationUtils::fadeWindow(this); });
|
||||||
}
|
}
|
||||||
|
|
||||||
void SettingsDialog::saveAiConfig()
|
void SettingsDialog::saveAiConfig()
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
#include "ElaScrollArea.h"
|
#include "ElaScrollArea.h"
|
||||||
#include "ElaText.h"
|
#include "ElaText.h"
|
||||||
#include "ui/panels/DiffPreviewCard.h"
|
#include "ui/panels/DiffPreviewCard.h"
|
||||||
|
#include "ui/theme/AnimationUtils.h"
|
||||||
|
|
||||||
ChatPanel::ChatPanel(AIService& aiService, QWidget* parent)
|
ChatPanel::ChatPanel(AIService& aiService, QWidget* parent)
|
||||||
: QWidget(parent)
|
: QWidget(parent)
|
||||||
@@ -178,6 +179,7 @@ void ChatPanel::rebuildMessages()
|
|||||||
m_aiService.rejectDiff(diffId);
|
m_aiService.rejectDiff(diffId);
|
||||||
});
|
});
|
||||||
m_messageLayout->addWidget(card);
|
m_messageLayout->addWidget(card);
|
||||||
|
AnimationUtils::fadeIn(card, 180);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,9 @@
|
|||||||
|
|
||||||
#include "ElaScrollArea.h"
|
#include "ElaScrollArea.h"
|
||||||
#include "ElaText.h"
|
#include "ElaText.h"
|
||||||
|
#include "ElaToolButton.h"
|
||||||
#include "TodayItemCard.h"
|
#include "TodayItemCard.h"
|
||||||
|
#include "ui/theme/AnimationUtils.h"
|
||||||
|
|
||||||
TodayPanel::TodayPanel(QWidget* parent)
|
TodayPanel::TodayPanel(QWidget* parent)
|
||||||
: QWidget(parent)
|
: QWidget(parent)
|
||||||
@@ -31,11 +33,26 @@ TodayPanel::TodayPanel(QWidget* parent)
|
|||||||
m_titleLabel->setFont(titleFont);
|
m_titleLabel->setFont(titleFont);
|
||||||
m_countLabel = new ElaText(this);
|
m_countLabel = new ElaText(this);
|
||||||
m_countLabel->setTextPixelSize(11);
|
m_countLabel->setTextPixelSize(11);
|
||||||
|
m_reviewButton = new ElaToolButton(this);
|
||||||
|
m_reviewButton->setIsTransparent(true);
|
||||||
|
m_reviewButton->setElaIcon(ElaIconType::ClipboardCheck);
|
||||||
|
m_reviewButton->setFixedSize(26, 26);
|
||||||
|
m_reviewButton->setToolTip(QStringLiteral("今日复盘 (Ctrl+R)"));
|
||||||
|
connect(m_reviewButton, &ElaToolButton::clicked, this, &TodayPanel::reviewRequested);
|
||||||
|
|
||||||
header->addWidget(m_titleLabel);
|
header->addWidget(m_titleLabel);
|
||||||
header->addStretch(1);
|
header->addStretch(1);
|
||||||
header->addWidget(m_countLabel, 0, Qt::AlignVCenter);
|
header->addWidget(m_countLabel, 0, Qt::AlignVCenter);
|
||||||
|
header->addWidget(m_reviewButton, 0, Qt::AlignVCenter);
|
||||||
root->addLayout(header);
|
root->addLayout(header);
|
||||||
|
|
||||||
|
m_insightLabel = new ElaText(this);
|
||||||
|
m_insightLabel->setTextPixelSize(11);
|
||||||
|
m_insightLabel->setTextStyle(ElaTextType::Caption);
|
||||||
|
m_insightLabel->setWordWrap(true);
|
||||||
|
m_insightLabel->setVisible(false);
|
||||||
|
root->addWidget(m_insightLabel);
|
||||||
|
|
||||||
m_scrollArea = new ElaScrollArea(this);
|
m_scrollArea = new ElaScrollArea(this);
|
||||||
m_scrollArea->setWidgetResizable(true);
|
m_scrollArea->setWidgetResizable(true);
|
||||||
m_scrollArea->setFrameShape(QFrame::NoFrame);
|
m_scrollArea->setFrameShape(QFrame::NoFrame);
|
||||||
@@ -59,9 +76,23 @@ TodayPanel::TodayPanel(QWidget* parent)
|
|||||||
void TodayPanel::setTokens(const ThemeTokens& tokens)
|
void TodayPanel::setTokens(const ThemeTokens& tokens)
|
||||||
{
|
{
|
||||||
m_tokens = tokens;
|
m_tokens = tokens;
|
||||||
|
if (m_insightLabel)
|
||||||
|
{
|
||||||
|
m_insightLabel->setStyleSheet(QStringLiteral("color:%1;").arg(tokens.accent.name()));
|
||||||
|
}
|
||||||
rebuild();
|
rebuild();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TodayPanel::setInsightText(const QString& text)
|
||||||
|
{
|
||||||
|
if (!m_insightLabel)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
m_insightLabel->setText(text);
|
||||||
|
m_insightLabel->setVisible(!text.trimmed().isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
void TodayPanel::setDate(const QDate& date)
|
void TodayPanel::setDate(const QDate& date)
|
||||||
{
|
{
|
||||||
if (!m_titleLabel)
|
if (!m_titleLabel)
|
||||||
@@ -176,6 +207,11 @@ void TodayPanel::rebuild()
|
|||||||
empty->setTextStyle(ElaTextType::Caption);
|
empty->setTextStyle(ElaTextType::Caption);
|
||||||
m_listLayout->addWidget(empty);
|
m_listLayout->addWidget(empty);
|
||||||
m_listLayout->addStretch(1);
|
m_listLayout->addStretch(1);
|
||||||
|
if (m_renderedCount != 0)
|
||||||
|
{
|
||||||
|
m_renderedCount = 0;
|
||||||
|
AnimationUtils::fadeIn(m_listWidget, 150);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -190,4 +226,9 @@ void TodayPanel::rebuild()
|
|||||||
m_listLayout->addWidget(card);
|
m_listLayout->addWidget(card);
|
||||||
}
|
}
|
||||||
m_listLayout->addStretch(1);
|
m_listLayout->addStretch(1);
|
||||||
|
if (m_renderedCount != sorted.size())
|
||||||
|
{
|
||||||
|
m_renderedCount = sorted.size();
|
||||||
|
AnimationUtils::fadeIn(m_listWidget, 150);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
class ElaScrollArea;
|
class ElaScrollArea;
|
||||||
class ElaText;
|
class ElaText;
|
||||||
|
class ElaToolButton;
|
||||||
class QVBoxLayout;
|
class QVBoxLayout;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -26,6 +27,7 @@ public:
|
|||||||
void setTokens(const ThemeTokens& tokens);
|
void setTokens(const ThemeTokens& tokens);
|
||||||
void setDate(const QDate& date);
|
void setDate(const QDate& date);
|
||||||
void setItems(const QVector<ScheduleItem>& items, const QDateTime& now);
|
void setItems(const QVector<ScheduleItem>& items, const QDateTime& now);
|
||||||
|
void setInsightText(const QString& text);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void editRequested(const QString& blockId);
|
void editRequested(const QString& blockId);
|
||||||
@@ -33,6 +35,7 @@ signals:
|
|||||||
void postponeRequested(const QString& blockId, int minutes);
|
void postponeRequested(const QString& blockId, int minutes);
|
||||||
void deleteRequested(const QString& blockId);
|
void deleteRequested(const QString& blockId);
|
||||||
void focusRequested(const QString& blockId);
|
void focusRequested(const QString& blockId);
|
||||||
|
void reviewRequested();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void rebuild();
|
void rebuild();
|
||||||
@@ -44,7 +47,10 @@ private:
|
|||||||
|
|
||||||
ElaText* m_titleLabel = nullptr;
|
ElaText* m_titleLabel = nullptr;
|
||||||
ElaText* m_countLabel = nullptr;
|
ElaText* m_countLabel = nullptr;
|
||||||
|
ElaText* m_insightLabel = nullptr;
|
||||||
|
ElaToolButton* m_reviewButton = nullptr;
|
||||||
ElaScrollArea* m_scrollArea = nullptr;
|
ElaScrollArea* m_scrollArea = nullptr;
|
||||||
QWidget* m_listWidget = nullptr;
|
QWidget* m_listWidget = nullptr;
|
||||||
QVBoxLayout* m_listLayout = nullptr;
|
QVBoxLayout* m_listLayout = nullptr;
|
||||||
|
int m_renderedCount = -1;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
#include "AnimationUtils.h"
|
||||||
|
|
||||||
|
#include <QGraphicsOpacityEffect>
|
||||||
|
#include <QPropertyAnimation>
|
||||||
|
#include <QWidget>
|
||||||
|
|
||||||
|
namespace AnimationUtils
|
||||||
|
{
|
||||||
|
void fadeIn(QWidget* widget, int durationMs)
|
||||||
|
{
|
||||||
|
if (!widget)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
widget->setGraphicsEffect(nullptr);
|
||||||
|
auto* effect = new QGraphicsOpacityEffect(widget);
|
||||||
|
effect->setOpacity(0.0);
|
||||||
|
widget->setGraphicsEffect(effect);
|
||||||
|
auto* animation = new QPropertyAnimation(effect, "opacity", widget);
|
||||||
|
animation->setDuration(durationMs);
|
||||||
|
animation->setStartValue(0.0);
|
||||||
|
animation->setEndValue(1.0);
|
||||||
|
animation->setEasingCurve(QEasingCurve::OutCubic);
|
||||||
|
QObject::connect(animation, &QPropertyAnimation::finished, widget, [widget, animation]() {
|
||||||
|
widget->setGraphicsEffect(nullptr);
|
||||||
|
animation->deleteLater();
|
||||||
|
});
|
||||||
|
animation->start();
|
||||||
|
}
|
||||||
|
|
||||||
|
void fadeWindow(QWidget* window, int durationMs)
|
||||||
|
{
|
||||||
|
if (!window)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
auto* animation = new QPropertyAnimation(window, "windowOpacity", window);
|
||||||
|
animation->setDuration(durationMs);
|
||||||
|
animation->setStartValue(0.0);
|
||||||
|
animation->setEndValue(1.0);
|
||||||
|
animation->setEasingCurve(QEasingCurve::OutCubic);
|
||||||
|
QObject::connect(animation, &QPropertyAnimation::finished, animation, &QPropertyAnimation::deleteLater);
|
||||||
|
window->setWindowOpacity(0.0);
|
||||||
|
animation->start();
|
||||||
|
}
|
||||||
|
} // namespace AnimationUtils
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
class QWidget;
|
||||||
|
|
||||||
|
namespace AnimationUtils
|
||||||
|
{
|
||||||
|
void fadeIn(QWidget* widget, int durationMs = 180);
|
||||||
|
void fadeWindow(QWidget* window, int durationMs = 220);
|
||||||
|
} // namespace AnimationUtils
|
||||||
@@ -102,6 +102,12 @@ const QVector<ScheduleItem>& ScheduleGridView::blocks() const
|
|||||||
return m_blocks;
|
return m_blocks;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ScheduleGridView::setGhostWindows(const QVector<FreeWindow>& windows)
|
||||||
|
{
|
||||||
|
m_ghostWindows = windows;
|
||||||
|
viewport()->update();
|
||||||
|
}
|
||||||
|
|
||||||
void ScheduleGridView::setTokens(const ThemeTokens& tokens)
|
void ScheduleGridView::setTokens(const ThemeTokens& tokens)
|
||||||
{
|
{
|
||||||
m_tokens = tokens;
|
m_tokens = tokens;
|
||||||
@@ -958,12 +964,54 @@ void ScheduleGridView::paintEvent(QPaintEvent* event)
|
|||||||
}
|
}
|
||||||
|
|
||||||
const int scroll = verticalScrollBar()->value();
|
const int scroll = verticalScrollBar()->value();
|
||||||
|
paintGhostWindows(painter, scroll);
|
||||||
paintBlocks(painter, scroll);
|
paintBlocks(painter, scroll);
|
||||||
paintNowLine(painter, scroll);
|
paintNowLine(painter, scroll);
|
||||||
paintCreatePreview(painter, scroll);
|
paintCreatePreview(painter, scroll);
|
||||||
paintEmptyHint(painter, scroll);
|
paintEmptyHint(painter, scroll);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ScheduleGridView::paintGhostWindows(QPainter& painter, int scrollY)
|
||||||
|
{
|
||||||
|
if (m_ghostWindows.isEmpty())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
painter.save();
|
||||||
|
painter.setClipRect(QRectF(m_axisWidth + 1,
|
||||||
|
0,
|
||||||
|
viewport()->width() - m_axisWidth - 1,
|
||||||
|
viewport()->height()));
|
||||||
|
painter.translate(0, -scrollY);
|
||||||
|
QColor fill = m_tokens.accent;
|
||||||
|
fill.setAlpha(m_tokens.dark ? 24 : 18);
|
||||||
|
QColor border = m_tokens.accent;
|
||||||
|
border.setAlpha(m_tokens.dark ? 100 : 80);
|
||||||
|
QFont font = painter.font();
|
||||||
|
font.setPixelSize(11);
|
||||||
|
painter.setFont(font);
|
||||||
|
for (const FreeWindow& window : m_ghostWindows)
|
||||||
|
{
|
||||||
|
QRectF rect = rectForTimes(window.start, window.end).adjusted(4, 2, -4, -2);
|
||||||
|
if (rect.height() < 16)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
QPainterPath path;
|
||||||
|
path.addRoundedRect(rect, 6, 6);
|
||||||
|
painter.fillPath(path, fill);
|
||||||
|
QPen pen(border, 1.0, Qt::DashLine);
|
||||||
|
painter.setPen(pen);
|
||||||
|
painter.setBrush(Qt::NoBrush);
|
||||||
|
painter.drawPath(path);
|
||||||
|
painter.setPen(m_tokens.textMuted);
|
||||||
|
const QString text = QStringLiteral("幽灵时间 · %1")
|
||||||
|
.arg(DateTimeUtils::formatDuration(window.minutes));
|
||||||
|
painter.drawText(rect.adjusted(10, 0, -8, 0), Qt::AlignLeft | Qt::AlignVCenter, text);
|
||||||
|
}
|
||||||
|
painter.restore();
|
||||||
|
}
|
||||||
|
|
||||||
void ScheduleGridView::paintBlocks(QPainter& painter, int scrollY)
|
void ScheduleGridView::paintBlocks(QPainter& painter, int scrollY)
|
||||||
{
|
{
|
||||||
painter.save();
|
painter.save();
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
#include <QSize>
|
#include <QSize>
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
|
|
||||||
|
#include "core/DailyInsights.h"
|
||||||
#include "core/ScheduleItem.h"
|
#include "core/ScheduleItem.h"
|
||||||
#include "ui/theme/ThemeTokens.h"
|
#include "ui/theme/ThemeTokens.h"
|
||||||
|
|
||||||
@@ -27,6 +28,7 @@ public:
|
|||||||
|
|
||||||
void setBlocks(const QVector<ScheduleItem>& blocks);
|
void setBlocks(const QVector<ScheduleItem>& blocks);
|
||||||
const QVector<ScheduleItem>& blocks() const;
|
const QVector<ScheduleItem>& blocks() const;
|
||||||
|
void setGhostWindows(const QVector<FreeWindow>& windows);
|
||||||
|
|
||||||
void setTokens(const ThemeTokens& tokens);
|
void setTokens(const ThemeTokens& tokens);
|
||||||
void setSnapMinutes(int minutes);
|
void setSnapMinutes(int minutes);
|
||||||
@@ -84,6 +86,7 @@ private:
|
|||||||
void ensureGridCache();
|
void ensureGridCache();
|
||||||
void invalidateGridCache();
|
void invalidateGridCache();
|
||||||
void paintGrid(QPainter& painter);
|
void paintGrid(QPainter& painter);
|
||||||
|
void paintGhostWindows(QPainter& painter, int scrollY);
|
||||||
void paintBlocks(QPainter& painter, int scrollY);
|
void paintBlocks(QPainter& painter, int scrollY);
|
||||||
void paintBlock(QPainter& painter, const VisualBlock& visual);
|
void paintBlock(QPainter& painter, const VisualBlock& visual);
|
||||||
void paintNowLine(QPainter& painter, int scrollY);
|
void paintNowLine(QPainter& painter, int scrollY);
|
||||||
@@ -117,6 +120,7 @@ private:
|
|||||||
|
|
||||||
QDate m_date;
|
QDate m_date;
|
||||||
QVector<ScheduleItem> m_blocks;
|
QVector<ScheduleItem> m_blocks;
|
||||||
|
QVector<FreeWindow> m_ghostWindows;
|
||||||
QVector<VisualBlock> m_visuals;
|
QVector<VisualBlock> m_visuals;
|
||||||
ThemeTokens m_tokens;
|
ThemeTokens m_tokens;
|
||||||
int m_snapMinutes = 15;
|
int m_snapMinutes = 15;
|
||||||
|
|||||||
@@ -26,6 +26,10 @@ add_executable(test_scheduler test_scheduler.cpp)
|
|||||||
target_link_libraries(test_scheduler PRIVATE schedule_core Qt6::Test schedule_warnings)
|
target_link_libraries(test_scheduler PRIVATE schedule_core Qt6::Test schedule_warnings)
|
||||||
add_test(NAME scheduler COMMAND test_scheduler)
|
add_test(NAME scheduler COMMAND test_scheduler)
|
||||||
|
|
||||||
|
add_executable(test_energy test_energy.cpp)
|
||||||
|
target_link_libraries(test_energy PRIVATE schedule_core Qt6::Test schedule_warnings)
|
||||||
|
add_test(NAME energy COMMAND test_energy)
|
||||||
|
|
||||||
add_executable(test_ai test_ai.cpp)
|
add_executable(test_ai test_ai.cpp)
|
||||||
target_link_libraries(test_ai PRIVATE schedule_ai Qt6::Test schedule_warnings)
|
target_link_libraries(test_ai PRIVATE schedule_ai Qt6::Test schedule_warnings)
|
||||||
add_test(NAME ai COMMAND test_ai)
|
add_test(NAME ai COMMAND test_ai)
|
||||||
@@ -47,7 +51,7 @@ endif()
|
|||||||
if(WIN32)
|
if(WIN32)
|
||||||
set_target_properties(
|
set_target_properties(
|
||||||
test_storage test_services test_grid test_mainwindow test_compactwindow
|
test_storage test_services test_grid test_mainwindow test_compactwindow
|
||||||
test_config test_scheduler test_ai test_openai_provider test_sync_integration
|
test_config test_scheduler test_energy test_ai test_openai_provider test_sync_integration
|
||||||
PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
|
PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
#include <QListWidget>
|
||||||
#include <QTemporaryDir>
|
#include <QTemporaryDir>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QtTest>
|
#include <QtTest>
|
||||||
@@ -7,6 +8,7 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include "ElaApplication.h"
|
#include "ElaApplication.h"
|
||||||
|
#include "ElaComboBox.h"
|
||||||
#include "ElaLineEdit.h"
|
#include "ElaLineEdit.h"
|
||||||
#include "ElaPushButton.h"
|
#include "ElaPushButton.h"
|
||||||
#include "ElaToolButton.h"
|
#include "ElaToolButton.h"
|
||||||
@@ -16,6 +18,9 @@
|
|||||||
#include "storage/SqliteStore.h"
|
#include "storage/SqliteStore.h"
|
||||||
#include "ui/CompactWindow.h"
|
#include "ui/CompactWindow.h"
|
||||||
#include "ui/MainWindow.h"
|
#include "ui/MainWindow.h"
|
||||||
|
#include "ui/dialogs/BlockEditDialog.h"
|
||||||
|
#include "ui/dialogs/DailyReviewDialog.h"
|
||||||
|
#include "ui/dialogs/SearchDialog.h"
|
||||||
#include "ui/dialogs/SettingsDialog.h"
|
#include "ui/dialogs/SettingsDialog.h"
|
||||||
#include "ui/panels/DiffPreviewCard.h"
|
#include "ui/panels/DiffPreviewCard.h"
|
||||||
#include "ui/theme/ThemeManager.h"
|
#include "ui/theme/ThemeManager.h"
|
||||||
@@ -60,6 +65,9 @@ class TestCompactWindow : public QObject
|
|||||||
private slots:
|
private slots:
|
||||||
void initTestCase();
|
void initTestCase();
|
||||||
void compactOpensScheduleAndReturns();
|
void compactOpensScheduleAndReturns();
|
||||||
|
void opensDailyReview();
|
||||||
|
void searchDialogFindsSchedules();
|
||||||
|
void repeatDialogShowsOptions();
|
||||||
void aiChatShowsDiffAndAccepts();
|
void aiChatShowsDiffAndAccepts();
|
||||||
void aiChatShowsMultiOperationDiff();
|
void aiChatShowsMultiOperationDiff();
|
||||||
|
|
||||||
@@ -217,6 +225,13 @@ void TestCompactWindow::compactOpensScheduleAndReturns()
|
|||||||
}
|
}
|
||||||
saveWindow(scheduleWindow, QStringLiteral("schedule-day.png"));
|
saveWindow(scheduleWindow, QStringLiteral("schedule-day.png"));
|
||||||
|
|
||||||
|
if (auto* grid = scheduleWindow->findChild<ScheduleGridView*>())
|
||||||
|
{
|
||||||
|
grid->scrollToHour(18);
|
||||||
|
QTest::qWait(80);
|
||||||
|
}
|
||||||
|
saveWindow(scheduleWindow, QStringLiteral("schedule-ghost.png"));
|
||||||
|
|
||||||
scheduleWindow->setView(MainWindow::View::Month);
|
scheduleWindow->setView(MainWindow::View::Month);
|
||||||
QTest::qWait(200);
|
QTest::qWait(200);
|
||||||
QCOMPARE(scheduleWindow->view(), MainWindow::View::Month);
|
QCOMPARE(scheduleWindow->view(), MainWindow::View::Month);
|
||||||
@@ -266,6 +281,104 @@ void TestCompactWindow::compactOpensScheduleAndReturns()
|
|||||||
QTest::mouseClick(settingsButton, Qt::LeftButton);
|
QTest::mouseClick(settingsButton, Qt::LeftButton);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TestCompactWindow::opensDailyReview()
|
||||||
|
{
|
||||||
|
QTemporaryDir databaseDir;
|
||||||
|
QVERIFY(databaseDir.isValid());
|
||||||
|
SqliteStore store(databaseDir.filePath(QStringLiteral("schedule.db")));
|
||||||
|
QString error;
|
||||||
|
QVERIFY2(store.open(&error), qPrintable(error));
|
||||||
|
|
||||||
|
ThemeManager theme(*m_settings);
|
||||||
|
theme.initialize();
|
||||||
|
ScheduleService service(store, QStringLiteral("review-test"));
|
||||||
|
NotificationService notifications(service);
|
||||||
|
AIService aiService(service, store, *m_settings);
|
||||||
|
createSampleData(service, QDate::currentDate());
|
||||||
|
|
||||||
|
CompactWindow compact(service, notifications, aiService, theme, *m_settings);
|
||||||
|
compact.show();
|
||||||
|
QVERIFY(QTest::qWaitForWindowExposed(&compact));
|
||||||
|
QTest::qWait(300);
|
||||||
|
|
||||||
|
ElaToolButton* reviewButton = nullptr;
|
||||||
|
for (ElaToolButton* button : compact.findChildren<ElaToolButton*>())
|
||||||
|
{
|
||||||
|
if (button->toolTip().startsWith(QStringLiteral("今日复盘")))
|
||||||
|
{
|
||||||
|
reviewButton = button;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
QVERIFY(reviewButton);
|
||||||
|
|
||||||
|
QTimer::singleShot(400, []() {
|
||||||
|
for (QWidget* widget : QApplication::topLevelWidgets())
|
||||||
|
{
|
||||||
|
if (auto* dialog = qobject_cast<DailyReviewDialog*>(widget))
|
||||||
|
{
|
||||||
|
saveWindow(dialog, QStringLiteral("review.png"));
|
||||||
|
dialog->reject();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
QTimer::singleShot(2000, []() {
|
||||||
|
for (QWidget* widget : QApplication::topLevelWidgets())
|
||||||
|
{
|
||||||
|
if (auto* dialog = qobject_cast<DailyReviewDialog*>(widget))
|
||||||
|
{
|
||||||
|
dialog->reject();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
QTest::mouseClick(reviewButton, Qt::LeftButton);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestCompactWindow::searchDialogFindsSchedules()
|
||||||
|
{
|
||||||
|
QTemporaryDir databaseDir;
|
||||||
|
QVERIFY(databaseDir.isValid());
|
||||||
|
SqliteStore store(databaseDir.filePath(QStringLiteral("schedule.db")));
|
||||||
|
QString error;
|
||||||
|
QVERIFY2(store.open(&error), qPrintable(error));
|
||||||
|
|
||||||
|
ThemeManager theme(*m_settings);
|
||||||
|
theme.initialize();
|
||||||
|
ScheduleService service(store, QStringLiteral("search-test"));
|
||||||
|
createSampleData(service, QDate::currentDate());
|
||||||
|
|
||||||
|
SearchDialog dialog(service, theme.tokens(), QStringLiteral("周报"));
|
||||||
|
dialog.show();
|
||||||
|
QVERIFY(QTest::qWaitForWindowExposed(&dialog));
|
||||||
|
QTest::qWait(300);
|
||||||
|
|
||||||
|
auto* results = dialog.findChild<QListWidget*>();
|
||||||
|
QVERIFY(results);
|
||||||
|
QVERIFY(results->count() > 0);
|
||||||
|
saveWindow(&dialog, QStringLiteral("search.png"));
|
||||||
|
dialog.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestCompactWindow::repeatDialogShowsOptions()
|
||||||
|
{
|
||||||
|
ThemeManager theme(*m_settings);
|
||||||
|
theme.initialize();
|
||||||
|
BlockEditDialog dialog(theme.tokens());
|
||||||
|
dialog.setCreateMode(true);
|
||||||
|
const QDateTime start(QDate::currentDate(), QTime(9, 0), Qt::LocalTime);
|
||||||
|
dialog.setValues(QStringLiteral("每日复盘"), start, start.addSecs(60 * 60));
|
||||||
|
auto* combo = dialog.findChild<ElaComboBox*>();
|
||||||
|
QVERIFY(combo);
|
||||||
|
combo->setCurrentIndex(1);
|
||||||
|
dialog.show();
|
||||||
|
QVERIFY(QTest::qWaitForWindowExposed(&dialog));
|
||||||
|
QTest::qWait(300);
|
||||||
|
saveWindow(&dialog, QStringLiteral("block-edit-repeat.png"));
|
||||||
|
dialog.accept();
|
||||||
|
QCOMPARE(dialog.recurrenceFrequency(), RecurrenceFrequency::Daily);
|
||||||
|
QCOMPARE(dialog.recurrenceUntil(), start.date().addMonths(3));
|
||||||
|
}
|
||||||
|
|
||||||
void TestCompactWindow::aiChatShowsDiffAndAccepts()
|
void TestCompactWindow::aiChatShowsDiffAndAccepts()
|
||||||
{
|
{
|
||||||
QTemporaryDir databaseDir;
|
QTemporaryDir databaseDir;
|
||||||
|
|||||||
@@ -0,0 +1,122 @@
|
|||||||
|
#include <QtTest>
|
||||||
|
|
||||||
|
#include "core/DailyInsights.h"
|
||||||
|
#include "core/EnergyProfile.h"
|
||||||
|
|
||||||
|
class TestEnergy : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void defaultProfileHasCurve();
|
||||||
|
void learnsFromSamples();
|
||||||
|
void rejectsInvalidCoordinates();
|
||||||
|
void findsGhostWindows();
|
||||||
|
void buildsDailyReviewAndSuggestions();
|
||||||
|
};
|
||||||
|
|
||||||
|
void TestEnergy::defaultProfileHasCurve()
|
||||||
|
{
|
||||||
|
const EnergyProfile profile = EnergyProfile::defaults();
|
||||||
|
QCOMPARE(profile.level(1, 9), 2);
|
||||||
|
QCOMPARE(profile.level(1, 13), 0);
|
||||||
|
QCOMPARE(profile.level(7, 9), 0);
|
||||||
|
QCOMPARE(profile.level(7, 10), 1);
|
||||||
|
QCOMPARE(profile.level(0, 9), -1);
|
||||||
|
QCOMPARE(EnergyProfile::label(2), QStringLiteral("高"));
|
||||||
|
QCOMPARE(profile.levels().size(), 7 * 24);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestEnergy::learnsFromSamples()
|
||||||
|
{
|
||||||
|
EnergyProfile profile = EnergyProfile::defaults();
|
||||||
|
profile.learn({{1, 13, 2}, {1, 13, 2}, {1, 9, 0}});
|
||||||
|
QCOMPARE(profile.level(1, 13), 2);
|
||||||
|
QCOMPARE(profile.level(1, 9), 0);
|
||||||
|
QCOMPARE(profile.level(2, 9), 2);
|
||||||
|
|
||||||
|
profile.setLevel(1, 13, 1);
|
||||||
|
QCOMPARE(profile.level(1, 13), 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestEnergy::rejectsInvalidCoordinates()
|
||||||
|
{
|
||||||
|
EnergyProfile profile = EnergyProfile::defaults();
|
||||||
|
QVERIFY(!profile.setLevel(0, 9, 2));
|
||||||
|
QVERIFY(!profile.setLevel(8, 9, 2));
|
||||||
|
QVERIFY(!profile.setLevel(1, 24, 2));
|
||||||
|
QCOMPARE(profile.level(1, 24), -1);
|
||||||
|
QCOMPARE(profile.level(QDateTime()), -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
QDate testDate()
|
||||||
|
{
|
||||||
|
return QDate(2026, 1, 5);
|
||||||
|
}
|
||||||
|
|
||||||
|
ScheduleItem item(int startHour, int endHour, const QString& status, const QString& title)
|
||||||
|
{
|
||||||
|
ScheduleItem result;
|
||||||
|
result.task.title = title;
|
||||||
|
result.task.energyReq = 1;
|
||||||
|
result.block.startAt = QDateTime(testDate(), QTime(startHour, 0), Qt::LocalTime);
|
||||||
|
result.block.endAt = QDateTime(testDate(), QTime(endHour, 0), Qt::LocalTime);
|
||||||
|
result.block.status = status;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
void TestEnergy::findsGhostWindows()
|
||||||
|
{
|
||||||
|
const QVector<ScheduleItem> items = {
|
||||||
|
item(9, 10, QStringLiteral("done"), QStringLiteral("A")),
|
||||||
|
item(13, 14, QStringLiteral("scheduled"), QStringLiteral("B")),
|
||||||
|
item(11, 12, QStringLiteral("dropped"), QStringLiteral("C")),
|
||||||
|
};
|
||||||
|
const auto windows = findFreeWindows(items,
|
||||||
|
testDate(),
|
||||||
|
QDateTime(testDate(), QTime(8, 0), Qt::LocalTime),
|
||||||
|
8,
|
||||||
|
22,
|
||||||
|
30);
|
||||||
|
QCOMPARE(windows.size(), 3);
|
||||||
|
QCOMPARE(windows[0].minutes, 60);
|
||||||
|
QCOMPARE(windows[0].start.time(), QTime(8, 0));
|
||||||
|
QCOMPARE(windows[1].minutes, 180);
|
||||||
|
QCOMPARE(windows[1].start.time(), QTime(10, 0));
|
||||||
|
QCOMPARE(windows[2].minutes, 8 * 60);
|
||||||
|
QCOMPARE(windows[2].start.time(), QTime(14, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestEnergy::buildsDailyReviewAndSuggestions()
|
||||||
|
{
|
||||||
|
const QVector<ScheduleItem> items = {
|
||||||
|
item(9, 10, QStringLiteral("done"), QStringLiteral("完成")),
|
||||||
|
item(13, 14, QStringLiteral("scheduled"), QStringLiteral("超时")),
|
||||||
|
};
|
||||||
|
const QDateTime now(testDate(), QTime(15, 0), Qt::LocalTime);
|
||||||
|
const DailyReview review = buildDailyReview(items, testDate(), now);
|
||||||
|
QCOMPARE(review.total, 2);
|
||||||
|
QCOMPARE(review.done, 1);
|
||||||
|
QCOMPARE(review.active, 1);
|
||||||
|
QCOMPARE(review.overdue, 1);
|
||||||
|
QCOMPARE(review.focusedMinutes, 60);
|
||||||
|
QCOMPARE(review.completionPercent, 50);
|
||||||
|
QVERIFY(!review.ghostWindows.isEmpty());
|
||||||
|
|
||||||
|
const auto suggestions = buildSuggestions(items, now, 3);
|
||||||
|
QCOMPARE(suggestions.size(), 2);
|
||||||
|
QCOMPARE(suggestions[0].kind, Suggestion::Kind::Overdue);
|
||||||
|
QCOMPARE(suggestions[1].kind, Suggestion::Kind::GhostTime);
|
||||||
|
|
||||||
|
const auto evening = buildSuggestions(items,
|
||||||
|
QDateTime(testDate(), QTime(19, 0), Qt::LocalTime),
|
||||||
|
3);
|
||||||
|
QCOMPARE(evening.size(), 3);
|
||||||
|
QCOMPARE(evening[2].kind, Suggestion::Kind::Review);
|
||||||
|
}
|
||||||
|
|
||||||
|
QTEST_GUILESS_MAIN(TestEnergy)
|
||||||
|
#include "test_energy.moc"
|
||||||
@@ -47,6 +47,7 @@ class TestOpenAiProvider : public QObject
|
|||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void streamsSseContent();
|
void streamsSseContent();
|
||||||
|
void streamsLocalWithoutApiKey();
|
||||||
void reportsHttpError();
|
void reportsHttpError();
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -92,6 +93,45 @@ void TestOpenAiProvider::streamsSseContent()
|
|||||||
QCOMPARE(text, QStringLiteral("你好,世界"));
|
QCOMPARE(text, QStringLiteral("你好,世界"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TestOpenAiProvider::streamsLocalWithoutApiKey()
|
||||||
|
{
|
||||||
|
FakeSseServer server;
|
||||||
|
QVERIFY(server.listen(QHostAddress::LocalHost, 0));
|
||||||
|
server.response =
|
||||||
|
"HTTP/1.1 200 OK\r\n"
|
||||||
|
"Content-Type: text/event-stream\r\n"
|
||||||
|
"Connection: close\r\n"
|
||||||
|
"\r\n"
|
||||||
|
"data: {\"choices\":[{\"delta\":{\"content\":\"local\"}}]}\n\n"
|
||||||
|
"data: [DONE]\n\n";
|
||||||
|
|
||||||
|
AiConfig config;
|
||||||
|
config.baseUrl = QStringLiteral("http://127.0.0.1:%1/v1").arg(server.serverPort());
|
||||||
|
config.model = QStringLiteral("local-model");
|
||||||
|
|
||||||
|
QJsonArray messages;
|
||||||
|
QJsonObject message;
|
||||||
|
message.insert(QStringLiteral("role"), QStringLiteral("user"));
|
||||||
|
message.insert(QStringLiteral("content"), QStringLiteral("hi"));
|
||||||
|
messages.append(message);
|
||||||
|
|
||||||
|
OpenAiProvider provider;
|
||||||
|
QString text;
|
||||||
|
QString error;
|
||||||
|
bool finished = false;
|
||||||
|
provider.streamCompletion(
|
||||||
|
config,
|
||||||
|
messages,
|
||||||
|
{
|
||||||
|
[&text](const QString& delta) { text += delta; },
|
||||||
|
[&error](const QString& message) { error = message; },
|
||||||
|
[&finished]() { finished = true; },
|
||||||
|
});
|
||||||
|
QTRY_VERIFY_WITH_TIMEOUT(finished, 5000);
|
||||||
|
QCOMPARE(error, QString());
|
||||||
|
QCOMPARE(text, QStringLiteral("local"));
|
||||||
|
}
|
||||||
|
|
||||||
void TestOpenAiProvider::reportsHttpError()
|
void TestOpenAiProvider::reportsHttpError()
|
||||||
{
|
{
|
||||||
FakeSseServer server;
|
FakeSseServer server;
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ private slots:
|
|||||||
void fallsBackWhenPreferredIsFull();
|
void fallsBackWhenPreferredIsFull();
|
||||||
void preferredWindowCanOverrideDefaultHours();
|
void preferredWindowCanOverrideDefaultHours();
|
||||||
void reportsFailureWhenNoRoom();
|
void reportsFailureWhenNoRoom();
|
||||||
|
void usesEnergyProfile();
|
||||||
};
|
};
|
||||||
|
|
||||||
void TestScheduler::skipsBusyIntervals()
|
void TestScheduler::skipsBusyIntervals()
|
||||||
@@ -157,5 +158,33 @@ void TestScheduler::reportsFailureWhenNoRoom()
|
|||||||
QCOMPARE(result.failures.size(), std::size_t(1));
|
QCOMPARE(result.failures.size(), std::size_t(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TestScheduler::usesEnergyProfile()
|
||||||
|
{
|
||||||
|
scheduler::Options options;
|
||||||
|
options.energyAt = [](SysTime value) {
|
||||||
|
const int hour = static_cast<int>((value.time_since_epoch().count() / 3600) % 24);
|
||||||
|
return hour < 14 ? 0 : 2;
|
||||||
|
};
|
||||||
|
|
||||||
|
auto high = task(QStringLiteral("high").toStdString(), 60);
|
||||||
|
high.energyRequired = 2;
|
||||||
|
auto result = scheduler::schedule({high}, {}, workWindows(1), at(0, 8), at(0, 22), options);
|
||||||
|
QCOMPARE(result.placements.size(), std::size_t(1));
|
||||||
|
QVERIFY(result.placements[0].start == at(0, 14));
|
||||||
|
QVERIFY(result.placements[0].end == at(0, 15));
|
||||||
|
|
||||||
|
auto medium = task(QStringLiteral("medium").toStdString(), 60);
|
||||||
|
medium.energyRequired = 1;
|
||||||
|
result = scheduler::schedule({medium}, {}, workWindows(1), at(0, 8), at(0, 22), options);
|
||||||
|
QCOMPARE(result.placements.size(), std::size_t(1));
|
||||||
|
QVERIFY(result.placements[0].start == at(0, 14));
|
||||||
|
|
||||||
|
auto strictHigh = task(QStringLiteral("strict-high").toStdString(), 60);
|
||||||
|
strictHigh.energyRequired = 2;
|
||||||
|
result = scheduler::schedule({strictHigh}, {}, workWindows(1), at(0, 8), at(0, 13), options);
|
||||||
|
QVERIFY(result.placements.empty());
|
||||||
|
QCOMPARE(result.failures.size(), std::size_t(1));
|
||||||
|
}
|
||||||
|
|
||||||
QTEST_GUILESS_MAIN(TestScheduler)
|
QTEST_GUILESS_MAIN(TestScheduler)
|
||||||
#include "test_scheduler.moc"
|
#include "test_scheduler.moc"
|
||||||
|
|||||||
@@ -25,6 +25,9 @@ private slots:
|
|||||||
void overdueAndNotificationDedup();
|
void overdueAndNotificationDedup();
|
||||||
void invalidRangeRejected();
|
void invalidRangeRejected();
|
||||||
void applyProposedCreatesOnlySelected();
|
void applyProposedCreatesOnlySelected();
|
||||||
|
void energyProfileLearnsFromHistory();
|
||||||
|
void searchFindsSchedules();
|
||||||
|
void createsRecurringSchedules();
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
@@ -313,5 +316,128 @@ void TestServices::applyProposedCreatesOnlySelected()
|
|||||||
QVERIFY(!context.service->applyProposedCreates(diff, {}, &error));
|
QVERIFY(!context.service->applyProposedCreates(diff, {}, &error));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TestServices::energyProfileLearnsFromHistory()
|
||||||
|
{
|
||||||
|
Context context;
|
||||||
|
QVERIFY(context.open());
|
||||||
|
|
||||||
|
const QDate date = QDate::currentDate();
|
||||||
|
QJsonObject task;
|
||||||
|
task.insert(QStringLiteral("title"), QStringLiteral("高精力任务"));
|
||||||
|
task.insert(QStringLiteral("priority"), 2);
|
||||||
|
task.insert(QStringLiteral("energy_req"), 2);
|
||||||
|
QJsonObject block;
|
||||||
|
block.insert(QStringLiteral("start_at"),
|
||||||
|
DateTimeUtils::toDb(QDateTime(date, QTime(13, 0), Qt::LocalTime)));
|
||||||
|
block.insert(QStringLiteral("end_at"),
|
||||||
|
DateTimeUtils::toDb(QDateTime(date, QTime(14, 0), Qt::LocalTime)));
|
||||||
|
QJsonObject create;
|
||||||
|
create.insert(QStringLiteral("temp_id"), QStringLiteral("energy"));
|
||||||
|
create.insert(QStringLiteral("task"), task);
|
||||||
|
create.insert(QStringLiteral("block"), block);
|
||||||
|
ProposedDiff diff;
|
||||||
|
diff.id = QStringLiteral("energy-diff");
|
||||||
|
diff.createdAt = DateTimeUtils::toDb(QDateTime::currentDateTimeUtc());
|
||||||
|
diff.state = QStringLiteral("pending");
|
||||||
|
diff.payload = QJsonObject{
|
||||||
|
{QStringLiteral("creates"), QJsonArray{create}},
|
||||||
|
{QStringLiteral("updates"), QJsonArray{}},
|
||||||
|
{QStringLiteral("deletes"), QJsonArray{}},
|
||||||
|
};
|
||||||
|
|
||||||
|
QString error;
|
||||||
|
QVERIFY2(context.service->applyProposedCreates(diff, {QStringLiteral("energy")}, &error),
|
||||||
|
qPrintable(error));
|
||||||
|
const QVector<ScheduleItem> items = context.service->itemsForDay(date);
|
||||||
|
QCOMPARE(items.size(), 1);
|
||||||
|
const QString blockId = items.first().block.id;
|
||||||
|
|
||||||
|
QCOMPARE(context.service->energyLevelFor(QDateTime(date, QTime(13, 0), Qt::LocalTime)), 0);
|
||||||
|
QVERIFY2(context.service->setBlockStatus(blockId, QStringLiteral("done"), &error), qPrintable(error));
|
||||||
|
QCOMPARE(context.service->energyLevelFor(QDateTime(date, QTime(13, 0), Qt::LocalTime)), 2);
|
||||||
|
QVERIFY(context.service->dailyReview(date).energySummary.contains(QStringLiteral("13:00–14:00")));
|
||||||
|
|
||||||
|
ScheduleService reloaded(*context.store, QStringLiteral("test-device"));
|
||||||
|
QCOMPARE(reloaded.energyLevelFor(QDateTime(date, QTime(13, 0), Qt::LocalTime)), 2);
|
||||||
|
|
||||||
|
QVERIFY2(context.service->setBlockStatus(blockId, QStringLiteral("scheduled"), &error), qPrintable(error));
|
||||||
|
QCOMPARE(context.service->energyLevelFor(QDateTime(date, QTime(13, 0), Qt::LocalTime)), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestServices::searchFindsSchedules()
|
||||||
|
{
|
||||||
|
Context context;
|
||||||
|
QVERIFY(context.open());
|
||||||
|
|
||||||
|
const QDate day = QDate::currentDate();
|
||||||
|
QString error;
|
||||||
|
QVERIFY(context.service->createBlock(QStringLiteral("写周报"),
|
||||||
|
QDateTime(day, QTime(9, 0), Qt::LocalTime),
|
||||||
|
QDateTime(day, QTime(10, 0), Qt::LocalTime),
|
||||||
|
&error));
|
||||||
|
QVERIFY(context.service->createBlock(QStringLiteral("团队会议"),
|
||||||
|
QDateTime(day, QTime(11, 0), Qt::LocalTime),
|
||||||
|
QDateTime(day, QTime(12, 0), Qt::LocalTime),
|
||||||
|
&error));
|
||||||
|
|
||||||
|
const QVector<ScheduleItem> weekly = context.service->search(QStringLiteral("周报"));
|
||||||
|
QCOMPARE(weekly.size(), 1);
|
||||||
|
QCOMPARE(weekly.first().task.title, QStringLiteral("写周报"));
|
||||||
|
|
||||||
|
const QVector<ScheduleItem> all = context.service->search(QString());
|
||||||
|
QCOMPARE(all.size(), 2);
|
||||||
|
QStringList titles;
|
||||||
|
for (const ScheduleItem& item : all)
|
||||||
|
{
|
||||||
|
titles.append(item.task.title);
|
||||||
|
}
|
||||||
|
QVERIFY(titles.contains(QStringLiteral("写周报")));
|
||||||
|
QVERIFY(titles.contains(QStringLiteral("团队会议")));
|
||||||
|
QCOMPARE(context.service->search(QStringLiteral("%")).size(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestServices::createsRecurringSchedules()
|
||||||
|
{
|
||||||
|
Context context;
|
||||||
|
QVERIFY(context.open());
|
||||||
|
|
||||||
|
const QDate first = QDate::currentDate().addDays(10);
|
||||||
|
const QDateTime start(first, QTime(9, 0), Qt::LocalTime);
|
||||||
|
const QDateTime end(first, QTime(10, 0), Qt::LocalTime);
|
||||||
|
int count = 0;
|
||||||
|
QString error;
|
||||||
|
QVERIFY2(context.service->createRecurringBlock(QStringLiteral("每日复盘"),
|
||||||
|
start,
|
||||||
|
end,
|
||||||
|
RecurrenceFrequency::Daily,
|
||||||
|
first.addDays(4),
|
||||||
|
&count,
|
||||||
|
&error),
|
||||||
|
qPrintable(error));
|
||||||
|
QCOMPARE(count, 5);
|
||||||
|
for (int offset = 0; offset < 5; ++offset)
|
||||||
|
{
|
||||||
|
const QVector<ScheduleItem> items = context.service->itemsForDay(first.addDays(offset));
|
||||||
|
QCOMPARE(items.size(), 1);
|
||||||
|
QCOMPARE(items.first().task.title, QStringLiteral("每日复盘"));
|
||||||
|
QCOMPARE(items.first().block.startAt.time(), QTime(9, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
const QString taskId = context.service->itemsForDay(first).first().task.id;
|
||||||
|
const auto recurrence = context.store->recurrenceForTask(taskId);
|
||||||
|
QVERIFY(recurrence.has_value());
|
||||||
|
QCOMPARE(recurrence->rule, QStringLiteral("FREQ=DAILY"));
|
||||||
|
QCOMPARE(recurrence->until.value(), first.addDays(4));
|
||||||
|
|
||||||
|
QVERIFY(!context.service->createRecurringBlock(QStringLiteral("错误"),
|
||||||
|
start,
|
||||||
|
end,
|
||||||
|
RecurrenceFrequency::Weekly,
|
||||||
|
first.addDays(-1),
|
||||||
|
&count,
|
||||||
|
&error));
|
||||||
|
QVERIFY(!error.isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
QTEST_GUILESS_MAIN(TestServices)
|
QTEST_GUILESS_MAIN(TestServices)
|
||||||
#include "test_services.moc"
|
#include "test_services.moc"
|
||||||
|
|||||||
@@ -8,6 +8,8 @@
|
|||||||
> 阶段 2(AI 日程闭环)已验证:[`validation/phase-2.md`](validation/phase-2.md)。
|
> 阶段 2(AI 日程闭环)已验证:[`validation/phase-2.md`](validation/phase-2.md)。
|
||||||
> 阶段 2.1(更新 / 删除 / 涟漪 / 拆分)已验证:[`validation/phase-2-1.md`](validation/phase-2-1.md)。
|
> 阶段 2.1(更新 / 删除 / 涟漪 / 拆分)已验证:[`validation/phase-2-1.md`](validation/phase-2-1.md)。
|
||||||
> 阶段 3(Go 同步服务端 / 多设备)已验证:[`validation/phase-3.md`](validation/phase-3.md)。
|
> 阶段 3(Go 同步服务端 / 多设备)已验证:[`validation/phase-3.md`](validation/phase-3.md)。
|
||||||
|
> 阶段 4(精力曲线 / 幽灵时间 / 每日复盘 / 主动建议)已验证:[`validation/phase-4.md`](validation/phase-4.md)。
|
||||||
|
> 阶段 4.1(搜索 / 重复日程 / Windows 安装包 / 动画)已验证:[`validation/phase-4-1.md`](validation/phase-4-1.md)。
|
||||||
|
|
||||||
## 0. 当前环境
|
## 0. 当前环境
|
||||||
|
|
||||||
@@ -108,7 +110,6 @@ Schedule/
|
|||||||
- [x] 长任务拆分(create)
|
- [x] 长任务拆分(create)
|
||||||
- [x] AI 测试:update/create/delete、涟漪、部分接受冲突、拆分
|
- [x] AI 测试:update/create/delete、涟漪、部分接受冲突、拆分
|
||||||
- [x] 真实本地模型 50 条中文指令回归:完整 49/50 (98%),#42 复测 PASS
|
- [x] 真实本地模型 50 条中文指令回归:完整 49/50 (98%),#42 复测 PASS
|
||||||
- [ ] 精力曲线、幽灵时间、每日复盘(阶段 4)
|
|
||||||
- [ ] 文件提取内嵌库替换(跨平台 PDF/Word)
|
- [ ] 文件提取内嵌库替换(跨平台 PDF/Word)
|
||||||
|
|
||||||
### 阶段 3:Go 同步服务端 + 多设备(已完成)
|
### 阶段 3:Go 同步服务端 + 多设备(已完成)
|
||||||
@@ -122,8 +123,24 @@ Schedule/
|
|||||||
- [x] 客户端双实例集成:创建 / 更新 / 删除 / 反向同步 / 服务端重启后离线恢复
|
- [x] 客户端双实例集成:创建 / 更新 / 删除 / 反向同步 / 服务端重启后离线恢复
|
||||||
- 验收:`ctest --preset linux-gcc` 11/11;`go test ./...`、`go vet ./...` 通过;见 [`validation/phase-3.md`](validation/phase-3.md)
|
- 验收:`ctest --preset linux-gcc` 11/11;`go test ./...`、`go vet ./...` 通过;见 [`validation/phase-3.md`](validation/phase-3.md)
|
||||||
|
|
||||||
### 阶段 4:智能增强(后续)
|
### 阶段 4:智能增强(已完成)
|
||||||
- 精力曲线学习与排程约束、幽灵时间、每日复盘、主动建议、本地模型 provider
|
- [x] 精力档案(7 天 × 24 小时,低/中/高)与 SQLite 缓存
|
||||||
|
- [x] 从已完成日程的 `energy_req` 学习精力曲线;撤销完成后回退
|
||||||
|
- [x] SchedulerEngine 按 `energy_req` 约束高精力任务的开始时段
|
||||||
|
- [x] AI 提示词注入精力高峰与 energy_req 语义,AI 排程使用学习后的曲线
|
||||||
|
- [x] 幽灵时间:工作时段空档计算、日视图半透明覆盖、复盘列表
|
||||||
|
- [x] 每日复盘:完成率、专注时长、待办/超时/放弃、精力高峰、幽灵时间
|
||||||
|
- [x] 主动建议:超时提醒、幽灵时间利用、傍晚复盘提示
|
||||||
|
- [x] 本地模型:Ollama / LM Studio / vLLM 等 OpenAI 兼容端点说明
|
||||||
|
- 验收:`ctest --preset linux-gcc` 12/12;详见 [`validation/phase-4.md`](validation/phase-4.md)
|
||||||
|
|
||||||
|
### 阶段 4.1:桌面体验补强(已完成)
|
||||||
|
- [x] 标题/说明搜索:SQLite LIKE、最近时间排序、搜索对话框、`Ctrl+F`
|
||||||
|
- [x] 每天/每周/每月重复日程:物化时间块、冲突跳过、最多 1 年 / 200 次
|
||||||
|
- [x] 重复规则存入本地 `recurrence` 表;物化日程照常同步
|
||||||
|
- [x] Windows 安装包:CPack NSIS + `package-windows.ps1`,安装阶段自动 `windeployqt`
|
||||||
|
- [x] 轻量动画:窗口/对话框淡入、视图切换淡入、任务列表与 Diff 卡片淡入
|
||||||
|
- 验收:`ctest --preset linux-gcc` 12/12;见 [`validation/phase-4-1.md`](validation/phase-4-1.md)
|
||||||
|
|
||||||
### 阶段 5:移动端(后续)
|
### 阶段 5:移动端(后续)
|
||||||
- Android 优先,复用同步协议与逻辑层
|
- Android 优先,复用同步协议与逻辑层
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 22 KiB |
|
After Width: | Height: | Size: 22 KiB |
|
Before Width: | Height: | Size: 65 KiB After Width: | Height: | Size: 72 KiB |
|
Before Width: | Height: | Size: 65 KiB After Width: | Height: | Size: 71 KiB |
@@ -0,0 +1,29 @@
|
|||||||
|
Test project /home/misaki/MisakiCodes/Schedule/build/linux-gcc
|
||||||
|
Start 1: go_server_tests
|
||||||
|
1/12 Test #1: go_server_tests .................. Passed 0.09 sec
|
||||||
|
Start 2: storage
|
||||||
|
2/12 Test #2: storage .......................... Passed 0.02 sec
|
||||||
|
Start 3: services
|
||||||
|
3/12 Test #3: services ......................... Passed 0.05 sec
|
||||||
|
Start 4: grid
|
||||||
|
4/12 Test #4: grid ............................. Passed 0.39 sec
|
||||||
|
Start 5: mainwindow
|
||||||
|
5/12 Test #5: mainwindow ....................... Passed 1.25 sec
|
||||||
|
Start 6: compactwindow
|
||||||
|
6/12 Test #6: compactwindow .................... Passed 4.29 sec
|
||||||
|
Start 7: config
|
||||||
|
7/12 Test #7: config ........................... Passed 0.01 sec
|
||||||
|
Start 8: scheduler
|
||||||
|
8/12 Test #8: scheduler ........................ Passed 0.01 sec
|
||||||
|
Start 9: energy
|
||||||
|
9/12 Test #9: energy ........................... Passed 0.00 sec
|
||||||
|
Start 10: ai
|
||||||
|
10/12 Test #10: ai ............................... Passed 0.11 sec
|
||||||
|
Start 11: openai_provider
|
||||||
|
11/12 Test #11: openai_provider .................. Passed 0.21 sec
|
||||||
|
Start 12: sync_integration
|
||||||
|
12/12 Test #12: sync_integration ................. Passed 7.72 sec
|
||||||
|
|
||||||
|
100% tests passed, 0 tests failed out of 12
|
||||||
|
|
||||||
|
Total Test time (real) = 14.15 sec
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
Test project /home/misaki/MisakiCodes/Schedule/build/linux-gcc
|
||||||
|
Start 1: go_server_tests
|
||||||
|
1/12 Test #1: go_server_tests .................. Passed 0.10 sec
|
||||||
|
Start 2: storage
|
||||||
|
2/12 Test #2: storage .......................... Passed 0.02 sec
|
||||||
|
Start 3: services
|
||||||
|
3/12 Test #3: services ......................... Passed 0.04 sec
|
||||||
|
Start 4: grid
|
||||||
|
4/12 Test #4: grid ............................. Passed 0.38 sec
|
||||||
|
Start 5: mainwindow
|
||||||
|
5/12 Test #5: mainwindow ....................... Passed 1.25 sec
|
||||||
|
Start 6: compactwindow
|
||||||
|
6/12 Test #6: compactwindow .................... Passed 3.66 sec
|
||||||
|
Start 7: config
|
||||||
|
7/12 Test #7: config ........................... Passed 0.01 sec
|
||||||
|
Start 8: scheduler
|
||||||
|
8/12 Test #8: scheduler ........................ Passed 0.00 sec
|
||||||
|
Start 9: energy
|
||||||
|
9/12 Test #9: energy ........................... Passed 0.01 sec
|
||||||
|
Start 10: ai
|
||||||
|
10/12 Test #10: ai ............................... Passed 0.11 sec
|
||||||
|
Start 11: openai_provider
|
||||||
|
11/12 Test #11: openai_provider .................. Passed 0.21 sec
|
||||||
|
Start 12: sync_integration
|
||||||
|
12/12 Test #12: sync_integration ................. Passed 7.82 sec
|
||||||
|
|
||||||
|
100% tests passed, 0 tests failed out of 12
|
||||||
|
|
||||||
|
Total Test time (real) = 13.62 sec
|
||||||
|
After Width: | Height: | Size: 45 KiB |
|
After Width: | Height: | Size: 44 KiB |
@@ -0,0 +1,111 @@
|
|||||||
|
# 阶段 4.1 验证报告:搜索 / 重复日程 / Windows 安装包 / 动画
|
||||||
|
|
||||||
|
> 日期:2026-10-26
|
||||||
|
> 环境:Ubuntu 24.04 / GCC 13.3 / Qt 6.6.3(Windows 安装包需在 Windows + MinGW 下验证)
|
||||||
|
|
||||||
|
## 1. 本次交付
|
||||||
|
|
||||||
|
### 1.1 搜索
|
||||||
|
|
||||||
|
- SQLite `LIKE` 查询任务标题、说明和来源引用,按离当前时间最近排序,最多 100 条。
|
||||||
|
- 新增 `SearchDialog`:输入即搜索,回车选择第一条,双击/回车跳转到对应日期并定位日程块。
|
||||||
|
- 详细日程工具栏搜索框启用;`Ctrl+F` 在紧凑/详细窗口均可打开。
|
||||||
|
- 搜索框内容通过 `ESCAPE` 处理,`%`、`_`、`\` 按字面量搜索。
|
||||||
|
|
||||||
|
### 1.2 重复日程
|
||||||
|
|
||||||
|
- 新建日程增加「重复:不重复 / 每天 / 每周 / 每月」和「重复结束」。
|
||||||
|
- 重复日程物化为共享同一任务的时间块,最多 1 年 / 200 次。
|
||||||
|
- 与既有日程冲突的重复日期自动跳过;全部冲突时拒绝创建并提示。
|
||||||
|
- `recurrence` 表保存本地规则元数据;物化后的任务/时间块沿用阶段 3 同步链路。
|
||||||
|
- 编辑重复块标题会修改共享任务标题(影响该系列);删除单个块只删除该次。
|
||||||
|
|
||||||
|
### 1.3 Windows 安装包
|
||||||
|
|
||||||
|
- 根 CMake 增加 CPack NSIS 配置:开始菜单项、桌面快捷方式、卸载信息。
|
||||||
|
- 安装阶段自动执行 `windeployqt`,安装 Qt DLL、平台插件和 MinGW 运行时。
|
||||||
|
- 新增 `windows-mingw-release` configure/build/test preset。
|
||||||
|
- 新增 `scripts/package-windows.ps1`:
|
||||||
|
- 配置并构建 Release;
|
||||||
|
- 运行测试;
|
||||||
|
- 优先 CPack NSIS 生成 `.exe` 安装包;
|
||||||
|
- 未安装 NSIS 时退化为 ZIP 便携包。
|
||||||
|
|
||||||
|
### 1.4 动画
|
||||||
|
|
||||||
|
- `AnimationUtils::fadeWindow`:紧凑窗口、详细窗口、设置、日程编辑、复盘、搜索对话框淡入。
|
||||||
|
- `AnimationUtils::fadeIn`:日/月/年视图切换、任务列表刷新、Diff 卡片出现时淡入。
|
||||||
|
- 全部使用 150–220ms `OutCubic`,不阻塞 UI;没有引入新第三方依赖。
|
||||||
|
|
||||||
|
## 2. 构建与自动化测试
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cmake --preset linux-gcc
|
||||||
|
cmake --build --preset linux-gcc --clean-first -j$(nproc)
|
||||||
|
ctest --preset linux-gcc
|
||||||
|
```
|
||||||
|
|
||||||
|
| 项目 | 结果 |
|
||||||
|
|---|---|
|
||||||
|
| 客户端全量构建 | 成功,项目代码 0 警告(`-Werror`) |
|
||||||
|
| `ctest --preset linux-gcc` | **12/12 通过**,总耗时约 14s |
|
||||||
|
|
||||||
|
完整输出见 [`ctest-phase-4-1.txt`](ctest-phase-4-1.txt)。
|
||||||
|
|
||||||
|
新增/扩展测试:
|
||||||
|
|
||||||
|
| 用例 | 覆盖 |
|
||||||
|
|---|---|
|
||||||
|
| `test_services::searchFindsSchedules` | 标题/空查询/通配符转义 |
|
||||||
|
| `test_services::createsRecurringSchedules` | 每天 5 次物化、规则持久化、非法结束日期 |
|
||||||
|
| `test_compactwindow::searchDialogFindsSchedules` | 搜索对话框结果与截图 |
|
||||||
|
| `test_compactwindow::repeatDialogShowsOptions` | 重复选项、对话框关闭后读取频率/结束日期 |
|
||||||
|
| 原有 12 组测试 | 存储、调度、精力、AI、同步、UI 全部通过 |
|
||||||
|
|
||||||
|
## 3. 界面截图
|
||||||
|
|
||||||
|
| 截图 | 说明 |
|
||||||
|
|---|---|
|
||||||
|
| [`search-dark.png`](search-dark.png) / [`search-light.png`](search-light.png) | 搜索对话框与结果 |
|
||||||
|
| [`block-edit-dialog.png`](block-edit-dialog.png) | 新建日程:重复 + 重复结束 |
|
||||||
|
| [`block-edit-repeat-light.png`](block-edit-repeat-light.png) | 浅色重复设置 |
|
||||||
|
| [`compact-dark.png`](compact-dark.png) | 紧凑窗口(含动画/建议) |
|
||||||
|
| [`schedule-ghost.png`](schedule-ghost.png) | 详细日程(启用搜索框、幽灵时间、动画) |
|
||||||
|
|
||||||
|
## 4. 同步冲突行为
|
||||||
|
|
||||||
|
这是阶段 3 已有策略,本阶段补充明确的 UI/文档说明:
|
||||||
|
|
||||||
|
- 同一任务/时间块在不同设备同时编辑:按 `updated_at` 做 LWW,较新版本获胜;等时间戳删除优先。
|
||||||
|
- 不同日程被安排在同一时间:属于不同实体,两个都会保留,日视图按重叠列展示;不会自动移动或删除。
|
||||||
|
- 服务端只追加有序变更流,不做语义合并;客户端无弹窗、后台重试,状态只在顶部标签显示。
|
||||||
|
- 重复日程的物化块正常同步;重复规则元数据仅本地保存。
|
||||||
|
- 如果产品需要“同一时间只保留一个”,需要额外实现客户端自动涟漪/冲突策略;当前优先保证不静默丢数据。
|
||||||
|
|
||||||
|
## 5. Windows 安装包验证状态
|
||||||
|
|
||||||
|
- Linux 侧已验证 `cmake --install` 能安装 `Schedule`、README 和两份第三方许可证。
|
||||||
|
- Windows CPack/NSIS 安装包无法在本机执行;需要在 Windows 上按 README 的 MinGW 步骤验证:
|
||||||
|
```powershell
|
||||||
|
.\scripts\package-windows.ps1
|
||||||
|
```
|
||||||
|
- 前置条件:NSIS 的 `makensis.exe` 在 `PATH`;Qt/MinGW 路径已按本机修改到 `CMakePresets.json`。
|
||||||
|
- 若未安装 NSIS,脚本会生成 ZIP 便携包,但不会生成 `.exe` 安装程序。
|
||||||
|
|
||||||
|
## 6. 已知限制
|
||||||
|
|
||||||
|
1. 搜索只覆盖标题、说明、来源引用,不是全文/模糊搜索引擎;最多返回 100 条。
|
||||||
|
2. 重复日程只支持单规则(每天/每周/每月),没有“仅工作日”、跳过节假日、例外日期或“删除整个系列”UI。
|
||||||
|
3. 重复规则元数据不参与同步;其他设备只看到已物化的任务/时间块。
|
||||||
|
4. 重复日期与现有日程冲突时跳过,不自动涟漪;一周/一月内可能因冲突少生成几次。
|
||||||
|
5. Windows 安装包尚未在真实 Windows 上验证;签名、自动更新、安装目录权限仍属于发布工程。
|
||||||
|
6. 动画没有“减少动态效果”偏好;对无障碍要求高的环境需要后续增加开关。
|
||||||
|
7. 多设备同时创建不同日程造成的时间重叠会保留双方;当前没有自动冲突合并。
|
||||||
|
|
||||||
|
## 7. 人工验收建议
|
||||||
|
|
||||||
|
1. 在详细日程搜索“周报”,确认结果、跳转和定位正确;输入 `%` 确认按字面量处理。
|
||||||
|
2. 新建一个每天重复 5 天的日程,确认只生成 5 个块且共享标题;删除其中一个块,确认只删除该次。
|
||||||
|
3. 在已有日程的时段创建重复日程,确认冲突日期被跳过,全部冲突时提示失败。
|
||||||
|
4. 搜索/打开/关闭窗口,观察淡入动画是否流畅;切换日/月/年视图确认淡入。
|
||||||
|
5. 在 Windows 上安装 NSIS,运行 `.\scripts\package-windows.ps1`,安装 `.exe` 后确认快捷方式、Qt 插件与 MinGW 运行库齐全。
|
||||||
@@ -0,0 +1,103 @@
|
|||||||
|
# 阶段 4 验证报告:精力曲线 / 幽灵时间 / 每日复盘 / 主动建议
|
||||||
|
|
||||||
|
> 日期:2026-10-26
|
||||||
|
> 环境:Ubuntu 24.04 / GCC 13.3 / Qt 6.6.3
|
||||||
|
|
||||||
|
## 1. 本次交付
|
||||||
|
|
||||||
|
1. **精力档案**:新增 `EnergyProfile`(7 天 × 24 小时,0 低 / 1 中 / 2 高),默认曲线覆盖工作日与周末;SQLite `energy_profile` 作为本地缓存。
|
||||||
|
2. **精力学习**:从已完成且带 `energy_req` 的日程学习;按小时聚合完成记录,撤销完成后重新计算并回退。精力档案按设备本地保存,不参与同步。
|
||||||
|
3. **排程约束**:`SchedulerEngine::Options` 增加 `energyAt` 回调;高精力任务只选择满足要求的开始时段。AI 排程、涟漪与拆分都使用同一约束;用户显式指定的时间仍优先。
|
||||||
|
4. **AI 上下文**:Prompt 注入当天精力高峰,并明确 `energy_req` 的 0/1/2 语义,让模型在生成建议时优先考虑精力。
|
||||||
|
5. **幽灵时间**:计算 08:00–22:00 内 30 分钟以上的空档;日视图以半透明虚线块覆盖显示,复盘对话框列出当天全部幽灵时间。
|
||||||
|
6. **每日复盘**:新增 `DailyReviewDialog`,展示完成率、专注分钟、待办/超时/错过/放弃、精力高峰与幽灵时间;支持紧凑窗口和详细窗口,快捷键 `Ctrl+R`。
|
||||||
|
7. **主动建议**:今日任务面板顶部展示确定性建议,优先级为超时日程 → 可利用的幽灵时间 → 傍晚复盘提醒。
|
||||||
|
8. **本地模型**:OpenAI 兼容 Provider 已支持 Ollama / LM Studio / vLLM;新增「无 API Key 的本地端点」测试与 README 配置说明。
|
||||||
|
|
||||||
|
## 2. 构建与自动化测试
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cmake --preset linux-gcc
|
||||||
|
cmake --build --preset linux-gcc --clean-first -j$(nproc)
|
||||||
|
ctest --preset linux-gcc
|
||||||
|
|
||||||
|
cd server
|
||||||
|
go test ./...
|
||||||
|
```
|
||||||
|
|
||||||
|
| 项目 | 结果 |
|
||||||
|
|---|---|
|
||||||
|
| 客户端全量构建 | 成功,项目代码 0 警告(`-Werror`) |
|
||||||
|
| `ctest --preset linux-gcc` | **12/12 通过**,总耗时约 14s |
|
||||||
|
| `go test ./...` | 通过(阶段 3 服务端无改动) |
|
||||||
|
|
||||||
|
完整输出见 [`ctest-phase-4.txt`](ctest-phase-4.txt)。
|
||||||
|
|
||||||
|
新增/扩展测试:
|
||||||
|
|
||||||
|
| 用例 | 覆盖 |
|
||||||
|
|---|---|
|
||||||
|
| `test_energy::defaultProfileHasCurve` | 默认 7×24 曲线与非法坐标 |
|
||||||
|
| `test_energy::learnsFromSamples` | 完成样本覆盖默认值、手动设置 |
|
||||||
|
| `test_energy::findsGhostWindows` | 忙碌/忽略已放弃块、空档合并与最短时长 |
|
||||||
|
| `test_energy::buildsDailyReviewAndSuggestions` | 完成率、专注时长、超时、幽灵时间、建议优先级 |
|
||||||
|
| `test_scheduler::usesEnergyProfile` | 高/中精力约束、无匹配时段时失败 |
|
||||||
|
| `test_services::energyProfileLearnsFromHistory` | 完成后学习、持久化、撤销回退、精力摘要 |
|
||||||
|
| `test_openai_provider::streamsLocalWithoutApiKey` | 本地 OpenAI 兼容端点无 API Key |
|
||||||
|
| `test_compactwindow::opensDailyReview` | 紧凑窗口打开复盘对话框并截图 |
|
||||||
|
|
||||||
|
## 3. 界面截图
|
||||||
|
|
||||||
|
| 截图 | 说明 |
|
||||||
|
|---|---|
|
||||||
|
| [`compact-dark.png`](compact-dark.png) / [`compact-light.png`](compact-light.png) | 紧凑窗口:主动建议、复盘入口 |
|
||||||
|
| [`schedule-ghost.png`](schedule-ghost.png) / [`schedule-ghost-light.png`](schedule-ghost-light.png) | 日视图中的幽灵时间覆盖 |
|
||||||
|
| [`daily-review-dark.png`](daily-review-dark.png) / [`daily-review-light.png`](daily-review-light.png) | 每日复盘:统计、精力高峰、幽灵时间 |
|
||||||
|
|
||||||
|
截图由真实 UI + 临时 SQLite 数据驱动;幽灵时间截图滚动到傍晚时段以展示空档覆盖。
|
||||||
|
|
||||||
|
## 4. 行为说明
|
||||||
|
|
||||||
|
### 精力曲线
|
||||||
|
|
||||||
|
- 默认工作日高峰:09:00–12:00、15:00–19:00;周末高峰较弱。
|
||||||
|
- 每完成一个带 `energy_req` 的时间块,该块覆盖的小时会作为样本参与聚合。
|
||||||
|
- 若没有样本,使用默认曲线;撤销完成会移除对应样本并回退。
|
||||||
|
- `energy_req = 0/1/2` 分别要求低/中/高精力;未指定(-1)不受约束。
|
||||||
|
- 没有满足要求的时段时,排程器返回失败;AI 会发出「未能安排」提示,而不是静默塞进低精力时段。
|
||||||
|
|
||||||
|
### 幽灵时间与建议
|
||||||
|
|
||||||
|
- 计算范围为每天 08:00–22:00,最短 30 分钟。
|
||||||
|
- 日视图从当前时刻开始显示今天的剩余空档;过去日期显示全天空档。
|
||||||
|
- 建议顺序:超时日程、幽灵时间、傍晚复盘;最多 3 条,界面展示第一条。
|
||||||
|
- 复盘总是列出当天所有幽灵时间,最多显示 5 条。
|
||||||
|
|
||||||
|
### 本地模型
|
||||||
|
|
||||||
|
| 服务 | 接口地址 | API Key |
|
||||||
|
|---|---|---|
|
||||||
|
| Ollama | `http://127.0.0.1:11434/v1` | 留空 |
|
||||||
|
| LM Studio | `http://127.0.0.1:1234/v1` | 留空 |
|
||||||
|
| vLLM / llama.cpp | 对应 `/v1` 地址 | 按服务要求 |
|
||||||
|
|
||||||
|
Provider 使用 OpenAI Chat Completions + SSE;本地端点无 Key 时不会发送 Authorization。
|
||||||
|
|
||||||
|
## 5. 已知限制
|
||||||
|
|
||||||
|
1. 精力学习只使用带 `energy_req` 的已完成日程;手工创建的日程目前没有 energy_req 编辑入口,因此不会贡献样本。
|
||||||
|
2. 精力档案按设备本地保存,不同设备的精力曲线不会同步或合并。
|
||||||
|
3. 幽灵时间工作时段固定为 08:00–22:00;尚未提供自定义工作时段。
|
||||||
|
4. 主动建议是确定性规则,不做模型推理;不主动弹窗,只在今日任务面板展示。
|
||||||
|
5. 每日复盘是确定性统计,不由 AI 生成叙事;如需 AI 总结,可后续作为可选动作接入。
|
||||||
|
6. 阶段 2 的 50 条真实模型回归未在阶段 4 重新全量执行;Prompt 增加了精力约束说明,模型行为可能略有波动。
|
||||||
|
7. 高精力任务在无匹配时段时会失败;显式指定的 preferred 时间不受精力约束。
|
||||||
|
|
||||||
|
## 6. 人工验收建议
|
||||||
|
|
||||||
|
1. 通过 AI 创建一条 `energy_req=2` 的任务,安排到默认低精力时段,确认排程器把它移到高峰时段。
|
||||||
|
2. 完成该任务,打开复盘,确认精力高峰包含实际完成时段;再撤销完成,确认曲线回退。
|
||||||
|
3. 在日视图中查看 08:00–22:00 的空档,确认幽灵时间虚线块和复盘列表一致。
|
||||||
|
4. 制造一个超时日程,确认今日任务面板出现「处理超时日程」建议;处理后再确认出现幽灵时间或复盘建议。
|
||||||
|
5. 按 `Ctrl+R` 或点击今日任务标题旁按钮,确认复盘统计(完成率、专注分钟、待办、超时、精力高峰、幽灵时间)正确。
|
||||||
|
6. 配置 Ollama 本地端点并留空 API Key,确认对话与排程可正常使用。
|
||||||
|
Before Width: | Height: | Size: 82 KiB After Width: | Height: | Size: 95 KiB |
|
After Width: | Height: | Size: 89 KiB |
|
After Width: | Height: | Size: 90 KiB |
|
Before Width: | Height: | Size: 108 KiB After Width: | Height: | Size: 119 KiB |
|
Before Width: | Height: | Size: 128 KiB After Width: | Height: | Size: 139 KiB |
|
After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 13 KiB |
@@ -0,0 +1,47 @@
|
|||||||
|
param(
|
||||||
|
[switch]$SkipTests,
|
||||||
|
[int]$Jobs = 8
|
||||||
|
)
|
||||||
|
|
||||||
|
$ErrorActionPreference = "Stop"
|
||||||
|
$root = Split-Path -Parent $PSScriptRoot
|
||||||
|
Push-Location $root
|
||||||
|
try {
|
||||||
|
Write-Host "Configuring release build..."
|
||||||
|
cmake --preset windows-mingw-release
|
||||||
|
|
||||||
|
Write-Host "Building..."
|
||||||
|
cmake --build --preset windows-mingw-release -j $Jobs
|
||||||
|
|
||||||
|
if (-not $SkipTests) {
|
||||||
|
Write-Host "Running tests..."
|
||||||
|
ctest --preset windows-mingw-release --output-on-failure
|
||||||
|
}
|
||||||
|
|
||||||
|
$buildDir = Join-Path $root "build/windows-mingw-release"
|
||||||
|
Push-Location $buildDir
|
||||||
|
try {
|
||||||
|
$nsis = Get-Command makensis -ErrorAction SilentlyContinue
|
||||||
|
if ($null -ne $nsis) {
|
||||||
|
Write-Host "Building NSIS installer..."
|
||||||
|
cpack -G NSIS
|
||||||
|
Get-ChildItem -Filter "Schedule-*.exe" | ForEach-Object {
|
||||||
|
Write-Host "Installer: $($_.FullName)"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Write-Warning "makensis not found; falling back to a portable ZIP package."
|
||||||
|
Write-Warning "Install NSIS and reopen PowerShell to build the .exe installer."
|
||||||
|
cpack -G ZIP
|
||||||
|
Get-ChildItem -Filter "Schedule-*.zip" | ForEach-Object {
|
||||||
|
Write-Host "Portable package: $($_.FullName)"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
Pop-Location
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
Pop-Location
|
||||||
|
}
|
||||||