Repository navigation
feat(ui): view contestant source code from judging results (#225) #338
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
zhuyanyu1234
wants to merge
11
commits into
Project-LemonLime:master
Choose a base branch
from
zhuyanyu1234:feat/225-view-source
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
8d3d3b6
feat(ui): view contestant source code from judging results (#225)
2dc11a1
fix(ui): build SourceViewerDialog against Qt 6.11
69b358a
feat(ui): polish source viewer colors, line numbers and highlight
b309db0
feat(ui): use Microsoft YaHei for the source viewer
d4b4c83
refactor(base): share the per-platform UI font in Lemon::uiFont()
2bd3980
chore: ignore local tooling directories .mimosa and .zcode
0f74e3c
feat(ui): use a monospace font for the source viewer
1a9293d
chore(gitignore): remove personal settings from .gitignore
zhuyanyu1234 73266a3
refactor(ui): use system font fallback instead of hardcoded families
10b1e8e
refactor(ui): open contestant sources in the system editor
c4ae7c1
fix(ui): resolve source paths from task config and drop unused font c…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| /* | ||
| * SPDX-FileCopyrightText: 2026 Project LemonLime | ||
| * | ||
| * SPDX-License-Identifier: GPL-3.0-or-later | ||
| * | ||
| */ | ||
|
|
||
| #include "sourceviewer.h" | ||
| // | ||
| #include "base/settings.h" | ||
| #include "core/contest.h" | ||
| #include "core/contestant.h" | ||
| #include "core/task.h" | ||
| // | ||
| #include <QDesktopServices> | ||
| #include <QDir> | ||
| #include <QFileInfo> | ||
| #include <QMessageBox> | ||
| #include <QUrl> | ||
|
|
||
| namespace { | ||
|
|
||
| // Mirror TaskJudger::traditionalTaskPrepare()'s layout: the contestant's | ||
| // source directory gains the task's source-file-name sub-folder only when | ||
| // SubFolderCheck is enabled. | ||
| QString contestantSourceDir(Contest *contest, Contestant *contestant, int taskIndex) { | ||
| const Task *task = contest->getTask(taskIndex); | ||
| QString dir = Settings::sourcePath() + contestant->getContestantName(); | ||
|
|
||
| if (task->getSubFolderCheck()) | ||
| dir += QDir::separator() + task->getSourceFileName(); | ||
|
|
||
| return dir; | ||
| } | ||
|
|
||
| } // namespace | ||
|
|
||
| void SourceViewer::viewSource(QWidget *parent, Contest *contest, Contestant *contestant, int taskIndex) { | ||
| const Task *task = contest->getTask(taskIndex); | ||
|
|
||
| if (task == nullptr || task->getTaskType() == Task::AnswersOnly) { | ||
| QMessageBox::information(parent, tr("View Source"), tr("Cannot find the source file of this task.")); | ||
| return; | ||
| } | ||
|
|
||
| const QString dir = contestantSourceDir(contest, contestant, taskIndex); | ||
|
|
||
| // Communication tasks: getSourceFile() holds the compiled names (e.g. | ||
| // send.cpp), while getSourceFilesPath() holds the actual submitted files. | ||
| // Ordinary tasks: getSourceFile() is one complete file name, which must not | ||
| // be split on spaces. | ||
| QStringList fileNames; | ||
|
|
||
| if (task->getTaskType() == Task::Communication || task->getTaskType() == Task::CommunicationExec) | ||
| fileNames = task->getSourceFilesPath(); | ||
| else | ||
| fileNames = {contestant->getSourceFile(taskIndex)}; | ||
|
|
||
| QStringList filePaths; | ||
|
|
||
| for (const QString &fileName : fileNames) { | ||
| if (! fileName.isEmpty()) | ||
| filePaths.append(dir + QDir::separator() + fileName); | ||
| } | ||
|
|
||
| if (filePaths.isEmpty()) { | ||
| QMessageBox::information(parent, tr("View Source"), tr("Cannot find the source file of this task.")); | ||
| return; | ||
| } | ||
|
|
||
| for (const QString &path : filePaths) { | ||
| if (! QFileInfo::exists(path)) { | ||
| QMessageBox::information(parent, tr("View Source"), | ||
| tr("Source file %1 does not exist.").arg(QDir::toNativeSeparators(path))); | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| for (const QString &path : filePaths) | ||
| QDesktopServices::openUrl(QUrl::fromLocalFile(QDir(path).absolutePath())); | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| /* | ||
| * SPDX-FileCopyrightText: 2026 Project LemonLime | ||
| * | ||
| * SPDX-License-Identifier: GPL-3.0-or-later | ||
| * | ||
| */ | ||
|
|
||
| #pragma once | ||
| // | ||
|
|
||
| #include <QObject> | ||
|
|
||
| class Contest; | ||
| class Contestant; | ||
| class QWidget; | ||
|
|
||
| // 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 { | ||
| Q_OBJECT | ||
|
|
||
| public: | ||
| /** Open the source file(s) of the contestant's taskIndex-th task in the system editor. */ | ||
| static void viewSource(QWidget *parent, Contest *contest, Contestant *contestant, int taskIndex); | ||
| }; | ||
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
过度封装