X-Git-Url: http://git.maemo.org/git/?p=vexed;a=blobdiff_plain;f=fieldview.cpp;fp=fieldview.cpp;h=2ccb7574507b30c5b72ccdd1217d9b8eb3d680a3;hp=0000000000000000000000000000000000000000;hb=287af054a087505036ec2658fcafc0dac2464eee;hpb=38dba1fd735443036b9d1bc33cd5a9f1f3882530;ds=sidebyside diff --git a/fieldview.cpp b/fieldview.cpp new file mode 100644 index 0000000..2ccb757 --- /dev/null +++ b/fieldview.cpp @@ -0,0 +1,150 @@ +#include +#include +#include + +#include "playfield.h" +#include "fieldview.h" + +FieldView::FieldView(QWidget *parent) : + QWidget(parent) +{ + selX=-1; + selY=-1; + moving=false; + moves=new QList(); + playField=0; + +} + +void FieldView::mousePressEvent(QMouseEvent *event) +{ + QPoint sel=cell(event->pos()); + + selX=sel.x(); + selY=sel.y(); + moveX=-1; + moveY=-1; + moving=true; + update(); +} + +void FieldView::mouseReleaseEvent(QMouseEvent *event) +{ + if(moving) + { + moving=false; + QPoint mov=cell(event->pos()); + moveX=mov.x(); + moveY=mov.y(); + if(moveX==selX && moveY==selY) + { + moveX=-1; + return; + } + } + delete moves; + moves=new QList(); + playField->move(selX, selY, moveX); + playMoves(); + emit updateMoves(playField->moves); +} + +PlayField* FieldView::setPlayField(PlayField *pf) +{ + if(playField) + { + delete playField; + } + playField = new PlayField(pf); + QObject::connect(playField,SIGNAL(cellMoved(int,int,int,int)),this,SLOT(cellMoved(int,int,int,int))); + QObject::connect(playField,SIGNAL(cellGone(int,int)),this,SLOT(cellGone(int,int))); + + updateWidgets(); + show(); + emit updateMoves(playField->moves); + return playField; +} + +void FieldView::cellMoved(int w, int h, int wnew, int hnew) +{ + QRect c=coo(w,h); + QRect cnew=coo(wnew,hnew); + moves->append(new Move(c,cnew)); +} +void FieldView::cellGone(int w, int h) +{ + QRect c=coo(w,h); + moves->append(new Hide(c)); +} +QWidget* FieldView::cellWidget(int w, int h) +{ + return childAt(coo(w,h).topLeft()); +} +void FieldView::playMove() +{ + if(moves->size()>0) + { + Animation *move=moves->at(0); + QWidget *item=childAt(move->src.topLeft()); + if(!item) + { + QPoint p=cell(move->src.left(),move->src.top()); + } + QPropertyAnimation *a=move->getAnimation(item); + moves->removeAt(0); + connect(a,SIGNAL(finished()),this,SLOT(playMove())); + a->start(); + delete move; + } else if(playField->checkSolved()) + { + emit solved(playField->moves); + } +} + +void FieldView::playMoves() +{ + playMove(); +} + +void FieldView::undo() +{ + playField->undo(); + updateWidgets(); + emit updateMoves(playField->moves); +} + +void FieldView::updateWidgets() +{ + QList childs=findChildren(); + QListIterator childsI(childs); + while(childsI.hasNext()) + { + delete childsI.next(); + } + + for(int w=0;wget(w,h); + QLabel *cellW; + switch(cell) + { + case PF::CELL_EMPTY: + break; + case PF::CELL_WALL: + cellW=new QLabel(this); + cellW->setPixmap(iconSet.wallIcon()); + cellW->setGeometry(r); + cellW->setFrameStyle(QFrame::NoFrame); + cellW->show(); + break; + default: + cellW=new QLabel(this); + cellW->setPixmap(iconSet.icon(cell-2)); + cellW->setGeometry(r); + cellW->setFrameStyle(QFrame::NoFrame); + cellW->show(); + } + } +}