Esempio n. 1
0
void MainWindow::on_btn_start_clicked()
{
    rsim->reset();
    scene->clear();
    graphicalInit();
    ui->liste_tributs_1->clear();
    ui->liste_tributs_2->clear();
    g_billes.clear();
    photos_g.clear();
    outlight_g.clear();

    int n = ui->nbilles_dial->value();

    for(int i=0;i<n;i++) {
        if(i%2 == 0) {
            ui->liste_tributs_1->addItem("Palmer?");
        } else if(i%2 == 1) {
            ui->liste_tributs_2->addItem("Palmer?");
        }
    }

    rsim->start(n);
    QVector<b2Body*> b=rsim->getBalls();

    for(int i=0;i<b.size();i++) {
        QGraphicsEllipseItem* g_bille = scene->addEllipse(-10,-10,35,35,QPen(), QBrush(QColor(200,86,23)));
        g_billes.append(g_bille);

        QGraphicsPixmapItem* p = scene->addPixmap(unknown);

        if(n<= 12) {
            p->setScale(0.5f);

            int total_height = (ceil(b.size()/2.0))*150+40;
            p->setPos(i%2==0? -540 : 520-100, -total_height/2+(i/2)*150);
        } else {
            float scale = 0.5*12/(float)n;
            p->setScale(scale);

            float height = 150*12/(float) n;
            int total_height = (ceil(b.size()/2.0))*height+40;
            p->setPos(i%2==0? -540 : 520-100*12/(float)n, -total_height/2+(i/2)*height);

        }
        photos_g.append(p);

        QVector<QPointF> points;
        points.append(QPointF(0,0));
        points.append(QPointF(1500,0));
        points.append(QPointF(1500*cos(1/48.0*2*3.14159),1500*sin(1/48.0*2*3.14159)));

        QGraphicsPolygonItem* outlight = scene->addPolygon(QPolygonF(points),QPen(QColor(255,255,255,128)),QBrush(QColor(255,192+(rand()%64 - 32),0,96)));
        outlight->setZValue(-1);
        outlight->setTransformOriginPoint(QPointF(0,0));
        outlight->setVisible(false);
        outlight_g.append(outlight);

    }

}
Esempio n. 2
0
void Dialog::setMap(QPolygonF *poly)
{
    QPen pen(Qt::green);
    pen.setWidth(0);
    QGraphicsPolygonItem* item = new QGraphicsPolygonItem(*poly);
    item->setPen(pen);
    item->setBrush(QBrush(Qt::darkGreen)); //, Qt::BDiagPattern)
    item->setZValue(-1);
    QMatrix m;
    m.scale(1, -1);
//    m.translate(60, -90);
    item->setMatrix(m);
//    QRectF bounds = item->sceneBoundingRect();
    QRectF bounds = item->boundingRect();
//    qDebug() << "Bounds: " << bounds;
//    qDebug() << "Bounds center: " << bounds.center();
    qreal viewHeight = myView->viewport()->rect().height();
    qreal sceneHeight = bounds.height();
    qreal ratio = 460 / sceneHeight;  //FIXME: Get actual height instead
//    qDebug() << "View/Scene ratio: " << ratio << " hv:" << viewHeight << " hs: " << sceneHeight;
    myView->setProperty("scale", ratio / 1.5);
    myView->centerItems(bounds.center());
    myView->setSceneRect(QRect(0, 0, 1, 1));  //To synchronize model and view center
    myView->addMap(poly);
//    myView->addItem(item);
//    polyItem->setCacheMode(QGraphicsItem::DeviceCoordinateCache);  //Boost?
}
Esempio n. 3
0
 void Editor::onMapReady()
 {
   myUi->graphicsView->scene()->setSceneRect(0, 0, myGame->generator()->width(), myGame->generator()->height());
   for (unsigned int i = 0; i < myGame->generator()->regions().size(); i++)
   {
     QPolygonF qring, sqring;
     auto ring = boost::geometry::exterior_ring(myGame->generator()->regions()[i].poly);
     boost::geometry::convert(ring, qring);
     boost::geometry::simplify(qring, sqring, 1);
     QPen pen;
     pen.setColor(QColor(0,0,0));
     pen.setStyle(Qt::PenStyle::DashLine);
     QBrush brush;
     brush.setStyle(Qt::BrushStyle::SolidPattern);
     std::string colour = myGame->biomes()[myGame->generator()->regions()[i].biome]->jsonValue["mapColour"].asString();
     pen.setColor(QColor(colour.c_str()));
     brush.setColor(QColor(colour.c_str()));
     QGraphicsPolygonItem * pi = new RegionPolygonItem(this);
     pi->setPen(pen);
     pi->setBrush(brush);
     pi->setPolygon(sqring);
     QPolygonF convex;
     boost::geometry::convex_hull(sqring, convex);
     double area = boost::geometry::area(convex);
     pi->setZValue(-area);
     pi->setData(0, i);
     pi->setFlag(QGraphicsItem::GraphicsItemFlag::ItemIsFocusable, true);
     pi->setFlag(QGraphicsItem::GraphicsItemFlag::ItemIsSelectable, true);
     myUi->graphicsView->scene()->addItem(pi);
   }
 }
Esempio n. 4
0
QGraphicsPolygonItem * KiviatView::addMarker(float position)
{
   QPolygonF polygon;

   for(int i=0; i<axisCount; i++)
      polygon << calcPosition(i,position);

   QGraphicsPolygonItem * polyItem = scene.addPolygon(polygon);
   polyItem->setZValue(0);

   return polyItem;
}
Esempio n. 5
0
void Main::addPolygon()
{
    const int size = int(canvas.width()/2);
    Q3PointArray pa(6);
    pa[0] = QPoint(0,0);
    pa[1] = QPoint(size,size/5);
    pa[2] = QPoint(size*4/5,size);
    pa[3] = QPoint(size/6,size*5/4);
    pa[4] = QPoint(size*3/4,size*3/4);
    pa[5] = QPoint(size*3/4,size/4);
    QGraphicsPolygonItem* i = canvas.addPolygon(pa);
    i->setFlag(QGraphicsItem::ItemIsMovable);
    i->setPen(Qt::NoPen);
    i->setBrush( QColor(qrand()%32*8,qrand()%32*8,qrand()%32*8) );
    i->setPos(qrand()%int(canvas.width()),qrand()%int(canvas.height()));
    i->setZValue(qrand()%256);
}
void VisualizationWorkstationExtensionPlugin::addSegmentationsToViewer() {
  if (_lst) {
    std::vector<std::shared_ptr<Annotation> > tmp = _lst->getAnnotations();
    float scl = _viewer->getSceneScale();
    for (std::vector<std::shared_ptr<Annotation> >::iterator it = tmp.begin(); it != tmp.end(); ++it) {
      QPolygonF poly;
      std::vector<Point> coords = (*it)->getCoordinates();
      for (std::vector<Point>::iterator pt = coords.begin(); pt != coords.end(); ++pt) {
        poly.append(QPointF(pt->getX()*scl, pt->getY()*scl));
      }
      QGraphicsPolygonItem* cur = new QGraphicsPolygonItem(poly);
      cur->setBrush(QBrush());
      cur->setPen(QPen(QBrush(QColor("red")), 1.));
      _viewer->scene()->addItem(cur);
      cur->setZValue(std::numeric_limits<float>::max());
      _polygons.append(cur);
    }
  }
}
void
rce::gui::RImageMarkerScene::
addPolygonObject(const QPolygonF &polygon,
                  const QBrush &brush,
                  const QPen &pen,
                  quint32 id)
{

    // remove old if exists
    deletePolygon(id);

    // create new
    QPolygonF closedPolygon = polygon;
    closePolygon(closedPolygon);

    QGraphicsPolygonItem *newItem = addPolygon(closedPolygon, pen, brush);
    newItem->setData(RCE_ITEM_TYPE_DATA_INDEX, PolygonType);
    newItem->setData(RCE_ITEM_ID_DATA_INDEX, id);
    newItem->setZValue(1);

    polygonItems_[id] = newItem;
}