8 FieldView::FieldView(QWidget *parent) :
14 moves=new QList<Animation*>();
19 void FieldView::mousePressEvent(QMouseEvent *event)
21 QPoint sel=cell(event->pos());
31 void FieldView::mouseReleaseEvent(QMouseEvent *event)
36 QPoint mov=cell(event->pos());
39 if(moveX==selX && moveY==selY)
46 moves=new QList<Animation*>();
47 playField->move(selX, selY, moveX);
49 emit updateMoves(playField->moves);
52 PlayField* FieldView::setPlayField(PlayField *pf)
58 playField = new PlayField(pf);
59 QObject::connect(playField,SIGNAL(cellMoved(int,int,int,int)),this,SLOT(cellMoved(int,int,int,int)));
60 QObject::connect(playField,SIGNAL(cellGone(int,int)),this,SLOT(cellGone(int,int)));
64 emit updateMoves(playField->moves);
68 void FieldView::cellMoved(int w, int h, int wnew, int hnew)
71 QRect cnew=coo(wnew,hnew);
72 moves->append(new Move(c,cnew));
74 void FieldView::cellGone(int w, int h)
77 moves->append(new Hide(c));
79 QWidget* FieldView::cellWidget(int w, int h)
81 return childAt(coo(w,h).topLeft());
83 void FieldView::playMove()
87 Animation *move=moves->at(0);
88 QWidget *item=childAt(move->src.topLeft());
91 QPoint p=cell(move->src.left(),move->src.top());
93 QPropertyAnimation *a=move->getAnimation(item);
95 connect(a,SIGNAL(finished()),this,SLOT(playMove()));
98 } else if(playField->checkSolved())
100 emit solved(playField->moves);
104 void FieldView::playMoves()
109 void FieldView::undo()
113 emit updateMoves(playField->moves);
116 void FieldView::updateWidgets()
118 QList<QWidget *> childs=findChildren<QWidget *>();
119 QListIterator<QWidget *> childsI(childs);
120 while(childsI.hasNext())
122 delete childsI.next();
125 for(int w=0;w<PF::FIELD_WIDTH;w++)
126 for(int h=0;h<PF::FIELD_HEIGHT;h++)
129 int cell=playField->get(w,h);
136 cellW=new QLabel(this);
137 cellW->setPixmap(iconSet.wallIcon());
138 cellW->setGeometry(r);
139 cellW->setFrameStyle(QFrame::NoFrame);
143 cellW=new QLabel(this);
144 cellW->setPixmap(iconSet.icon(cell-2));
145 cellW->setGeometry(r);
146 cellW->setFrameStyle(QFrame::NoFrame);