Exemple #1
0
/*!
  \internal
  \fn void Animator::draw(QPainter *painter,SelectedItem *item,int width,int height)

  This method can be called by derived classes to draw the SelectedItem for the
  given width and height parameters. It uses the item's SVG renderer, if it can -
  otherwise it attempts to retrieve the pixmap for the selected item.
  The method is intended to be called at each step of the animation, from the
  method animate(...).
*/
void Animator::draw(QPainter *painter,SelectedItem *item,int w,int h)
{
    // Get the GridItem object that is currently associated with the SelectedItem, and
    // find out whether we have a valid renderer we can use to draw it, or whether we
    // must use the pixmap.
    GridItem *currentItem = item->current();
    if ( currentItem ) {
        Renderer *renderer = currentItem->renderer();
        if ( renderer ) {
            draw(painter,renderer,item,w,h);
            return;
        }
        const QPixmap &pixmap = currentItem->selectedPic(); // use the pixmap
        if ( !(pixmap.isNull()) ) {
            draw(painter,pixmap,item,w,h);
        }
    }
}
Exemple #2
0
/*!
  \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);
        }
    }
}