Add quiz description
authorCharles Clément <caratorn@gmail.com>
Wed, 17 Feb 2010 18:48:47 +0000 (10:48 -0800)
committerCharles Clément <caratorn@gmail.com>
Wed, 17 Feb 2010 18:48:47 +0000 (10:48 -0800)
README
src/quiz.cpp
src/quiz.h

diff --git a/README b/README
index c204b8e..3416199 100644 (file)
--- a/README
+++ b/README
@@ -8,6 +8,7 @@ for each question and tries to complete in the minimum amount of time.
 
 Here's the syntax for the quiz files :
 Quiz title
+Description of the quiz
 # This is a comment
 # Author : name email_address
 # subset: number of questions to put in a game, example 30. Optional
index e7d04b1..967c896 100644 (file)
@@ -124,12 +124,19 @@ void quiz::choose_quiz() {
                        menu->addAction(give_up);
                        display_score();
                        display_grid();
+                       current_time = total_time;
+                       display_timer();
+                       start_dialog();
                        if (total_time) {
-                               current_time = total_time;
                                timer = new QTimer(this);
                                connect(timer, SIGNAL(timeout()), this, SLOT(update_timer()));
                                timer->start(1000);
                        }
+               } else {
+                       QString message = "Can't read file :\n";
+
+                       message.append(current->path.absolutePath());
+                       QMessageBox::warning (window, tr("Input file error"), message);
                }
        }
 }
@@ -144,6 +151,7 @@ int quiz::read_quiz(const char *filename) {
        ifstream ifs (filename);
        max_label_length = 0;
        int i = 0;
+    bool ok;
 
        total_time = 0;
        if (!ifs) {
@@ -157,13 +165,23 @@ int quiz::read_quiz(const char *filename) {
                do {
                        getline(ifs, buffer);
                } while (buffer[0] == '#');
+               description = QString::fromStdString(buffer);
+               do {
+                       getline(ifs, buffer);
+               } while (buffer[0] == '#');
                if (! buffer.compare(0, strlen(SUBSET_PATTERN), SUBSET_PATTERN)) {
-                       subset = atoi(buffer.substr(strlen(SUBSET_PATTERN)).c_str());
-                               do {
-                                       getline(ifs, buffer);
-                               } while (buffer[0] == '#');
+                       subset = QString::fromStdString(buffer.substr(strlen(SUBSET_PATTERN))).toInt(&ok);
+                       if (!ok) {
+                               return 0;
+                       }
+                       do {
+                               getline(ifs, buffer);
+                       } while (buffer[0] == '#');
+               }
+               total_time = QString::fromStdString(buffer).toInt(&ok);
+               if (!ok) {
+                       return 0;
                }
-               total_time = atoi(buffer.c_str());
                /* convert minutes to seconds */
                total_time *= 60;
                while (getline(ifs, parse_line)){
@@ -306,6 +324,12 @@ void quiz::init_gui() {
        QObject::connect(give_up, SIGNAL(triggered()), this, SLOT(end()));
 }
 
+void quiz::start_dialog() {
+
+     QMessageBox::information(window, tr("Description"), description);
+
+}
+
 void quiz::buzz(const QString& buffer) {
        map <QString, int>::iterator itr;
        question *q;
@@ -385,8 +409,12 @@ void quiz::display_grid() {
 }
 
 void quiz::update_timer() {
-
        current_time--;
+       display_timer();
+}
+
+void quiz::display_timer() {
+
        QTime t(0, current_time / 60, current_time % 60);
        timer_label->setText(t.toString("m:ss"));
        if (current_time == 0) {
index b6cd245..1850aa3 100644 (file)
@@ -70,9 +70,10 @@ class quiz : public QObject{
                void trim_questions();
                void build_index();
                void init_gui();
+               void start_dialog();
                void display_score();
                void display_grid();
-               void clean_gui();
+               void display_timer();
        public slots:
                void buzz(const QString& text);
                void update_timer();
@@ -83,6 +84,7 @@ class quiz : public QObject{
                vector<quiz_file *> files;
                quiz_file * current;
                QString title;
+               QString description;
                int total;
                int subset;
                int correct;