Exemplo n.º 1
0
void ClsDiagConnectionHandleStart::refresh(){
    qrectParentBR.setSize(parentItem()->boundingRect().size());

    qrectParentBR.setX(0);
    qrectParentBR.setY(0);

    setPos(qrectParentBR.center());
    if(dynamic_cast<ClsDiagItemAP*>(parentItem())){
	iOrientation = dynamic_cast<ClsDiagItemAP*>(parentItem())->getOrientation();
	setOrientation(iOrientation);
    }
    QPointF qpHere = parentItem()->scenePos() + qrectParentBR.center();	    
    
    QGraphicsLineItem *qlinePost = parentConnection->getFirstSegment();
    if(qlinePost!=NULL){
	if(iOrientation == ClsDiagConnection::WEST_EAST){
	    qlinePost->setLine(qpHere.x() - qrectMyBR.height(), qpHere.y() - 1, qlinePost->line().p2().x(), qlinePost->line().p2().y()); /* height because we are rotated! */
	} else if(iOrientation == ClsDiagConnection::EAST_WEST){
	    qlinePost->setLine(qpHere.x() + qrectMyBR.height(), qpHere.y(), qlinePost->line().p2().x(), qlinePost->line().p2().y()); /* height because we are rotated! */
	} else if(iOrientation == ClsDiagConnection::NORTH_SOUTH){
	    qlinePost->setLine(qpHere.x(), qpHere.y() - qrectMyBR.height(), qlinePost->line().p2().x(), qlinePost->line().p2().y());
	} else if(iOrientation == ClsDiagConnection::SOUTH_NORTH){
	    qlinePost->setLine(qpHere.x() - 1, qpHere.y() + qrectMyBR.height(), qlinePost->line().p2().x(), qlinePost->line().p2().y());
	}
    }
    qlinePost->setZValue(0);	    
    setZValue(10);	    
}
Exemplo n.º 2
0
QVariant ClsDiagConnectionHandleStart::itemChange ( GraphicsItemChange change, const QVariant & value ){




    if(change == QGraphicsItem::ItemParentHasChanged  && scene()){



	if(parentItem()!=NULL){
	    refresh();
	} else {
	    setSourceID("");
	    QGraphicsLineItem *qlinePost = parentConnection->getFirstSegment();
	    if(qlinePost!=NULL){
		QPointF p = qlinePost->line().p1();
		setPos(p);
	    }
	}

	if(scene()!=NULL){
	    if(dynamic_cast<ClsScene*>(scene())->getCanvasType()==ClsScene::CANVAS_PROCESS){
		setCursor(Qt::OpenHandCursor);
	    } else {
		setCursor(Qt::ArrowCursor);
	    }
	}
    }
    return QGraphicsItem::itemChange(change,value);
}
Exemplo n.º 3
0
void GraphGraphicsView::drawPath(NodeGraphicsItem *from, NodeGraphicsItem *to)
{
    QPen pen(QColor(qrand()%256,qrand()%256,qrand()%256));

    double Pi = 3.1415926535897932384626433832795028;
    qreal x1, x2, y1, y2;
    if (isBelow(from, to))
    {
        x1 = from->pos().x()+15;
        y1 = from->pos().y()+10;
        x2 = to->pos().x()+15;
        y2 = to->pos().y()-20;
    }
    else
    {
        x1 = from->pos().x()+15;
        y1 = from->pos().y()-20;
        x2 = to->pos().x()+15;
        y2 = to->pos().y()+10;
    }

    lines.push_back(scene.addLine(x1, y1,
                                  x2, y2,pen));
    qreal arrowsize = 15;
    QGraphicsLineItem* line = lines.last();


    // I HAVE NO IDEA WHAT I'M CALCULATING MODE ON

    double angle = ::acos(line->line().dx() / line->line().length());

    if (line->line().dy() >= 0)
             angle = (Pi * 2) - angle;

    QPointF arrowP1 = line->line().p1()  + QPointF(sin(angle + Pi / 3 ) * arrowsize,
                                                   cos(angle+Pi/3)*arrowsize);
    QPointF arrowP2 = line->line().p1() + QPointF(sin(angle + Pi - Pi / 3) * arrowsize,
                                            cos(angle + Pi - Pi / 3) * arrowsize);

    // I HAVE NO IDEA WHAT I'M CALCULATING MODE OFF


    arrows.push_back(scene.addLine(line->line().p1().x(), line->line().p1().y(),
                                   arrowP1.x(), arrowP1.y(),pen));
    arrows.push_back(scene.addLine(line->line().p1().x(), line->line().p1().y(),
                                   arrowP2.x(), arrowP2.y(),pen));
}
Exemplo n.º 4
0
void ClsDiagConnectionHandleStart::moveChildren (){
//    cout << "ClsDiagConnectionHandleStart::moveChildrenBy ( double dx, double dy)" << endl;
    
    QPointF qpHere = parentItem()->scenePos() + qrectParentBR.center();

    QGraphicsLineItem *qlinePost = parentConnection->getFirstSegment();
    if(qlinePost!=NULL){
	if(iOrientation == ClsDiagConnection::WEST_EAST){
	    qlinePost->setLine(qpHere.x() - qrectMyBR.height(), qpHere.y() -1 , qlinePost->line().p2().x(), qlinePost->line().p2().y()); /* height because we are rotated! */
	} else if(iOrientation == ClsDiagConnection::EAST_WEST){
	    qlinePost->setLine(qpHere.x() + qrectMyBR.height(), qpHere.y(), qlinePost->line().p2().x(), qlinePost->line().p2().y()); /* height because we are rotated! */
	} else if(iOrientation == ClsDiagConnection::NORTH_SOUTH){
	    qlinePost->setLine(qpHere.x(), qpHere.y() - qrectMyBR.height(), qlinePost->line().p2().x(), qlinePost->line().p2().y());
	} else if(iOrientation == ClsDiagConnection::SOUTH_NORTH){
	    qlinePost->setLine(qpHere.x() - 1, qpHere.y() + qrectMyBR.height(), qlinePost->line().p2().x(), qlinePost->line().p2().y());
	}
    }



}
Exemplo n.º 5
0
void GraphiItemCtrl::OnDrawEvent()
{

	switch(i_CurrentType)
	{
	case ITM_TYPE_LINE:
		{
			QGraphicsLineItem* pLine = o_ItemScene.addLine(o_PointA.x(),o_PointA.y(),
				o_PointB.x(), o_PointB.y(),o_CurrentPen);
			int iKey = GetNextItemKey();
			QLineF oLine = pLine->line();
			map_Lines.insert(iKey,oLine);
			map_LineItems.insert(iKey, pLine);
			pLine->setData(CUSTDATA_KEY,iKey);
			
			emit NotifyLineAdded(iKey,oLine);
			break;
		}
	case ITM_TYPE_RECTANGLE:
		{
			double dWidth = o_PointB.x() - o_PointA.x();
			double dHeight = o_PointB.y() - o_PointA.y();
			QGraphicsRectItem* pRect = o_ItemScene.addRect(o_PointA.x(),o_PointA.y(),
				dWidth ,dHeight,o_CurrentPen);
			int iKey = GetNextItemKey();
			QRectF oRect = pRect->rect();
			map_Rects.insert(iKey, oRect);
			pRect->setData(CUSTDATA_KEY,iKey);
			
			emit NotifyRectAdded(iKey,oRect);
		
			break;
		}
	case ITM_TYPE_ELIPSE:
		{
			double dWidth = o_PointB.x() - o_PointA.x();
			double dHeight = o_PointB.y() - o_PointA.y();
			QGraphicsEllipseItem* pElipse =	o_ItemScene.addEllipse(o_PointA.x(),o_PointA.y(),
				dWidth ,dHeight,o_CurrentPen);
			
			int iKey = GetNextItemKey();
			pElipse->setData(CUSTDATA_KEY, iKey);
			QRectF oRect = pElipse->rect();
			map_Elipses.insert(iKey,oRect);
			
			emit NotifyElipseAdded(iKey,oRect);
			break;
		}
	}



}
Exemplo n.º 6
0
    void advance()
    {
        QPointF unit = (end - start)/sqrt(QPointF::dotProduct(end - start, end - start));
        currentPos += 4.*unit;

        QLineF l = line->line();
        l.setP1(currentPos + QPoint(GameScene::tile_width/2, GameScene::tile_height/2));
        line->setLine(l);

        if ((currentPos - end).manhattanLength() < 4.) {
            finished = true;
        }
    }
Exemplo n.º 7
0
void QTableManager::Update(QgraphicsItemTable *table, qreal Vx,qreal Vy)
    {
     QGraphicsLineItem* line ;
        for (int i = 0 ;i<ProjectData->NodeCount();i++){
            line = ProjectData->getNode(i)->link;
            if (ProjectData->getNode(i)->start==table)
                line->setLine(line->line().x1()+Vx,line->line().y1()+Vy,line->line().x2(),line->line().y2());
                if (ProjectData->getNode(i)->end==table){
                    line->setLine(line->line().x1(),line->line().y1(),line->line().x2()+Vx,line->line().y2()+Vy);
                }
            }
    }