Beispiel #1
0
void ColDiagramView::contentsMousePressEvent(QMouseEvent * e)
{
    if (!window()->frozen()) {
        if (e->button() == ::Qt::RightButton)
            DiagramView::contentsMousePressEvent(e);
        else {
            UmlCode c = window()->buttonOn();

            switch (c) {
            case UmlClass: {
                history_protected = FALSE;
                unselect_all();
                window()->selectOn();
                history_save();

                BrowserNode * parent =
                    ((BrowserNode *) window()->browser_diagram()->parent());
                BrowserClass * b =
                    BrowserClass::get_class(parent);

                if (b != 0) {
                    CodClassInstCanvas * cl =
                        new CodClassInstCanvas(b, the_canvas(),
                                               e->x(), e->y(), 0);

                    cl->show();
                    cl->upper();
                    window()->package_modified();
                }
            }

            canvas()->update();
            break;

            case UmlClassInstance: {
                history_protected = TRUE;
                unselect_all();
                window()->selectOn();
                history_save();

                BrowserNode * parent =
                    ((BrowserNode *) window()->browser_diagram()->parent());
                BrowserClassInstance * b =
                    BrowserClassInstance::get_classinstance(parent);

                if (b != 0) {
                    CodClassInstCanvas * cl =
                        new CodClassInstCanvas(b, the_canvas(),
                                               e->x(), e->y(), 0);

                    cl->show();
                    cl->upper();
                    window()->package_modified();
                }
            }

            canvas()->update();
            history_protected = FALSE;
            break;

            case UmlSelfLink: {
                history_protected = TRUE;
                window()->selectOn();
                history_save();

                Q3CanvasItem * ci = the_canvas()->collision(e->pos());

                if (ci != 0) {
                    DiagramItem * i = QCanvasItemToDiagramItem(ci);

                    if (i != 0) {
                        QString err = i->may_start(c);

                        if (!err.isEmpty())
                            msg_critical("Douml", err);
                        else {
                            i->connexion(c, i, e->pos(), e->pos());
                            window()->package_modified();
                        }
                    }
                }
            }

            canvas()->update();
            history_protected = FALSE;
            break;

            default:
                DiagramView::contentsMousePressEvent(e);
                break;
            }
        }
    }
    else
        DiagramView::contentsMousePressEvent(e);
}
void SeqDiagramView::mousePressEvent(QMouseEvent * e)
{
    if (!window()->frozen()) {
        if (e->button() == ::Qt::RightButton)
            DiagramView::mousePressEvent(e);
        else {
            QPoint diagramPoint(e->x(), e->y());
            QPointF scenePoint = mapToScene(diagramPoint);
            UmlCode c = window()->buttonOn();

            switch (c) {
            case UmlClass: {
                history_protected = FALSE;
                unselect_all();
                window()->selectOn();
                history_save();

                BrowserNode * parent =
                        ((BrowserNode *) window()->browser_diagram()->parent());
                BrowserClass * b =
                        BrowserClass::get_class(parent);
                if (b != 0) {
                    SdClassInstCanvas * cli =
                            new SdClassInstCanvas(b, the_canvas(), scenePoint.x(), 0);

                    cli->show();
                    cli->moveBy(scenePoint.x() - cli->center().x(), 0);
                    cli->upper();
                    window()->package_modified();
                }
            }
                break;

            case UmlClassInstance: {
                history_protected = TRUE;
                unselect_all();
                window()->selectOn();
                history_save();

                BrowserNode * parent =
                        ((BrowserNode *) window()->browser_diagram()->parent());
                BrowserClassInstance * b =
                        BrowserClassInstance::get_classinstance(parent);
                if (b != 0) {
                    SdClassInstCanvas * cli =
                            new SdClassInstCanvas(b, the_canvas(), scenePoint.x(), 0);

                    cli->show();
                    cli->moveBy(scenePoint.x() - cli->center().x(), 0);
                    cli->upper();
                    window()->package_modified();
                }
            }
                break;

            case UmlSyncSelfMsg:
            case UmlAsyncSelfMsg:
            case UmlSelfReturnMsg: {
                history_protected = TRUE;
                unselect_all();
                window()->selectOn();
                history_save();

                QGraphicsItem * ci = the_canvas()->collision(scenePoint.toPoint());

                if (ci != 0) {
                    DiagramItem * i = QCanvasItemToDiagramItem(ci);

                    if (i != 0) {
                        QString err = i->may_start(c);

                        if (!err.isEmpty())
                            msg_critical("Douml" , err);
                        else {
                            i->connexion(c, i, scenePoint.toPoint(), scenePoint.toPoint());
                            window()->package_modified();
                        }
                    }
                }
            }
                break;

            case UmlContinuation: {
                history_protected = TRUE;
                unselect_all();
                window()->selectOn();
                history_save();
                SdContinuationCanvas * cont =
                        new SdContinuationCanvas(the_canvas(), scenePoint.x(), scenePoint.y(), 0);
                cont->show();
                cont->upper();
                window()->package_modified();
            }
                break;

            default:
                DiagramView::mousePressEvent(e);
                return;
            }

            canvas()->update();
            history_protected = FALSE;
        }
    }
    else
        DiagramView::mousePressEvent(e);
}