QAbstractAnimation *CardItem::getGoBackAnimation(bool doFade, bool smoothTransition, int duration) { m_animationMutex.lock(); if (m_currentAnimation != NULL) { m_currentAnimation->stop(); delete m_currentAnimation; m_currentAnimation = NULL; } QPropertyAnimation *goback = new QPropertyAnimation(this, "pos"); goback->setEndValue(home_pos); goback->setEasingCurve(QEasingCurve::OutQuad); goback->setDuration(duration); if (doFade) { QParallelAnimationGroup *group = new QParallelAnimationGroup; QPropertyAnimation *disappear = new QPropertyAnimation(this, "opacity"); double middleOpacity = qMax(opacity(), m_opacityAtHome); if (middleOpacity == 0) middleOpacity = 1.0; disappear->setEndValue(m_opacityAtHome); if (!smoothTransition) { disappear->setKeyValueAt(0.2, middleOpacity); disappear->setKeyValueAt(0.8, middleOpacity); disappear->setDuration(duration); } group->addAnimation(goback); group->addAnimation(disappear); m_currentAnimation = group; } else { m_currentAnimation = goback; } m_animationMutex.unlock(); connect(m_currentAnimation, SIGNAL(finished()), this, SIGNAL(movement_animation_finished())); return m_currentAnimation; }
bool DiscardPile::_addCardItems(QList<CardItem*> &card_items, Player::Place place) { _m_mutex_pileCards.lock(); m_visibleCards.append(card_items); int numAdded = card_items.size(); int numRemoved = m_visibleCards.size() - qMax(m_numCardsVisible, numAdded + 1); for (int i = 0; i < numRemoved; i++) { CardItem* toRemove = m_visibleCards.first(); toRemove->setZValue(0.0); toRemove->setHomeOpacity(0.0); connect(toRemove, SIGNAL(movement_animation_finished()), this, SLOT(_destroyCard())); toRemove->goBack(true); m_visibleCards.removeFirst(); } foreach (CardItem* card_item, m_visibleCards) { card_item->setHomeOpacity(0.7); }
void TablePile::clear(bool playAnimation) { if (m_visibleCards.empty()) return; _m_mutex_pileCards.lock(); // check again since we just gain the lock. int shift = 1 * G_COMMON_LAYOUT.m_cardNormalWidth; QParallelAnimationGroup* group = new QParallelAnimationGroup; foreach (CardItem* toRemove, m_visibleCards) { toRemove->setZValue(0.0); toRemove->setHomeOpacity(0.0); toRemove->setHomePos(QPointF(toRemove->x() - shift, toRemove->y())); if (playAnimation) { connect(toRemove, SIGNAL(movement_animation_finished()), this, SLOT(_destroyCard())); group->addAnimation(toRemove->getGoBackAnimation(true)); } else delete toRemove; }