toolbarstate.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include "toolbarstate.h"
00014
00015
00016 #include <qwmatrix.h>
00017
00018
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
00054
00055 m_pUMLView->emitRemovePopupMenu();
00056
00057
00058 m_pUMLView->setPos(m_pMouseEvent->pos());
00059
00060
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
00078
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
00094
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
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
00163 AssociationWidget* association = getAssociationAt(m_pMouseEvent->pos());
00164 if (association) {
00165 setCurrentAssociation(association);
00166 return;
00167 }
00168
00169
00170
00171 MessageWidget* message = getMessageAt(m_pMouseEvent->pos());
00172 if (message) {
00173 setCurrentWidget(message);
00174 return;
00175 }
00176
00177
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"
This file is part of the documentation for umbrello Version 3.1.0.