コード例 #1
0
void DiagramScene::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent)
{
    if (mouseEvent->button() != Qt::LeftButton)
        return;

    DiagramItem *item;
    switch (myMode) {
        case InsertItem:
            item = new DiagramItem(myItemType, myItemMenu);
            addItem(item);
            connect(item, SIGNAL(itemSelected(DiagramItem*)), this, SIGNAL(itemSelected(DiagramItem*)));
            connect(item, SIGNAL(PropertiesRequest(DiagramItem*)), this, SIGNAL(propertiesRequest(DiagramItem*)));
            item->setPos(mouseEvent->scenePos());
            emit itemInserted(item);
            break;
        case InsertLine:
            line = new QGraphicsLineItem(QLineF(mouseEvent->scenePos(),
                                        mouseEvent->scenePos()));
            addItem(line);
            break;
    default:
        ;
    }
    QGraphicsScene::mousePressEvent(mouseEvent);
}
コード例 #2
0
void DiagramScene::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent)
{
    if (mouseEvent->button() != Qt::LeftButton)
        return;

    DiagramItem *item;
    DiagramNode nod;
    QDomNode xmlNode;
    switch (myMode)
    {
        case InsertItem:
            if(((DiagramWindow*)parent())->itemListEmpty(myItemType))
                return;
            nod  = ((DiagramWindow*)parent())->returnCurrentItem(myItemType);
            xmlNode = createItemXml(nod,mouseEvent->scenePos());
            item = new DiagramItem(myItemType, myItemMenu,nod.name,
                                   xmlNode,itemCount,
                                   nod.inputs);
            itemCount++;
            addItem(item);
            item->setPos(mouseEvent->scenePos());
            diagItems.append(item);
            emit itemInserted(item);
            break;
        case InsertLine:
            line = new QGraphicsLineItem(QLineF(mouseEvent->scenePos(),
                                            mouseEvent->scenePos()));
            line->setPen(QPen(myLineColor, 2));
            addItem(line);
        break;
    default:
        ;
    }
    QGraphicsScene::mousePressEvent(mouseEvent);
}
コード例 #3
0
//! [6]
void DiagramScene::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent)
{
    if (mouseEvent->button() != Qt::LeftButton)
        return;

    DiagramItem *item;
    switch (myMode) {
        case InsertItem:
            item = new DiagramItem(myItemType, myItemMenu);
            item->setBrush(myItemColor);
            addItem(item);
            item->setPos(mouseEvent->scenePos());
            emit itemInserted(item);
            break;
//! [6] //! [7]
        case InsertLine:
            line = new QGraphicsLineItem(QLineF(mouseEvent->scenePos(),
                                        mouseEvent->scenePos()));
            line->setPen(QPen(myLineColor, 2));
            addItem(line);
            break;
//! [7] //! [8]
        case InsertText:
            textItem = new DiagramTextItem();
            textItem->setFont(myFont);
            textItem->setTextInteractionFlags(Qt::TextEditorInteraction);
            textItem->setZValue(1000.0);
            connect(textItem, SIGNAL(lostFocus(DiagramTextItem*)),
                    this, SLOT(editorLostFocus(DiagramTextItem*)));
            connect(textItem, SIGNAL(selectedChange(QGraphicsItem*)),
                    this, SIGNAL(itemSelected(QGraphicsItem*)));
            addItem(textItem);
            textItem->setDefaultTextColor(myTextColor);
            textItem->setPos(mouseEvent->scenePos());
            emit textInserted(textItem);
//! [8] //! [9]
    default:
        ;
    }
    QGraphicsScene::mousePressEvent(mouseEvent);
}
コード例 #4
0
void DiagramScene::addHexagon(int count)
{
    std::cout << "-------------- addHexagon------------------,count = " << count << std::endl;

    DiagramItem *item;
    item = new DiagramItem(myItemType, myItemMenu);
    item->setBrush(myItemColor);
    addItem(item);
    count*=100;
    QPointF point(100+count,100+count);
    item->setPos(point);

//    // draw polygon
//    static const QPointF points[6] = {
//        QPointF(-0.5, 0.866+count),
//        QPointF(0.5, 0.866+count),
//        QPointF(1, 0+count),
//        QPointF(0.5, -0.866+count),
//        QPointF(-0.5, -0.866+count),
//        QPointF(-1,0+count)
//    };
//    this->painter->drawPolygon(points, 6);

}
コード例 #5
0
void DiagramScene::loadDiagram()
{
    QDomNodeList lst = projXml->elementsByTagName("item");

    for(int i=0;i<lst.count();i++)
    {
        QDomNode xmlNode = lst.at(i);
        QDomNamedNodeMap attr = xmlNode.attributes();
        int type = attr.namedItem("type").nodeValue().toInt();
        int id = attr.namedItem("id").nodeValue().toInt();
        int diagId = attr.namedItem("diagId").nodeValue().toInt();

        qreal x = attr.namedItem("x").nodeValue().toDouble();
        qreal y = attr.namedItem("y").nodeValue().toDouble();

        DiagramNode nod = ((DiagramWindow*)parent())->searchById(type,id);

        DiagramItem* item = new DiagramItem(((DiagramItem::DiagramType)type),
                                            myItemMenu,
                                            nod.name,
                                            xmlNode,
                                            diagId,
                                            nod.inputs);

        item->setPos(x,y);

        diagItems.append(item);
        addItem(item);
    }

    QDomNodeList lst2 = projXml->elementsByTagName("arrow");

    for(int i=0;i<lst2.count();i++)
    {
        QDomNamedNodeMap attr = lst2.at(i).attributes();

        DiagramItem* startParent =
                getItemById(attr.namedItem("parentInId").nodeValue().toInt());

        DiagramItem* endParent =
                getItemById(attr.namedItem("parentOutId").nodeValue().toInt());

        Connector* start =
                startParent->childAt(attr.namedItem("connectorInId").nodeValue().toInt());

        Connector* end =
                endParent->childAt(attr.namedItem("connectorOutId").nodeValue().toInt());

        Arrow *arrow = new Arrow(start, end,lst2.at(i));
        arrowList.append(arrow);

        arrow->setColor(myLineColor);
        start->addArrow(arrow);
        end->addArrow(arrow);
        addItem(arrow);
        arrow->setZValue(-1000.0);
        arrow->updatePosition();
    }

    for(int i=0;i<diagItems.count();i++)
    {
        diagItems.at(i)->updateId(itemCount);
        itemCount++;
    }
}