update dict
[QFreeRecite.git] / src / gui / TesterWidget.cpp
blob9a925fee62bc99a9d17d643fa1eba90c5aab2bbd
1 #include <Tester.h>
2 #include <Manager.h>
3 #include "TesterWidget.h"
4 #include "ResultWidget.h"
6 using freeRecite::manager;
8 TesterWidget::TesterWidget(QWidget *parent)
9 : ScannerWidget(parent)
10 { /* Do Nothing Here! */ }
12 void TesterWidget::start(time_t taskID) {
13 freeRecite::Tester *tester = new freeRecite::Tester;
14 tester->load(taskID);
15 scanner = dynamic_cast<freeRecite::Scanner *>(tester);
16 topicLabel->setText(tr("Testing"));
17 setInfo();
18 showNext();
19 time(&startTime);
22 void TesterWidget::displayResult() {
23 time_t endTime = 0;
24 time(&endTime);
25 startTime = endTime - startTime;
26 startTime /= 60;
27 startTime = startTime > 1 ? startTime : 1;
29 QString str11,str12,str21,str22,str31,str32;
30 unsigned score = scanner->getScore();
31 str11 = tr("Amount: ");
32 str12 = QVariant(scanner->capability()).toString();
33 str21 = tr("Used Time: ");
34 str22 = QVariant(static_cast<unsigned>(startTime)).toString() + tr(" min");
35 str31 = tr("Score: ");
36 str32 = QVariant(score).toString();
38 resultWidget = new ResultWidget(this);
39 connect(resultWidget,SIGNAL(confirmed()),this,SIGNAL(finished()));
41 resultWidget->setInfo(str11,str12,str21,str22,str31,str32);
42 int testResult = manager.test(scanner->id(),scanner->getScore());
43 if(testResult == 0) {
44 resultWidget->setTailer(tr("You passed it!"));
45 }else if(testResult == -1){
46 resultWidget->setTailer(tr("You haven't passed it!"));
47 }else { // testResult == 1
48 resultWidget->setTailer(tr("You have complished this task!"));
50 manager.refresh();
51 emit showResult();