Skip to content

Commit 331307b

Browse files
committed
improve: shrink color
1 parent aaea0e8 commit 331307b

5 files changed

Lines changed: 57 additions & 25 deletions

File tree

assets/js/jquery.slim.min.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

makespec/BUILDVERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
198
1+
199

resource.qrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,7 @@
4343
<file alias="system-help.svg">assets/pics/system-help.svg</file>
4444
<file alias="acrobat.svg">assets/pics/acrobat.svg</file>
4545
</qresource>
46+
<qresource prefix="/js">
47+
<file alias="jquery.slim.min.js">assets/js/jquery.slim.min.js</file>
48+
</qresource>
4649
</RCC>

src/base/LemonType.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ enum ResultState {
3232
Skipped,
3333
InteractorError,
3434
PresentationError,
35-
OutputLimitExceeded
35+
OutputLimitExceeded,
36+
LastResultState
3637
};
3738

3839
#include <QList>

src/component/exportutil/exportutil.cpp

Lines changed: 49 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#include "settings.h"
2020
#include "visualmainsettings.h"
2121
#include "visualsettings.h"
22-
//
22+
2323
#include <QApplication>
2424
#include <QFileDialog>
2525
#include <QMessageBox>
@@ -29,6 +29,15 @@
2929

3030
ExportUtil::ExportUtil(QObject *parent) : QObject(parent) {}
3131

32+
const auto resultStateMap = []() {
33+
QMap<ResultState, std::tuple<QString, QString, QString>> resMap;
34+
for (int i = static_cast<int>(CorrectAnswer); i != static_cast<int>(LastResultState); i++) {
35+
QString text, frColor, bgColor;
36+
Settings::setTextAndColor(static_cast<ResultState>(i), text, frColor, bgColor);
37+
resMap[static_cast<ResultState>(i)] = {text, frColor, bgColor};
38+
}
39+
return resMap;
40+
}();
3241
auto ExportUtil::getContestantHtmlCode(Contest *contest, Contestant *contestant, int num) -> QString {
3342
QString htmlCode;
3443
QList<Task *> taskList = contest->getTaskList();
@@ -137,14 +146,10 @@ auto ExportUtil::getContestantHtmlCode(Contest *contest, Contestant *contestant,
137146
}
138147

139148
htmlCode += QString("<td>%1</td>").arg(inputFiles[j][k]);
140-
QString text;
141-
QString bgColor = "rgb(255, 255, 255)";
142-
QString frColor = "rgb(0, 0, 0)";
149+
QString text, bgColor, frColor;
143150
Settings::setTextAndColor(result[j][k], text, frColor, bgColor);
144-
htmlCode += QString("<td style=\"background-color: %2; color: %3;\">%1")
145-
.arg(text)
146-
.arg(bgColor)
147-
.arg(frColor);
151+
htmlCode +=
152+
QString("<td class=\"result%2\">%1").arg(text).arg(static_cast<int>(result[j][k]));
148153

149154
if (! message[j][k].isEmpty()) {
150155
QString tmp = message[j][k];
@@ -181,20 +186,18 @@ auto ExportUtil::getContestantHtmlCode(Contest *contest, Contestant *contestant,
181186
if (score[j][t] < minv)
182187
minv = score[j][t];
183188

184-
QString bgColor = "rgb(255, 192, 192)";
189+
QString bgClass = "zero-score";
185190

186191
if (minv >= maxv)
187-
bgColor = "rgb(192, 255, 192)";
192+
bgClass = "full-score";
188193
else if (minv > 0)
189-
bgColor = "rgb(192, 255, 255)";
190-
191-
htmlCode +=
192-
QString(
193-
R"(<td rowspan="%1" style="background-color: %2;"><span class="c">%3</span> / %4</td>)")
194-
.arg(inputFiles[j].size())
195-
.arg(bgColor)
196-
.arg(minv)
197-
.arg(maxv);
194+
bgClass = "partial-score";
195+
196+
htmlCode += QString(R"(<td rowspan="%1" class="%2"><span class="c">%3</span> / %4</td>)")
197+
.arg(inputFiles[j].size())
198+
.arg(bgClass)
199+
.arg(minv)
200+
.arg(maxv);
198201
}
199202

200203
htmlCode += "</tr>";
@@ -238,9 +241,32 @@ void ExportUtil::exportHtml(QWidget *widget, Contest *contest, const QString &fi
238241
".th-1 {border-style: none solid solid none; border-width: 3px 2px; border-color: #000;}"
239242
".a-0 {color: black; text-decoration: none;} .c {font-weight: bold; font-size: large;}"
240243
".td-2 {border-radius: 5px; font-weight: bold;}"
241-
".td-3 {border-radius: 5px;}</style>";
244+
".td-3 {border-radius: 5px;}"
245+
".full-score {background: rgb(192, 255, 192)}"
246+
".partial-score {background: rgb(192, 255, 255)}"
247+
".zero-score {background: rgb(255, 192, 192)}";
248+
for (auto [k, v] : resultStateMap.toStdMap()) {
249+
out << ".result" << static_cast<int>(k);
250+
out << QString(" {color: %1;background: %2;}").arg(std::get<1>(v)).arg(std::get<2>(v));
251+
}
252+
out << "</style>";
253+
254+
/*下载jquery有几个时间段
255+
* 1是编译前
256+
* 2是编译期
257+
* 3是运行LemonLime时
258+
* 4是打开result.html时
259+
* 这里选了第1种
260+
*/
261+
262+
// out << R"(<script src="https://unpkg.com/jquery@3/dist/jquery.slim.min.js"></script>)";
263+
264+
QFile jqFile(":/js/jquery.slim.min.js");
265+
jqFile.open(QFile::ReadOnly);
266+
QString jq(jqFile.readAll());
267+
268+
out << "<script>" << jq << "</script>";
242269

243-
out << R"(<script src="https://unpkg.com/jquery@3/dist/jquery.slim.min.js"></script>)";
244270
out << "<title>" << contest->getContestTitle() << " : " << tr("Contest Result") << "</title>";
245271
out << "</head><body>";
246272
QList<std::pair<int, QString>> sortList;
@@ -312,7 +338,7 @@ void ExportUtil::exportHtml(QWidget *widget, Contest *contest, const QString &fi
312338
#endif
313339
colors->getColorGrand(allScore, sfullScore).getHslF(&h, &s, &l);
314340
h *= 360, s *= 100, l *= 100;
315-
out << QString("<td class=\"td-2\" style=\"background-color: hsl(%2,%3%,%4%); border: 2px solid "
341+
out << QString("<td class=\"td-2\" style=\"background: hsl(%2,%3%,%4%); border: 2px solid "
316342
"hsl(%2,%3%,%5%);\">%1</td>")
317343
.arg(allScore)
318344
.arg(h)
@@ -375,7 +401,6 @@ void ExportUtil::exportHtml(QWidget *widget, Contest *contest, const QString &fi
375401
out << getContestantHtmlCode(contest, contestantList[i], i);
376402
}
377403

378-
out << "</body>";
379404
out << R"(
380405
<script>
381406
$("div[id^='c'] th").addClass("td-0");
@@ -385,6 +410,7 @@ void ExportUtil::exportHtml(QWidget *widget, Contest *contest, const QString &fi
385410
$("div[id^='c']>p>table th").attr("scope", "col");
386411
</script>
387412
)";
413+
out << "</body>";
388414
out << "</html>";
389415
QApplication::restoreOverrideCursor();
390416
QMessageBox::information(widget, tr("LemonLime"), tr("Export is done"), QMessageBox::Ok);

0 commit comments

Comments
 (0)