fe5e9eba52a5cc818a0d244f146a2cddbe0f47cc
[qquiz] / 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 CHAR_DELIM                      ';'
37 #define ANSWER_DELIM            '|'
38
39 #define DEFAULT_NR_COL          2
40
41 using namespace std;
42
43 class question {
44         public:
45                 question();
46                 ~question();
47                 question(QString s, QString r);
48                 QString hint;
49                 QString answer;
50                 QLabel *label;
51                 int answered;
52 };
53
54 class quiz_file {
55         public:
56                 QDir path;
57                 QString title;
58                 int id;
59 };
60
61 class quiz : public QObject{
62         Q_OBJECT
63         public:
64                 quiz();
65                 ~quiz();
66                 void retrieve_quizzes();
67                 int read_quiz(const char *filename);
68                 void init_gui();
69                 void display_score();
70                 void display_grid();
71                 void clean_gui();
72         public slots:
73                 void buzz(const QString& text);
74                 void update_timer();
75                 void choose_quiz();
76                 void end();
77         private:
78                 vector<question *> questions;
79                 vector<quiz_file *> files;
80                 quiz_file * current;
81                 QString title;
82                 int total;
83                 int correct;
84                 unsigned int total_time;
85                 unsigned int current_time;
86                 unsigned int max_label_length;
87                 map < QString, int > index;
88                 QWidget *window;
89                 QMenuBar *menu;
90                 QAction *give_up;
91                 QGridLayout *grid;
92                 QVBoxLayout *layout;
93                 QLineEdit *line;
94                 QScrollArea *scrollArea;
95                 QWidget *sub_window;
96                 QLabel *score;
97                 QLabel *timer_label;
98                 QTimer *timer;
99 };
100