示例#1
0
void SCgTupleArranger::startOperation()
{
    // affect changes to bus
    SCgBus *bus = mTupleNode->bus();
    Q_ASSERT(bus != 0);
    SCgBus *ghostBus = qgraphicsitem_cast<SCgBus*>(mGhosts[bus]);
    Q_ASSERT(ghostBus != 0);

    // map points into bus coordinates
    registerCommand(bus, ghostBus->points());

    // affect pairs and objects
    foreach(SCgPair *pair, mBusPairs)
    {
        SCgObject *end = pair->endObject();
        SCgObject *beg = pair->beginObject();
        Q_ASSERT(end != 0 && beg != 0);
        SCgPair *ghostPair = qgraphicsitem_cast<SCgPair*>(mGhosts[pair]);
        Q_ASSERT(ghostPair != 0);

        registerCommand(pair, ghostPair->points());

        if (beg->type() == SCgBus::Type)
            registerCommand(end, mGhosts[end]->pos());
        else
            registerCommand(beg, mGhosts[beg]->pos());
    }
示例#2
0
void SCgInsertMode::mousePress(QGraphicsSceneMouseEvent *event)
{
    SCgMode::mousePress(event);
    if (mInsertedObjectGroup)
    {
        SCgObject* underMouseObj = mScene->objectAt(event->scenePos());
        SCgContour* parent = 0;
        if (underMouseObj && underMouseObj->type() == SCgContour::Type)
            parent = static_cast<SCgContour*>(underMouseObj);
        mScene->pasteCommand(mInsertedObjectGroup->childItems(), parent);
    }
    else
        mScene->setEditMode(mScene->previousMode());
    clean();
}
void SCgBusModeEventHandler::mousePress(QGraphicsSceneMouseEvent *event)
{
    SCgEventHandler::mousePress(event);
    if (event->button() == Qt::LeftButton)
    {
        QPointF mousePos = event->scenePos();

        if (!mPathItem)
        {
            SCgObject *obj = mScene->objectAt(mousePos);
            SCgNode *owner = (obj != 0 && obj->type() == SCgNode::Type) ? static_cast<SCgNode*>(obj) : 0;

            if (owner != 0 && owner->bus())
                QMessageBox::information(0, qAppName(), tr("Node can't have more than one bus!"));
            else
                if(owner)
                    startLineCreation(mousePos);

        }else
        {
            QVector2D vec(*(mLinePoints.end() - 2) - mousePos);
            Q_ASSERT(mObjectAtFirstPoint);
            if (mLinePoints.size() > 2 && vec.length() < 5.f && !mObjectAtFirstPoint->isDead())
            {
                mLinePoints.pop_back();

                SCgContour* contour = 0;
                // get parent contour
                QGraphicsItem* parent = mObjectAtFirstPoint->parentItem();

                if (parent && parent->type() == SCgContour::Type)
                    contour = static_cast<SCgContour*>(parent);

                SCgNode *owner = static_cast<SCgNode*>(mObjectAtFirstPoint);
                mScene->createBusCommand(owner, mLinePoints, contour);
                endLineCreation();
            }
        }
    }
}
示例#4
0
文件: scgmodepair.cpp 项目: mcdir/sui
void SCgModePair::mousePressEvent ( QGraphicsSceneMouseEvent * mouseEvent, bool afterSceneEvent )
{
    if(afterSceneEvent)
    {
        if(mDecoratedMode)
            mDecoratedMode->mousePressEvent(mouseEvent, afterSceneEvent);
        return;
    }

    if (mPathItem)
    {
        mouseEvent->accept();
        QPointF mousePos = mouseEvent->scenePos();

        if (mouseEvent->button() == Qt::LeftButton)
            mPathItem->pushPoint(mousePos);

        if (mouseEvent->button() == Qt::RightButton)
        {
            mPathItem->popPoint();
            // If there is no more points
            if (mPathItem->points().isEmpty())
                endPairCreation(false);
        }
    }

    if (mouseEvent->button() == Qt::LeftButton)
    {
        QPointF mousePos = mouseEvent->scenePos();

        SCgVisualObject *obj = scene()->scgVisualObjectAt(mousePos);
        // if we have not createed pair yet and press on scg-object, then
        // start pair creation
        if (obj && !mPathItem)
        {
            mouseEvent->accept();
            startPairCreation(obj, mousePos);
            return;
        }

        if (obj && obj != mObjectAtFirstPoint->parentItem())
        {
            mouseEvent->accept();

            SCgVisualObject *begObj = mObjectAtFirstPoint;
            SCgVisualObject *endObj = obj;
            bool success = begObj != endObj && begObj;

            // do not create lines with equivalent begin end end object
            if (success)
            {
                SCgContour* c=0;
                // get parent contour
                SCgObject* parent = begObj->baseObject()->parentObject();
                if(parent && parent == endObj->baseObject()->parentObject())
                    if (parent->type() == SCgObject::Contour)
                        c = static_cast<SCgContour*>(parent);

                scene()->pushCommand(new SCgCommandCreatePair(scene(), mPathItem->points(),
                                                                    begObj->baseObject(),
                                                                    endObj->baseObject(), c));
            }

            endPairCreation(success);

            return;
        } // if (obj && obj != mObjectAtFirstPoint->parentItem())
    } // if (mouseEvent->button() == Qt::LeftButton)

    mPassMouseReleaseEvent = true;
    if (mDecoratedMode)
        mDecoratedMode->mousePressEvent(mouseEvent, afterSceneEvent);
}