* Generate the HTML code for the summary page * Might be difficult to maintain * Use Javascript to shrink the filesize */
| 216 | * Use Javascript to shrink the filesize |
| 217 | */ |
| 218 | void ExportUtil::exportHtml(QWidget *widget, Contest *contest, const QString &fileName) { |
| 219 | Settings settings; |
| 220 | contest->copySettings(settings); |
| 221 | ColorTheme colors = settings.getCurrentColorTheme(); |
| 222 | |
| 223 | QFile file(fileName); |
| 224 | |
| 225 | if (! file.open(QFile::WriteOnly)) { |
| 226 | QMessageBox::warning(widget, tr("LemonLime"), |
| 227 | tr("Cannot open file %1").arg(QFileInfo(file).fileName()), QMessageBox::Ok); |
| 228 | return; |
| 229 | } |
| 230 | |
| 231 | QApplication::setOverrideCursor(Qt::WaitCursor); |
| 232 | QTextStream out(&file); |
| 233 | QList<Contestant *> contestantList = contest->getContestantList(); |
| 234 | QList<Task *> taskList = contest->getTaskList(); |
| 235 | out << "<html><head>"; |
| 236 | out << R"(<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />)"; |
| 237 | |
| 238 | // Style sheet |
| 239 | out << "<style type=\"text/css\">" |
| 240 | "th, td {padding-left: 1em; padding-right: 1em; white-space: nowrap; " |
| 241 | "text-align: center; verticle-align: middle;}" |
| 242 | ".td-0 {border-style: none solid solid none; border-width: 1px 3px; border-color: #ccc;}" |
| 243 | ".th-0 {border-style: none solid solid none; border-width: 3px 3px; border-color: #000;}" |
| 244 | ".th-1 {border-style: none solid solid none; border-width: 3px 2px; border-color: #000;}" |
| 245 | ".a-0 {color: black; text-decoration: none;} .c {font-weight: bold; font-size: large;}" |
| 246 | ".td-2 {border-radius: 5px; font-weight: bold;}" |
| 247 | ".td-3 {border-radius: 5px;}" |
| 248 | ".full-score {background: rgb(192, 255, 192)}" |
| 249 | ".partial-score {background: rgb(192, 255, 255)}" |
| 250 | ".zero-score {background: rgb(255, 192, 192)}"; |
| 251 | for (auto [k, v] : resultStateMap.toStdMap()) { |
| 252 | out << ".result" << static_cast<int>(k); |
| 253 | out << QString(" {color: %1;background: %2;}").arg(std::get<1>(v)).arg(std::get<2>(v)); |
| 254 | } |
| 255 | out << "</style>"; |
| 256 | |
| 257 | out << "<title>" << contest->getContestTitle() << " : " << tr("Contest Result") << "</title>"; |
| 258 | out << "</head><body>"; |
| 259 | QList<std::pair<int, QString>> sortList; |
| 260 | |
| 261 | for (auto &i : contestantList) { |
| 262 | int totalScore = i->getTotalScore(); |
| 263 | |
| 264 | if (totalScore != -1) { |
| 265 | sortList.append(std::make_pair(-totalScore, i->getContestantName())); |
| 266 | } else { |
| 267 | sortList.append(std::make_pair(1, i->getContestantName())); |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | std::sort(sortList.begin(), sortList.end()); |
| 272 | QMap<QString, int> rankList; |
| 273 | |
| 274 | for (int i = 0; i < sortList.size(); i++) { |
| 275 | if (i > 0 && sortList[i].first == sortList[i - 1].first) { |
nothing calls this directly
no test coverage detected