umbrello API Documentation

toolbarstatemessages.cpp

00001 /***************************************************************************
00002  *                                                                         *
00003  *   This program is free software; you can redistribute it and/or modify  *
00004  *   it under the terms of the GNU General Public License as published by  *
00005  *   the Free Software Foundation; either version 2 of the License, or     *
00006  *   (at your option) any later version.                                   *
00007  *                                                                         *
00008  *   copyright (C) 2004-2006                                               *
00009  *   Umbrello UML Modeller Authors <uml-devel@uml.sf.net>                  *
00010  ***************************************************************************/
00011 
00012 // own header
00013 #include "toolbarstatemessages.h"
00014 
00015 // kde includes
00016 #include <kdebug.h>
00017 
00018 // local includes
00019 #include "floatingtextwidget.h"
00020 #include "messagewidget.h"
00021 #include "objectwidget.h"
00022 #include "uml.h"
00023 #include "umldoc.h"
00024 #include "umlview.h"
00025 
00026 ToolBarStateMessages::ToolBarStateMessages(UMLView *umlView) : ToolBarStatePool(umlView) {
00027     m_firstObject = 0;
00028     m_messageLine = 0;
00029 }
00030 
00031 ToolBarStateMessages::~ToolBarStateMessages() {
00032     delete m_messageLine;
00033 }
00034 
00035 void ToolBarStateMessages::init() {
00036     ToolBarStatePool::init();
00037 
00038     cleanMessage();
00039 }
00040 
00041 void ToolBarStateMessages::cleanBeforeChange() {
00042     ToolBarStatePool::cleanBeforeChange();
00043 
00044     cleanMessage();
00045 }
00046 
00047 void ToolBarStateMessages::mouseMove(QMouseEvent* ome) {
00048     ToolBarStatePool::mouseMove(ome);
00049 
00050     if (m_messageLine) {
00051         QPoint sp = m_messageLine->startPoint();
00052         m_messageLine->setPoints(sp.x(), sp.y(), m_pMouseEvent->x(), m_pMouseEvent->y());
00053     }
00054 }
00055 
00056 void ToolBarStateMessages::slotWidgetRemoved(UMLWidget* widget) {
00057     ToolBarState::slotWidgetRemoved(widget);
00058 
00059     if (widget == m_firstObject) {
00060         cleanMessage();
00061     }
00062 }
00063 
00064 void ToolBarStateMessages::setCurrentElement() {
00065     m_isObjectWidgetLine = false;
00066 
00067     ObjectWidget* objectWidgetLine = m_pUMLView->onWidgetLine(m_pMouseEvent->pos());
00068     if (objectWidgetLine) {
00069         setCurrentWidget(objectWidgetLine);
00070         m_isObjectWidgetLine = true;
00071         return;
00072     }
00073 
00074     //commit 515177 fixed a setting creation messages only working properly at 100% zoom
00075     //However, the applied patch doesn't seem to be necessary no more, so it was removed
00076     //The widgets weren't got from UMLView, but from a method in this class similarto the
00077     //one in UMLView but containing special code to handle the zoom
00078     UMLWidget *widget = m_pUMLView->getWidgetAt(m_pMouseEvent->pos());
00079     if (widget) {
00080         setCurrentWidget(widget);
00081         return;
00082     }
00083 }
00084 
00085 void ToolBarStateMessages::mouseReleaseWidget() {
00086     //TODO When an association between UMLObjects of invalid types is made, an error message
00087     //is shown. Shouldn't also a message be used here?
00088     if (m_pMouseEvent->button() != Qt::LeftButton ||
00089                 getCurrentWidget()->getBaseType() != Uml::wt_Object) {
00090         cleanMessage();
00091         return;
00092     }
00093 
00094     if (!m_isObjectWidgetLine && !m_firstObject) {
00095         return;
00096     }
00097 
00098     if (!m_isObjectWidgetLine) {
00099         setSecondWidget(static_cast<ObjectWidget*>(getCurrentWidget()), CreationMessage);
00100         return;
00101     }
00102 
00103     if (!m_firstObject) {
00104         setFirstWidget(static_cast<ObjectWidget*>(getCurrentWidget()));
00105     } else {
00106         setSecondWidget(static_cast<ObjectWidget*>(getCurrentWidget()), NormalMessage);
00107     }
00108 }
00109 
00110 void ToolBarStateMessages::mouseReleaseEmpty() {
00111     cleanMessage();
00112 }
00113 
00114 void ToolBarStateMessages::setFirstWidget(ObjectWidget* firstObject) {
00115     m_firstObject = firstObject;
00116 
00117     m_messageLine = new QCanvasLine(m_pUMLView->canvas());
00118     m_messageLine->setPoints(m_pMouseEvent->x(), m_pMouseEvent->y(), m_pMouseEvent->x(), m_pMouseEvent->y());
00119     m_messageLine->setPen(QPen(m_pUMLView->getLineColor(), m_pUMLView->getLineWidth(), Qt::DashLine));
00120 
00121     m_messageLine->setVisible(true);
00122 
00123     m_pUMLView->viewport()->setMouseTracking(true);
00124 }
00125 
00126 void ToolBarStateMessages::setSecondWidget(ObjectWidget* secondObject, MessageType messageType) {
00127     Uml::Sequence_Message_Type msgType = getMessageType();
00128 
00129     //TODO shouldn't start position in the first widget be used also for normal messages
00130     //and not only for creation?
00131     int y = m_pMouseEvent->y();
00132     if (messageType == CreationMessage) {
00133         msgType = Uml::sequence_message_creation;
00134         y = m_messageLine->startPoint().y();
00135     }
00136 
00137     MessageWidget* message = new MessageWidget(m_pUMLView, m_firstObject,
00138                                                secondObject, y, msgType);
00139 
00140     cleanMessage();
00141 
00142     m_pUMLView->getMessageList().append(message);
00143 
00144     FloatingTextWidget *ft = message->getFloatingTextWidget();
00145     //TODO cancel doesn't cancel the creation of the message, only cancels setting an operation.
00146     //Shouldn't it cancel also the whole creation?
00147     ft->showOpDlg();
00148     message->setTextPosition();
00149     m_pUMLView->getWidgetList().append(ft);
00150 
00151     UMLApp::app()->getDocument()->setModified();
00152 }
00153 
00154 Uml::Sequence_Message_Type ToolBarStateMessages::getMessageType() {
00155     if (getButton() == WorkToolBar::tbb_Seq_Message_Synchronous) {
00156         return Uml::sequence_message_synchronous;
00157     }
00158 
00159     return Uml::sequence_message_asynchronous;
00160 }
00161 
00162 void ToolBarStateMessages::cleanMessage() {
00163     m_firstObject = 0;
00164 
00165     delete m_messageLine;
00166     m_messageLine = 0;
00167 }
00168 
00169 #include "toolbarstatemessages.moc"
KDE Logo
This file is part of the documentation for umbrello Version 3.1.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Jun 26 08:08:00 2007 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003