[0928] 用 QML 重构调色板 - #4408
Open
PinkMagicFly wants to merge 9 commits into
Open
Conversation
PinkMagicFly
force-pushed
the
pigmagicfly/0928/qml-color-picker
branch
from
August 27, 2026 08:10
4df5e0d to
be18afa
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
任务
0928:用 QML 重构调色板,功能不能缺失,样式参考现有 QML 弹窗体系并更具现代感。
What
将 Qt 原生
QColorDialog实现的调色板替换为项目统一 QML 弹窗体系下的ColorPicker.qml,保持widget-color-picker/interactive-color/interactive-background调用链不变。Why
QColorDialog::getColor,风格与 Mogan 正在迁移的 QML 模态对话框体系不一致;DialogShell/DialogButtons/Theme等原子组件,统一暗色/亮色、DPI 缩放、圆角与按钮交互。How
src/Plugins/Qt/qml/ColorPicker.qml:HSV 取色面板 + 色相条、HSV/RGB/HEX 数值输入、基础色块、实时预览、OK/Cancel;src/Plugins/Qt/ColorPickerBridge.*:屏幕取色(抓屏快照 + 全屏十字光标 overlay 点选,Esc 取消;macOS 需屏幕录制权限,未授权返回空串,与 Qt 自带行为一致);QTMQmlDialog.cpp/hpp新增阻塞式 glue 入口cpp_color_picker_dialog(title, proposals, pickPattern),走run_qml_dialogexec 引擎,OK 返回(tuple "#rrggbb")、Cancel 返回空 tuple;qt_color_picker_widget.cpp/hpp:showDialog()改调cpp_color_picker_dialog(),解包sel[0]回调 scheme;color picker custom colors跨会话持久化,Cancel 不保存;qt_translate注入,zh_CN 字典按字母序新增 6 条;ai-docs/qml/qml-dialog.html新增 ColorPicker 设计稿面板;qml_load_test.cpp新增test_color_picker_loads。功能对照(旧 QColorDialog → 新 QML)
验证
xmake b stem构建通过 ✅xmake b qml_load_test && xmake r qml_load_test:15 passed, 0 failed ✅gf fmt --check:OK ✅MOGAN_TEST_COLOR_PICKER=<hex>|cancel,返回形状与真实路径一致测试入口
MOGAN_TEST_COLOR_PICKER=ff0000/cancel可绕过弹窗做契约测试追加修复(屏幕取色)
QRhi::endOffscreenFrame):原实现在 QML 事件处理器内对取色 overlay 跑嵌套exec(),嵌套事件循环期间宿主弹窗的 QQuickWidget 被迫重绘导致 QRhi 崩溃。改为异步:overlay 用open()非嵌套模态,结果经screenColorPicked(QString)信号回流(QML 侧Connections接收);取色期间隐藏宿主弹窗,结束后恢复。grabWindow返回空图/全黑快照),全屏 overlay 显示全黑。新增canPickScreen只读属性,Wayland 下隐藏「Pick screen color」按钮;不支持平台调用直接回空串兜底。tests/Plugins/Qt/color_picker_bridge_test.cpp(5 passed:平台门控、点击回传合法#rrggbb、Esc 取消回空串、宿主隐藏/恢复);qml_load_test15 passed;xmake b stem通过。