KAsteroidsView::KAsteroidsView( QWidget *parent) : QWidget( parent), field(0, 0, 640, 440), view(&field, this) { view.setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); view.setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); view.setCacheMode(QGraphicsView::CacheBackground); view.setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate); view.setOptimizationFlags(QGraphicsView::DontClipPainter | QGraphicsView::DontSavePainterState | QGraphicsView::DontAdjustForAntialiasing); view.viewport()->setFocusProxy( this ); QPixmap pm( IMG_BACKGROUND ); field.setBackgroundBrush( pm ); textSprite = new QGraphicsTextItem( 0, &field ); QFont font( "helvetica", 18 ); textSprite->setFont( font ); textSprite->setCacheMode(QGraphicsItem::DeviceCoordinateCache); shield = 0; shieldOn = FALSE; refreshRate = REFRESH_DELAY; initialized = readSprites(); shieldTimer = new QTimer( this ); connect( shieldTimer, SIGNAL(timeout()), this, SLOT(hideShield()) ); mTimerId = -1; shipPower = MAX_POWER_LEVEL; vitalsChanged = TRUE; can_destroy_powerups = FALSE; mPaused = TRUE; if ( !initialized ) { textSprite->setHtml( tr("<font color=red>Error: Cannot read sprite images</font>") ); textSprite->setPos( (field.width()-textSprite->boundingRect().width()) / 2, (field.height()-textSprite->boundingRect().height()) / 2 ); } }
void ProjectReader::readProject() { Q_ASSERT(isStartElement() && name() == "project"); project = new Project(); bool dirExists; //message("readProject"); QDir::setCurrent(fileinfo.absolutePath()); // Since we need to load our bitmaps first, we just read in all of the filenames // and then load the actual resources last. That way, if <tilesets> isn't the // first section, there won't be any errors. while (!atEnd()) { readNext(); if (isEndElement()) break; if (isStartElement()) { if (name() == "name") { project->SetName(readElementText()); //message("Map name: " + map->GetName()); } else if (name() == "maps") { readMaps(); } else if (name() == "tilesets") { readTilesets(); } else if (name() == "sprites") { readSprites(); } else if (name() == "scripts") { readScripts(); } else { readUnknownElement(); } } } // Load bitmaps dirExists = QDir::setCurrent("tilesets"); BitmapReader bitmapReader; while(!tilesetlist.isEmpty()) { QString b = tilesetlist.takeFirst(); // load bitmap bitmapReader.read(b); } if(dirExists) QDir::setCurrent(".."); // load sprites dirExists = QDir::setCurrent("sprites"); SpriteReader spriteReader; while(!spritelist.isEmpty()) { QString s = spritelist.takeFirst(); // load sprite spriteReader.read(s); } if(dirExists) QDir::setCurrent(".."); // load maps dirExists = QDir::setCurrent("maps"); MapReader mapReader; while(!maplist.isEmpty()) { QString m = maplist.takeFirst(); // load map mapReader.read(m); } if(dirExists) QDir::setCurrent(".."); }