Exemple #1
0
/*!
  \internal
  \fn void PhoneLauncherView::resizeEvent(QResizeEvent *event)
  Resizes all the scene objects, relative to the new size of this view.
*/
void PhoneLauncherView::resizeEvent(QResizeEvent *event)
{
    scene->setSceneRect(0,0,event->size().width(),event->size().height());

    if ( !selectedItem ) {
        return;
    }

    // Get the width and height of each item.
    int itemWidth;
    int itemHeight;
    itemDimensions(&itemWidth,&itemHeight);

    // Loop through all the GridItem objects and reset their sizes.
    for ( int row = 0; row < m_rows; row++ ) {
        for ( int col = 0; col < m_columns; col++ ) {
            GridItem *item = selectedItem->item(row,col);
            if ( !item ) {
                // Create and add an empty content for this row and column.
                item = createItem(0,row,col);
            }

            // Calculate the item's position in the scene.
            int x = col * itemWidth;
            int y = row * itemHeight;
            item->setRect(x,y,itemWidth,itemHeight);
        }
    }

    // Ask the SelectedItem to also recalculate its size.
    selectedItem->resize();

    QGraphicsView::resizeEvent(event);
}
Exemple #2
0
/*!
  \internal
  \fn QContent *PhoneLauncherView::itemAt(const QPoint &point) const
  Returns the QContent object that resides at the given pixel position.
*/
QContent *PhoneLauncherView::itemAt(const QPoint &point) const
{
    QContent *ret = 0;
    GridItem *gridItem = gridItemAt(point);
    if (gridItem) {
        ret = gridItem->content();
    }
    return ret;
}
Exemple #3
0
/*!
  \internal
  \fn QContent *PhoneLauncherView::itemAt(int row, int column) const
  Returns the QContent object that resides at the given row and column.
*/
QContent *PhoneLauncherView::itemAt(int row, int column) const
{
    QContent *ret = 0;
    GridItem *gridItem = gridItemAt(row, column);
    if (gridItem) {
        ret = gridItem->content();
    }
    return ret;
}
Exemple #4
0
/*!
  \fn QContent *PhoneLauncherView::currentItem() const
  Returns the content information for the current GridItem object, or 0 if no item is current.
*/
QContent *PhoneLauncherView::currentItem() const
{
    GridItem *currentItem = currentGridItem();
    if ( currentItem ) {
        return currentItem->content();
    } else {
        return 0;
    }
}
Exemple #5
0
/*!
  \internal
*/
void PhoneLauncherView::changeEvent(QEvent *e)
{
    if (e->type() == QEvent::PaletteChange && selectedItem) {
        for ( int row = 0; row < m_rows; row++ ) {
            for ( int col = 0; col < m_columns; col++ ) {
                GridItem *item = selectedItem->item(row,col);
                if ( item )
                    item->paletteChanged();
            }
        }
        selectedItem->paletteChanged();
    } else if (e->type() == QEvent::StyleChange) {
        //icons may have changed size
        updateImages();
    }
}
Exemple #6
0
/*!
  \internal
  \fn void SelectedItem::updateImages()
  Updates all the Pixmaps for all the GridItem objects.
*/
void SelectedItem::updateImages()
{
    // The images have changed. First, get the SelectedItem to disconnect from the movie.
    detachAnimation();

    // Get all the GridItem objects to rebuild their pixmaps.
    for ( int row = 0; row <= table.topRow(); row++ ) {
        for ( int col = 0; col <= table.topColumn(); col++ ) {
            GridItem *item = table.item(row,col);
            if ( item ) {
                item->updateImages();
            }
        }
    }

    // SelectedItem now has to grab the revised movie.
    resetAnimation();
}
Exemple #7
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 #8
0
/*!
  \fn void PhoneLauncherView::addItem(QContent* content, int pos)
  Creates a new GridItem object and adds it to the scene, or else updates the GridItem
  at the given position, if it already exists. When a new GridItem object is added,
  its position and size will be calculated and set in response to resizeevent(...).
  When an existing GridItem object is modified, its position and size do not
  change in response to \a content -- position and size are determined by other factors,
  such as the size of the view and the current resolution.

  \a content: Contains information to be used by the GridItem object, such as the
  Icon used to display it, the name of its underlying application, etc.
  \a pos: The index of the GridItem object, which will be converted into a
  row and a column position.
*/
void PhoneLauncherView::addItem(QContent* content, int pos)
{
    if ( !selectedItem ) {
        qWarning("PhoneLauncherView::addItem(...): Could not add GridItem for pos %d - no selected item.",pos);
        return;
    }

    // Calculate row and column from pos.
    int row, column;
    rowAndColumn(pos,row,column);

    GridItem *item = 0;
    if ( (item = selectedItem->item(row,column)) ) {
        // Already have an item for that row and column. That means we need to update it, not
        // create it.
        item->setContent(content);
        scene->update();
    } else {
        // Create the new GridItem object.
        createItem(content,row,column);
    }
}
Exemple #9
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);
        }
    }
}
Exemple #10
0
/*!
  \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);
}
Exemple #11
0
void Plot::populate()
{
    GridItem *gridItem = new GridItem();
#if 0
    gridItem->setOrientations( Qt::Horizontal );
#endif
    gridItem->attach( this );

    const Qt::GlobalColor colors[] =
    {
        Qt::red,
        Qt::blue,
        Qt::darkCyan,
        Qt::darkMagenta,
        Qt::darkYellow
    };

    const int numColors = sizeof( colors ) / sizeof( colors[0] );

    for ( int i = 0; i < QuoteFactory::NumStocks; i++ )
    {
        QuoteFactory::Stock stock = static_cast<QuoteFactory::Stock>( i );

        QwtPlotTradingCurve *curve = new QwtPlotTradingCurve();
        curve->setTitle( QuoteFactory::title( stock ) );
        curve->setOrientation( Qt::Vertical );
        curve->setSamples( QuoteFactory::samples2010( stock ) );

        // as we have one sample per day a symbol width of
        // 12h avoids overlapping symbols. We also bound
        // the width, so that is is not scaled below 3 and
        // above 15 pixels.

        curve->setSymbolExtent( 12 * 3600 * 1000.0 );
        curve->setMinSymbolWidth( 3 );
        curve->setMaxSymbolWidth( 15 );

        const Qt::GlobalColor color = colors[ i % numColors ];

        curve->setSymbolPen( color );
        curve->setSymbolBrush( QwtPlotTradingCurve::Decreasing, color );
        curve->setSymbolBrush( QwtPlotTradingCurve::Increasing, Qt::white );
        curve->attach( this );

        showItem( curve, true );
    }

    for ( int i = 0; i < 2; i++ )
    {
        QwtPlotMarker *marker = new QwtPlotMarker();

        marker->setTitle( QString( "Event %1" ).arg( i + 1 ) );
        marker->setLineStyle( QwtPlotMarker::VLine );
        marker->setLinePen( colors[ i % numColors ], 0, Qt::DashLine );
        marker->setVisible( false );

        QDateTime dt( QDate( 2010, 1, 1 ) );
        dt = dt.addDays( 77 * ( i + 1 ) );
        
        marker->setValue( QwtDate::toDouble( dt ), 0.0 );

        marker->setItemAttribute( QwtPlotItem::Legend, true );

        marker->attach( this );
    }

    // to show how QwtPlotZoneItem works

    ZoneItem *zone1 = new ZoneItem( "Zone 1");
    zone1->setColor( Qt::darkBlue );
    zone1->setInterval( QDate( 2010, 3, 10 ), QDate( 2010, 3, 27 ) );
    zone1->setVisible( false );
    zone1->attach( this );

    ZoneItem *zone2 = new ZoneItem( "Zone 2");
    zone2->setColor( Qt::darkMagenta );
    zone2->setInterval( QDate( 2010, 8, 1 ), QDate( 2010, 8, 24 ) );
    zone2->setVisible( false );
    zone2->attach( this );

}