Exemple #1
0
void Background::initSprite()
{
	_sprite = new QGraphicsWidget();
	_sprite->resize(BACKGROUND_W, BACKGROUND_H);
	_sprite->setFlags(QGraphicsItem::ItemClipsChildrenToShape);

	QGraphicsRectItem* rect;
	QGraphicsWidget* widget;

	// Background Layer 1
	widget = new QGraphicsWidget();
	widget->setParentItem(_sprite);
	widget->setPos(0.0f, -ROW_H);
	_sprite_bg << widget;

	// Background Solid 1
	rect = new QGraphicsRectItem(0.0f, 0.0f, BACKGROUND_W, BACKGROUND_H * 2.0f);
	rect->setBrush(QBrush(QColor::fromRgb(0x00, 0x80, 0xC0)));
	rect->setParentItem(widget);

	// Background Noise 1
	rect = new QGraphicsRectItem(0.0f, 0.0f, BACKGROUND_W + ROW_H, BACKGROUND_H * 2.0f);
	rect->setBrush(QBrush(LoaderThread::instance()->getCachedPixmap(IMAGE_NOISE).scaled(TEXTURE_W, TEXTURE_H)));
	rect->setParentItem(widget);
	rect->setPos(-(ROW_H * 0.5f), 0.0f);

	// Background Layer 2
	widget = new QGraphicsWidget();
	widget->setParentItem(_sprite);
	widget->setPos(0.0f, 0.0f);
	_sprite_bg << widget;

	// Background Solid 2
	rect = new QGraphicsRectItem(0.0f, 0.0f, BACKGROUND_W, BACKGROUND_H * 2.0f);
	rect->setBrush(QBrush(QColor::fromRgb(0x00, 0x80, 0xC0)));
	rect->setParentItem(widget);

	// Background Noise 2
	rect = new QGraphicsRectItem(0.0f, 0.0f, BACKGROUND_W + ROW_H, BACKGROUND_H * 2.0f);
	rect->setBrush(QBrush(LoaderThread::instance()->getCachedPixmap(IMAGE_NOISE).scaled(TEXTURE_W, TEXTURE_H)));
	rect->setParentItem(widget);
	rect->setPos(-(ROW_H * 0.5f), 0.0f);

	// Fence
	rect = new QGraphicsRectItem(0.0f, 0.0f, BACKGROUND_W, BACKGROUND_H + ROW_H);
	rect->setBrush(QBrush(LoaderThread::instance()->getCachedPixmap(IMAGE_FENCE)));
	rect->setParentItem(_sprite);
	rect->setPos(0.0f, -(ROW_H * 0.5f));

	// Background Gradient
	rect = new QGraphicsRectItem(0.0f, 0.0f, BACKGROUND_W, BACKGROUND_H);
	rect->setBrush(QBrush(LoaderThread::instance()->getCachedPixmap(IMAGE_COVER_BG)));
	rect->setParentItem(_sprite);
	
	// Foreground Gradient
	rect = new QGraphicsRectItem(0.0f, 0.0f, BACKGROUND_W, BACKGROUND_H);
	rect->setBrush(QBrush(LoaderThread::instance()->getCachedPixmap(IMAGE_COVER_FG)));
	rect->setParentItem(_sprite);
}
Exemple #2
0
int main(int argc, char **argv)
{
	QApplication app(argc, argv);
        qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
//        qsrand(1);
        srand(time(0));
//        srand(1);

        int screenWidth = 600;
        int screenHeight = 300;
	CopsScene scene;
        scene.setBackgroundBrush(Qt::black);
        scene.setSceneRect(0, 0, screenWidth, screenHeight);
	scene.setItemIndexMethod(QGraphicsScene::NoIndex);

	Cops *helicops = new Cops();
        helicops->setPos(50, 50);
	scene.addItem(helicops);

        QGraphicsRectItem *downRect = new QGraphicsRectItem(0, 0, screenWidth, 10);
        downRect->setBrush(Qt::green);
        downRect->setPos(0,screenHeight - 10);
        scene.addItem(downRect);

        QGraphicsRectItem *upRect = new QGraphicsRectItem(0, 0, screenWidth, 10);
        upRect->setBrush(Qt::green);
        upRect->setPos(0,0);
        scene.addItem(upRect);

        Barrier *barrier = new Barrier(0, 0, 20, 70);
        barrier->setBrush(Qt::green);
        barrier->setPos(400, 100);
        scene.addItem(barrier);

	QGraphicsView view(&scene);
        view.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
        view.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
	view.setRenderHint(QPainter::Antialiasing);
	view.setCacheMode(QGraphicsView::CacheBackground);
	view.setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);
	view.setDragMode(QGraphicsView::ScrollHandDrag);
	view.setWindowTitle(QT_TRANSLATE_NOOP(QGraphicsView, "Helicops!"));
        view.resize(screenWidth + 20, screenHeight + 20);
	view.show();

	return app.exec();
}
Exemple #3
0
Pong::Pong() {
    // players
    player1 = new QGraphicsRectItem(0, 0, PADDLE, PADDLE * 3);
    player1->setPos(PADDLE, (HEIGHT - PADDLE * 3) / 2);
    player1->setBrush(QBrush(Qt::gray));
    addItem(player1);
    player2 = new QGraphicsRectItem(0, 0, PADDLE, PADDLE * 3);
    player2->setPos(WIDTH - PADDLE * 2, (HEIGHT - PADDLE * 3) / 2);
    player2->setBrush(QBrush(Qt::gray));
    addItem(player2);

    // ball
    ball = new QGraphicsEllipseItem(0, 0, PADDLE, PADDLE);
    ball->setPos((WIDTH - PADDLE) / 2, (HEIGHT - PADDLE) / 2);
    ball->setBrush(QBrush(Qt::gray));
    addItem(ball);

    // score
    tscore1 = new QGraphicsSimpleTextItem();
    tscore1->setText("0");
    tscore1->setFont(QFont("Times", 36, QFont::Bold));
    tscore1->setPos(WIDTH / 2 - PADDLE - 24, PADDLE);
    tscore1->setBrush(QBrush(Qt::gray));
    addItem(tscore1);
    tscore2 = new QGraphicsSimpleTextItem();
    tscore2->setText("0");
    tscore2->setFont(QFont("Times", 36, QFont::Bold));
    tscore2->setPos(WIDTH / 2 + PADDLE, PADDLE);
    tscore2->setBrush(QBrush(Qt::gray));
    addItem(tscore2);

    // line
    int h = 0;
    int pointSize = PADDLE / 4;
    while (h < HEIGHT) {
        QGraphicsRectItem *linePoint = new QGraphicsRectItem(0, 0, pointSize, pointSize);
        linePoint->setBrush(QBrush(Qt::gray));
        linePoint->setPos((WIDTH - pointSize) / 2, h);
        addItem(linePoint);
        h += pointSize * 2;
    }

    score1 = 0;
    score2 = 0;
    dx = -1;
    dy = -1;
    speedUpCounter = 0;
    ballSpeed = 0.2;
    setSceneRect(0, 0, WIDTH, HEIGHT);
    setBackgroundBrush(QBrush(Qt::black));

    QTimeLine *timer = new QTimeLine();
    timer->setFrameRange(0, 100);
    timer->setLoopCount(10000);
    timer->start();

    connect(timer, SIGNAL(frameChanged(int)), this, SLOT(value_changed(int)));
}
Exemple #4
0
void CanvasNavigator::updateMarkers()
{
    MarkerList* markers = song->marker();
    for (iMarker m = markers->begin(); m != markers->end(); ++m)
    {
        QPointF point(calcSize(m->second.tick()), 0.0);
        QGraphicsRectItem* marker = m_markers.value(m->second.id());
        if(marker)
            marker->setPos(point);
    }
}
/// Fills the specified cell.
///
/// Marks it filled in the pathingMap_ and draws a gray square to visually
/// represent it.
void Game::fill( int x,  int y){
    pathingMap_.fillCell(x,y);

    // draw rectangle
    QGraphicsRectItem* rect = new QGraphicsRectItem(0,0,cellSize_,cellSize_);
    rect->setPos(x*cellSize_,y*cellSize_);
    QBrush brush;
    brush.setColor(Qt::gray);
    brush.setStyle(Qt::SolidPattern);
    rect->setBrush(brush);
    scene_->addItem(rect);
}
Exemple #6
0
void ViewScene::drawTile(r2d2::Box box,QColor color){
    QRectF tempRect = box_tile_2_qrect(box);
    QGraphicsRectItem *block = new QGraphicsRectItem;
    block->setBrush(* new QBrush(color));
    //check current draw outline state
    if(!outlined){
        block->setPen(Qt::NoPen);
    }
    block->setRect(0,0,tempRect.width(),tempRect.height());
    block->setPos(tempRect.x(),tempRect.y());
    block->setVisible(true);
    addItem(block);
}
void MainWindow::slotAddRectItem()      //在场景中加入一个长方形图元
{
    QGraphicsRectItem *item = new QGraphicsRectItem(QRectF(0,0,60,60));
    QPen pen;
    pen.setWidth(3);
    pen.setColor(QColor(qrand()%256,qrand()%256,qrand()%256));
    item->setPen(pen);
    item->setBrush(QColor(qrand()%256,qrand()%256,qrand()%256));
    item->setFlag(QGraphicsItem::ItemIsMovable);

    scene->addItem(item);
    item->setPos((qrand()%int(scene->sceneRect().width()))-200,(qrand()%int(scene->sceneRect().height()))-200);
}
Exemple #8
0
    void DesktopView::addCoreExtension(const QString& name)
    {

        d->widgets = static_cast<WidgetPlugin*>(PluginLoader::getInstance()->instance(name));
        if (d->widgets) {
            QGraphicsRectItem  * widget = (QGraphicsRectItem*) d->widgets->item();
            if (widget) {
                scene()->addItem(widget);
                widget->setPos(d->row,d->column);
                d->row += widget->boundingRect().width();
            }
        }

    }
void 
DataVisualizer::draw(SceneType scene, qreal& lastXPos, Element::Ptr e, int propertyIndex)
{
	if (e.isNull()) return;

	// see if item should be drawn
	Element::Property p(Element::getProperty(propertyIndex));
	Element::PropertyType type(Element::propertyType(p));
	Element::PropertyVariant var(e->propertyConst(p));

	if (p == Element::NUCLEONS_PROPERTY && !e->isIsotope()) return;
	if (!Element::isValidVariant(var)) return;

	// build the text item
	QGraphicsItem * item(0);
	QGraphicsTextItem * text = new QGraphicsTextItem();
	text->setHtml( getLinkText(*e) + "<br>" +
		mMainWindow->toString(var));
	text->setTextInteractionFlags(Qt::TextBrowserInteraction);
	text->setToolTip(tr("formattedFormulaToolTip"));
	connect(text, SIGNAL(linkActivated(const QString&)), 
		this, SLOT(emitElementLinkActivated(const QString&)));
	item = text;

	// build the encapsulating box item
	QGraphicsRectItem * rect = new QGraphicsRectItem(
		item->boundingRect() );
	rect->setBrush(QBrush(QColor(196, 255, 196)));

	// combine both and add them to the scene
	item->setParentItem(rect);
	scene->addItem(rect);

	QPointF pos(boost::apply_visitor(DrawingPositionFromPropertyVariant(), var));
	if (type == Element::COMPLEX_TYPE ||
	    type == Element::STRING_TYPE) {
		// no stacking for 2D drawing
		// item positions are stretched in X direction
		if (lastXPos > pos.x()) {
		       	pos.setX(lastXPos);
		}
		rect->setPos(pos);
		// update drawing position for the next item
		lastXPos = pos.x() + rect->boundingRect().width() + itemMargin;
	} else {
		setItemPos(rect, pos);
	}
}
Exemple #10
0
QGraphicViewDm::QGraphicViewDm(QWidget *parent) :
    QGraphicsView(parent)
{
    int iWidth , iHeight ;
//    iWidth = width( );
//    iHeight = height( );

    iWidth = 600 ;
    iHeight = 230 ;

    QGraphicsScene *scene = new QGraphicsScene(this);
    scene->setSceneRect(-iWidth/2,-iHeight/2,iWidth,iHeight);
    setScene(scene);
    setCacheMode(CacheBackground);

    //加一个矩形
    QRectF r = QRectF(-iWidth/2,-iHeight/2,iWidth,iHeight);
//    qDebug( ) <<  r.topLeft() << r.bottomRight() ;

    QRectF r1  = r.adjusted( 20, 20, -20, -20 );
//    qDebug( ) <<  r1.topLeft() << r1.bottomRight() ;

    QGraphicsRectItem * pRect = scene->addRect( r1 );  //创建用的是对象座标
    pRect->setPos( 0, 0 );    //给的是场景座标

    pItemDm = new ItemDm ;

    // 4/5 的宽度  2/3的高度
    float  fAdjust1, fAdjust2 ;

    fAdjust1 = 1.0 / 10.0 * iWidth  ;
    fAdjust2 = 1.0 / 6.0 * iHeight  ;

//    qDebug( ) << fAdjust1 << fAdjust2 << r.adjusted( fAdjust1 , fAdjust2, -1*fAdjust1, -1*fAdjust2 ) ;
    pItemDm->init( r.adjusted( fAdjust1 , fAdjust2, -1*fAdjust1, -1*fAdjust2 ) );
    pItemDm->setWater( 1250.00 );

    scene->addItem( pItemDm );
    pItemDm->setPos( 0, 0 );

    //制作
    QRectF  rectFish( 0, 0, 15, 5 );
    pFish = scene->addEllipse( rectFish );
    pFish->setPos( 0, 0 );
    //pFish->setBrush( QBrush(Qt::red) );
    pFish->setBrush( QBrush(Qt::green) );

}
void DivePictureItem::setPixmap(const QPixmap &pix)
{
	DivePixmapItem::setPixmap(pix);
	QRectF r = boundingRect();
	QGraphicsRectItem *rect = new QGraphicsRectItem(0 - 10, 0 -10, r.width() + 20, r.height() + 20, this);
	rect->setPen(Qt::NoPen);
	rect->setBrush(QColor(Qt::white));
	rect->setFlag(ItemStacksBehindParent);
	rect->setZValue(-1);

	QGraphicsRectItem *shadow = new QGraphicsRectItem(rect->boundingRect(), this);
	shadow->setPos(5,5);
	shadow->setPen(Qt::NoPen);
	shadow->setBrush(QColor(Qt::lightGray));
	shadow->setFlag(ItemStacksBehindParent);
	shadow->setZValue(-2);
}
Exemple #12
0
void ViewerWidget::load(const QByteArray &data)
{
    scene->clear();
    QList<QGraphicsItem *> items;
    QPixmap pixmap;
    if (pixmap.loadFromData(data)) {
        items << new QGraphicsPixmapItem(pixmap);
    }
    else if (data.startsWith("%PDF")) {
        fz_stream *stream = fz_open_memory(context, (unsigned char *)data.constData(), data.length());
        fz_document *doc = fz_open_document_with_stream(context, ".pdf", stream);
        fz_close(stream);
        int pagecount = fz_count_pages(doc);
        for (int i = 0; i < pagecount; i++) {
            fz_page *page = fz_load_page(doc, i);
            fz_rect bounds;
            fz_bound_page(doc, page, &bounds);
            fz_display_list *list = fz_new_display_list(context);
            fz_device *dev = fz_new_list_device(context, list);
            fz_run_page(doc, page, dev, &fz_identity, NULL);
            fz_free_device(dev);
            fz_free_page(doc, page);
            PageItem *item = new PageItem(context, list, bounds.x1 - bounds.x0, bounds.y1 - bounds.y0);
            item->setCacheMode(QGraphicsItem::DeviceCoordinateCache);
            items << item;
        }
        fz_close_document(doc);
    } else {
        scene->setSceneRect(0, 0, 0, 0);
        return;
    }
    int top = 0;
    QPen outline(Qt::lightGray, 2, Qt::SolidLine, Qt::SquareCap, Qt::MiterJoin);
    outline.setCosmetic(true);
    foreach (QGraphicsItem *item, items) {
        QGraphicsRectItem *rim = new QGraphicsRectItem(item->boundingRect());
        item->setPos(0, top);
        rim->setPos(0, top);
        rim->setPen(outline);
        rim->setBrush(Qt::NoBrush);
        scene->addItem(rim);
        scene->addItem(item);
        top += item->boundingRect().height() + SPACING;
    }
void ProfileGraphicsView::plot_pp_text()
{
    double pp, dpp, m;
    int hpos;
    static text_render_options_t tro = {PP_TEXT_SIZE, PP_LINES, LEFT, MIDDLE};
    QGraphicsRectItem *pressureMarkers = new QGraphicsRectItem();

    setup_pp_limits(&gc);
    pp = floor(gc.pi.maxpp * 10.0) / 10.0 + 0.2;
    dpp = pp > 4 ? 1.0 : 0.5;
    hpos = gc.pi.entry[gc.pi.nr - 1].sec;
    QColor c = getColor(PP_LINES);

    for (m = 0.0; m <= pp; m += dpp) {
        QGraphicsLineItem *item = new QGraphicsLineItem(SCALEGC(0, m), SCALEGC(hpos, m));
        QPen pen(defaultPen);
        pen.setColor(c);
        item->setPen(pen);
        scene()->addItem(item);
        plot_text(&tro, QPointF(hpos, m), QString::number(m), pressureMarkers);
    }
    scene()->addItem(pressureMarkers);
    pressureMarkers->setPos(pressureMarkers->pos().x() + 10, 0);
}
Exemple #14
0
void B2WorldView::createWorldItems()
{
    qDebug() << "~ " << __PRETTY_FUNCTION__;

    if(_world && _scene) {

        // create world ground

        QGraphicsRectItem *groundItem = _scene->addRect(-100, -0.5, 200, 1);
        groundItem->setBrush(Qt::gray);
        groundItem->setPos(0, -0.5);

        // ground body define
        b2BodyDef groundBD;
        groundBD.type = b2_staticBody;
        groundBD.position.Set(0.0f, 0.5f);

        // ground shape define
        b2PolygonShape groundSD;
        groundSD.SetAsBox(100.0f, 0.5f, b2Vec2(0.0f, 0.0f), 0);

        // ground fixture define
        b2FixtureDef groundFD;
        groundFD.shape = &groundSD;
        groundFD.density = 0.1f;
        groundFD.friction = 5.0f;

        b2Body* groundBody = _world->CreateBody(&groundBD);
        groundBody->CreateFixture(&groundFD);

        groundItem = _scene->addRect(-1.0, -2.0, 2.0, 4.0);
        groundItem->setBrush(Qt::blue);
        groundItem->setPos(-100.0, -1.0);

        groundSD.SetAsBox(1.0f, 2.0f, b2Vec2(-100.0f, 0.5f), 0);
        groundBody->CreateFixture(&groundFD);

        groundItem = _scene->addRect(-1.0, -2.0, 2.0, 4.0);
        groundItem->setBrush(Qt::blue);
        groundItem->setPos(100.0, -0.5);

        groundSD.SetAsBox(1.0f, 2.0f, b2Vec2(100.0f, 1.0f), 0);
        groundBody->CreateFixture(&groundFD);

        groundItem = _scene->addRect(-3.0, -0.5, 6.0, 1.0);
        groundItem->setBrush(Qt::blue);
        groundItem->setPos(5, -2.0);
        groundItem->setRotation(-(PI / 4.0 * 360.0) / (2 * PI));

        groundSD.SetAsBox(3.0f, 0.5f, b2Vec2(5.0f, 1.5f), PI/4.0);
        groundBody->CreateFixture(&groundFD);

        groundItem = _scene->addRect(-3.0, -0.5, 6.0, 1.0);
        groundItem->setBrush(Qt::blue);
        groundItem->setPos(3.5, -1.5);
        groundItem->setRotation(-(PI / 8.0 * 360.0) / (2 * PI));

        groundSD.SetAsBox(3.0f, 0.5f, b2Vec2(3.5f, 1.0f), PI/8.0);
        groundBody->CreateFixture(&groundFD);

        groundItem = _scene->addRect(-3.0, -0.5, 6, 1.0);
        groundItem->setBrush(Qt::blue);
        groundItem->setPos(9, -2.0);
        groundItem->setRotation(-(-PI / 4.0 * 360.0) / (2 * PI));

        groundSD.SetAsBox(3.0f, 0.5f, b2Vec2(9.0f, 1.5f), -PI/4.0);
        groundBody->CreateFixture(&groundFD);

        groundItem = _scene->addRect(-3, -0.5, 6, 1.0);
        groundItem->setBrush(Qt::blue);
        groundItem->setPos(10.5, -1.5);
        groundItem->setRotation(-(-PI / 8.0 * 360.0) / (2 * PI));

        groundSD.SetAsBox(3.0f, 0.5f, b2Vec2(10.5f, 1.0f), -PI/8.0);
        groundBody->CreateFixture(&groundFD);

        // add random shit //

        b2CircleShape circleShape;

        b2FixtureDef circleFixture;
        circleFixture.shape = &circleShape;
        circleFixture.density = 0.01;
        circleFixture.friction = 0.1;
        circleFixture.restitution = 0.5;

        for (int i = 0; i < 30; i++) {

            qreal radius = qrand()%20*0.01+0.02;

            QGraphicsEllipseItem* circle = _scene->addEllipse(-radius, -radius, radius*2, radius*2);
            circle->setBrush(Qt::green);
            circle->setPos(qrand()%35+15.0, -1.5);

            _circles << circle;

            circleShape.m_radius = radius;

            b2BodyDef circleBD;
            circleBD.type = b2_dynamicBody;
            circleBD.position.Set(circle->pos().x(), -circle->pos().y());
            circleBD.allowSleep = true;
            circleBD.linearDamping = 0.1;
            circleBD.angularDamping = 0.1;

            b2Body* circleBody = _world->CreateBody(&circleBD);
            circleBody->CreateFixture(&circleFixture);

            _circleBodies << circleBody;
        }

        // create kart
        _kart = new B2Kart(_world, _scene);
    }
}
Exemple #15
0
bool ZipplXmlReader::read( QIODevice *dev )
{
  setDevice( dev );
  bool res = true;
  bool metaMode = false;
  mCurrParent = 0;
  mCurrSpot = 0;

  QGraphicsScene *scene = mGraphWidget->scene();
  int spotID = 0;

  while (!atEnd()) {
    readNext();

    if( isStartElement() ) {
      qDebug() << "XML name: " << name();

      if( name() == "presentation") {
        // presentation mode: debug & presentation
        QString mode = attributes().value("mode").toString();
        if( !mode.isEmpty() ) mMode = mode;

        mPath = attributes().value("path").toString();
        if( !mPath.endsWith('/') ) mPath += "/";


        qreal dx = qrealAttrib("width") / -2.0;
        qreal dy = qrealAttrib("height") / -2.0;
        QRectF rect( dx, dy, -2.0*dx, -2.0*dy );
        scene->setSceneRect( rect );
      } else if( name() == "meta" ) {
        metaMode = true;
      } else if( name() == "title" && metaMode ) {
        mPresentationTitle = readElementText();
      } else if( name() == "description" && metaMode ) {
        mPresentationDescr = readElementText();
      } else if( name() == "date" && metaMode ) {
        mPresentationDate = readElementText();
      } else if( name() == "name" && metaMode ) {
        mAuthorName = readElementText();
      } else if( name() == "email" && metaMode ) {
        mAuthorEmail = readElementText();
      } else if( name() == "tocentry" ) {
        if( mCurrSpot ) {
          mCurrSpot->setData( TOCENTRY, readElementText() );
        }
      } else if( name() == "spot" ) {
        if( mCurrParent != 0 ) {
          qDebug() << "Strange: Current Parent should be zero here!";
        }
        QGraphicsRectItem *rectItem = new QGraphicsRectItem( );

        rectItem->setPen( pen( rectItem->pen(), QColor("#aeaeae") ));

        mCurrParent = rectItem;
        mCurrSpot = rectItem;
        mCurrParent->setData( ID, QVariant( spotID++ ));

        mCurrParent->setPos( position() );

        rectItem->setBrush( brush( rectItem->brush() ) );

        scene->addItem( mCurrParent );
        mSpots.append( mCurrParent );

        // Prepare the hidden items list
        GraphicsItemList list;
        mHiddenItems.insert( mCurrParent, list );

      } else if( name() == "hidden" ) {
        QGraphicsRectItem *rectItem = new QGraphicsRectItem( mCurrParent, scene );
        rectItem->setPen( QPen( QColor( 240, 240, 240 )));

        // append this hidden item to the list of hiddens of the parent spot.
        GraphicsItemList list = mHiddenItems[mCurrSpot];
        list.append( rectItem );
        mHiddenItems[mCurrSpot] = list;

        mCurrParent = rectItem;
        mCurrParent->setData( ID, QVariant( spotID++ ));

      } else if( name() == "rect" ) {
        if( mCurrParent ) { // within a spot
          qDebug() << "Creating a rectangle!";
          QGraphicsRectItem *rectItem = new QGraphicsRectItem( mCurrParent, scene );

          qreal width = qrealAttrib( "width" );
          qreal height = qrealAttrib( "height" );

          QPointF pos = position();
          if( width > 0 && height > 0 ) {
            rectItem->setRect( pos.x(), pos.y(), width, height );
          } else {
            rectItem->setPos( pos );
          }
          rectItem->setPen( pen( rectItem->pen() ) );

          mCurrParent = rectItem;
        }
      } else if( name() == "circle" ) {
        QPointF pos = position();
        QGraphicsEllipseItem *ellipse = new QGraphicsEllipseItem( mCurrParent, scene );
        // ellipse->setBrush( getBrush() );
        qreal r = 2.0 * qrealAttrib( "r" );

        QRectF rect( pos, QSizeF( r, r ) );

        ellipse->setPen( pen( ellipse->pen() ) );

        ellipse->setRect( rect );


      } else if( name() == "text" ) {
        QGraphicsSimpleTextItem *textItem = new QGraphicsSimpleTextItem( mCurrParent, scene );

        QString font = attributes().value("font").toString();
        QString size = attributes().value("size").toString();


        QFont currFont = textItem->font();
        if( !font.isEmpty() ) {
          currFont.setFamily( font );
          textItem->setFont( currFont );
        }
        if( !size.isEmpty() ) {
          currFont.setPointSize( size.toInt() );
          textItem->setFont( currFont );
        }

        textItem->setPos( position() );

        // set the brush
        QBrush b( textItem->brush() );
        b.setColor( color() );

        textItem->setBrush( b );

        QString text = readElementText();
        textItem->setText( text );

      } else if( name() == "image" ) {
        if( handleImg( scene ) ) {

        }
      }
    } else if( isEndElement() ) {
      qDebug( ) << "XML CLOSE: " << name().toString();
      if( name() == "spot" || name() == "toc" ) {
        QRectF rect = mCurrParent->childrenBoundingRect();
        rect.setX(0);
        rect.setY(0);
        qgraphicsitem_cast<QGraphicsRectItem*>(mCurrParent)->setRect( rect);
        mCurrParent = 0;
      } else if( name() == "rect" ) {
        QGraphicsRectItem *item = qgraphicsitem_cast<QGraphicsRectItem*>(mCurrParent);

        if( item->rect().isEmpty() )
          item->setRect( mCurrParent->childrenBoundingRect() );
        mCurrParent = mCurrParent->parentItem();
      } else if( name() == "hidden") {
        mCurrParent->setOpacity( 0.0 );
        mCurrParent = mCurrParent->parentItem();
      } else if( name() == "meta" ) {
        metaMode = false;
      }
    }
  }

  createToc( scene );

  return res;
}
void QGraphicsVolumeView::updateDisplay(int volumeId) {
    if (this->isHidden()) {
        return;
    }
    
    if (_airImages == NULL) {
        return;
    }

    _currentSliceMarker = NULL;

    QFont sliceIndexFont("Courier", 20);

    int showingVolumeCount = _showAll ? _airImages->Count() : 1;
    for (int id = 0; id < showingVolumeCount; id++) {
        AIRImageDisplay src = _airImages->at(id);
        if (_volumeDisplays.size() <= id) {
            _volumeDisplays.push_back(AIRVolumeDisplay());
        }
        if (!_volumeDisplays[id].Has(src)) {
            _volumeDisplays[id].SetDisplay(src);
        }
        if (_volumeDisplays[id].UpdateSlice(_directionCache, _useNavigationImage)) {
            const int w = _volumeDisplays[id].Width();
            const int h = _volumeDisplays[id].Height();
            const int s = _volumeDisplays[id].Count();

            for (int i = 0; i < s; i++) {
                int realSliceIdx = i;
                int colPos = i * w;
                int rowPos = id * h;

                QGraphicsRectItem* item = _volumeDisplays[id].GetSliceData<QGraphicsRectItem>(i);
                QGraphicsPixmapItem* pixmapItem = NULL;
                uchar* colorPointer = _volumeDisplays[id].GetColorImageBuffer(i);

                QPixmap pixmap = QPixmap::fromImage(QImage(colorPointer, w, h, QImage::Format_ARGB32));
                if (item == NULL) {
                    item = new QGraphicsRectItem(QRect(0, 0, w, h));
                    item->setPen(Qt::NoPen);
                    item->setBrush(Qt::NoBrush);
                    item->setPos(colPos, rowPos);
                    item->setData(SliceIndex, QVariant(i));
                    item->setData(AnnotationType, QVariant(SliceImage));
                    item->setData(RealSliceIndex, QVariant(realSliceIdx));

                    pixmapItem = new QGraphicsPixmapItem(QPixmap::fromImage(QImage(_volumeDisplays[id].GetColorImageBuffer(i), w, h, QImage::Format_ARGB32)), item);
                    pixmapItem->setZValue(1);

                    QGraphicsTextItem* text = new QGraphicsTextItem(QString("#%1.%2").arg(id).arg(realSliceIdx), item);
                    text->setFont(sliceIndexFont);
                    text->setPos(3, 3);
                    text->setZValue(2);
                    text->setDefaultTextColor(Qt::yellow);

                    _volumeDisplays[id].SetSliceData(i, item);
                    scene()->addItem(item);
                } else {
                    QGraphicsPixmapItem* pixmapItem = (QGraphicsPixmapItem*) item->childItems()[0];
                    pixmapItem->setPixmap(pixmap);
                }

                if (_workingSet.contains(i)) {
                    addWorkingSetItem(item);
                }
            }
        }
    }
    updatePixmaps();
}