bool ChicaneCardGame::mousePressCard( Card *card, QPoint p ) { Q_UNUSED(p); CanvasCard *item = (CanvasCard *)card; if (item->isFacing() != TRUE) { // From facedown stack if ((item->x() == 2) && ((int)item->y() == 10)) { // Deal a row of 8 cards // Move 8 cards, one to each workingPile beginDealing(); for (int i=0; i<8 && faceDownDealingPile->cardOnTop(); i++) { CanvasCard *card = (CanvasCard *)faceDownDealingPile->cardOnTop(); card->setZ(highestZ); highestZ++; faceDownDealingPile->removeCard(card); workingPiles[i]->addCardToTop(card); card->setCardPile( workingPiles[i] ); card->setFace(FALSE); QPoint p = workingPiles[i]->getCardPos(card); card->flipTo( p.x(), p.y() ); } endDealing(); } moving = NULL; moved = FALSE; return TRUE; } else if ( !card->getCardPile()->isAllowedToBeMoved(card) ) { // Don't allow unclean columns to be moved moving = NULL; return TRUE; } return FALSE; }
void CanvasPlayer::position() { int x = 0, y = 0; int num = 0; int w = m_scene->width(); int h = m_scene->height(); int offsetl = 0; //Hiermit kann man am linken Rand Platz schaffen fuer z.B. ein Bild des Spielers (Netzwerkmodus). int availw = m_scene->width() - 2*DIST - offsetl; int cardw = Card::backgroundPixmap()->width(); int cardh = Card::backgroundPixmap()->height(); float cardoverlap = 1./8.; //Ueberlapp der Karten im Verhaeltnis zur Kartenbreite for( unsigned int z = 0; z < NUMCARDS; z++ ) { CanvasCard* card = m_items[z]; if(card->isVisible()) num++; } if(!Settings::instance()->rearrangeCards()) num=NUMCARDS; if(m_position==1||m_position==3) qSwap( cardw, cardh ); switch( m_position ) { case 0: if(availw>num*cardw+(num-1)) x=(w-cardw*num)/2-(num-1)/2-offsetl; else x=DIST+offsetl; y=h-cardh-DIST; m_name->setPos( (w-m_name->sceneBoundingRect().width())/2, y-m_name->sceneBoundingRect().height() ); break; case 1: x=DIST; y=(h-((cardh*cardoverlap)*(num-1)+cardh))/2; m_name->setPos(x,y-m_name->sceneBoundingRect().height()); break; case 2: x=( w-( (cardw*cardoverlap)*(num-1)+cardw ) )/2; //berechnet die Position der linken Seite des Kartenstapels y=DIST; m_name->setPos( (w-m_name->sceneBoundingRect().width())/2, y+cardh ); break; case 3: default: x=w-cardw-DIST; y=(h-((cardh*cardoverlap)*(num-1)+cardh))/2; m_name->setPos(x, y-m_name->sceneBoundingRect().height()); break; } for( unsigned int z = 0; z < NUMCARDS; z++ ) { CanvasCard* card = m_items[z]; // only move if necessary! if(card->isVisible() || !Settings::instance()->rearrangeCards()) { if( x != card->x() || y != card->y() ) { if(num==NUMCARDS) card->setPos( x, y ); else { card->setDestination( x, y ); card->animatedMove(); } } if(m_position==0) { if(availw>num*cardw+(num-1)) x += cardw+1; else x += (availw-cardw)/(num-1); } else { if(m_position==2) x += (cardw*cardoverlap); else y += (cardh*cardoverlap); } } } // swap them back if(m_position==1||m_position==3) qSwap( cardw, cardh ); }