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