/*! \internal \fn void Bouncer::animate(QPainter *painter,SelectedItem *item,qreal percent) */ void Bouncer::animate(QPainter *painter,SelectedItem *item,qreal percent) { GridItem *currentItem = item->current(); if ( !currentItem ) { return; } int imageSize = currentItem->selectedImageSize(); // Create an oscillator which will produce a sin wave whose lower bound is the // first parameter (i.e. the lowest dimension the image will take, and whose // upper bound is the second parameter (i.e. the highest dimension the image // will take). Oscillator oscillator(imageSize + minVariation * imageSize, imageSize + maxVariation * imageSize, frameMax, // upper bound of x SPEED_FACTOR, imageSize); // Ask the oscillator to produce a suitable width/height value for this stage // of the animation. int y = qRound(oscillator(percent*frameMax)); if (((y-imageSize) % 2) != 0) { y -= 1; } painter->setRenderHint(QPainter::SmoothPixmapTransform); //lazy man's version of mipmapping if (y > imageSize) { if (!bigpixmap.isNull()) draw(painter,bigpixmap,item,y,y); } else { const QPixmap &pixmap = currentItem->selectedPic(); if ( !(pixmap.isNull()) ) { draw(painter,pixmap,item,y,y); } } }
/*! \internal \fn QRectF Animator::renderingBounds(QGraphicsRectItem *item,int width,int height) Returns the geometry for the renderer, i.e. position, width and height. */ QRectF Animator::renderingBounds(QGraphicsRectItem *item,int w,int h) { // Position the image in the middle of the drawing area. qreal x = item->rect().x(); qreal y = item->rect().y(); x += (item->rect().width() - w)/2; y += (item->rect().height() - h)/2; { // TODO: this is a workaround. not casting to ints at // higher levels (GridItem, SelectedItem, etc) would be better solution. GridItem *currentItem = ((SelectedItem*)item)->current(); if ( !currentItem ) { return QRectF(); } int imageSize = currentItem->selectedImageSize(); qreal xoffset = (static_cast<int>(item->rect().width()) - imageSize)/2 - (item->rect().width() - imageSize)/2; qreal yoffset = (static_cast<int>(item->rect().height()) - imageSize)/2 - (item->rect().height() - imageSize)/2; x += xoffset; y += yoffset; } return QRectF(x,y,w,h); }