Exemple #1
0
void FormView::showSetting(Setting setting)
{
    QGraphicsScene *s = scene();

    s->clear();
    resetTransform();


    int scale_fac = 10;
    int spacing = 20;
    int planeWidth = setting.get_problem()->get_plane_width()*scale_fac;
    int planeHeight = setting.get_problem()->get_plane_height()*scale_fac;
    QRectF bound;
    for (int i=0; i<setting.get_number_of_planes(); ++i)
    {
        int x_offset = i*(planeWidth+spacing)+(spacing/2);
        int y_offset = (spacing/2);
        QRectF plane(x_offset,y_offset,planeWidth, planeHeight);
        s->addRect(plane,QPen(), QBrush(QColor(188, 198, 204),Qt::SolidPattern));
        for (int j=0; j<setting.get_plane_at(i)->get_number_of_forms(); ++j)
        {
            QPolygonF polygon;
            Form form;
            setting.get_plane_at(i)->get_form_at(j, form);
            vector<Point>  points_of_current_form = *(form.get_points());
            for (int k=0; k<points_of_current_form.size(); ++k){
                Point point = points_of_current_form[k];
                polygon.push_back(QPointF(point.get_x()*scale_fac, point.get_y()*scale_fac));
            }

            QGraphicsPolygonItem * polyitem = s->addPolygon(polygon, QPen(QColor(Qt::red)), QBrush(Qt::SolidPattern));
            polyitem->setPos(x_offset, y_offset);
            bound = polygon.boundingRect();
        }
    }


    float realwidth = container->width() - 50;
    float width = setting.get_number_of_planes()*(planeWidth+spacing);
    float realheight = container->height() - 50;
    float height = planeHeight+spacing;
    s->setSceneRect(0,0,width,height);

    float relw = 1;
    if(width > 0){
        relw =  realwidth / width;
    }

    float relh = 1;
    if(height > 0){
        relh = realheight / height;
    }

    float rel = relw;
    if(relh < relw){
        rel = relh;
    }

    scale(rel,rel);

}