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