Beispiel #1
0
QGraphicsView *Page::GenerateGraphicsView()
{
    QGraphicsView *graphicsView = new QGraphicsView();

    graphicsView->setRenderHint(QPainter::Antialiasing, false);
    graphicsView->setDragMode(QGraphicsView::RubberBandDrag);
    graphicsView->setOptimizationFlags(QGraphicsView::DontSavePainterState);
    graphicsView->setViewportUpdateMode(QGraphicsView::SmartViewportUpdate);
    #ifndef QT_NO_OPENGL
    //graphicsView->setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers)));
    #endif
    graphicsView->setRenderHint(QPainter::Antialiasing, true);
    return graphicsView;
}
Beispiel #2
0
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    QWidget w;
    QGraphicsView *view = new QGraphicsView;
    QGraphicsScene scene;
    view->setScene(&scene);
    SmileyItem *item = new SmileyItem;
    scene.addItem(item);
    item->setFlag(QGraphicsItem::ItemIsMovable);

    QSlider *slider = new QSlider(Qt::Horizontal);
    slider->setRange(0,100);
    slider->setValue(item->smileSize());
    QObject::connect(slider, SIGNAL(valueChanged(int)), item, SLOT(setSmileSize(int)));
    QObject::connect(item, SIGNAL(smileSizeChanged(int)), slider, SLOT(setValue(int)));

    QVBoxLayout *l = new QVBoxLayout(&w);
    l->addWidget(view);
    l->addWidget(slider);

    view->setRenderHint(QPainter::Antialiasing);
    w.show();
    w.resize(600,400);
    return a.exec();
}
Beispiel #3
0
int main(int argc, char** argv)
{
    //Reading polygon files
    Polygon_2 poly;
    QPolygonF poly_qt;
    read_file("models/turtle_w.txt", poly, poly_qt);

    //Compute straight skeleton
    //*****This program now works for polygon WITHOUT HOLES.
    SsPtr iss = CGAL::create_interior_straight_skeleton_2(poly.vertices_begin(), poly.vertices_end());
    SsPtr ess = CGAL::create_exterior_straight_skeleton_2(EMaxOffset, poly);

    //Constructing the graph combining the straight skeleton and polygon
    std::vector<BridgingGraph> bg;
    construct_bridging_graph(poly, *iss, *ess, bg);

    //Compute perpendiculars
    std::list<Perpendiculars> ppd;
    generate_perpendiculars(*iss, *ess, bg, ppd);
    deduplicate_perpendiculars<K>(ppd);

    //Assign mountain and valley
    std::list<Segment> mt;
    std::list<Segment> vl;
    MountainValley<K>(*iss, *ess, bg, ppd,  mt, vl);

    //Extracts skeleton from cgal and converts them to qt
    std::list<QLineF> bis_qt;
    convert_straight_skeleton(*iss, bis_qt);
    convert_straight_skeleton(*ess, bis_qt);

    std::list<QLineF> ppd_qt;
    convert_perpendiculars<K>(ppd, ppd_qt);

    std::list<QLineF> mt_qt, vl_qt;
    convert_mountain_valley<K>(mt, mt_qt);
    convert_mountain_valley<K>(vl, vl_qt);

    //SETUP QT
    //Create applicaiton
    QApplication app(argc, argv);

    //Create scene
    QGraphicsScene scene;
    createQTscene(scene, poly_qt, bis_qt, ppd_qt, mt_qt, vl_qt);

    //Create view
    QGraphicsView* view = new QGraphicsView(&scene);
    CGAL::Qt::GraphicsViewNavigation nav;
    view->installEventFilter(&nav);
    view->viewport()->installEventFilter(&nav);
    view->setRenderHint(QPainter::Antialiasing);
    //view->keyPressEvent();

    //Show view
    view->show();

    return app.exec();
}
Beispiel #4
0
Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{


    ui->setupUi(this);
    this->setWindowState(this->windowState() ^ Qt::WindowFullScreen);
    QGraphicsView *view = ui->graphicsView;
    view->setScene(&scene);

    view->setWindowFlags (Qt::FramelessWindowHint);
    view->setAlignment(Qt::AlignLeft | Qt::AlignTop);
    view->setRenderHint(QPainter::Antialiasing);

    view->setMaximumSize(size());
    view->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
    view->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
    view->setCacheMode(QGraphicsView::CacheBackground);


    QGMenu *menu = new QGMenu(view->rect());
    //menu->setOpacity(0);
    scene.addItem(menu);

    int size = 152 + 16;

    for (int i = 0; i < 20 ;i++) {
        int r = i / 5;
        int c = i % 5;
        QGTile *tile = new QGTile;
        scene.addItem(tile);
        tile->moveBy(c * size,  r * size);
        tile->installSceneEventFilter(menu);
    }
    menu->setZValue(100);

//    QGraphicsItem *ball = new QGraphicsEllipseItem(0, 0, 20, 20);

//    QTimeLine *timer = new QTimeLine(5000);
//    timer->setFrameRange(0, 100);

//    QGraphicsItemAnimation *animation = new QGraphicsItemAnimation;
//    animation->setItem(ball);
//    animation->setTimeLine(timer);

//    for (int i = 0; i < 200; ++i)
//        animation->setPosAt(i / 200.0, QPointF(i, i));

//    scene.addItem(ball);

//    timer->start();

}
Beispiel #5
0
int main(int argc, char *argv[])
{
  QApplication app(argc, argv);

  // build data
  GVGraph *graph = new GVGraph("Graph");
  NodeId nid1 = graph->addNode("Node1");

  GraphId gid1 = graph->addGraph("SubGraph1");
  NodeId nid2 = graph->addNode("Node2", gid1);
  NodeId nid3 = graph->addNode("Node3", gid1);

  EdgeId eid1 = graph->addEdge(nid1, nid2, "Edge1");
  graph->setEdgeAttribute(eid1, "label", "Edge1");
  EdgeId eid2 = graph->addEdge(nid2, nid3, "Edge2");
  graph->setEdgeAttribute(eid2, "label", "Edge2");
  EdgeId eid3 = graph->addEdge(nid1, nid3, "Edge3");
  graph->setEdgeAttribute(eid3, "label", "Edge3");
  graph->applyLayout();

  if (argc > 1 && strcmp(argv[1], "--no-gui") == 0) {
    return 0;
  }

  // build ui
  QGraphicsView *view = new QGraphicsView;
  view->setRenderHint(QPainter::Antialiasing);
  QGraphicsScene *scene = new QGraphicsScene;
  view->setScene(scene);

  Q_FOREACH (const GVNodePair &pair, graph->gvNodes()) {
    const GVNode node = pair.second;
    QGraphicsItem *item = new GVNodeItem(node, 0);
    scene->addItem(item);
  }
  Q_FOREACH (const GVEdgePair &pair, graph->gvEdges()) {
    const GVEdge edge = pair.second;
    QGraphicsItem *item = new GVEdgeItem(edge, 0);
    scene->addItem(item);
  }
  Q_FOREACH (const GVSubGraphPair &pair, graph->gvSubGraphs()) {
    const GVSubGraph graph = pair.second;
    QGraphicsItem *item = new GVGraphItem(graph, 0);
    scene->addItem(item);
  }
  delete graph;
  graph = 0;

  view->show();

  return app.exec();
}
Beispiel #6
0
int main(int argc, char **argv)
{
    QApplication app(argc, argv);


    QGraphicsScene scene;
    scene.setSceneRect(0,0, 100, 100);
    scene.addRect(QRectF(0,0, 100, 100));
    scene.addLine(QLineF(0,0, 100, 100));
    scene.addLine(QLineF(0,100, 100, 0));

    QGraphicsView* view = new QGraphicsView(&scene);
    CGAL::Qt::GraphicsViewNavigation navigation;
    view->installEventFilter(&navigation);
    view->viewport()->installEventFilter(&navigation);
    view->setRenderHint(QPainter::Antialiasing);

    view->show();
    return app.exec();
}
Beispiel #7
0
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    QGraphicsView w;
    QGraphicsScene scene;
    w.setScene(&scene);

    QGraphicsItem *smiley1 = addSmiley();
    scene.addItem(smiley1);

    QGraphicsItem *smiley2 = addSmiley();
    scene.addItem(smiley2);

    QGraphicsItem *smiley3 = addSmiley();
    scene.addItem(smiley3);

    // enter your code here
    
    w.setRenderHint(QPainter::Antialiasing);
    w.show();

    return a.exec();
}
Beispiel #8
0
Widget::Widget(QWidget *parent)
    : QWidget(parent)
{
    QHBoxLayout * hbox = new QHBoxLayout;
    QGraphicsView * view = new QGraphicsView;
    GraphicsScene * scene = new GraphicsScene;

    QPolygonF polygon;
    qreal side = 20;
    qreal dx = qSqrt(3)/2 * side;
    polygon
            // standing on a point
            << QPointF(dx, -side/2)
            << QPointF(0, -side)
            << QPointF(-dx, -side/2)
            << QPointF(-dx, side/2)
            << QPointF(0, side)
            << QPointF(dx, side/2);
    // Sitting flat
    //            << QPointF(-side/2, dx)
    //            << QPointF(-side, 0)
    //            << QPointF(-side/2, -dx)
    //            << QPointF(side/2, -dx)
    //            << QPointF(side, 0)
    //            << QPointF(side/2, dx);

    int h = 9;
    int w = 17;
    int mid_h = h/2;
    int mid_w = w/2;

    for(int r = 0; r < h; r++)
    {
        for(int c = 0; c < w; c++)
        {
            if(qAbs(mid_h - r) + qAbs(mid_w - c) > 8
                    || (r % 2 != c % 2))
            {
                // don't add a hexagon, it isn't on the board!
            }
            else
            {
                BoardHexagon * hexagon = new BoardHexagon(0);
                hexagon->setPolygon(polygon);
                scene->addItem(hexagon);
                hexagon->setPos(dx * c, side * 1.5 * r);
                hexagon->setToolTip(QString::number(r) + "," + QString::number(c));
            }
        }
    }

    QGraphicsEllipseItem * ellipse = scene->addEllipse(-20, -20, 20, 20,QPen(), QBrush(QColor(Qt::green)));
    this->makeDraggable(ellipse);


    view->setRenderHint(QPainter::Antialiasing);
    view->setScene(scene);

    view->setMouseTracking(true);

    hbox->addWidget(view);
    this->setLayout(hbox);

    this->resize(600, 400);
}