• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdesdk API Reference
  • KDE Home
  • Contact Us
 

umbrello/umbrello

  • sources
  • kde-4.12
  • kdesdk
  • umbrello
  • umbrello
toolbarstate.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * This program is free software; you can redistribute it and/or modify *
3  * it under the terms of the GNU General Public License as published by *
4  * the Free Software Foundation; either version 2 of the License, or *
5  * (at your option) any later version. *
6  * *
7  * copyright (C) 2004-2013 *
8  * Umbrello UML Modeller Authors <umbrello-devel@kde.org> *
9  ***************************************************************************/
10 
11 // own header
12 #include "toolbarstate.h"
13 
14 // app includes
15 #include "associationwidget.h"
16 #include "debug_utils.h"
17 #include "messagewidget.h"
18 #include "floatingdashlinewidget.h"
19 #include "objectwidget.h"
20 #include "uml.h"
21 #include "umlview.h"
22 #include "umlwidget.h"
23 
24 // qt includes
25 #include <QWMatrix> // need for inverseWorldMatrix.map
26 #include <QScrollBar>
27 
32 ToolBarState::~ToolBarState()
33 {
34  delete m_pMouseEvent;
35 }
36 
41 void ToolBarState::init()
42 {
43  m_pUMLScene->activeView()->viewport()->setMouseTracking(false);
44  m_pMouseEvent = 0;
45  m_currentWidget = 0;
46  m_currentAssociation = 0;
47 
48  connect(m_pUMLScene, SIGNAL(sigAssociationRemoved(AssociationWidget*)),
49  this, SLOT(slotAssociationRemoved(AssociationWidget*)));
50  connect(m_pUMLScene, SIGNAL(sigWidgetRemoved(UMLWidget*)),
51  this, SLOT(slotWidgetRemoved(UMLWidget*)));
52 }
53 
59 void ToolBarState::cleanBeforeChange()
60 {
61  disconnect(m_pUMLScene, SIGNAL(sigAssociationRemoved(AssociationWidget*)),
62  this, SLOT(slotAssociationRemoved(AssociationWidget*)));
63  disconnect(m_pUMLScene, SIGNAL(sigWidgetRemoved(UMLWidget*)),
64  this, SLOT(slotWidgetRemoved(UMLWidget*)));
65 }
66 
78 void ToolBarState::mousePress(QGraphicsSceneMouseEvent* ome)
79 {
80  setMouseEvent(ome, QEvent::MouseButtonPress);
81 
82  m_pUMLScene->activeView()->viewport()->setMouseTracking(true);
83 
84  // TODO: Check who needs this.
85  m_pUMLScene->setPos(m_pMouseEvent->scenePos());
86 
87  //TODO check why
88  m_pUMLScene->setPaste(false);
89 
90  setCurrentElement();
91 
92  if (currentWidget()) {
93  mousePressWidget();
94  } else if (currentAssociation()) {
95  mousePressAssociation();
96  } else {
97  mousePressEmpty();
98  }
99 }
100 
110 void ToolBarState::mouseRelease(QGraphicsSceneMouseEvent* ome)
111 {
112  setMouseEvent(ome, QEvent::MouseButtonRelease);
113 
114  // Set the position of the mouse
115  // TODO, should only be available in this state?
116  m_pUMLScene->setPos(m_pMouseEvent->scenePos());
117 
118  m_pUMLScene->activeView()->viewport()->setMouseTracking(false);
119 
120  if (currentWidget()) {
121  mouseReleaseWidget();
122  setCurrentWidget(0);
123  } else if (currentAssociation()) {
124  mouseReleaseAssociation();
125  setCurrentAssociation(0);
126  } else {
127  mouseReleaseEmpty();
128  }
129 
130  // Default, rightbutton changes the tool.
131  // The arrow tool overrides the changeTool() function.
132  changeTool();
133 }
134 
143 void ToolBarState::mouseDoubleClick(QGraphicsSceneMouseEvent* ome)
144 {
145  setMouseEvent(ome, QEvent::MouseButtonDblClick);
146 
147  UMLWidget* currentWidget = m_pUMLScene->widgetAt(m_pMouseEvent->scenePos());
148  AssociationWidget* currentAssociation = associationAt(m_pMouseEvent->scenePos());
149  if (currentWidget) {
150  setCurrentWidget(currentWidget);
151  mouseDoubleClickWidget();
152  setCurrentWidget(0);
153  } else if (currentAssociation) {
154  setCurrentAssociation(currentAssociation);
155  mouseDoubleClickAssociation();
156  setCurrentAssociation(0);
157  } else {
158  mouseDoubleClickEmpty();
159  }
160 }
161 
175 void ToolBarState::mouseMove(QGraphicsSceneMouseEvent* ome)
176 {
177  setMouseEvent(ome, QEvent::MouseMove);
178 
179  if (currentWidget()) {
180  mouseMoveWidget();
181  } else if (currentAssociation()) {
182  mouseMoveAssociation();
183  } else {
184  mouseMoveEmpty();
185  }
186 #if 0
187  // scrolls the view
188  static int mouseCount = 0;
189  int vx = ome->scenePos().x();
190  int vy = ome->scenePos().y();
191  UMLView* view = m_pUMLScene->activeView();
192 // QRectF maxArea = view->sceneRect();
193  QRectF visibleArea = view->mapToScene(view->rect()).boundingRect();
194  int dtr = visibleArea.x() + visibleArea.width() - vx; // delta right
195  int dtb = visibleArea.y() + visibleArea.height() - vy; // delta bottom
196  int dtt = vy - visibleArea.y(); // delta top
197  int dtl = vx - visibleArea.x(); // delta left
198 // uDebug() << "mouse [x, y] = [ " << vx << ", " << vy << "] / "
199 // << "visibleArea [x, y, w, h] = [ " << visibleArea.x() << ", " << visibleArea.y() << ", " << visibleArea.width() << ", " << visibleArea.height() << "] / "
200 // << "maxArea [x, y, w, h] = [ " << maxArea.x() << ", " << maxArea.y() << ", " << maxArea.width() << ", " << maxArea.height() << "] / "
201 // << "delta right=" << dtr << ", bottom=" << dtb << ", top=" << dtt << ", left=" << dtl;
202  if (dtr < 30) { uDebug() << "translate RIGHT"; view->ensureVisible(vx, vy, 0.1 /*30-dtr*/, 0, 2, 2); }
203  if (dtb < 30) {
204  mouseCount++;
205  uDebug() << "translate BOTTOM " << mouseCount;
206 // view->ensureVisible(vx, vy, 0, 0.1 /*30-dtb*/, 2, 2);
207  if (mouseCount > 30) {
208  view->verticalScrollBar()->triggerAction(QAbstractSlider::SliderSingleStepAdd);
209  mouseCount = 0;
210  }
211  }
212  if (dtl < 30) { uDebug() << "translate LEFT"; view->ensureVisible(vx, vy, -0.1 /*-(30-dtl)*/, 0, 2, 2); }
213  if (dtt < 30) { uDebug() << "translate TOP"; view->ensureVisible(vx, vy, 0, -0.1 /*-(30-dtt)*/, 2, 2); }
214 #endif
215 }
216 
223 void ToolBarState::slotAssociationRemoved(AssociationWidget* association)
224 {
225  if (association == currentAssociation()) {
226  setCurrentAssociation(0);
227  }
228 }
229 
236 void ToolBarState::slotWidgetRemoved(UMLWidget* widget)
237 {
238  if (widget == currentWidget()) {
239  setCurrentWidget(0);
240  }
241 }
242 
251 ToolBarState::ToolBarState(UMLScene *umlScene)
252  : QObject(umlScene),
253  m_pUMLScene(umlScene),
254  m_pMouseEvent(0)
255 {
256  init();
257 }
258 
267 void ToolBarState::setCurrentElement()
268 {
269  // Check associations.
270  AssociationWidget* association = associationAt(m_pMouseEvent->scenePos());
271  if (association) {
272  setCurrentAssociation(association);
273  return;
274  }
275 
276  // Check messages.
277  //TODO check why message widgets are treated different
278  MessageWidget* message = messageAt(m_pMouseEvent->scenePos());
279  if (message) {
280  setCurrentWidget(message);
281  return;
282  }
283 
284  //TODO check why message widgets are treated different
285  FloatingDashLineWidget* floatingline = floatingLineAt(m_pMouseEvent->scenePos());
286  if (floatingline) {
287  setCurrentWidget(floatingline);
288  return;
289  }
290 
291  ObjectWidget* objectWidgetLine = m_pUMLScene->onWidgetDestructionBox(m_pMouseEvent->scenePos());
292  if (objectWidgetLine) {
293  setCurrentWidget(objectWidgetLine);
294  return;
295  }
296 
297  // Check widgets.
298  UMLWidget *widget = m_pUMLScene->widgetAt(m_pMouseEvent->scenePos());
299  if (widget) {
300  setCurrentWidget(widget);
301  return;
302  }
303 }
304 
309 void ToolBarState::mousePressAssociation()
310 {
311 }
312 
317 void ToolBarState::mousePressWidget()
318 {
319 }
320 
325 void ToolBarState::mousePressEmpty()
326 {
327  // TODO activate when QGraphicsScene selection handling is used
328  //m_pUMLScene->clearSelection();
329  m_pUMLScene->clearSelected();
330 }
331 
336 void ToolBarState::mouseReleaseAssociation()
337 {
338 }
339 
344 void ToolBarState::mouseReleaseWidget()
345 {
346 }
347 
352 void ToolBarState::mouseReleaseEmpty()
353 {
354 }
355 
360 void ToolBarState::mouseDoubleClickAssociation()
361 {
362 }
363 
368 void ToolBarState::mouseDoubleClickWidget()
369 {
370 }
371 
376 void ToolBarState::mouseDoubleClickEmpty()
377 {
378  // TODO activate when QGraphicsScene selection handling is used
379  //m_pUMLScene->clearSelection();
380  m_pUMLScene->clearSelected();
381 }
382 
388 void ToolBarState::mouseMoveAssociation()
389 {
390 }
391 
397 void ToolBarState::mouseMoveWidget()
398 {
399 }
400 
406 void ToolBarState::mouseMoveEmpty()
407 {
408 }
409 
414 void ToolBarState::changeTool()
415 {
416  if (m_pMouseEvent->buttons() == Qt::RightButton) {
417  UMLApp::app()->workToolBar()->setDefaultTool();
418  }
419 }
420 
426 UMLWidget* ToolBarState::currentWidget() const
427 {
428  return m_currentWidget;
429 }
430 
440 void ToolBarState::setCurrentWidget(UMLWidget* widget)
441 {
442  m_currentWidget = widget;
443 }
444 
450 AssociationWidget* ToolBarState::currentAssociation() const
451 {
452  return m_currentAssociation;
453 }
454 
464 void ToolBarState::setCurrentAssociation(AssociationWidget* association)
465 {
466  m_currentAssociation = association;
467 }
468 
477 void ToolBarState::setMouseEvent(QGraphicsSceneMouseEvent* ome, const QEvent::Type &type)
478 {
479  delete m_pMouseEvent;
480 
481  //:TODO: uDebug() << "[PORT] Check if scenePos works like view->inverseWorldMatrix().map()";
482  // Using copy constructor here.
483  m_pMouseEvent = new QGraphicsSceneMouseEvent(type);
484  m_pMouseEvent->setPos(ome->pos());
485  m_pMouseEvent->setScenePos(ome->scenePos());
486  m_pMouseEvent->setScreenPos(ome->screenPos());
487  m_pMouseEvent->setLastPos(ome->lastPos());
488  m_pMouseEvent->setLastScenePos(ome->lastScenePos());
489  m_pMouseEvent->setLastScreenPos(ome->lastScreenPos());
490  m_pMouseEvent->setButtons(ome->buttons());
491  m_pMouseEvent->setButton(ome->button());
492  m_pMouseEvent->setModifiers(ome->modifiers());
493 }
494 
504 MessageWidget* ToolBarState::messageAt(const QPointF& pos)
505 {
506  foreach (MessageWidget* message, m_pUMLScene->messageList()) {
507  if (message->isVisible() && message->onWidget(pos)) {
508  return message;
509  }
510  }
511  return 0;
512 }
513 
522 AssociationWidget* ToolBarState::associationAt(const QPointF& pos)
523 {
524  foreach (AssociationWidget* association, m_pUMLScene->associationList()) {
525  if (association->onAssociation(pos)) {
526  return association;
527  }
528  }
529  return 0;
530 }
531 
539 FloatingDashLineWidget* ToolBarState::floatingLineAt(const QPointF& pos)
540 {
541  FloatingDashLineWidget* floatingline = 0;
542 
543  foreach (UMLWidget* widget, m_pUMLScene->widgetList()) {
544  if (widget->baseType() == WidgetBase::wt_FloatingDashLine){
545  if (dynamic_cast<FloatingDashLineWidget*>(widget)->onLine(pos)) {
546  floatingline = dynamic_cast<FloatingDashLineWidget*>(widget);
547  }
548  }
549  }
550 
551  return floatingline;
552 }
553 
554 #include "toolbarstate.moc"
ObjectWidget
Displays an instance UMLObject of a concept.
Definition: objectwidget.h:32
ToolBarState::messageAt
MessageWidget * messageAt(const QPointF &pos)
Returns the MessageWidget at the specified position, or null if there is none.
Definition: toolbarstate.cpp:504
ToolBarState::m_pUMLScene
UMLScene * m_pUMLScene
The UMLScene.
Definition: toolbarstate.h:120
ToolBarState::mouseReleaseEmpty
virtual void mouseReleaseEmpty()
Called when the release event happened on an empty space.
Definition: toolbarstate.cpp:352
messagewidget.h
ToolBarState::mouseReleaseAssociation
virtual void mouseReleaseAssociation()
Called when the release event happened on an association.
Definition: toolbarstate.cpp:336
ToolBarState::floatingLineAt
FloatingDashLineWidget * floatingLineAt(const QPointF &pos)
Returns the FloatingDashLineWidget at the specified position, or null if there is none...
Definition: toolbarstate.cpp:539
umlview.h
UMLScene::widgetList
UMLWidgetList & widgetList()
Returns a reference to the widget list.
Definition: umlscene.cpp:424
ToolBarState::mouseMoveWidget
virtual void mouseMoveWidget()
Called when the move event happened when a widget is currently available.
Definition: toolbarstate.cpp:397
UMLView
UMLView instances represent diagrams.
Definition: umlview.h:32
ToolBarState::mouseDoubleClickWidget
virtual void mouseDoubleClickWidget()
Called when the double click event happened on a widget.
Definition: toolbarstate.cpp:368
UMLApp::app
static UMLApp * app()
Get the last created instance of this class.
Definition: uml.cpp:206
ToolBarState::mousePressWidget
virtual void mousePressWidget()
Called when the press event happened on a widget.
Definition: toolbarstate.cpp:317
ToolBarState::~ToolBarState
virtual ~ToolBarState()
Destroys this ToolBarState.
Definition: toolbarstate.cpp:32
AssociationWidget::onAssociation
bool onAssociation(const QPointF &point)
Returns true if the given point is on the association line.
Definition: associationwidget.cpp:3748
ToolBarState::mouseRelease
virtual void mouseRelease(QGraphicsSceneMouseEvent *ome)
Handler for mouse release events.
Definition: toolbarstate.cpp:110
QObject
ToolBarState::ToolBarState
ToolBarState(UMLScene *umlScene)
Creates a new ToolBarState.
Definition: toolbarstate.cpp:251
debug_utils.h
ToolBarState::slotAssociationRemoved
virtual void slotAssociationRemoved(AssociationWidget *association)
An association was removed from the UMLScene.
Definition: toolbarstate.cpp:223
AssociationWidget
This class represents an association inside a diagram.
Definition: associationwidget.h:50
objectwidget.h
ToolBarState::mouseMove
virtual void mouseMove(QGraphicsSceneMouseEvent *ome)
Handler for mouse move events.
Definition: toolbarstate.cpp:175
ToolBarState::changeTool
virtual void changeTool()
Changes the current tool to the default one if the right button was released.
Definition: toolbarstate.cpp:414
ToolBarState::mousePressEmpty
virtual void mousePressEmpty()
Called when the press event happened on an empty space.
Definition: toolbarstate.cpp:325
MessageWidget
Used to display a message on a sequence diagram.
Definition: messagewidget.h:41
umlwidget.h
ToolBarState::cleanBeforeChange
virtual void cleanBeforeChange()
Called when the current tool is changed to use another tool.
Definition: toolbarstate.cpp:59
UMLScene::widgetAt
UMLWidget * widgetAt(const QPointF &p)
Tests the given point against all widgets and returns the widget for which the point is within its bo...
Definition: umlscene.cpp:968
Type
Type
Definition: preprocesslexer.h:59
UMLScene::associationList
AssociationWidgetList & associationList()
Returns a reference to the association list.
Definition: umlscene.cpp:416
floatingdashlinewidget.h
WidgetBase::wt_FloatingDashLine
Definition: widgetbase.h:66
FloatingDashLineWidget
This class is used to draw dash lines for UML combined fragments.
Definition: floatingdashlinewidget.h:33
ToolBarState::mouseDoubleClick
virtual void mouseDoubleClick(QGraphicsSceneMouseEvent *ome)
Handler for mouse double click events.
Definition: toolbarstate.cpp:143
ToolBarState::mouseDoubleClickEmpty
virtual void mouseDoubleClickEmpty()
Called when the double click event happened on an empty space.
Definition: toolbarstate.cpp:376
toolbarstate.h
uDebug
#define uDebug()
Definition: debug_utils.h:95
ToolBarState::setCurrentWidget
virtual void setCurrentWidget(UMLWidget *widget)
Sets the widget currently in use.
Definition: toolbarstate.cpp:440
ToolBarState::setCurrentAssociation
virtual void setCurrentAssociation(AssociationWidget *association)
Sets the association currently in use.
Definition: toolbarstate.cpp:464
associationwidget.h
UMLScene::setPaste
void setPaste(bool paste)
Sets the status on whether in a paste state.
Definition: umlscene.cpp:3041
ToolBarState::slotWidgetRemoved
virtual void slotWidgetRemoved(UMLWidget *widget)
A widget was removed from the UMLScene.
Definition: toolbarstate.cpp:236
ToolBarState::mouseMoveAssociation
virtual void mouseMoveAssociation()
Called when the move event happened when an association is currently available.
Definition: toolbarstate.cpp:388
UMLScene::activeView
UMLView * activeView() const
Returns the active view associated with this scene.
Definition: umlscene.cpp:193
ToolBarState::associationAt
AssociationWidget * associationAt(const QPointF &pos)
Returns the AssociationWidget at the specified position, or null if there is none.
Definition: toolbarstate.cpp:522
ToolBarState::mouseReleaseWidget
virtual void mouseReleaseWidget()
Called when the release event happened on a widget.
Definition: toolbarstate.cpp:344
UMLScene::clearSelected
void clearSelected()
Clear the selected widgets list.
Definition: umlscene.cpp:1291
ToolBarState::mousePressAssociation
virtual void mousePressAssociation()
Called when the press event happened on an association.
Definition: toolbarstate.cpp:309
ToolBarState::init
virtual void init()
Goes back to the initial state.
Definition: toolbarstate.cpp:41
ToolBarState::m_pMouseEvent
QGraphicsSceneMouseEvent * m_pMouseEvent
The mouse event currently in use.
Definition: toolbarstate.h:121
UMLApp::workToolBar
WorkToolBar * workToolBar() const
Returns the toolbar being used.
Definition: uml.cpp:1663
WidgetBase::baseType
WidgetType baseType() const
Read property of m_baseType.
Definition: widgetbase.cpp:76
ToolBarState::mouseDoubleClickAssociation
virtual void mouseDoubleClickAssociation()
Called when the double click event happened on an association.
Definition: toolbarstate.cpp:360
ToolBarState::currentWidget
virtual UMLWidget * currentWidget() const
Returns the widget currently in use.
Definition: toolbarstate.cpp:426
ToolBarState::currentAssociation
virtual AssociationWidget * currentAssociation() const
Returns the association currently in use.
Definition: toolbarstate.cpp:450
ToolBarState::setCurrentElement
virtual void setCurrentElement()
Sets the current association or widget.
Definition: toolbarstate.cpp:267
ToolBarState::mousePress
virtual void mousePress(QGraphicsSceneMouseEvent *ome)
Handler for mouse press events.
Definition: toolbarstate.cpp:78
UMLScene::setPos
void setPos(const QPointF &pos)
Sets the position of the diagram.
Definition: umlscene.cpp:296
UMLScene::messageList
MessageWidgetList & messageList()
Returns a reference to the message list.
Definition: umlscene.cpp:432
WorkToolBar::setDefaultTool
void setDefaultTool()
Sets the current tool to the default tool.
Definition: worktoolbar.cpp:282
UMLScene
UMLScene instances represent diagrams.
Definition: umlscene.h:70
UMLScene::onWidgetDestructionBox
ObjectWidget * onWidgetDestructionBox(const QPointF &point) const
Determine whether on a sequence diagram we have clicked on the destruction box of an Object...
Definition: umlscene.cpp:933
MessageWidget::onWidget
qreal onWidget(const QPointF &p)
Overrides operation from UMLWidget.
Definition: messagewidget.cpp:597
uml.h
ToolBarState::mouseMoveEmpty
virtual void mouseMoveEmpty()
Called when the move event happened when no association nor widget are currently available.
Definition: toolbarstate.cpp:406
ToolBarState::setMouseEvent
void setMouseEvent(QGraphicsSceneMouseEvent *ome, const QEvent::Type &type)
Sets m_pMouseEvent as the equivalent of the received event after transforming it using the inverse wo...
Definition: toolbarstate.cpp:477
UMLWidget
This is the base class for nearly all graphical widgets.
Definition: umlwidget.h:40
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:06:00 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

umbrello/umbrello

Skip menu "umbrello/umbrello"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdesdk API Reference

Skip menu "kdesdk API Reference"
  • kapptemplate
  • kcachegrind
  • kompare
  • lokalize
  • okteta
  • umbrello
  •   umbrello

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal