06ccf288f0363da58e103a7204c8b7e807c37724
[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     Field (QWidget *parent, const QVector<QBrush> &brushes, FieldSize size);
37     Field (QWidget *parent);
38     ~Field ();
39
40     FieldSize getSize () const;
41     void randomize ();
42
43     static int getNumRectsOfSize (FieldSize size);
44     static int getNumTurnsOfSize (FieldSize size);
45
46 private:
47     typedef struct
48     {
49         char brush;
50         bool flood;
51     }FieldRect;
52
53     static const int rects[NUM_SIZES];
54     static const int turns[NUM_SIZES];
55
56     void init (const QVector<QBrush> &brushes, FieldSize size);
57     static int getRectSize (FieldSize size);
58
59     FieldSize          size;
60     QVector<QBrush>    brushes;
61     QVector<FieldRect> data;
62
63 protected:
64     void paintEvent (QPaintEvent *event);
65 };
66
67 #endif // !_FIELD_HPP