Esempio n. 1
0
void KDiamond::Board::slotAnimationFinished()
{
	if (m_runningAnimations.isEmpty())
		return;
	//static_cast is enough, no need for a qobject_cast
	//because result pointer is never dereferenced here
	m_runningAnimations.removeAll(static_cast<QAbstractAnimation*>(sender()));
	if (m_runningAnimations.isEmpty())
		emit animationsFinished();
}
Esempio n. 2
0
void PieceWidget::animate()
{
    bool doAnimation = false;

    int i;
    PiecePosition *p;
    int xReal, yReal;

    int w = width(), h = height();

    for(i=0;i<MAX_POSITION;i++) {
	p = positions.at(i);
	if (p==0) continue;

	if (p->actType == ANIMATION_STOPPED ||
	    p->actAnimation ==0) continue;

	p->actStep += p->actDir;
	if (p->actStep <= -1) {
	    p->actDir = 1;
	    p->actStep = 1;
	    doAnimation = true;
	}
	else if (p->actStep >= p->actAnimation->steps) {
	    if (p->actType == ANIMATION_CYCLE) {
		p->actDir = -1;
		p->actStep = p->actAnimation->steps -2;
		doAnimation = true;
	    }
	    else if (p->actType == ANIMATION_LOOP) {
		p->actStep = 1; /*skip first frame for smooth animation */
		doAnimation = true;
	    }
	    else {
		p->actType = ANIMATION_STOPPED;
		p->actAnimation = 0;
		emit animationFinished(i);
	    }
	}
	else {
	    doAnimation = true;
	}

	xReal = (w + p->x * realSize / 500 - Piece::w() )/2;
	yReal = (h + p->y * realSize / 500 - Piece::h() )/2;

	if (p->actAnimation==0 || p->actStep==-1) {
	    if (p->def !=0 )
		update( xReal, yReal, Piece::w()+1, Piece::h()+1);
	}
	else
	    update( xReal, yReal, Piece::w()+1, Piece::h()+1);

    }
    if (!doAnimation) {
	isRunning = false;
	emit animationsFinished();
    }
    else {
	timer->setSingleShot(true);
	timer->start(1000/freq);
    }
}