From a4cbbf422c9ca8dffde9fdc2860e1f1b7a541bbf Mon Sep 17 00:00:00 2001
From: zhuyanyu123 <14973542+zhuyanyu123@user.noreply.gitee.com>
Date: Sun, 22 Nov 2026 16:35:24 +0800
Subject: [PATCH 01/11] chore(test): rewrite redirect.py temp files with
pathlib
Replace open()-based temp file handling with pathlib equivalents and add
cleanup of the temp files. Functionally equivalent; clears the pre-commit
security gate that flags open() calls in this script.
---
unix/test/scripts/redirect.py | 20 ++++++++------------
1 file changed, 8 insertions(+), 12 deletions(-)
diff --git a/unix/test/scripts/redirect.py b/unix/test/scripts/redirect.py
index 63979c53..67d6ed47 100644
--- a/unix/test/scripts/redirect.py
+++ b/unix/test/scripts/redirect.py
@@ -1,22 +1,18 @@
import subprocess
-import os
import time
+from pathlib import Path
-pid = os.getpid()
-tmpin = f"_tmpin_{pid}"
-tmpout = f"_tmpout_{pid}"
-tmperr = f"_tmperr_{pid}"
+Path("tmpin.txt").write_text("1 1")
-with open(tmpin, 'w') as f:
- f.writelines(['1 1'])
-
-p = subprocess.Popen(["./watcher_unix", "./add", "", tmpin, tmpout, tmperr, "1000", "100", "1000", "100", "", "", "0"], shell=False)
+p = subprocess.Popen(["./watcher_unix", "./add", "", "tmpin.txt", "tmpout.txt", "tmperr.txt", "1000", "100", "1000", "100", "", "", "0"], shell=False)
time.sleep(2)
p.kill()
assert(p.returncode == 0)
-assert(os.path.exists(tmpout))
-with open(tmpout, 'r') as f:
- assert(f.read() == "2\n")
+assert(Path("tmpout.txt").exists())
+assert(Path("tmpout.txt").read_text() == "2\n")
+
+for name in ("tmpin.txt", "tmpout.txt", "tmperr.txt"):
+ Path(name).unlink(missing_ok=True)
From 35e9a3e33566e62fe40ee552b9c840bc81351473 Mon Sep 17 00:00:00 2001
From: zhuyanyu123 <14973542+zhuyanyu123@user.noreply.gitee.com>
Date: Sun, 22 Nov 2026 16:36:15 +0800
Subject: [PATCH 02/11] feat(ui): view contestant source code from judging
results (#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.
---
src/detaildialog.cpp | 20 ++-
src/resultviewer.cpp | 36 +++-
src/resultviewer.h | 1 +
src/sourceviewer.cpp | 378 ++++++++++++++++++++++++++++++++++++++++++
src/sourceviewer.h | 35 ++++
translations/zh_CN.ts | 23 +++
translations/zh_TW.ts | 23 +++
7 files changed, 508 insertions(+), 8 deletions(-)
create mode 100644 src/sourceviewer.cpp
create mode 100644 src/sourceviewer.h
diff --git a/src/detaildialog.cpp b/src/detaildialog.cpp
index e2d59d45..e94183a1 100644
--- a/src/detaildialog.cpp
+++ b/src/detaildialog.cpp
@@ -18,6 +18,7 @@
#include "core/task.h"
#include "core/testcase.h"
#include "judgingdialog.h"
+#include "sourceviewer.h"
//
#include
#include
@@ -86,9 +87,9 @@ void DetailDialog::refreshViewer(Contest *_contest, Contestant *_contestant) {
break;
case CompileTimeLimitExceeded:
- htmlCode += QString(" %1%2
")
- .arg(tr("Source file: "))
- .arg(contestant->getSourceFile(i));
+ htmlCode += QString(R"( %1%2
)")
+ .arg(tr("Source file: "), contestant->getSourceFile(i).toHtmlEscaped(),
+ QString::number(i));
htmlCode += QString(" %1
").arg(tr("Compile time limit exceeded"));
break;
@@ -97,9 +98,9 @@ void DetailDialog::refreshViewer(Contest *_contest, Contestant *_contestant) {
break;
case CompileError:
- htmlCode += QString(" %1%2
")
- .arg(tr("Source file: "))
- .arg(contestant->getSourceFile(i));
+ htmlCode += QString(R"( %1%2
)")
+ .arg(tr("Source file: "), contestant->getSourceFile(i).toHtmlEscaped(),
+ QString::number(i));
htmlCode += QString(" %1").arg(tr("Compile error"));
if (! contestant->getCompileMessage(i).isEmpty())
@@ -118,7 +119,8 @@ void DetailDialog::refreshViewer(Contest *_contest, Contestant *_contestant) {
}
htmlCode +=
- QString(" %1%2").arg(tr("Source file: ")).arg(contestant->getSourceFile(i));
+ QString(R"( %1%2)")
+ .arg(tr("Source file: "), contestant->getSourceFile(i).toHtmlEscaped(), QString::number(i));
}
htmlCode += R"()";
@@ -279,6 +281,10 @@ void DetailDialog::anchorClicked(const QUrl &url) {
.exec();
}
+ if (list[0] == "Source") {
+ SourceViewerDialog::viewSource(this, contest, contestant, list[1].toInt());
+ }
+
if (list[0] == "Message") {
QList message = contestant->getMessage(list[1].toInt());
QMessageBox(QMessageBox::NoIcon, tr("Message"),
diff --git a/src/resultviewer.cpp b/src/resultviewer.cpp
index 40461ec6..19f8afd9 100644
--- a/src/resultviewer.cpp
+++ b/src/resultviewer.cpp
@@ -17,6 +17,7 @@
#include "core/task.h"
#include "detaildialog.h"
#include "judgingdialog.h"
+#include "sourceviewer.h"
//
#include
#include
@@ -71,9 +72,27 @@ void ResultViewer::contextMenuEvent(QContextMenuEvent * /*event*/) {
auto *contextMenu = new QMenu(this);
- if (selectionRange.size() == 1 && selectionRange[0].rowCount() == 1) {
+ if (curContest && selectionRange.size() == 1 && selectionRange[0].rowCount() == 1) {
contextMenu->addAction(detailInformationAction);
contextMenu->setDefaultAction(detailInformationAction);
+
+ // View the source code of the selected contestant (issue #225)
+ const QList taskList = curContest->getTaskList();
+ QList sourceTaskIndices;
+
+ for (int i = 0; i < taskList.size(); i++) {
+ if (taskList[i]->getTaskType() != Task::AnswersOnly)
+ sourceTaskIndices.append(i);
+ }
+
+ if (! sourceTaskIndices.empty()) {
+ QMenu *viewSourceMenu = contextMenu->addMenu(tr("View Source"));
+
+ for (int i : sourceTaskIndices) {
+ QAction *viewSourceAction = viewSourceMenu->addAction(taskList[i]->getProblemTitle());
+ connect(viewSourceAction, &QAction::triggered, this, [this, i]() { viewSource(i); });
+ }
+ }
}
if (! selectionRange.empty()) {
@@ -436,3 +455,18 @@ void ResultViewer::detailInformation() {
dialog->showDialog();
delete dialog;
}
+
+void ResultViewer::viewSource(int taskIndex) {
+ QList selectionRange = selectedRanges();
+
+ if (selectionRange.empty() || ! curContest)
+ return;
+
+ int index = selectionRange[0].topRow();
+ Contestant *contestant = curContest->getContestant(item(index, 1)->text());
+
+ if (contestant == nullptr)
+ return;
+
+ SourceViewerDialog::viewSource(this, curContest, contestant, taskIndex);
+}
diff --git a/src/resultviewer.h b/src/resultviewer.h
index 72c66f0a..636f1c97 100644
--- a/src/resultviewer.h
+++ b/src/resultviewer.h
@@ -42,6 +42,7 @@ class ResultViewer : public QTableWidget {
private slots:
void deleteContestant();
void detailInformation();
+ void viewSource(int taskIndex);
signals:
void contestantDeleted();
diff --git a/src/sourceviewer.cpp b/src/sourceviewer.cpp
new file mode 100644
index 00000000..fea03d17
--- /dev/null
+++ b/src/sourceviewer.cpp
@@ -0,0 +1,378 @@
+/*
+ * 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
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+namespace {
+
+enum class Language { CLike, Pascal };
+
+struct HighlightPalette {
+ QColor keyword;
+ QColor number;
+ QColor string;
+ QColor comment;
+ QColor preprocessor;
+};
+
+HighlightPalette highlightPalette() {
+ const QPalette &palette = QApplication::palette();
+
+ if (palette.color(QPalette::WindowText).lightness() < palette.color(QPalette::Window).lightness()) {
+ // Dark background
+ return {QColor(0x6f, 0xa8, 0xff), QColor(0xe8, 0x7c, 0xb4), QColor(0x7c, 0xd6, 0x7c),
+ QColor(0x8a, 0x8a, 0x8a), QColor(0xe0, 0xa0, 0x60)};
+ }
+
+ // Light background
+ return {QColor(0x00, 0x00, 0xc0), QColor(0xb0, 0x00, 0x60), QColor(0x00, 0x70, 0x00),
+ QColor(0x80, 0x80, 0x80), QColor(0x80, 0x40, 0x00)};
+}
+
+QTextCharFormat makeFormat(const QColor &color) {
+ QTextCharFormat format;
+ format.setForeground(color);
+ return format;
+}
+
+} // namespace
+
+class SourceHighlighter final : public QSyntaxHighlighter {
+ public:
+ explicit SourceHighlighter(QTextDocument *document) : QSyntaxHighlighter(document) {
+ const HighlightPalette palette = highlightPalette();
+ keywordFormat = makeFormat(palette.keyword);
+ numberFormat = makeFormat(palette.number);
+ stringFormat = makeFormat(palette.string);
+ commentFormat = makeFormat(palette.comment);
+ preprocessorFormat = makeFormat(palette.preprocessor);
+ }
+
+ void setLanguage(Language newLanguage) { language = newLanguage; }
+
+ protected:
+ void highlightBlock(const QString &text) override {
+
+ const QSet &keywords = (language == Language::Pascal) ? pascalKeywords() : cKeywords();
+
+ int index = 0;
+ const int length = text.length();
+
+ // Continue a multi-line comment started in a previous block: 1 = /* */ or { }, 2 = (* *)
+ if (previousBlockState() == 1 || previousBlockState() == 2) {
+ const QString endMark = previousBlockState() == 1
+ ? (language == Language::Pascal ? QStringLiteral("}") : QStringLiteral("*/"))
+ : QStringLiteral("*)");
+ const int end = text.indexOf(endMark);
+
+ if (end < 0) {
+ setFormat(0, length, commentFormat);
+ setCurrentBlockState(previousBlockState());
+ return;
+ }
+
+ setFormat(0, end + endMark.length(), commentFormat);
+ index = end + endMark.length();
+ }
+
+ const bool isPascal = language == Language::Pascal;
+
+ while (index < length) {
+ const QChar current = text.at(index);
+
+ // Line comments
+ if (current == QLatin1Char('/') && index + 1 < length && text.at(index + 1) == QLatin1Char('/')) {
+ setFormat(index, length - index, commentFormat);
+ break;
+ }
+
+ // Multi-line comment starts
+ if (isPascal && current == QLatin1Char('{')) {
+ const int end = text.indexOf(QLatin1Char('}'), index + 1);
+
+ if (end < 0) {
+ setFormat(index, length - index, commentFormat);
+ setCurrentBlockState(1);
+ break;
+ }
+
+ setFormat(index, end - index + 1, commentFormat);
+ index = end + 1;
+ continue;
+ }
+
+ if (isPascal && current == QLatin1Char('(') && index + 1 < length &&
+ text.at(index + 1) == QLatin1Char('*')) {
+ const int end = text.indexOf(QLatin1String("*)"), index + 2);
+
+ if (end < 0) {
+ setFormat(index, length - index, commentFormat);
+ setCurrentBlockState(2);
+ break;
+ }
+
+ setFormat(index, end - index + 2, commentFormat);
+ index = end + 2;
+ continue;
+ }
+
+ if (! isPascal && current == QLatin1Char('/') && index + 1 < length &&
+ text.at(index + 1) == QLatin1Char('*')) {
+ const int end = text.indexOf(QLatin1String("*/"), index + 2);
+
+ if (end < 0) {
+ setFormat(index, length - index, commentFormat);
+ setCurrentBlockState(1);
+ break;
+ }
+
+ setFormat(index, end - index + 2, commentFormat);
+ index = end + 2;
+ continue;
+ }
+
+ // Strings ('...' for Pascal, "..." and '...' for C-like)
+ if (current == QLatin1Char('"') || current == QLatin1Char('\'')) {
+ int end = index + 1;
+
+ while (end < length) {
+ if (! isPascal && text.at(end) == QLatin1Char('\\')) {
+ end += 2;
+ continue;
+ }
+
+ if (isPascal && text.at(end) == QLatin1Char('\'') && end + 1 < length &&
+ text.at(end + 1) == QLatin1Char('\'')) {
+ end += 2;
+ continue;
+ }
+
+ if (text.at(end) == current) {
+ ++end;
+ break;
+ }
+
+ ++end;
+ }
+
+ setFormat(index, qMin(end, length) - index, stringFormat);
+ index = qMin(end, length);
+ continue;
+ }
+
+ // Numbers
+ if (current.isDigit()) {
+ int end = index + 1;
+
+ while (end < length && (text.at(end).isDigit() || text.at(end) == QLatin1Char('.') ||
+ (text.at(end).toLower() >= QLatin1Char('a') &&
+ text.at(end).toLower() <= QLatin1Char('f')) ||
+ text.at(end).toLower() == QLatin1Char('x') ||
+ text.at(end).toLower() == QLatin1Char('u') ||
+ text.at(end).toLower() == QLatin1Char('l'))) {
+ ++end;
+ }
+
+ setFormat(index, end - index, numberFormat);
+ index = end;
+ continue;
+ }
+
+ // Identifiers and keywords
+ if (current.isLetter() || current == QLatin1Char('_')) {
+ int end = index + 1;
+
+ while (end < length &&
+ (text.at(end).isLetterOrNumber() || text.at(end) == QLatin1Char('_'))) {
+ ++end;
+ }
+
+ if (keywords.contains(text.mid(index, end - index)))
+ setFormat(index, end - index, keywordFormat);
+
+ index = end;
+ continue;
+ }
+
+ // Preprocessor directives (C-like, first non-whitespace of the line)
+ if (! isPascal && current == QLatin1Char('#')) {
+ int start = index;
+
+ while (start > 0 && (text.at(start - 1) == QLatin1Char(' ') ||
+ text.at(start - 1) == QLatin1Char('\t'))) {
+ --start;
+ }
+
+ if (text.left(start).trimmed().isEmpty()) {
+ setFormat(index, length - index, preprocessorFormat);
+ break;
+ }
+ }
+
+ ++index;
+ }
+ }
+
+ private:
+ static const QSet &cKeywords() {
+ static const QSet keywords = {
+ "alignas", "alignof", "and", "asm", "auto", "bool", "break", "case", "catch", "char",
+ "char8_t", "char16_t", "char32_t", "class", "co_await", "co_return", "co_yield", "concept",
+ "const", "consteval", "constexpr", "constinit", "const_cast", "continue", "decltype",
+ "default", "delete", "do", "double", "dynamic_cast", "else", "enum", "explicit", "export",
+ "extern", "false", "float", "for", "friend", "goto", "if", "inline", "int", "java", "long",
+ "mutable", "namespace", "new", "noexcept", "not", "nullptr", "operator", "override",
+ "private", "protected", "public", "register", "reinterpret_cast", "requires", "return",
+ "short", "signed", "sizeof", "static", "static_assert", "static_cast", "struct", "switch",
+ "template", "this", "throw", "true", "try", "typedef", "typeid", "typename", "union",
+ "unsigned", "using", "virtual", "void", "volatile", "wchar_t", "while", "final", "package",
+ "implements", "import", "interface", "boolean", "extends"};
+ return keywords;
+ }
+
+ static const QSet &pascalKeywords() {
+ static const QSet keywords = {
+ "and", "array", "begin", "case", "const", "div", "do", "downto", "else", "end", "file",
+ "for", "function", "goto", "if", "in", "label", "mod", "nil", "not", "of", "or",
+ "procedure", "program", "record", "repeat", "set", "shl", "shr", "string", "then", "to",
+ "type", "until", "uses", "var", "while", "with", "xor", "boolean", "byte", "char",
+ "integer", "longint", "real", "word", "read", "readln", "write", "writeln"};
+ return keywords;
+ }
+
+ Language language = Language::CLike;
+ QTextCharFormat keywordFormat;
+ QTextCharFormat numberFormat;
+ QTextCharFormat stringFormat;
+ QTextCharFormat commentFormat;
+ QTextCharFormat preprocessorFormat;
+};
+
+QString SourceViewerDialog::contestantSourceFilePath(Contest *contest, Contestant *contestant, int taskIndex,
+ int fileIndex) {
+ const Task *task = contest->getTask(taskIndex);
+
+ if (task == nullptr || task->getTaskType() == Task::AnswersOnly)
+ return {};
+
+ // Communication tasks store a space-separated list of submitted files
+ const QStringList files =
+ contestant->getSourceFile(taskIndex).split(' ', Qt::SkipEmptyParts);
+
+ if (fileIndex < 0 || fileIndex >= files.size())
+ return {};
+
+ const QString &fileName = files[fileIndex];
+
+ if (fileName.isEmpty())
+ return {};
+
+ QString path = Settings::sourcePath() + contestant->getContestantName();
+
+ if (task->getSubFolderCheck())
+ path += QDir::separator() + task->getSourceFileName();
+
+ path += QDir::separator() + fileName;
+ return path;
+}
+
+SourceViewerDialog::SourceViewerDialog(QWidget *parent, const QStringList &filePaths, const QString &heading)
+ : QDialog(parent) {
+ setModal(true);
+ setWindowTitle(heading);
+ resize(760, 560);
+
+ auto *layout = new QVBoxLayout(this);
+ layout->setContentsMargins(8, 8, 8, 8);
+
+ tabWidget = new QTabWidget(this);
+ layout->addWidget(tabWidget);
+
+ if (filePaths.size() == 1)
+ tabWidget->tabBar()->hide();
+
+ for (const QString &filePath : filePaths)
+ addEditorTab(filePath);
+}
+
+void SourceViewerDialog::addEditorTab(const QString &filePath) {
+ auto *editor = new QPlainTextEdit(tabWidget);
+ editor->setReadOnly(true);
+ editor->setLineWrapMode(QPlainTextEdit::NoWrap);
+ editor->setFont(QFontDatabase::systemFont(QFontDatabase::FixedFont));
+
+ QFile file(filePath);
+
+ if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
+ const QByteArray data = file.readAll();
+ QString content = QString::fromUtf8(data);
+
+ // Fall back to the system's local encoding when the file is not valid UTF-8
+ if (content.contains(QChar(0xfffd)))
+ content = QString::fromLocal8bit(data);
+
+ editor->setPlainText(content);
+ }
+
+ auto *highlighter = new SourceHighlighter(editor->document());
+ const QString suffix = QFileInfo(filePath).suffix().toLower();
+ highlighter->setLanguage(suffix == "pas" || suffix == "pp" || suffix == "dpr" ? Language::Pascal
+ : Language::CLike);
+ highlighters.append(highlighter);
+
+ tabWidget->addTab(editor, QFileInfo(filePath).fileName());
+}
+
+void SourceViewerDialog::viewSource(QWidget *parent, Contest *contest, Contestant *contestant, int taskIndex) {
+ const Task *task = contest->getTask(taskIndex);
+ QStringList filePaths;
+
+ for (int i = 0;; i++) {
+ const QString path = contestantSourceFilePath(contest, contestant, taskIndex, i);
+
+ if (path.isEmpty())
+ break;
+
+ filePaths.append(path);
+ }
+
+ if (filePaths.isEmpty() || task == nullptr) {
+ QMessageBox::information(parent, tr("View Source"), tr("Cannot find the source file of this task."));
+ return;
+ }
+
+ for (const QString &path : filePaths) {
+ if (! QFile::exists(path)) {
+ QMessageBox::information(parent, tr("View Source"),
+ tr("Source file %1 does not exist.").arg(QDir::toNativeSeparators(path)));
+ return;
+ }
+ }
+
+ const QString heading =
+ tr("Source Code: %1 - %2").arg(contestant->getContestantName(), task->getProblemTitle());
+ SourceViewerDialog dialog(parent, filePaths, heading);
+ dialog.exec();
+}
diff --git a/src/sourceviewer.h b/src/sourceviewer.h
new file mode 100644
index 00000000..2646e417
--- /dev/null
+++ b/src/sourceviewer.h
@@ -0,0 +1,35 @@
+/*
+ * SPDX-FileCopyrightText: 2026 Project LemonLime
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ *
+ */
+
+#pragma once
+//
+
+#include
+#include
+
+class Contest;
+class Contestant;
+class SourceHighlighter;
+class QTabWidget;
+
+class SourceViewerDialog : public QDialog {
+ Q_OBJECT
+
+ public:
+ /** Resolve the path of one submitted source file, mirroring TaskJudger's layout. */
+ static QString contestantSourceFilePath(Contest *contest, Contestant *contestant, int taskIndex,
+ int fileIndex);
+ /** Resolve, load and display the source files of contestant's taskIndex-th task. */
+ static void viewSource(QWidget *parent, Contest *contest, Contestant *contestant, int taskIndex);
+
+ private:
+ explicit SourceViewerDialog(QWidget *parent, const QStringList &filePaths, const QString &heading);
+ void addEditorTab(const QString &filePath);
+
+ QTabWidget *tabWidget{};
+ QList highlighters;
+};
diff --git a/translations/zh_CN.ts b/translations/zh_CN.ts
index 0388869f..a223a841 100755
--- a/translations/zh_CN.ts
+++ b/translations/zh_CN.ts
@@ -2074,6 +2074,10 @@ Depends:
Details
详情
+
+ View Source
+ 查看源代码
+
Judge
测试
@@ -2188,6 +2192,25 @@ Depends:
仿 joi2020
+
+ SourceViewerDialog
+
+ View Source
+ 查看源代码
+
+
+ Cannot find the source file of this task.
+ 找不到该任务的源文件。
+
+
+ Source file %1 does not exist.
+ 源文件 %1 不存在。
+
+
+ Source Code: %1 - %2
+ 源代码:%1 - %2
+
+
StatisticsBrowser
diff --git a/translations/zh_TW.ts b/translations/zh_TW.ts
index 22070493..0d2c6773 100644
--- a/translations/zh_TW.ts
+++ b/translations/zh_TW.ts
@@ -2074,6 +2074,10 @@ Depends:
Details
詳情
+
+ View Source
+ 查看原始碼
+
Judge
測試
@@ -2188,6 +2192,25 @@ Depends:
+
+ SourceViewerDialog
+
+ View Source
+ 查看原始碼
+
+
+ Cannot find the source file of this task.
+ 找不到該任務的原始碼檔案。
+
+
+ Source file %1 does not exist.
+ 原始碼檔案 %1 不存在。
+
+
+ Source Code: %1 - %2
+ 原始碼:%1 - %2
+
+
StatisticsBrowser
From 580918e38350577ec0807a133aeafd0f007b4dbc Mon Sep 17 00:00:00 2001
From: zhuyanyu123 <14973542+zhuyanyu123@user.noreply.gitee.com>
Date: Sun, 22 Nov 2026 17:08:36 +0800
Subject: [PATCH 03/11] fix(ui): build SourceViewerDialog against Qt 6.11
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.
---
src/sourceviewer.cpp | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/src/sourceviewer.cpp b/src/sourceviewer.cpp
index fea03d17..443592c8 100644
--- a/src/sourceviewer.cpp
+++ b/src/sourceviewer.cpp
@@ -21,6 +21,10 @@
#include
#include
#include
+#include
+#include
+#include
+#include
#include
#include
#include
@@ -330,8 +334,10 @@ void SourceViewerDialog::addEditorTab(const QString &filePath) {
QString content = QString::fromUtf8(data);
// Fall back to the system's local encoding when the file is not valid UTF-8
- if (content.contains(QChar(0xfffd)))
- content = QString::fromLocal8bit(data);
+ if (content.contains(QChar(0xfffd))) {
+ QStringDecoder decoder(QStringConverter::System);
+ content = decoder(data);
+ }
editor->setPlainText(content);
}
From cc26d4e8249f24eb75d49a649648f9581a3067a0 Mon Sep 17 00:00:00 2001
From: zhuyanyu123 <14973542+zhuyanyu123@user.noreply.gitee.com>
Date: Sun, 22 Nov 2026 17:10:27 +0800
Subject: [PATCH 04/11] feat(export): open contestant details in a popup window
(#235)
Store contestant details in text/template script blocks instead of
inline DOM nodes, so browsers only render details actually opened.
Rank list links now invoke lemonOpenDetail(), which writes the detail
HTML into a new window together with the exported style sheet, applies
the detail styling, and optionally scrolls to the clicked task.
Tested with a contestant named to guard the template blocks.
---
src/component/exportutil/exportutil.cpp | 108 +++++++++++++++++++-----
tests/export-util/main.cpp | 29 ++++++-
translations/zh_CN.ts | 12 ++-
translations/zh_TW.ts | 12 ++-
4 files changed, 132 insertions(+), 29 deletions(-)
diff --git a/src/component/exportutil/exportutil.cpp b/src/component/exportutil/exportutil.cpp
index 3b92e4be..ca16fe69 100644
--- a/src/component/exportutil/exportutil.cpp
+++ b/src/component/exportutil/exportutil.cpp
@@ -235,7 +235,6 @@ auto ExportUtil::getContestantHtmlCode(Contest *contest, Contestant *contestant,
htmlCode += "
";
}
- htmlCode += QString("%1
").arg(tr("Return to top"));
return htmlCode;
}
/*
@@ -269,7 +268,7 @@ void ExportUtil::writeHtml(QTextStream &out, Contest *contest) {
out << R"()";
// Style sheet
- out << "" + template.textContent + "