Initial commit
[vexed] / fieldview.h
diff --git a/fieldview.h b/fieldview.h
new file mode 100644 (file)
index 0000000..3a4dc4a
--- /dev/null
@@ -0,0 +1,113 @@
+#ifndef FIELDVIEW_H
+#define FIELDVIEW_H
+
+#include <QtCore>
+#include <QtGui>
+
+#include "playfield.h"
+#include "iconset.h"
+
+namespace FV
+{
+    const int FIELD_WIDTH=34; //GUI size
+    const int FIELD_HEIGHT=34;
+}
+
+class Animation
+{
+public:
+  QPropertyAnimation *a;
+  QRect src;
+  QString name;
+
+  Animation(QRect _src, QString _name):src(_src),name(_name)
+  {
+  }
+  QPropertyAnimation* getAnimation(QWidget *i)
+  {
+          a->setTargetObject(i);
+          return a;
+  }
+};
+
+class Move : public Animation
+{
+public:
+        Move(QRect _src, QRect _dst):Animation(_src,"Move")
+        {
+                a=new QPropertyAnimation();
+                a->setPropertyName("geometry");
+                a->setDuration(100);
+                a->setStartValue(_src);
+                a->setEndValue(_dst);
+        }
+};
+class Hide : public Animation
+{
+public:
+        Hide(QRect _src): Animation (_src,"Hide")
+        {
+                a=new QPropertyAnimation();
+                QRect dst(src);
+                dst.setWidth(0);
+                dst.setHeight(0);
+                a->setPropertyName("geometry");
+                a->setDuration(100);
+                a->setStartValue(src);
+                a->setEndValue(dst);
+        }
+};
+class FieldView : public QWidget
+{
+        Q_OBJECT
+public:
+        explicit FieldView(QWidget *parent = 0);
+        PlayField* setPlayField(PlayField *pf);
+
+private:
+        PlayField *playField;
+        int selX, selY;
+        int moveX, moveY;
+        QStateMachine *machine;
+        QState *rotL, *rotR;
+        QTimer timer;
+        bool moving;
+        QList<Animation*> *moves;
+
+        void playMoves();
+signals:
+        void solved(int moves);
+        void updateMoves(int moves);
+
+public slots:
+        void cellMoved(int w, int h, int wnew, int hnew);
+        void cellGone(int w, int h);
+        void playMove();
+        void undo();
+
+
+protected:
+        IconSet iconSet;
+
+        void mousePressEvent(QMouseEvent *event);
+        void mouseReleaseEvent(QMouseEvent *event);
+        void updateWidgets();
+
+        void paintCell(int x, int y, int cell, QPainter &painter);
+        QWidget *cellWidget(int w, int h);
+        QRect coo(int x, int y, int off=1)
+        {
+                return QRect(x*FV::FIELD_WIDTH+off,y*FV::FIELD_HEIGHT+off,FV::FIELD_WIDTH-off,FV::FIELD_HEIGHT-off);
+        }
+        QPoint cell(int worldX, int worldY)
+        {
+                return QPoint(width()/worldX, height()/worldY);
+        }
+        QPoint cell(const QPoint &pos)
+        {
+                return QPoint(pos.x()/FV::FIELD_WIDTH, pos.y()/FV::FIELD_HEIGHT);
+        }
+
+};
+
+#endif // FIELDVIEW_H