umbrello API Documentation

toolbarstate.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 "toolbarstate.h"
00014 
00015 // qt includes
00016 #include <qwmatrix.h> // need for inverseWorldMatrix.map
00017 
00018 // app includes
00019 #include "associationwidget.h"
00020 #include "messagewidget.h"
00021 #include "uml.h"
00022 #include "umlview.h"
00023 #include "umlwidget.h"
00024 
00025 ToolBarState::~ToolBarState() {
00026     delete m_pMouseEvent;
00027 }
00028 
00029 void ToolBarState::init() {
00030     m_pUMLView->viewport()->setMouseTracking(false);
00031     m_pMouseEvent = 0;
00032     m_currentWidget = 0;
00033     m_currentAssociation = 0;
00034 
00035     connect(m_pUMLView, SIGNAL(sigAssociationRemoved(AssociationWidget*)),
00036             this, SLOT(slotAssociationRemoved(AssociationWidget*)));
00037     connect(m_pUMLView, SIGNAL(sigWidgetRemoved(UMLWidget*)),
00038             this, SLOT(slotWidgetRemoved(UMLWidget*)));
00039 }
00040 
00041 void ToolBarState::cleanBeforeChange() {
00042     disconnect(m_pUMLView, SIGNAL(sigAssociationRemoved(AssociationWidget*)),
00043                this, SLOT(slotAssociationRemoved(AssociationWidget*)));
00044     disconnect(m_pUMLView, SIGNAL(sigWidgetRemoved(UMLWidget*)),
00045                this, SLOT(slotWidgetRemoved(UMLWidget*)));
00046 }
00047 
00048 void ToolBarState::mousePress(QMouseEvent* ome) {
00049     setMouseEvent(ome, QEvent::MouseButtonPress);
00050 
00051     m_pUMLView->viewport()->setMouseTracking(true);
00052 
00053     //TODO Doesn't another way of emiting the signal exist? A method only for
00054     //that seems a bit dirty.
00055     m_pUMLView->emitRemovePopupMenu();
00056 
00057     // TODO: Check who needs this.
00058     m_pUMLView->setPos(m_pMouseEvent->pos());
00059 
00060     //TODO check why
00061     m_pUMLView->setPaste(false);
00062 
00063     setCurrentElement();
00064 
00065     if (getCurrentWidget()) {
00066         mousePressWidget();
00067     } else if (getCurrentAssociation()) {
00068         mousePressAssociation();
00069     } else {
00070         mousePressEmpty();
00071     }
00072 }
00073 
00074 void ToolBarState::mouseRelease(QMouseEvent* ome) {
00075     setMouseEvent(ome, QEvent::MouseButtonRelease);
00076 
00077     // Set the position of the mouse
00078     // TODO, should only be available in this state?
00079     m_pUMLView->setPos(m_pMouseEvent->pos());
00080 
00081     m_pUMLView->viewport()->setMouseTracking(false);
00082 
00083     if (getCurrentWidget()) {
00084         mouseReleaseWidget();
00085         setCurrentWidget(0);
00086     } else if (getCurrentAssociation()) {
00087         mouseReleaseAssociation();
00088         setCurrentAssociation(0);
00089     } else {
00090         mouseReleaseEmpty();
00091     }
00092 
00093     // Default, rightbutton changes the tool.
00094     // The arrow tool overrides the changeTool() function.
00095     changeTool();
00096 }
00097 
00098 void ToolBarState::mouseDoubleClick(QMouseEvent* ome) {
00099     setMouseEvent(ome, QEvent::MouseButtonDblClick);
00100 
00101     UMLWidget* currentWidget = m_pUMLView->getWidgetAt(m_pMouseEvent->pos());
00102     AssociationWidget* currentAssociation = getAssociationAt(m_pMouseEvent->pos());
00103     if (currentWidget) {
00104         setCurrentWidget(currentWidget);
00105         mouseDoubleClickWidget();
00106         setCurrentWidget(0);
00107     } else if (currentAssociation) {
00108         setCurrentAssociation(currentAssociation);
00109         mouseDoubleClickAssociation();
00110         setCurrentAssociation(0);
00111     } else {
00112         mouseDoubleClickEmpty();
00113     }
00114 }
00115 
00116 void ToolBarState::mouseMove(QMouseEvent* ome) {
00117     setMouseEvent(ome, QEvent::MouseMove);
00118 
00119     if (getCurrentWidget()) {
00120         mouseMoveWidget();
00121     } else if (getCurrentAssociation()) {
00122         mouseMoveAssociation();
00123     } else {
00124         mouseMoveEmpty();
00125     }
00126 
00127     //Scrolls the view
00128     int vx = ome->x();
00129     int vy = ome->y();
00130     int contsX = m_pUMLView->contentsX();
00131     int contsY = m_pUMLView->contentsY();
00132     int visw = m_pUMLView->visibleWidth();
00133     int vish = m_pUMLView->visibleHeight();
00134     int dtr = visw - (vx-contsX);
00135     int dtb = vish - (vy-contsY);
00136     int dtt =  (vy-contsY);
00137     int dtl =  (vx-contsX);
00138     if (dtr < 30) m_pUMLView->scrollBy(30-dtr,0);
00139     if (dtb < 30) m_pUMLView->scrollBy(0,30-dtb);
00140     if (dtl < 30) m_pUMLView->scrollBy(-(30-dtl),0);
00141     if (dtt < 30) m_pUMLView->scrollBy(0,-(30-dtt));
00142 }
00143 
00144 void ToolBarState::slotAssociationRemoved(AssociationWidget* association) {
00145     if (association == getCurrentAssociation()) {
00146         setCurrentAssociation(0);
00147     }
00148 }
00149 
00150 void ToolBarState::slotWidgetRemoved(UMLWidget* widget) {
00151     if (widget == getCurrentWidget()) {
00152         setCurrentWidget(0);
00153     }
00154 }
00155 
00156 ToolBarState::ToolBarState(UMLView *umlView) : QObject(umlView), m_pUMLView(umlView) {
00157     m_pMouseEvent = NULL;
00158     init();
00159 }
00160 
00161 void ToolBarState::setCurrentElement() {
00162     // Check associations.
00163     AssociationWidget* association = getAssociationAt(m_pMouseEvent->pos());
00164     if (association) {
00165         setCurrentAssociation(association);
00166         return;
00167     }
00168 
00169     // Check messages.
00170     //TODO check why message widgets are treated different
00171     MessageWidget* message = getMessageAt(m_pMouseEvent->pos());
00172     if (message) {
00173         setCurrentWidget(message);
00174         return;
00175     }
00176 
00177     // Check widgets.
00178     UMLWidget *widget = m_pUMLView->getWidgetAt(m_pMouseEvent->pos());
00179     if (widget) {
00180         setCurrentWidget(widget);
00181         return;
00182     }
00183 }
00184 
00185 void ToolBarState::mousePressAssociation() {
00186 }
00187 
00188 void ToolBarState::mousePressWidget() {
00189 }
00190 
00191 void ToolBarState::mousePressEmpty() {
00192     m_pUMLView->clearSelected();
00193 }
00194 
00195 void ToolBarState::mouseReleaseAssociation() {
00196 }
00197 
00198 void ToolBarState::mouseReleaseWidget() {
00199 }
00200 
00201 void ToolBarState::mouseReleaseEmpty() {
00202 }
00203 
00204 void ToolBarState::mouseDoubleClickAssociation() {
00205 }
00206 
00207 void ToolBarState::mouseDoubleClickWidget() {
00208 }
00209 
00210 void ToolBarState::mouseDoubleClickEmpty() {
00211     m_pUMLView->clearSelected();
00212 }
00213 
00214 void ToolBarState::mouseMoveAssociation() {
00215 }
00216 
00217 void ToolBarState::mouseMoveWidget() {
00218 }
00219 
00220 void ToolBarState::mouseMoveEmpty() {
00221 }
00222 
00223 void ToolBarState::changeTool() {
00224     if (m_pMouseEvent->state() == Qt::RightButton) {
00225         UMLApp::app()->getWorkToolBar()->setDefaultTool();
00226     }
00227 }
00228 
00229 void ToolBarState::setMouseEvent(QMouseEvent* ome, const QEvent::Type &type) {
00230     if (m_pMouseEvent) delete m_pMouseEvent;
00231 
00232     m_pMouseEvent = new QMouseEvent(type, m_pUMLView->inverseWorldMatrix().map(ome->pos()),
00233                                     ome->button(),ome->state());
00234 }
00235 
00236 MessageWidget* ToolBarState::getMessageAt(QPoint pos) {
00237     MessageWidget* message = 0;
00238     for (MessageWidgetListIt it(m_pUMLView->getMessageList());
00239                                 (message = it.current()) != 0; ++it) {
00240         if (message->isVisible() && message->onWidget(pos)) {
00241             return message;
00242         }
00243     }
00244 
00245     return message;
00246 }
00247 
00248 AssociationWidget* ToolBarState::getAssociationAt(QPoint pos) {
00249     AssociationWidget* association = 0;
00250     for (AssociationWidgetListIt it(m_pUMLView->getAssociationList());
00251                                 (association = it.current()) != 0; ++it) {
00252         if (association->onAssociation(pos)) {
00253             return association;
00254         }
00255     }
00256 
00257     return association;
00258 }
00259 
00260 #include "toolbarstate.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