Added "About"
[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=45; //GUI size
13     const int FIELD_HEIGHT=45;
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         bool moving;
72         QList<Animation*> *moves;
73
74         void playMoves();
75 signals:
76         void solved(int moves);
77         void updateMoves(int moves);
78
79 public slots:
80         void cellMoved(int w, int h, int wnew, int hnew);
81         void cellGone(int w, int h);
82         void playMove();
83         void undo();
84
85
86 protected:
87         IconSet iconSet;
88
89         void mousePressEvent(QMouseEvent *event);
90         void mouseReleaseEvent(QMouseEvent *event);
91         virtual void updateWidgets();
92
93         //void paintCell(int x, int y, int cell, QPainter &painter);
94         QWidget *cellWidget(int w, int h);
95         QRect coo(int x, int y, int off=1)
96         {
97                 return QRect(x*FV::FIELD_WIDTH+off,y*FV::FIELD_HEIGHT+off,FV::FIELD_WIDTH-off,FV::FIELD_HEIGHT-off);
98         }
99         QPoint cell(int worldX, int worldY)
100         {
101                 return QPoint(width()/worldX, height()/worldY);
102         }
103         QPoint cell(const QPoint &pos)
104         {
105                 return QPoint(pos.x()/FV::FIELD_WIDTH, pos.y()/FV::FIELD_HEIGHT);
106         }
107
108 };
109
110 #endif // FIELDVIEW_H