5 #include <ConfigHolder.h>
8 #include "MainWidget.h"
9 #include "ReciterWidget.h"
10 #include "TesterWidget.h"
11 #include "MainWindow.h"
12 #include "ResultWidget.h"
14 MainWindow::MainWindow()
18 if(!freeRecite::manager
.load()) {
21 std::cerr
<< "Can't load "
22 << freeRecite::configHolder
.mgrFile() << std::endl
23 << "The program exit!\n";
27 if(!freeRecite::dictionary
.load()) {
30 std::cerr
<< "Can't load dictionary.\n"
31 << "The program exit!\n";
35 stackedWidget
= new QStackedWidget(this);
36 setCentralWidget(stackedWidget
);
37 mainWidget
= new MainWidget(this);
38 stackedWidget
->addWidget(mainWidget
);
39 connect(mainWidget
->reciteButton
,SIGNAL(clicked()),
41 connect(mainWidget
->testButton
,SIGNAL(clicked()),
43 connect(mainWidget
->quitButton
,SIGNAL(clicked()),
47 MainWindow::~MainWindow() {
49 mainWidget
->deleteLater();
50 if(scannerWidget
!= 0)
51 scannerWidget
->deleteLater();
54 void MainWindow::recite() {
55 if(mainWidget
->getCurrentTaskID() == 0)
57 scannerWidget
= new ReciterWidget(this);
58 stackedWidget
->addWidget(scannerWidget
);
59 stackedWidget
->setCurrentWidget(scannerWidget
);
60 connect(scannerWidget
,SIGNAL(showResult(ResultWidget
*)),
61 this,SLOT(showResult(ResultWidget
*)));
62 connect(scannerWidget
->stopButton
,SIGNAL(clicked()),
63 this,SLOT(showMain()));
64 scannerWidget
->start(mainWidget
->getCurrentTaskID());
67 void MainWindow::test() {
68 if(mainWidget
->getCurrentTaskID() == 0)
70 scannerWidget
= new TesterWidget(this);
71 stackedWidget
->addWidget(scannerWidget
);
72 stackedWidget
->setCurrentWidget(scannerWidget
);
73 connect(scannerWidget
,SIGNAL(showResult(ResultWidget
*)),
74 this,SLOT(showResult(ResultWidget
*)));
75 connect(scannerWidget
->stopButton
,SIGNAL(clicked()),
76 this,SLOT(showMain()));
77 scannerWidget
->start(mainWidget
->getCurrentTaskID());
80 void MainWindow::showMain(ResultWidget
*resultWidget
) {
81 stackedWidget
->setCurrentWidget(mainWidget
);
82 stackedWidget
->removeWidget(scannerWidget
);
83 stackedWidget
->removeWidget(resultWidget
);
84 scannerWidget
->deleteLater();
86 resultWidget
->deleteLater();
91 std::cerr
<< stackedWidget
->count();
95 void MainWindow::showResult(ResultWidget
*resultWidget
) {
96 if(resultWidget
->isTester()) {
98 freeRecite::manager
.test(resultWidget
->id(),resultWidget
->score());
100 resultWidget
->setTailer(tr("You passed it!"));
101 }else if(testResult
== -1){
102 resultWidget
->setTailer(tr("You haven't passed it!"));
103 }else { // testResult == 1
104 resultWidget
->setTailer(tr("You have complished this task!"));
107 stackedWidget
->addWidget(resultWidget
);
108 stackedWidget
->setCurrentWidget(resultWidget
);
109 connect(resultWidget
,SIGNAL(confirmed(ResultWidget
*)),
110 this,SLOT(showMain(ResultWidget
*)));