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()));
106 if(playField->checkSolved() && !inSolution)
108 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 connect(solutionTimer,SIGNAL(timeout()),this,SLOT(playSolutionMove()));
175 void FieldView::stop()
177 disconnect(this,SIGNAL(animationEnd()),this,SLOT(playSolutionMove()));
180 solutionTimer->stop();
181 delete solutionTimer;
187 void FieldView::playSolutionMove()
189 // drawn from original
190 char chX=playField->solution.at(solutionMove * 2).toAscii();
191 char chY=playField->solution.at(solutionMove * 2 + 1).toAscii();
207 if(x<0 || x>PF::FIELD_WIDTH || y<0 || y>PF::FIELD_HEIGHT)
214 solutionTimer->start(500);