0d78d3475d7a81839aebf28be3603ba67cccc94a
[colorflood] / colorflood / src / field.hpp
1 /*
2   Copyright 2010 Serge Ziryukin <ftrvxmtrx@gmail.com>
3
4   This program is free software; you can redistribute it and/or modify
5   it under the terms of the GNU General Public License as published by
6   the Free Software Foundation; version 2 of the License.
7
8   This program is distributed in the hope that it will be useful,
9   but WITHOUT ANY WARRANTY; without even the implied warranty of
10   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11   GNU General Public License for more details.
12 */
13
14 #ifndef _FIELD_HPP
15 #define _FIELD_HPP
16
17 #include <QWidget>
18 #include <QVector>
19 #include <QBrush>
20
21 class QPaintEvent;
22
23 class Field : public QWidget
24 {
25     Q_OBJECT;
26
27 public:
28     typedef enum
29     {
30         SIZE_SMALL = 0,
31         SIZE_NORMAL,
32         SIZE_LARGE,
33         NUM_SIZES
34     }FieldSize;
35
36     typedef struct
37     {
38         quint8 brush;
39         bool   flood;
40     }FieldRect;
41
42     typedef QVector<Field::FieldRect> RectVector;
43
44     Field (QWidget *parent);
45     ~Field ();
46
47     FieldSize getSize () const;
48     void randomize ();
49
50     static int getNumRectsOfSize (FieldSize size);
51     static int getNumTurnsOfSize (FieldSize size);
52
53 private:
54     static const int rects[NUM_SIZES];
55     static const int turns[NUM_SIZES];
56
57     void init (const QVector<QBrush> &brushes, FieldSize size);
58     static int getRectSize (FieldSize size);
59
60     FieldSize  size;
61     RectVector data;
62
63 protected:
64     void paintEvent (QPaintEvent *event);
65 };
66
67 #endif // !_FIELD_HPP