Пример #1
0
void Main::addLine()
{
    QGraphicsLineItem* i = canvas.addLine(QLineF( qrand()%int(canvas.width()), qrand()%int(canvas.height()),
                                                  qrand()%int(canvas.width()), qrand()%int(canvas.height()) ));
    i->setFlag(QGraphicsItem::ItemIsMovable);
    i->setPen( QPen(QColor(qrand()%32*8,qrand()%32*8,qrand()%32*8), 6) );
    i->setZValue(qrand()%256);
}
Пример #2
0
void NavigationView::plotLineForSelected() {
    if (scene()->selectedItems().count()<2)
        return;

    QLineF vectorLine(scene()->selectedItems().at(0)->pos(), scene()->selectedItems().at(1)->pos());

    QLineF sides[4] = {
        QLineF(0, 0, 0, scene()->height()),
        QLineF(scene()->width(), 0, scene()->width(), scene()->height()),
        QLineF(0, 0, scene()->width(), 0),
        QLineF(0, scene()->height(), scene()->width(), scene()->height())
    };

    QPointF yStart;
    QPointF xStart;
    int i=0;

    while(yStart.isNull()) {
        if (vectorLine.intersect(sides[i++], &yStart)!=QLineF::BoundedIntersection) {
            qDebug("could not intersect y");
        }
        i++;
    }

    i=1;

    while(xStart.isNull()) {
        if (vectorLine.intersect(sides[i++], &xStart)!=QLineF::BoundedIntersection) {
            qDebug("could not intersect x");
        }
    }

    //IntersectionLineItem lineItem(QLineF(yStart, xStart);

    QPen linePen(Qt::black);
    linePen.setWidth(3);
    QGraphicsLineItem * line = scene()->addLine(QLineF(yStart, xStart));
    line->setPen(linePen);
    line->setFlag(QGraphicsItem::ItemIsSelectable, true);

    emit newLineAdded(mapSceneToGeo(scene()->selectedItems().at(0)->pos()), mapSceneToGeo(scene()->selectedItems().at(1)->pos()));
}
	treeVisualiserFrame::treeVisualiserFrame(const observationTree& tree, float pointSize)
		:pointSize(pointSize), highlightItem(NULL)
	{
		graphicsScene = new QGraphicsScene();
		graphicsScene->installEventFilter(this);
		graphicsScene->setItemIndexMethod(QGraphicsScene::NoIndex);

		graphicsView = new ZoomGraphicsView(graphicsScene);
		graphicsView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
		graphicsView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
		graphicsView->installEventFilter(this);

		const observationTree::treeGraphType treeGraph = tree.getTreeGraph();
		observationTree::treeGraphType::vertex_iterator currentVertex, endVertex;
		boost::tie(currentVertex, endVertex) = boost::vertices(treeGraph);

		QPen blackPen(QColor("black"));
		blackPen.setStyle(Qt::NoPen);
		QBrush blueBrush(QColor("blue"));
		QBrush redBrush(QColor("red"));
		for(; currentVertex != endVertex; currentVertex++)
		{
			float x = treeGraph[*currentVertex].x;
			float y = treeGraph[*currentVertex].y;
			treeVisualiserVertex* vertexItem = new treeVisualiserVertex(x - pointSize/2, y - pointSize/2, pointSize, pointSize);
			vertexItem->setVertexID((int)*currentVertex);
			if(treeGraph[*currentVertex].potentiallyDisconnected)
			{
				vertexItem->setPen(blackPen);
				vertexItem->setBrush(blueBrush);
			}
			else
			{
				vertexItem->setPen(blackPen);
				vertexItem->setBrush(redBrush);
			}
			vertexItem->setFlag(QGraphicsItem::ItemIsSelectable, true);
			graphicsScene->addItem(vertexItem);
		}

		blackPen.setStyle(Qt::SolidLine);
		blackPen.setWidthF(pointSize/8);
		observationTree::treeGraphType::edge_iterator currentEdge, endEdge;
		boost::tie(currentEdge, endEdge) = boost::edges(treeGraph);
		for(; currentEdge != endEdge; currentEdge++)
		{
			int sourceVertex = (int)boost::source(*currentEdge, treeGraph);
			int targetVertex = (int)boost::target(*currentEdge, treeGraph);
			float sourceX = treeGraph[sourceVertex].x;
			float sourceY = treeGraph[sourceVertex].y;
			float targetX = treeGraph[targetVertex].x;
			float targetY = treeGraph[targetVertex].y;

			QGraphicsLineItem* lineItem = graphicsScene->addLine(sourceX, sourceY, targetX, targetY, blackPen);
			lineItem->setFlag(QGraphicsItem::ItemIsSelectable, false);
		}
		layout = new QHBoxLayout;
		layout->addWidget(graphicsView, 1);
		layout->setContentsMargins(0,0,0,0);
		setLayout(layout);
		graphicsView->fitInView(graphicsView->sceneRect(), Qt::KeepAspectRatioByExpanding);
	}