Repository navigation
feat(ui): view contestant source code from judging results (#225) - #338
zhuyanyu1234 wants to merge 11 commits into
Conversation
| font.setFamilies({"Microsoft YaHei"}); | ||
| font.setHintingPreference(QFont::PreferNoHinting); | ||
| #elif defined(Q_OS_LINUX) | ||
| font.setFamilies({"Noto Sans CJK SC", "WenQuanYi Micro Hei"}); |
There was a problem hiding this comment.
Don't assume user-installed fonts, leave it empty or use QFont::System to use user-chose fonts via system font fallback mechanism like Fontconfig.
| #ifdef Q_OS_WIN32 | ||
| font.setFamilies({"Consolas", "Microsoft YaHei"}); | ||
| #elif defined(Q_OS_LINUX) | ||
| font.setFamilies({"DejaVu Sans Mono", "Noto Sans Mono CJK SC"}); |
There was a problem hiding this comment.
Don't assume user-installed fonts, use QFont::Monospace to use user-chose monospace fonts via system font fallback mechanism.
|
|
||
| } // namespace | ||
|
|
||
| class SourceHighlighter final : public QSyntaxHighlighter { |
There was a problem hiding this comment.
Don't do parser by yourself, use a library like KSyntaxHighlighting.
|
我觉得应该直接打开吧,用用户的文本编辑器打开就好 |
|
直接打开的话...会不会用户只有记事本?对于这种情况怎么处理呢?(或许可以加一个外部打开的选项) |
|
项目组不愿意维护代码高亮,这个工作量肯定是要外包出去的。我觉得只有 notepad 的话应该让机房管理员装一个什么 dev cpp 之类的。 |
|
改了,现在在系统查看器里看 |
…emonLime#225) Add a read-only SourceViewerDialog with lightweight C-like/Pascal syntax highlighting and UTF-8 fallback to local 8-bit encoding. Reach it from the ResultViewer context menu (View Source, per task) and from clickable source file names in DetailDialog. Submitted source paths are resolved the same way TaskJudger does, including subfolder and communication multi-file tasks.
Include QTabBar/QString explicitly and replace QString::fromLocal8bit (removed in Qt 6.11) with a QStringDecoder using the System codec for the non-UTF-8 fallback.
Fix the inverted light/dark theme detection that rendered light-theme highlight colors on the dark editor background. Use self-contained VS Code-inspired palettes with an explicit editor stylesheet so keywords, strings, comments and identifiers stay readable on both themes, and add a line-number gutter, a current-line highlight, a larger font and 4-space tab stops.
CJK comments in contestant code rendered via an ugly bitmap fallback with the monospace system font; Microsoft YaHei keeps them crisp, with CJK-aware fallback families for other platforms.
Extract the font setup previously inlined in main.cpp's #ifdef blocks into Lemon::uiFont(), activate the Linux (Noto Sans CJK SC) and macOS (PingFang SC) branches that had been left commented out, and let the source code viewer use the same font so CJK comments stay crisp on every platform. Missing families fall back to the platform default.
6fb8066 to
10b1e8e
Compare
|
等一下,那之前加的字体回退要删吗? |
|
|
||
| // Opens a contestant's submitted sources with the user's own editor via the | ||
| // platform file association, instead of embedding a syntax-highlighting viewer. | ||
| class SourceViewer final : public QObject { |
| return {}; | ||
|
|
||
| // Communication tasks store a space-separated list of submitted files | ||
| const QStringList files = contestant->getSourceFile(taskIndex).split(' ', Qt::SkipEmptyParts); |
There was a problem hiding this comment.
通信题的 getSourceFile() 保存编译时使用的名称。选手提交 sender.cc、题目配置将其复制为 send.cpp 时,此处会在选手目录查找 send.cpp,可能报缺失,也可能打开同名的其他文件。通信题应从 Task::getSourceFilesPath() 取得提交文件列表。普通题的 getSourceFile() 则保存单个完整文件名,按空格拆分会使 sum pairs.cpp 被误查为 sum。
| // glyphs automatically. | ||
| inline QFont uiFont() { | ||
| QFont font; | ||
| font.setStyleHint(QFont::System); |
Closes #225
功能
评测结束后可直接查看选手源代码,无需切换到资源管理器查找文件(适用于教师讲评场景)。
anchorClicked伪 URL 机制SourceViewerDialog:TaskJudger完全一致(含子文件夹模式)实现
src/sourceviewer.{h,cpp}(由aux_source_directory自动收录)src/resultviewer.{h,cpp}:右键子菜单 +viewSource(int)槽src/detaildialog.cpp:三处 Source file 文本改为链接,并接入anchorClicked处理src/base/LemonBase.hpp:Lemon::uiFont():跨平台 UI 字体(Windows 微软雅黑 / Linux Noto Sans CJK SC / macOS PingFang SC);main.cpp原有的#ifdef字体块收敛为一行,并激活原本注释掉的 Linux/macOS 分支(缺字体自动回退默认)Lemon::codeFont():等宽代码字体 —— Windows Consolas + 微软雅黑、Linux DejaVu Sans Mono + Noto Sans Mono CJK SC、macOS Menlo + PingFang SC,并设置QFont::Monospace样式提示;sourceviewer.cpp编辑器改用此字体,全局 UI 字体不受影响QString::fromLocal8bit,本地编码回退改用QStringDecoder(System)测试
附带
chore(test):unix/test/scripts/redirect.py改用 pathlib 并补充临时文件清理(行为等价,如不需要可去掉该提交)