8 FieldView::FieldView(QWidget *parent) :
14 moves=new QList<Animation*>();
20 void FieldView::mousePressEvent(QMouseEvent *event)
22 QPoint sel=cell(event->pos());
32 void FieldView::mouseReleaseEvent(QMouseEvent *event)
37 QPoint mov=cell(event->pos());
40 if(moveX==selX && moveY==selY)
46 move(selX,selY,moveX);
49 void FieldView::move(int x, int y, int dest_x)
52 moves=new QList<Animation*>();
53 playField->move(x, y, dest_x);
55 emit updateMoves(playField->moves);
58 PlayField* FieldView::setPlayField(PlayField *pf)
64 playField = new PlayField(pf);
65 QObject::connect(playField,SIGNAL(cellMoved(int,int,int,int)),this,SLOT(cellMoved(int,int,int,int)));
66 QObject::connect(playField,SIGNAL(cellGone(int,int)),this,SLOT(cellGone(int,int)));
70 emit updateMoves(playField->moves);
74 void FieldView::cellMoved(int w, int h, int wnew, int hnew)
77 QRect cnew=coo(wnew,hnew);
78 moves->append(new Move(c,cnew));
80 void FieldView::cellGone(int w, int h)
83 moves->append(new Hide(c));
85 QWidget* FieldView::cellWidget(int w, int h)
87 return childAt(coo(w,h).topLeft());
89 void FieldView::playMove()
93 Animation *move=moves->at(0);
94 QWidget *item=childAt(move->src.topLeft());
97 QPoint p=cell(move->src.left(),move->src.top());
99 QPropertyAnimation *a=move->getAnimation(item);
101 connect(a,SIGNAL(finished()),this,SLOT(playMove()));
107 if(playField->checkSolved())
109 emit solved(playField->moves);
114 void FieldView::playMoves()
119 void FieldView::undo()
123 emit updateMoves(playField->moves);
126 void FieldView::updateWidgets()
128 QList<QWidget *> childs=findChildren<QWidget *>();
129 QListIterator<QWidget *> childsI(childs);
130 while(childsI.hasNext())
132 delete childsI.next();
135 for(int w=0;w<PF::FIELD_WIDTH;w++)
136 for(int h=0;h<PF::FIELD_HEIGHT;h++)
139 int cell=playField->get(w,h);
146 cellW=new QLabel(this);
147 cellW->setPixmap(iconSet.wallIcon());
148 cellW->setGeometry(r);
149 cellW->setFrameStyle(QFrame::NoFrame);
153 cellW=new QLabel(this);
154 cellW->setPixmap(iconSet.icon(cell-2));
155 cellW->setGeometry(r);
156 cellW->setFrameStyle(QFrame::NoFrame);
163 // level should be resetted to show solution!
165 void FieldView::showSolution()
170 solutionTimer=new QTimer(this);
171 solutionTimer->setInterval(500);
172 solutionTimer->setSingleShot(true);
173 connect(this,SIGNAL(animationEnd()),solutionTimer,SLOT(start()));
174 connect(solutionTimer,SIGNAL(timeout()),this,SLOT(playSolutionMove()));
178 void FieldView::stop()
182 disconnect(this,SIGNAL(animationEnd()),solutionTimer,SLOT(start()));
183 solutionTimer->stop();
184 delete solutionTimer;
189 void FieldView::playSolutionMove()
191 if(solutionMove >= playField->solution.size() / 2)
193 //disconnect(solutionTimer,SIGNAL(timeout()),this,SLOT(playSolutionMove()));
194 //connect(solutionTimer,SIGNAL(timeout()),this,SLOT(stop()));
195 puts("no more. stop");
199 // drawn from original
200 char chX=playField->solution.at(solutionMove * 2).toAscii();
201 char chY=playField->solution.at(solutionMove * 2 + 1).toAscii();