/** * Sets the first widget in the association using the current widget. * If the widget can't be associated using the current type of association, * an error is shown and the widget isn't set. * Otherwise, the temporal visual association is created and the mouse * tracking is enabled, so move events will be delivered. */ void ToolBarStateAssociation::setFirstWidget() { UMLWidget* widget = currentWidget(); Uml::AssociationType::Enum type = getAssociationType(); if (!AssocRules::allowAssociation(type, widget)) { //TODO improve error feedback: tell the user what are the valid type of associations for //that widget KMessageBox::error(0, i18n("Incorrect use of associations."), i18n("Association Error")); return; } //set up position QPoint pos; pos.setX(widget->x() + (widget->width() / 2)); pos.setY(widget->y() + (widget->height() / 2)); //TODO why is this needed? m_pUMLScene->setPos(pos); m_firstWidget = widget; m_associationLine = new QGraphicsLineItem(); m_pUMLScene->addItem(m_associationLine); m_associationLine->setLine(pos.x(), pos.y(), pos.x(), pos.y()); m_associationLine->setPen(QPen(m_pUMLScene->lineColor(), m_pUMLScene->lineWidth(), Qt::DashLine)); m_associationLine->setVisible(true); m_pUMLScene->activeView()->viewport()->setMouseTracking(true); }
Autolayout::Graph * Autolayout::AutolayouterAdapter::setGraph( UMLView * view ) { if (! view) return 0; Autolayout::Graph * g=getGraph(); if (g&&g->empty()) { UMLWidgetList list = view->getWidgetList(); UMLWidget* widget; for ( widget = list.first(); widget; widget= list.next() ) { if (widget->getBaseType() == Uml::wt_Class) { g->addNode(widget->getID().c_str(),widget->getWidth(), widget->getHeight()); } } AssociationWidgetList as_list=view->getAssociationList(); AssociationWidget* assoc; AssociationWidgetListIt it(as_list); while ( (assoc = it.current()) != 0 ) { ++it; addRelationship(assoc); } } return g; }
/** * This method simply ensures presence of two points and * adds the needed points for self associations. */ void AssociationLine::calculateInitialEndPoints() { if (m_associationWidget->isSelf() && count() < 4) { for (int i = count(); i < 4; ++i) { insertPoint(i, QPointF()); } UMLWidget *wid = m_associationWidget->widgetForRole(Uml::RoleType::B); if (!wid) { uError() << "AssociationWidget is partially constructed." "UMLWidget for role B is null."; return; } const QRectF rect = m_associationWidget->mapFromScene( mapToScene(wid->rect()).boundingRect()).boundingRect(); qreal l = rect.left() + .25 * rect.width(); qreal r = rect.left() + .75 * rect.width(); bool drawAbove = rect.top() >= SelfAssociationMinimumHeight; qreal y = drawAbove ? rect.top() : rect.bottom(); qreal yOffset = SelfAssociationMinimumHeight; if (drawAbove) { yOffset *= -1.0; } setPoint(0, QPointF(l, y)); setPoint(1, QPointF(l, y + yOffset)); setPoint(2, QPointF(r, y + yOffset)); setPoint(3, QPointF(r, y)); } else if (!m_associationWidget->isSelf() && count() < 2) { setEndPoints(QPointF(), QPointF()); } }
/** * Sets the second widget in the association using the current widget and * creates the association. * If the association between the two widgets using the current type of * association is illegitimate, an error is shown and the association cancelled. * Otherwise, the association is created and added to the scene, and the tool * is changed to the default tool. * * @todo Why change to the default tool? Shouldn't it better to stay on * association and let the user change with a right click? The tool to * create widgets doesn't change to default after creating a widget */ void ToolBarStateAssociation::setSecondWidget() { Uml::AssociationType::Enum type = getAssociationType(); UMLWidget* widgetA = m_firstWidget; UMLWidget* widgetB = currentWidget(); WidgetBase::WidgetType at = widgetA->baseType(); bool valid = true; if (type == Uml::AssociationType::Generalization) { type = AssocRules::isGeneralisationOrRealisation(widgetA, widgetB); } if (widgetA == widgetB) { valid = AssocRules::allowSelf(type, at); if (valid && type == Uml::AssociationType::Association) { type = Uml::AssociationType::Association_Self; } } else { valid = AssocRules::allowAssociation(type, widgetA, widgetB); } if (valid) { AssociationWidget *temp = AssociationWidget::create(m_pUMLScene, widgetA, type, widgetB); FloatingTextWidget *wt = temp->textWidgetByRole(Uml::TextRole::Coll_Message); if (wt) wt->showOperationDialog(); if (addAssociationInViewAndDoc(temp)) { if (type == Uml::AssociationType::Containment) { UMLObject *newContainer = widgetA->umlObject(); UMLObject *objToBeMoved = widgetB->umlObject(); if (newContainer && objToBeMoved) { Model_Utils::treeViewMoveObjectTo(newContainer, objToBeMoved); } } UMLApp::app()->document()->setModified(); } } else { //TODO improve error feedback: tell the user what are the valid type of associations for //the second widget using the first widget KMessageBox::error(0, i18n("Incorrect use of associations."), i18n("Association Error")); } cleanAssociation(); }
void UMLWidget::setSelected(bool _select) { const Uml::Widget_Type wt = m_Type; if( _select ) { if( m_pView -> getSelectCount() == 0 ) { if ( widgetHasUMLObject(wt) ) { m_pView->showDocumentation(m_pObject, false); } else { m_pView->showDocumentation(this, false); } }//end if /* if (wt != wt_Text && wt != wt_Box) { setZ(9);//keep text on top and boxes behind so don't touch Z value } */ } else { /* if (wt != wt_Text && wt != wt_Box) { setZ(m_origZ); } */ if( m_bSelected ) m_pView -> updateDocumentation( true ); } m_bSelected = _select; const QPoint pos(getX(), getY()); UMLWidget *bkgnd = m_pView->getWidgetAt(pos); if (bkgnd && bkgnd != this && _select) { kDebug() << "UMLWidget::setSelected: setting Z to " << bkgnd->getZ() + 1 << ", SelectState: " << _select << endl; setZ( bkgnd->getZ() + 1 ); } else { setZ( m_origZ ); } update(); /* selection changed, we have to make sure the copy and paste items * are correctly enabled/disabled */ UMLApp::app()->slotCopyChanged(); }
/** * Overload '==' operator */ bool UMLWidget::operator==(const UMLWidget& other) const { if (this == &other) return true; if (m_Type != other.m_Type) { return false; } if (id() != other.id()) return false; /* Testing the associations is already an exaggeration, no? The type and ID should uniquely identify an UMLWidget. */ if (m_Assocs.count() != other.m_Assocs.count()) { return false; } // if(getBaseType() != wt_Text) // DON'T do this for floatingtext widgets, an infinite loop will result // { AssociationWidgetListIt assoc_it(m_Assocs); AssociationWidgetListIt assoc_it2(other.m_Assocs); AssociationWidget * assoc = 0, *assoc2 = 0; while (assoc_it.hasNext() && assoc_it2.hasNext()) { assoc = assoc_it.next(); assoc2 = assoc_it2.next(); if (!(*assoc == *assoc2)) { return false; } } // } return true; // NOTE: In the comparison tests we are going to do, we don't need these values. // They will actually stop things functioning correctly so if you change these, be aware of that. /* if(m_useFillColor != other.m_useFillColor) return false; if(m_nId != other.m_nId) return false; if( m_Font != other.m_Font ) return false; if(m_nX != other.m_nX) return false; if(m_nY != other.m_nY) return false; */ }
void Autolayout::AutolayouterAdapter::updateView( UMLView* view ) { if (! view) return ; UMLWidgetList list = view->getWidgetList(); UMLWidget* widget; Graph *g=getGraph(); if (! view||!g) return ; for ( widget = list.first(); widget; widget= list.next() ) if (widget->getBaseType() == Uml::wt_Class) { Node* n =g->getNode(widget->getID().c_str()); //printf("old values widgets %s x,y:%d,%d\n",widget->getID().c_str(),widget->getX(),widget->getY()); //int x_old=widget->getX(); //int x_calc=n.getX(); //int x_calc2=30 +n.getX()-widget->getWidth()/2; widget->setX(getCanvas()->getBaseX() +n->getX()-widget->getWidth()/2); //int x=widget->getX(); widget->setY(getCanvas()->getMaxY()/2-(n->getY()+(widget->getHeight()/2))); widget->updateWidget(); } }
/** * Moves the point or line if active. */ void AssociationLine::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { UMLScene* scene = m_associationWidget->umlScene(); QPointF oldPos = event->scenePos(); QPointF newPos( scene->snappedX(oldPos.x()), scene->snappedY(oldPos.y()) ); // Prevent the moving vertex from disappearing underneath a widget // (else there's no way to get it back.) UMLWidget *onW = scene->widgetAt(newPos); if (onW && onW->baseType() != WidgetBase::wt_Box) { // boxes are transparent const qreal pX = newPos.x(); const qreal pY = newPos.y(); const qreal wX = onW->x(); const qreal wY = onW->y(); const qreal wWidth = onW->width(); const qreal wHeight = onW->height(); if (pX > wX && pX < wX + wWidth) { const qreal midX = wX + wWidth / 2.0; if (pX <= midX) newPos.setX(wX); else newPos.setX(wX + wWidth); } if (pY > wY && pY < wY + wHeight) { const qreal midY = wY + wHeight / 2.0; if (pY <= midY) newPos.setY(wY); else newPos.setY(wY + wHeight); } } if (m_activePointIndex != -1) { // Move a single point (snap behaviour) setPoint(m_activePointIndex, newPos); } else if (m_activeSegmentIndex != -1 && !isEndSegmentIndex(m_activeSegmentIndex)) { // Move a segment (between two points, snap behaviour not implemented) QPointF delta = event->scenePos() - event->lastScenePos(); setPoint(m_activeSegmentIndex, m_points[m_activeSegmentIndex] + delta); setPoint(m_activeSegmentIndex + 1, m_points[m_activeSegmentIndex + 1] + delta); } }
void CmdMoveWidget::undo() { UMLWidget* umlWidget = widget(); umlWidget->setPos(m_posOld); umlWidget->updateGeometry(); }
/** * Creates and adds a new widget to the UMLView (if widgets of that type * don't have an associated UMLObject). * If the type of the widget doesn't use an UMLObject (for example, a note * or a box), it creates the widget, adds it to the view and returns true. * Otherwise, it returns false. * * @return True if the widget was created, false otherwise. * @todo Rename to something more clear. The name is a bit confusing. */ bool ToolBarStateOther::newWidget() { UMLWidget* umlWidget = 0; switch (getButton()) { case WorkToolBar::tbb_Note: umlWidget = new NoteWidget(m_pUMLScene, NoteWidget::Normal); break; case WorkToolBar::tbb_Box: umlWidget = new BoxWidget(m_pUMLScene); break; case WorkToolBar::tbb_Text: umlWidget = new FloatingTextWidget(m_pUMLScene, Uml::TextRole::Floating, QString()); break; // Activity buttons case WorkToolBar::tbb_Initial_Activity: umlWidget = new ActivityWidget(m_pUMLScene, ActivityWidget::Initial); break; case WorkToolBar::tbb_Activity: umlWidget = new ActivityWidget(m_pUMLScene, ActivityWidget::Normal); break; case WorkToolBar::tbb_End_Activity: umlWidget = new ActivityWidget(m_pUMLScene, ActivityWidget::End); break; case WorkToolBar::tbb_Final_Activity: umlWidget = new ActivityWidget(m_pUMLScene, ActivityWidget::Final); break; case WorkToolBar::tbb_Branch: umlWidget = new ActivityWidget(m_pUMLScene, ActivityWidget::Branch); break; case WorkToolBar::tbb_Fork: umlWidget = new ForkJoinWidget(m_pUMLScene); break; case WorkToolBar::tbb_Initial_State: umlWidget = new StateWidget(m_pUMLScene, StateWidget::Initial); break; case WorkToolBar::tbb_State: umlWidget = new StateWidget(m_pUMLScene, StateWidget::Normal); break; case WorkToolBar::tbb_End_State: umlWidget = new StateWidget(m_pUMLScene, StateWidget::End); break; case WorkToolBar::tbb_StateFork: umlWidget = new StateWidget(m_pUMLScene, StateWidget::Fork); break; case WorkToolBar::tbb_StateJoin: umlWidget = new StateWidget(m_pUMLScene, StateWidget::Join); break; case WorkToolBar::tbb_Junction: umlWidget = new StateWidget(m_pUMLScene, StateWidget::Junction); break; case WorkToolBar::tbb_DeepHistory: umlWidget = new StateWidget(m_pUMLScene, StateWidget::DeepHistory); break; case WorkToolBar::tbb_ShallowHistory: umlWidget = new StateWidget(m_pUMLScene, StateWidget::ShallowHistory); break; case WorkToolBar::tbb_Choice: umlWidget = new StateWidget(m_pUMLScene, StateWidget::Choice); break; case WorkToolBar::tbb_Send_Signal: umlWidget = new SignalWidget(m_pUMLScene, SignalWidget::Send); break; case WorkToolBar::tbb_Accept_Signal: umlWidget = new SignalWidget(m_pUMLScene, SignalWidget::Accept); break; case WorkToolBar::tbb_Accept_Time_Event: umlWidget = new SignalWidget(m_pUMLScene, SignalWidget::Time); break; case WorkToolBar::tbb_Region: umlWidget = new RegionWidget(m_pUMLScene); break; case WorkToolBar::tbb_Seq_Combined_Fragment: umlWidget = new CombinedFragmentWidget(m_pUMLScene); break; case WorkToolBar::tbb_Object_Node: umlWidget = new ObjectNodeWidget(m_pUMLScene, ObjectNodeWidget::Data); break; case WorkToolBar::tbb_PrePostCondition: umlWidget = new NoteWidget(m_pUMLScene, NoteWidget::Normal); break; default: break; } // Return false if we didn't find a suitable widget. if (umlWidget == 0) { return false; } // Special treatment for some buttons switch (getButton()) { case WorkToolBar::tbb_Activity: { Dialog_Utils::askNameForWidget( umlWidget, i18n("Enter Activity Name"), i18n("Enter the name of the new activity:"), i18n("new activity")); } break; case WorkToolBar::tbb_Accept_Signal: case WorkToolBar::tbb_Send_Signal: { Dialog_Utils::askNameForWidget( umlWidget, i18n("Enter Signal Name"), i18n("Enter Signal"), i18n("new Signal")); } break; case WorkToolBar::tbb_Accept_Time_Event: { Dialog_Utils::askNameForWidget( umlWidget, i18n("Enter Time Event Name"), i18n("Enter Time Event"), i18n("new time event")); } break; case WorkToolBar::tbb_Seq_Combined_Fragment: { umlWidget->asCombinedFragmentWidget()->askNameForWidgetType( umlWidget, i18n("Enter Combined Fragment Name"), i18n("Enter the Combined Fragment"), i18n("new Combined Fragment")); } break; case WorkToolBar::tbb_State: { Dialog_Utils::askNameForWidget( umlWidget, i18n("Enter State Name"), i18n("Enter the name of the new state:"), i18n("new state")); } break; case WorkToolBar::tbb_Text: { // It is pretty invisible otherwise. FloatingTextWidget* ft = (FloatingTextWidget*) umlWidget; ft->showChangeTextDialog(); } break; case WorkToolBar::tbb_Object_Node: { umlWidget->asObjectNodeWidget()->askForObjectNodeType(umlWidget); } break; case WorkToolBar::tbb_PrePostCondition: { umlWidget->asNoteWidget()->askForNoteType(umlWidget); } break; default: uWarning() << "Unknown ToolBar_Buttons: " << QLatin1String(ENUM_NAME(WorkToolBar, WorkToolBar::ToolBar_Buttons, getButton())); break; } // Create the widget. Some setup functions can remove the widget. if (umlWidget != 0) { m_pUMLScene->setupNewWidget(umlWidget); } return true; }
UMLWidget *createWidget(UMLView *view, UMLObject *o) { QPoint pos = view->getPos(); int y = pos.y(); Uml::Diagram_Type diagramType = view->getType(); Uml::Object_Type type = o->baseType(); UMLWidget *newWidget = NULL; switch (type) { case Uml::ot_Actor: if (diagramType == Uml::dt_Sequence) { ObjectWidget *ow = new ObjectWidget(view, o, view->getLocalID()); ow->setDrawAsActor(true); y = ow->topMargin(); newWidget = ow; } else newWidget = new ActorWidget(view, static_cast<UMLActor*>(o)); break; case Uml::ot_UseCase: newWidget = new UseCaseWidget(view, static_cast<UMLUseCase*>(o)); break; case Uml::ot_Package: newWidget = new PackageWidget(view, static_cast<UMLPackage*>(o)); break; case Uml::ot_Component: newWidget = new ComponentWidget(view, static_cast<UMLComponent*>(o)); if (diagramType == Uml::dt_Deployment) { newWidget->setIsInstance(true); } break; case Uml::ot_Node: newWidget = new NodeWidget(view, static_cast<UMLNode*>(o)); break; case Uml::ot_Artifact: newWidget = new ArtifactWidget(view, static_cast<UMLArtifact*>(o)); break; case Uml::ot_Datatype: newWidget = new DatatypeWidget(view, static_cast<UMLClassifier*>(o)); break; case Uml::ot_Enum: newWidget = new EnumWidget(view, static_cast<UMLEnum*>(o)); break; case Uml::ot_Entity: newWidget = new EntityWidget(view, static_cast<UMLEntity*>(o)); break; case Uml::ot_Interface: if (diagramType == Uml::dt_Sequence || diagramType == Uml::dt_Collaboration) { ObjectWidget *ow = new ObjectWidget(view, o, view->getLocalID() ); if (diagramType == Uml::dt_Sequence) { y = ow->topMargin(); } newWidget = ow; } else { UMLClassifier *c = static_cast<UMLClassifier*>(o); ClassifierWidget* interfaceWidget = new ClassifierWidget(view, c); if (diagramType == Uml::dt_Component || diagramType == Uml::dt_Deployment) { interfaceWidget->setDrawAsCircle(true); } newWidget = interfaceWidget; } break; case Uml::ot_Class: //see if we really want an object widget or class widget if (diagramType == Uml::dt_Class || diagramType == Uml::dt_Component) { UMLClassifier *c = static_cast<UMLClassifier*>(o); ClassifierWidget *cw = new ClassifierWidget(view, c); if (diagramType == Uml::dt_Component) cw->setDrawAsCircle(true); newWidget = cw; } else { ObjectWidget *ow = new ObjectWidget(view, o, view->getLocalID() ); if (diagramType == Uml::dt_Sequence) { y = ow->topMargin(); } newWidget = ow; } break; case Uml::ot_Category: newWidget = new CategoryWidget(view, static_cast<UMLCategory*>(o)); break; default: uWarning() << "trying to create an invalid widget"; } if (newWidget) { newWidget->setX( pos.x() ); newWidget->setY( y ); } return newWidget; }
/** If clipboard has mime type application/x-uml-clip4, Pastes the data from the clipboard into the current Doc */ bool UMLClipboard::pasteClip4(QMimeSource* data) { UMLDoc *doc = UMLApp::app()->getDocument(); UMLObjectList objects; objects.setAutoDelete(false); UMLWidgetList widgets; widgets.setAutoDelete(false); AssociationWidgetList assocs; assocs.setAutoDelete(false); IDChangeLog* idchanges = 0; Uml::Diagram_Type diagramType; if( !UMLDrag::decodeClip4(data, objects, widgets, assocs, diagramType) ) { return false; } if( diagramType != UMLApp::app()->getCurrentView()->getType() ) { if( !checkPasteWidgets(widgets) ) { assocs.setAutoDelete(true); assocs.clear(); return false; } } UMLObjectListIt object_it(objects); idchanges = doc->getChangeLog(); if(!idchanges) { return false; } //make sure the file we are pasting into has the objects //we need if there are widgets to be pasted UMLObject* obj = 0; while ( (obj=object_it.current()) != 0 ) { ++object_it; if(!doc->assignNewIDs(obj)) { return false; } } //now add any widget we are want to paste bool objectAlreadyExists = false; UMLView *currentView = UMLApp::app()->getCurrentView(); currentView->beginPartialWidgetPaste(); UMLWidget* widget =0; UMLWidgetListIt widget_it(widgets); while ( (widget=widget_it.current()) != 0 ) { ++widget_it; Uml::IDType oldId = widget->getID(); Uml::IDType newId = idchanges->findNewID(oldId); if (currentView->findWidget(newId)) { kError() << "UMLClipboard::pasteClip4: widget (oldID=" << ID2STR(oldId) << ", newID=" << ID2STR(newId) << ") already exists in target view." << endl; widgets.remove(widget); delete widget; objectAlreadyExists = true; } else if (! currentView->addWidget(widget, true)) { currentView->endPartialWidgetPaste(); return false; } } //now paste the associations AssociationWidget* assoc; AssociationWidgetListIt assoc_it(assocs); while ( (assoc=assoc_it.current()) != 0 ) { ++assoc_it; if (!currentView->addAssociation(assoc, true)) { currentView->endPartialWidgetPaste(); return false; } } //Activate all the pasted associations and widgets currentView->activate(); currentView->endPartialWidgetPaste(); /* UMLListView *listView = UMLApp::app()->getListView(); UMLListViewItem* item = 0; UMLListViewItem* itemdata = 0; UMLListViewItemListIt it(itemdatalist); while ( (itemdata=it.current()) != 0 ) { item = listView->createItem(*itemdata, *idchanges); if(!item) { return false; } if(itemdata -> childCount()) { if(!pasteChildren(item, idchanges)) { return false; } } ++it; }*/ if (objectAlreadyExists) { pasteItemAlreadyExists(); } return true; }
void UMLWidget::slotMenuSelection(int sel) { QFont font; QColor newColour; const Uml::Widget_Type wt = m_Type; UMLWidget* widget = 0; // use for select the first object properties (fill, line color) switch(sel) { case ListPopupMenu::mt_Rename: m_pDoc -> renameUMLObject(m_pObject); // adjustAssocs( getX(), getY() );//adjust assoc lines break; case ListPopupMenu::mt_Delete: //remove self from diagram m_pView -> removeWidget(this); break; //UMLWidgetController::doMouseDoubleClick relies on this implementation case ListPopupMenu::mt_Properties: if (wt == wt_Actor || wt == wt_UseCase || wt == wt_Package || wt == wt_Interface || wt == wt_Datatype || wt == wt_Component || wt == wt_Artifact || wt == wt_Node || wt == wt_Enum || wt == wt_Entity || (wt == wt_Class && m_pView -> getType() == dt_Class)) { showProperties(); } else if (wt == wt_Object) { m_pObject->showProperties(); } else { kWarning() << "making properties dialog for unknown widget type" << endl; } // adjustAssocs( getX(), getY() );//adjust assoc lines break; case ListPopupMenu::mt_Line_Color: case ListPopupMenu::mt_Line_Color_Selection: widget = m_pView->getFirstMultiSelectedWidget(); if (widget) { newColour = widget->getLineColor(); } if( KColorDialog::getColor(newColour) ) { m_pView -> selectionSetLineColor( newColour ); m_pDoc -> setModified(true); } break; case ListPopupMenu::mt_Fill_Color: case ListPopupMenu::mt_Fill_Color_Selection: widget = m_pView->getFirstMultiSelectedWidget(); if (widget) { newColour = widget->getFillColour(); } if ( KColorDialog::getColor(newColour) ) { m_pView -> selectionSetFillColor( newColour ); m_pDoc -> setModified(true); } break; case ListPopupMenu::mt_Use_Fill_Color: m_bUseFillColour = !m_bUseFillColour; m_bUsesDiagramUseFillColour = false; m_pView->selectionUseFillColor( m_bUseFillColour ); break; case ListPopupMenu::mt_Show_Attributes_Selection: case ListPopupMenu::mt_Show_Operations_Selection: case ListPopupMenu::mt_Visibility_Selection: case ListPopupMenu::mt_DrawAsCircle_Selection: case ListPopupMenu::mt_Show_Operation_Signature_Selection: case ListPopupMenu::mt_Show_Attribute_Signature_Selection: case ListPopupMenu::mt_Show_Packages_Selection: case ListPopupMenu::mt_Show_Stereotypes_Selection: case ListPopupMenu::mt_Show_Public_Only_Selection: m_pView->selectionToggleShow(sel); m_pDoc->setModified(true); break; case ListPopupMenu::mt_ViewCode: { UMLClassifier *c = dynamic_cast<UMLClassifier*>(m_pObject); if(c) { UMLApp::app()->viewCodeDocument(c); } break; } case ListPopupMenu::mt_Delete_Selection: m_pView -> deleteSelection(); break; case ListPopupMenu::mt_Change_Font: font = getFont(); if( KFontDialog::getFont( font, false, m_pView ) ) { setFont( font ); m_pDoc->setModified(true); } break; case ListPopupMenu::mt_Change_Font_Selection: font = getFont(); if( KFontDialog::getFont( font, false, m_pView ) ) { m_pView -> selectionSetFont( font ); m_pDoc->setModified(true); } break; case ListPopupMenu::mt_Cut: m_pView -> setStartedCut(); UMLApp::app() -> slotEditCut(); break; case ListPopupMenu::mt_Copy: UMLApp::app() -> slotEditCopy(); break; case ListPopupMenu::mt_Paste: UMLApp::app() -> slotEditPaste(); break; case ListPopupMenu::mt_Refactoring: //check if we are operating on a classifier, or some other kind of UMLObject if(dynamic_cast<UMLClassifier*>(m_pObject)) { UMLApp::app()->refactor(static_cast<UMLClassifier*>(m_pObject)); } break; case ListPopupMenu::mt_Clone: // In principle we clone all the uml objects. { UMLObject *pClone = m_pObject->clone(); m_pView->addObject(pClone); } break; case ListPopupMenu::mt_Rename_MultiA: case ListPopupMenu::mt_Rename_MultiB: case ListPopupMenu::mt_Rename_Name: case ListPopupMenu::mt_Rename_RoleAName: case ListPopupMenu::mt_Rename_RoleBName: { FloatingTextWidget *ft = static_cast<FloatingTextWidget*>(this); ft->handleRename(); break; } } }
/** * Captures any popup menu signals for menus it created. * * @param action The action which has to be executed. */ void UMLWidget::slotMenuSelection(QAction* action) { QColor newColor; const WidgetBase::WidgetType wt = m_Type; UMLWidget* widget = 0; // use for select the first object properties (fill, line color) ListPopupMenu::MenuType sel = m_pMenu->getMenuType(action); switch (sel) { case ListPopupMenu::mt_Rename: m_doc->renameUMLObject(m_pObject); // adjustAssocs( getX(), getY() );//adjust assoc lines break; case ListPopupMenu::mt_Delete: //remove self from diagram m_scene->removeWidget(this); break; //UMLWidgetController::doMouseDoubleClick relies on this implementation case ListPopupMenu::mt_Properties: if (wt == WidgetBase::wt_Actor || wt == WidgetBase::wt_UseCase || wt == WidgetBase::wt_Package || wt == WidgetBase::wt_Interface || wt == WidgetBase::wt_Datatype || wt == WidgetBase::wt_Component || wt == WidgetBase::wt_Artifact || wt == WidgetBase::wt_Node || wt == WidgetBase::wt_Enum || wt == WidgetBase::wt_Entity || (wt == WidgetBase::wt_Class && m_scene->type() == Uml::DiagramType::Class)) { UMLApp::app()->beginMacro(i18n("Change Properties")); showPropertiesDialog(); UMLApp::app()->endMacro(); } else if (wt == wt_Object) { UMLApp::app()->beginMacro(i18n("Change Properties")); m_pObject->showPropertiesPagedDialog(); UMLApp::app()->endMacro(); } else { uWarning() << "making properties dialog for unknown widget type"; } // adjustAssocs( getX(), getY() );//adjust assoc lines break; case ListPopupMenu::mt_Line_Color: widget = m_scene->getFirstMultiSelectedWidget(); if (widget) { newColor = widget->lineColor(); } if (KColorDialog::getColor(newColor)) { m_scene->selectionSetLineColor(newColor); m_doc->setModified(true); } break; case ListPopupMenu::mt_Fill_Color: widget = m_scene->getFirstMultiSelectedWidget(); if (widget) { newColor = widget->fillColor(); } if (KColorDialog::getColor(newColor)) { m_scene->selectionSetFillColor(newColor); m_doc->setModified(true); } break; case ListPopupMenu::mt_Use_Fill_Color: m_useFillColor = !m_useFillColor; m_usesDiagramUseFillColor = false; m_scene->selectionUseFillColor(m_useFillColor); break; case ListPopupMenu::mt_Show_Attributes_Selection: case ListPopupMenu::mt_Show_Operations_Selection: case ListPopupMenu::mt_Visibility_Selection: case ListPopupMenu::mt_DrawAsCircle_Selection: case ListPopupMenu::mt_Show_Operation_Signature_Selection: case ListPopupMenu::mt_Show_Attribute_Signature_Selection: case ListPopupMenu::mt_Show_Packages_Selection: case ListPopupMenu::mt_Show_Stereotypes_Selection: case ListPopupMenu::mt_Show_Public_Only_Selection: m_scene->selectionToggleShow(sel); m_doc->setModified(true); break; case ListPopupMenu::mt_ViewCode: { UMLClassifier *c = dynamic_cast<UMLClassifier*>(m_pObject); if (c) { UMLApp::app()->viewCodeDocument(c); } break; } case ListPopupMenu::mt_Delete_Selection: m_scene->deleteSelection(); break; case ListPopupMenu::mt_Change_Font: case ListPopupMenu::mt_Change_Font_Selection: { QFont font = UMLWidget::font(); if (KFontDialog::getFont(font, KFontChooser::NoDisplayFlags, m_scene)) { UMLApp::app()->executeCommand(new CmdChangeFontSelection(m_doc, m_scene, font)); } } break; case ListPopupMenu::mt_Cut: m_scene->setStartedCut(); UMLApp::app()->slotEditCut(); break; case ListPopupMenu::mt_Copy: UMLApp::app()->slotEditCopy(); break; case ListPopupMenu::mt_Paste: UMLApp::app()->slotEditPaste(); break; case ListPopupMenu::mt_Refactoring: //check if we are operating on a classifier, or some other kind of UMLObject if (dynamic_cast<UMLClassifier*>(m_pObject)) { UMLApp::app()->refactor(static_cast<UMLClassifier*>(m_pObject)); } break; case ListPopupMenu::mt_Clone: // In principle we clone all the uml objects. { UMLObject *pClone = m_pObject->clone(); m_scene->addObject(pClone); } break; case ListPopupMenu::mt_Rename_MultiA: case ListPopupMenu::mt_Rename_MultiB: case ListPopupMenu::mt_Rename_Name: case ListPopupMenu::mt_Rename_RoleAName: case ListPopupMenu::mt_Rename_RoleBName: { FloatingTextWidget *ft = static_cast<FloatingTextWidget*>(this); ft->handleRename(); break; } default: uDebug() << "MenuType " << ListPopupMenu::toString(sel) << " not implemented"; } }
/** * Activates a MessageWidget. Connects its m_pOw[] pointers * to UMLObjects and also send signals about its FloatingTextWidget. */ bool MessageWidget::activate(IDChangeLog * /*Log = 0*/) { m_scene->resetPastePoint(); // UMLWidget::activate(Log); CHECK: I don't think we need this ? if (m_pOw[Uml::RoleType::A] == 0) { UMLWidget *pWA = m_scene->findWidget(m_widgetAId); if (pWA == 0) { DEBUG(DBG_SRC) << "role A object " << Uml::ID::toString(m_widgetAId) << " not found"; return false; } m_pOw[Uml::RoleType::A] = pWA->asObjectWidget(); if (m_pOw[Uml::RoleType::A] == 0) { DEBUG(DBG_SRC) << "role A widget " << Uml::ID::toString(m_widgetAId) << " is not an ObjectWidget"; return false; } } if (m_pOw[Uml::RoleType::B] == 0) { UMLWidget *pWB = m_scene->findWidget(m_widgetBId); if (pWB == 0) { DEBUG(DBG_SRC) << "role B object " << Uml::ID::toString(m_widgetBId) << " not found"; return false; } m_pOw[Uml::RoleType::B] = pWB->asObjectWidget(); if (m_pOw[Uml::RoleType::B] == 0) { DEBUG(DBG_SRC) << "role B widget " << Uml::ID::toString(m_widgetBId) << " is not an ObjectWidget"; return false; } } updateResizability(); UMLClassifier *c = m_pOw[Uml::RoleType::B]->umlObject()->asUMLClassifier(); UMLOperation *op = 0; if (c && !m_CustomOp.isEmpty()) { Uml::ID::Type opId = Uml::ID::fromString(m_CustomOp); op = c->findChildObjectById(opId, true)->asUMLOperation(); if (op) { // If the UMLOperation is set, m_CustomOp isn't used anyway. // Just setting it empty for the sake of sanity. m_CustomOp.clear(); } } if(!m_pFText) { Uml::TextRole::Enum tr = Uml::TextRole::Seq_Message; if (isSelf()) tr = Uml::TextRole::Seq_Message_Self; m_pFText = new FloatingTextWidget(m_scene, tr, operationText(m_scene)); m_scene->addFloatingTextWidget(m_pFText); m_pFText->setFontCmd(UMLWidget::font()); } if (op) setOperation(op); // This requires a valid m_pFText. setLinkAndTextPos(); m_pFText->setText(QString()); m_pFText->setActivated(); QString messageText = m_pFText->text(); m_pFText->setVisible(messageText.length() > 1); connect(m_pOw[Uml::RoleType::A], SIGNAL(sigWidgetMoved(Uml::ID::Type)), this, SLOT(slotWidgetMoved(Uml::ID::Type))); connect(m_pOw[Uml::RoleType::B], SIGNAL(sigWidgetMoved(Uml::ID::Type)), this, SLOT(slotWidgetMoved(Uml::ID::Type))); connect(this, SIGNAL(sigMessageMoved()), m_pOw[Uml::RoleType::A], SLOT(slotMessageMoved())); connect(this, SIGNAL(sigMessageMoved()), m_pOw[Uml::RoleType::B], SLOT(slotMessageMoved())); m_pOw[Uml::RoleType::A]->messageAdded(this); if (!isSelf()) m_pOw[Uml::RoleType::B]->messageAdded(this); // Calculate the size and position of the message widget calculateDimensions(); // Position the floating text accordingly setTextPosition(); emit sigMessageMoved(); return true; }
void CmdChangeTextColor::undo() { UMLWidget* umlWidget = widget(); umlWidget->setTextColorCmd(m_oldColor); umlWidget->setUsesDiagramTextColor(m_oldUsesDiagramValue); }