/** * Sets the second object of the message using the specified widget and * creates the message. * The association is created and added to the view. The dialog to select * the operation of the message is shown. * * @param secondObject The second object of the message. * @param messageType The type of the message to create. */ void ToolBarStateMessages::setSecondWidget(ObjectWidget* secondObject, MessageType messageType) { Uml::Sequence_Message_Type msgType = getMessageType(); //There shouldn't be second widget for a lost or a found message if (msgType == Uml::sequence_message_lost || msgType == Uml::sequence_message_found) { cleanMessage(); xclick = 0; yclick = 0; return; } //TODO shouldn't start position in the first widget be used also for normal messages //and not only for creation? int y = m_pMouseEvent->y(); if (messageType == CreationMessage) { msgType = Uml::sequence_message_creation; y = m_messageLine->startPoint().y(); } MessageWidget* message = new MessageWidget(m_pUMLScene, m_firstObject, secondObject, y, msgType); cleanMessage(); m_pUMLScene->getMessageList().append(message); FloatingTextWidget *ft = message->floatingTextWidget(); //TODO cancel doesn't cancel the creation of the message, only cancels setting an operation. //Shouldn't it cancel also the whole creation? ft->showOperationDialog(); message->setTextPosition(); m_pUMLScene->getWidgetList().append(ft); UMLApp::app()->document()->setModified(); }
bool UMLClipboard::checkPasteWidgets( UMLWidgetList & widgetList ) { bool retval = true; UMLWidget * p = 0; UMLWidgetListIt it( widgetList ); while ( ( p = it.current()) != 0 ) { ++it; switch( p -> getBaseType() ) { case Uml::wt_Note: break; case Uml::wt_Text: { FloatingTextWidget *ft = static_cast<FloatingTextWidget*>(p); if (ft->getRole() != Uml::tr_Floating) { widgetList.remove(p); delete ft; retval = false; } } break; default: widgetList.remove(p); delete p; retval = false; break; } } return retval; }
/** * Sets the first object of the message using the specified object. * The temporal visual message is created and mouse tracking enabled, so * mouse events will be delivered. * * @param firstObject The first object of the message. */ void ToolBarStateMessages::setFirstWidget(ObjectWidget* firstObject) { m_firstObject = firstObject; Uml::Sequence_Message_Type msgType = getMessageType(); if (msgType == Uml::sequence_message_found && xclick!=0 && yclick!=0) { MessageWidget* message = new MessageWidget(m_pUMLScene, m_firstObject,xclick, yclick, msgType); cleanMessage(); m_pUMLScene->getMessageList().append(message); xclick = 0; yclick = 0; FloatingTextWidget *ft = message->floatingTextWidget(); //TODO cancel doesn't cancel the creation of the message, only cancels setting an operation. //Shouldn't it cancel also the whole creation? ft->showOperationDialog(); message->setTextPosition(); m_pUMLScene->getWidgetList().append(ft); UMLApp::app()->document()->setModified(); } else { m_messageLine = new UMLSceneLine(m_pUMLScene->canvas()); m_messageLine->setPoints(m_pMouseEvent->x(), m_pMouseEvent->y(), m_pMouseEvent->x(), m_pMouseEvent->y()); m_messageLine->setPen(QPen(m_pUMLScene->lineColor(), m_pUMLScene->lineWidth(), Qt::DashLine)); m_messageLine->setVisible(true); m_pUMLScene->viewport()->setMouseTracking(true); } }
bool UMLWidget::activate(IDChangeLog* /*ChangeLog = 0 */) { if (widgetHasUMLObject(m_Type) && m_pObject == NULL) { m_pObject = m_pDoc->findObjectById(m_nId); if (m_pObject == NULL) { kError() << "UMLWidget::activate: cannot find UMLObject with id=" << ID2STR(m_nId) << endl; return false; } } setFont(m_Font); setSize(getWidth(), getHeight()); m_bActivated = true; updateComponentSize(); if (m_pView->getPaste()) { FloatingTextWidget * ft = 0; QPoint point = m_pView -> getPastePoint(); int x = point.x() + getX(); int y = point.y() + getY(); x = x < 0?0:x; y = y < 0?0:y; if( m_pView -> getType() == dt_Sequence ) { switch( getBaseType() ) { case wt_Object: case wt_Message: setY( getY() ); setX( x ); break; case wt_Text: ft = static_cast<FloatingTextWidget *>( this ); if (ft->getRole() == tr_Seq_Message) { setX( x ); setY( getY() ); } else { setX( getX() ); setY( getY() ); } break; default: setY( y ); break; }//end switch base type }//end if sequence else { setX( x ); setY( y ); } }//end if pastepoint else { setX( getX() ); setY( getY() ); } if ( m_pView -> getPaste() ) m_pView -> createAutoAssociations( this ); updateComponentSize(); return true; }
void ToolBarStateMessages::setupMessageWidget(MessageWidget *message) { m_pUMLScene->messageList().append(message); m_pUMLScene->addItem(message); message->activate(); FloatingTextWidget *ft = message->floatingTextWidget(); //TODO cancel doesn't cancel the creation of the message, only cancels setting an operation. //Shouldn't it cancel also the whole creation? ft->showOperationDialog(); message->setTextPosition(); m_pUMLScene->widgetList().append(ft); UMLApp::app()->document()->setModified(); }
/** * 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(); }
// TODO: The name is a bit confusing. bool ToolBarStateOther::newWidget() { UMLWidget* umlWidget = NULL; switch (getButton()) { case WorkToolBar::tbb_Note: umlWidget = new NoteWidget(m_pUMLView); break; case WorkToolBar::tbb_Box: umlWidget = new BoxWidget(m_pUMLView); break; case WorkToolBar::tbb_Text: umlWidget = new FloatingTextWidget(m_pUMLView, tr_Floating, ""); break; // Activity buttons case WorkToolBar::tbb_Initial_Activity: umlWidget = new ActivityWidget(m_pUMLView, ActivityWidget::Initial); break; case WorkToolBar::tbb_Activity: umlWidget = new ActivityWidget(m_pUMLView, ActivityWidget::Normal); break; case WorkToolBar::tbb_End_Activity: umlWidget = new ActivityWidget(m_pUMLView, ActivityWidget::End); break; case WorkToolBar::tbb_Branch: umlWidget = new ActivityWidget(m_pUMLView, ActivityWidget::Branch); break; case WorkToolBar::tbb_Fork: case WorkToolBar::tbb_StateFork: umlWidget = new ForkJoinWidget(m_pUMLView); break; case WorkToolBar::tbb_Initial_State: umlWidget = new StateWidget(m_pUMLView, StateWidget::Initial); break; case WorkToolBar::tbb_State: umlWidget = new StateWidget(m_pUMLView, StateWidget::Normal); break; case WorkToolBar::tbb_End_State: umlWidget = new StateWidget(m_pUMLView, StateWidget::End); break; default: break; } // Return false if we didn't find a suitable widget. if (umlWidget == NULL) { return false; } // Special treatment for some buttons if (getButton() == WorkToolBar::tbb_Activity) { Dialog_Utils::askNameForWidget( umlWidget, i18n("Enter Activity Name"), i18n("Enter the name of the new activity:"), i18n("new activity")); } else if (getButton() == WorkToolBar::tbb_State) { Dialog_Utils::askNameForWidget( umlWidget, i18n("Enter State Name"), i18n("Enter the name of the new state:"), i18n("new state")); } else if (getButton() == WorkToolBar::tbb_Text) { // It is pretty invisible otherwise. FloatingTextWidget* ft = (FloatingTextWidget*) umlWidget; ft->changeTextDlg(); } // Create the widget. Some setup functions can remove the widget. if (umlWidget != NULL) { m_pUMLView->setupNewWidget(umlWidget); } return true; }
/** * 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; }
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"; } }