1850aa3c434680ba052fbd9f1840d225732368a2
[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 start_dialog();
74                 void display_score();
75                 void display_grid();
76                 void display_timer();
77         public slots:
78                 void buzz(const QString& text);
79                 void update_timer();
80                 void choose_quiz();
81                 void end();
82         private:
83                 vector<question *> questions;
84                 vector<quiz_file *> files;
85                 quiz_file * current;
86                 QString title;
87                 QString description;
88                 int total;
89                 int subset;
90                 int correct;
91                 unsigned int total_time;
92                 unsigned int current_time;
93                 unsigned int max_label_length;
94                 map < QString, int > index;
95                 QWidget *window;
96                 QMenuBar *menu;
97                 QAction *give_up;
98                 QGridLayout *grid;
99                 QVBoxLayout *layout;
100                 QLineEdit *line;
101                 QScrollArea *scrollArea;
102                 QWidget *sub_window;
103                 QLabel *score;
104                 QLabel *timer_label;
105                 QTimer *timer;
106 };
107