Repository navigation
Expand file tree
/
Copy pathendscreen.cpp
More file actions
75 lines (59 loc) · 2.1 KB
/
Copy pathendscreen.cpp
File metadata and controls
75 lines (59 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include "endscreen.h"
#include "ui_endscreen.h"
EndScreen::EndScreen(QWidget *parent, int percentage, QStringList* wrongWords,
QTime* remainigTime, QString text)
: QWidget(parent)
, ui(new Ui::EndScreen)
{
ui->setupUi(this);
// Lowercase + replace ’ with '
QStringList lowerWrongWords;
for (const QString &w : *wrongWords) {
lowerWrongWords << w.toLower().replace(QChar(0x2019), '\'');
}
model->setStringList(lowerWrongWords);
ui->listView->setModel(model);
QString formatted = text.toHtmlEscaped();
formatted.replace("\n", "<br>");
for (const QString &w : *wrongWords) {
QString escaped = QRegularExpression::escape(w);
QRegularExpression re("\\b" + escaped + "\\b",
QRegularExpression::CaseInsensitiveOption);
QRegularExpressionMatchIterator it = re.globalMatch(formatted);
int offset = 0;
while (it.hasNext()) {
QRegularExpressionMatch m = it.next();
int start = m.capturedStart();
int end = m.capturedEnd();
QString matchedText = m.captured(0);
QString replacement =
"<span style=\"color:red; font-weight:bold;\">" + matchedText + "</span>";
formatted.replace(start + offset, end - start, replacement);
offset += replacement.length() - (end - start);
}
}
ui->textBrowser->setHtml(formatted);
ui->lcdNumber->display(percentage);
ui->timeEdit->setTime(*remainigTime);
connect(ui->pushButton, &QPushButton::clicked,
this, &EndScreen::onButtonPress);
connect(ui->listView, &QListView::doubleClicked,
this, &EndScreen::onItemDoubleClicked);
}
void EndScreen::onButtonPress(){
StartMenu* menu = new StartMenu();
menu->show();
this->close();
}
void EndScreen::onItemDoubleClicked(const QModelIndex &index)
{
if (!index.isValid())
return;
QString itemText = model->data(index, Qt::DisplayRole).toString();
InfoBox box(this, &itemText);
box.exec();
}
EndScreen::~EndScreen()
{
delete ui;
}