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