b6cd245df86d0e979977a8f3a52cb51a5a1914ab
[qquiz] / src / quiz.h
1 /*
2  *  Copyright (C) 2010 Charles Clement <caratorn _at_ gmail.com>
3  *
4  *  This file is part of qquiz.
5  *
6  *  qquiz is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2 of the License, or
9  *  (at your option) any later version.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  *  02110-1301  USA
20  *
21  */
22
23 #include <map>
24 #include <iostream>
25 #include <fstream>
26 #include <vector>
27 #include<cstdlib>
28
29 #include <QLabel>
30 #include <QtGui>
31 #include <QObject>
32 #include <QGridLayout>
33
34 #define APP_NAME                        "qquiz"
35
36 #define SUBSET_PATTERN          "subset:"
37 #define CHAR_DELIM                      ';'
38 #define ANSWER_DELIM            '|'
39
40 #define DEFAULT_NR_COL          2
41
42 using namespace std;
43
44 class question {
45         public:
46                 question();
47                 ~question();
48                 question(QString s, QString r);
49                 QString hint;
50                 QString answer;
51                 QList<QString> alternate_answers;
52                 QLabel *label;
53                 int answered;
54 };
55
56 class quiz_file {
57         public:
58                 QDir path;
59                 QString title;
60                 int id;
61 };
62
63 class quiz : public QObject{
64         Q_OBJECT
65         public:
66                 quiz();
67                 ~quiz();
68                 void retrieve_quizzes();
69                 int read_quiz(const char *filename);
70                 void trim_questions();
71                 void build_index();
72                 void init_gui();
73                 void display_score();
74                 void display_grid();
75                 void clean_gui();
76         public slots:
77                 void buzz(const QString& text);
78                 void update_timer();
79                 void choose_quiz();
80                 void end();
81         private:
82                 vector<question *> questions;
83                 vector<quiz_file *> files;
84                 quiz_file * current;
85                 QString title;
86                 int total;
87                 int subset;
88                 int correct;
89                 unsigned int total_time;
90                 unsigned int current_time;
91                 unsigned int max_label_length;
92                 map < QString, int > index;
93                 QWidget *window;
94                 QMenuBar *menu;
95                 QAction *give_up;
96                 QGridLayout *grid;
97                 QVBoxLayout *layout;
98                 QLineEdit *line;
99                 QScrollArea *scrollArea;
100                 QWidget *sub_window;
101                 QLabel *score;
102                 QLabel *timer_label;
103                 QTimer *timer;
104 };
105