Пример #1
0
void CMapScene::setMap(CMap *map, int startType)
{
    if(!map)
    {
        clearMap();
        removeItem(Pixmap);
        return;
    }
    //Shaman dance.
    //Map will not change if map == Map
    //and map wasn't removed from scene (i.e. map wasn't destroyed in CBattle::changeMap();
    if((Map == map) && (items().contains(Pixmap)))
        return;

    QGraphicsView *View;

    if((Map != map) && (items().contains(Pixmap)))
        removeItem(Pixmap);

    Map = map;
    connect(Map, SIGNAL(destroyed()), this, SLOT(mapDestroyed()));

    clearMap();
    Pixmap->resetTransform();
    Pixmap->setPixmap(Map->getBigMinimap());
    Pixmap->setTransform(QTransform::fromScale((Map->width() / 1024.0), (Map->height() / 1024.0)));
    setSceneRect(Pixmap->mapRectToScene(Pixmap->boundingRect()));
    addItem(Pixmap);

    SceneScale = qMax(Map->width() / 1024.0, Map->height() / 1024.0);

    foreach(View, views())
    {
        View->fitInView(Pixmap, Qt::KeepAspectRatio);
    }
Пример #2
0
        void draw_graph(QGraphicsView& v, int px, int py, int x, int y, int& max_y, const QPen& pen)
        {
            REQUIRE(v.scene());
            if(y > max_y) max_y = y;

            auto s = v.scene();
            s->addLine(px, -py, x, -y, pen);

            v.fitInView(x-GRAPH_WIDTH,-int(max_y),GRAPH_WIDTH, max_y+2); 
        }
Пример #3
0
ImageUI::ImageUI(Image &_img) : QWidget()
{
    
    img = _img;

    QGraphicsScene *scene = new QGraphicsScene();
    QGraphicsPixmapItem *item = new QGraphicsPixmapItem(QPixmap(img["path"].toString()));
    scene->addItem(item);
        
    QGraphicsView *view = new QGraphicsView(scene);
    view->fitInView(0,0,1500,1500, Qt::KeepAspectRatioByExpanding);
    view->setParent(this);

}
Пример #4
0
void TimeGraphContainer::redraw() {
	//redraw it all:
	QGraphicsView * v;
	GraphScene * gs;
	for (int i=0;i<list.size();i++) {
		v=list.at(i);
		gs=(GraphScene *)v->scene();
		gs->updateArea();
		//v->fitInView ( 0,-10,3,20);
		
		v->fitInView ( (double)time_widget->getTimeControl()->getVisibleRange()->getMin() ,
									 (double)gs->sceneRect().y(),
									 (double)time_widget->getTimeControl()->getVisibleRange()->getLength(),
									  (double)gs->sceneRect().height(),
									  //20,
									  Qt::IgnoreAspectRatio );
									  
		qDebug("fit %f, %f, %f, %f\n",(double)time_widget->getTimeControl()->getVisibleRange()->getMin() ,
									 (double)gs->sceneRect().y(),
									 (double)time_widget->getTimeControl()->getVisibleRange()->getLength(),
									  (double)gs->sceneRect().height());
	}
}
Пример #5
0
SEXP
qt_qfitScene_QGraphicsView(SEXP v) {
  QGraphicsView *view = unwrapQObject(v, QGraphicsView);
  view->fitInView(view->sceneRect());
  return R_NilValue;
}
Пример #6
0
void MainWindow::updateGraphics()
{
    // restart scene
    QGraphicsScene *previousScene = scene;
    scene = new QGraphicsScene(0, 0, levelPlist.value("level_width").toInt(), levelPlist.value("level_height").toInt());

    // Add player object to scene
    QRect playerRect = spriteSheetLocations.value("Volt1.png");
    Q_ASSERT_X(playerRect != QRect(0,0,0,0), "MainWindow::loadFile()", "Could not find sprite location!");
    QImage player = spriteSheet.copy(playerRect);

    QGraphicsPixmapItem *item = scene->addPixmap(QPixmap::fromImage(player));
    item->setTransformOriginPoint(item->boundingRect().width()/2, item->boundingRect().height()/2);
    float scale = levelPlist.value("starting_size").toFloat() / playerRect.width();
    item->scale(scale, scale);
    int startX = levelPlist.value("start_x").toInt() - item->boundingRect().width()*scale/2;
    int startY = levelPlist.value("level_height").toInt() - (levelPlist.value("start_y").toInt() + item->boundingRect().height()*scale/2);
    item->setPos(startX, startY);
    item->setData(1, "player");     // type of object
    item->setData(2, -1);           // object id
    item->setData(3, false);        // is the object rotated?
    item->setData(4, QPoint(0,0));  // MouseOffset of the object (not used yet)

    // Add objects to scene
    for(int i = 0; i < levelObjects.length(); i++)
    {
        QRect objRect;
        objRect = spriteSheetLocations.value(levelObjects.at(i).value("frame_name").toString());

        // Make sure we are good to go
        Q_ASSERT_X(objRect != QRect(0,0,0,0), "MainWindow::loadFile()", "Could not find sprite location!");

        QImage img = spriteSheet.copy(objRect);
        float height = levelObjects.at(i).value("height").toFloat();
        float width = levelObjects.at(i).value("width").toFloat();
        float x = levelObjects.at(i).value("x").toFloat();
        float y = levelObjects.at(i).value("y").toFloat();
        img = img.scaled(QSize(width, height), Qt::IgnoreAspectRatio);
        item = scene->addPixmap(QPixmap::fromImage(img));
        float xPos = x - width/2;
        float yPos = levelPlist.value("level_height").toFloat() - (y + height/2);

        // Rotate object around its own center as opposed to its top left corner
        float rotation = levelObjects[i].value("rotation").toFloat();
        //float rotationRadians = (3.141592653/180) * rotation;
        //float xShift = (width/2 * qCos(rotationRadians)) - (height/2 * qSin(rotationRadians)) - width/2;
        //float yShift = (-width/2 * qSin(rotationRadians)) - (height/2 * qCos(rotationRadians)) + height/2;

        //item->setPos((int)(xPos - xShift), (int)(yPos + yShift));
        item->setPos((int)xPos, (int)yPos);
        item->setTransformOriginPoint(width/2, height/2);
        item->setRotation((int)rotation);
        item->setData(1, "object");
        item->setData(2, i);
        item->setData(3, (rotation != 0 && rotation != 360));
        //item->setData(4, QPoint(xShift, yShift));
    }

    // Display a yellow box around whichever objects are selected
    updateSelectedObjects(scene, false);

    // Display grid
    float levelHeight = levelPlist.value("level_height").toFloat();
    float levelWidth = levelPlist.value("level_width").toFloat();
    for(int i = 0; i < levelHeight; i += GRID_RESOLUTION)
    {
        scene->addLine(0, i, levelWidth, i, QPen(QColor(255, 255, 255, 50)));
    }
    for(int j = 0; j < levelWidth; j += GRID_RESOLUTION)
    {
        scene->addLine(j, 0, j, levelHeight, QPen(QColor(255, 255, 255, 50)));
    }

    // Display border of level
    QColor borderColor = QColor(50, 50, 255, 150);
    scene->addLine(0, 0, 0, levelHeight, QPen(borderColor));
    scene->addLine(levelWidth, levelHeight, 0, levelHeight, QPen(borderColor));
    scene->addLine(levelWidth, 0, levelWidth, levelHeight, QPen(borderColor));
    scene->addLine(0, 0, levelWidth, 0, QPen(borderColor));

    // Setup graphics view with the newly created scene
    QGraphicsView *view = ui->graphicsView;
    view->setScene(scene);
    view->setMaximumSize(levelPlist.value("level_width").toInt() + 2, levelPlist.value("level_height").toInt() + 3);

    // If we just loaded the level, zoom out all the way.
    if(justLoaded)
    {
        justLoaded = false;
        view->fitInView(0, 0, levelPlist.value("level_width").toInt(), levelPlist.value("level_height").toInt(), Qt::KeepAspectRatio);
    }

    // set background
    scene->setBackgroundBrush(Qt::black);

    // avoid memory leak.  We can't do this earlier, or the QGraphicsView resets its viewport.
    delete previousScene;
}