/** * 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(); }
/** * 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? qreal y = m_pMouseEvent->scenePos().y(); if (messageType == CreationMessage) { msgType = Uml::sequence_message_creation; y = m_messageLine->line().p1().y(); } MessageWidget* message = new MessageWidget(m_firstObject, secondObject, msgType); message->setPos(message->pos().x(), y); setupMessageWidget(message); cleanMessage(); }
/** * Called when the release event happened on an empty space. * Cleans the message. * Empty spaces are not only actual empty spaces, but also associations. */ void ToolBarStateMessages::mouseReleaseEmpty() { Uml::Sequence_Message_Type msgType = getMessageType(); if (m_firstObject && msgType == Uml::sequence_message_lost) { xclick = m_pMouseEvent->scenePos().x(); yclick = m_pMouseEvent->scenePos().y(); MessageWidget* message = new MessageWidget(m_firstObject, QPointF(xclick, yclick), msgType); setupMessageWidget(message); cleanMessage(); xclick = 0; yclick = 0; } else if (!m_firstObject && msgType == Uml::sequence_message_found && xclick == 0 && yclick == 0) { xclick = m_pMouseEvent->scenePos().x(); yclick = m_pMouseEvent->scenePos().y(); m_messageLine = new UMLSceneLineItem(); m_pUMLScene->addItem(m_messageLine); qreal x = m_pMouseEvent->scenePos().x(), y = m_pMouseEvent->scenePos().y(); m_messageLine->setLine(x, y, x, y); m_messageLine->setPen(QPen(m_pUMLScene->lineColor(), m_pUMLScene->lineWidth(), Qt::DashLine)); m_messageLine->setVisible(true); } else { cleanMessage(); } }
/** * Called when the release event happened on an empty space. * Cleans the message. * Empty spaces are not only actual empty spaces, but also associations. */ void ToolBarStateMessages::mouseReleaseEmpty() { Uml::SequenceMessage::Enum msgType = getMessageType(); if (m_firstObject && msgType == Uml::SequenceMessage::Lost) { xclick = m_pMouseEvent->scenePos().x(); yclick = m_pMouseEvent->scenePos().y(); MessageWidget* message = new MessageWidget(m_pUMLScene, m_firstObject, xclick, yclick, msgType); setupMessageWidget(message); cleanMessage(); xclick = 0; yclick = 0; } else if (!m_firstObject && msgType == Uml::SequenceMessage::Found && xclick == 0 && yclick == 0) { xclick = m_pMouseEvent->scenePos().x(); yclick = m_pMouseEvent->scenePos().y(); m_messageLine = new QGraphicsLineItem(); m_pUMLScene->addItem(m_messageLine); qreal x = m_pMouseEvent->scenePos().x(); qreal y = m_pMouseEvent->scenePos().y(); m_messageLine->setLine(x, y, x, y); m_messageLine->setPen(QPen(m_pUMLScene->lineColor(), m_pUMLScene->lineWidth(), Qt::DashLine)); m_messageLine->setVisible(true); m_pUMLScene->activeView()->viewport()->setMouseTracking(true); } else { cleanMessage(); } }
/** * 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); } }
/** * Called when the release event happened on a widget. * If the button pressed isn't left button or the widget isn't an object * widget, the message is cleaned. * If the release event didn't happen on the line of an object and the first * object wasn't selected, nothing is done. If the first object was already * selected, a creation message is made. * If the event happened on the line of an object, the first object or the * second are set, depending on whether the first object was already set or * not. */ void ToolBarStateMessages::mouseReleaseWidget() { //TODO When an association between UMLObjects of invalid types is made, an error message //is shown. Shouldn't also a message be used here? if (m_pMouseEvent->button() != Qt::LeftButton || getCurrentWidget()->baseType() != WidgetBase::wt_Object) { cleanMessage(); return; } if (!m_isObjectWidgetLine && !m_firstObject) { return; } if (!m_isObjectWidgetLine) { setSecondWidget(static_cast<ObjectWidget*>(getCurrentWidget()), CreationMessage); return; } if (!m_firstObject) { setFirstWidget(static_cast<ObjectWidget*>(getCurrentWidget())); } else { setSecondWidget(static_cast<ObjectWidget*>(getCurrentWidget()), NormalMessage); } }
/** * A widget was removed from the UMLView. * If the widget removed was the current widget, the current widget is set * to 0. * Also, if it was the first object, the message is cleaned. */ void ToolBarStateMessages::slotWidgetRemoved(UMLWidget* widget) { ToolBarState::slotWidgetRemoved(widget); if (widget == m_firstObject) { cleanMessage(); } }
/** * Called when the current tool is changed to use another tool. * Executes base method and cleans the message. */ void ToolBarStateMessages::cleanBeforeChange() { ToolBarStatePool::cleanBeforeChange(); cleanMessage(); }
/** * Goes back to the initial state. */ void ToolBarStateMessages::init() { ToolBarStatePool::init(); cleanMessage(); }