Fixed bug with non-working control buttons.
[vexed] / fieldview.h
1 #ifndef FIELDVIEW_H
2 #define FIELDVIEW_H
3
4 #include <QtCore>
5 #include <QtGui>
6
7 #include "playfield.h"
8 #include "iconset.h"
9
10 namespace FV
11 {
12     const int FIELD_WIDTH=34; //GUI size
13     const int FIELD_HEIGHT=34;
14 }
15
16 class Animation
17 {
18 public:
19   QPropertyAnimation *a;
20   QRect src;
21   QString name;
22
23   Animation(QRect _src, QString _name):src(_src),name(_name)
24   {
25   }
26   QPropertyAnimation* getAnimation(QWidget *i)
27   {
28           a->setTargetObject(i);
29           return a;
30   }
31 };
32
33 class Move : public Animation
34 {
35 public:
36         Move(QRect _src, QRect _dst):Animation(_src,"Move")
37         {
38                 a=new QPropertyAnimation();
39                 a->setPropertyName("geometry");
40                 a->setDuration(100);
41                 a->setStartValue(_src);
42                 a->setEndValue(_dst);
43         }
44 };
45 class Hide : public Animation
46 {
47 public:
48         Hide(QRect _src): Animation (_src,"Hide")
49         {
50                 a=new QPropertyAnimation();
51                 QRect dst(src);
52                 dst.setWidth(0);
53                 dst.setHeight(0);
54                 a->setPropertyName("geometry");
55                 a->setDuration(100);
56                 a->setStartValue(src);
57                 a->setEndValue(dst);
58         }
59 };
60 class FieldView : public QWidget
61 {
62         Q_OBJECT
63 public:
64         explicit FieldView(QWidget *parent = 0);
65         PlayField* setPlayField(PlayField *pf);
66
67 private:
68         PlayField *playField;
69         int selX, selY;
70         int moveX, moveY;
71         QStateMachine *machine;
72         QState *rotL, *rotR;
73         QTimer timer;
74         bool moving;
75         QList<Animation*> *moves;
76
77         void playMoves();
78 signals:
79         void solved(int moves);
80         void updateMoves(int moves);
81
82 public slots:
83         void cellMoved(int w, int h, int wnew, int hnew);
84         void cellGone(int w, int h);
85         void playMove();
86         void undo();
87
88
89 protected:
90         IconSet iconSet;
91
92         void mousePressEvent(QMouseEvent *event);
93         void mouseReleaseEvent(QMouseEvent *event);
94         void updateWidgets();
95
96         void paintCell(int x, int y, int cell, QPainter &painter);
97         QWidget *cellWidget(int w, int h);
98         QRect coo(int x, int y, int off=1)
99         {
100                 return QRect(x*FV::FIELD_WIDTH+off,y*FV::FIELD_HEIGHT+off,FV::FIELD_WIDTH-off,FV::FIELD_HEIGHT-off);
101         }
102         QPoint cell(int worldX, int worldY)
103         {
104                 return QPoint(width()/worldX, height()/worldY);
105         }
106         QPoint cell(const QPoint &pos)
107         {
108                 return QPoint(pos.x()/FV::FIELD_WIDTH, pos.y()/FV::FIELD_HEIGHT);
109         }
110
111 };
112
113 #endif // FIELDVIEW_H