• 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
umlview.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) 2002-2013 *
8  * Umbrello UML Modeller Authors <umbrello-devel@kde.org> *
9  ***************************************************************************/
10 
11 // own header
12 #include "umlview.h"
13 
14 // application specific includes
15 #include "debug_utils.h"
16 #include "docwindow.h"
17 #include "model_utils.h"
18 #include "notewidget.h"
19 #include "uml.h"
20 #include "umldoc.h"
21 #include "umldragdata.h"
22 #include "umlscene.h"
23 #include "umlviewdialog.h"
24 #include "umlwidget.h"
25 
26 #include <QPointer>
27 
28 DEBUG_REGISTER(UMLView)
29 
30 
33 UMLView::UMLView(UMLFolder *parentFolder)
34  : QGraphicsView(UMLApp::app()->mainViewWidget()),
35  m_nZoom(100)
36 {
37  setAcceptDrops(true);
38  setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
39  setDragMode(NoDrag); //:TODO: RubberBandDrag);
40  // [PORT] For now the following is used. Shd check for creation of
41  // new scene later.
42  UMLScene *scene = new UMLScene(parentFolder, this);
43  setScene(scene);
44 }
45 
49 UMLView::~UMLView()
50 {
51  //TODO: Check if the scene shd be deleted
52 }
53 
58 UMLScene* UMLView::umlScene() const
59 {
60  return static_cast<UMLScene*>(scene());
61 }
62 
66 int UMLView::zoom() const
67 {
68  return m_nZoom;
69 }
70 
74 void UMLView::setZoom(int zoom)
75 {
76  if (zoom < 10) {
77  zoom = 10;
78  } else if (zoom > 500) {
79  zoom = 500;
80  }
81 
82  QMatrix wm;
83  wm.scale(zoom / 100.0, zoom / 100.0);
84  setMatrix(wm);
85 
86  m_nZoom = currentZoom();
87  umlScene()->resizeSceneToItems();
88 }
89 
93 int UMLView::currentZoom()
94 {
95  return (int)(matrix().m11()*100.0);
96 }
97 
101 bool UMLView::showPropDialog()
102 {
103  bool success = false;
104  QPointer<UMLViewDialog> dlg = new UMLViewDialog(this, umlScene());
105  if (dlg->exec() == QDialog::Accepted) {
106  success = true;
107  }
108  delete dlg;
109  return success;
110 }
111 
112 void UMLView::zoomIn()
113 {
114  QMatrix wm = matrix();
115  wm.scale(1.5, 1.5); // adjust zooming step here
116  setZoom((int)(wm.m11()*100.0));
117 }
118 
119 void UMLView::zoomOut()
120 {
121  QMatrix wm = matrix();
122  wm.scale(2.0 / 3.0, 2.0 / 3.0); //adjust zooming step here
123  setZoom((int)(wm.m11()*100.0));
124 }
125 
130 void UMLView::show()
131 {
132  QWidget::show();
133  umlScene()->resizeSceneToItems();
134 }
135 
139 void UMLView::wheelEvent(QWheelEvent* event)
140 {
141  // get the position of the mouse before scaling, in scene coords
142  QPointF pointBeforeScale(mapToScene(event->pos()));
143 
144  // get the original screen centerpoint
145  QPointF screenCenter = center();
146 
147  // scale the view ie. do the zoom
148  double scaleFactor = 1.15;
149  if (event->delta() > 0) {
150  // zoom in
151  if (currentZoom() < 500) {
152  scale(scaleFactor, scaleFactor);
153  }
154  } else {
155  // zooming out
156  if (currentZoom() > 10) {
157  scale(1.0 / scaleFactor, 1.0 / scaleFactor);
158  }
159  }
160 
161  // get the position after scaling, in scene coords
162  QPointF pointAfterScale(mapToScene(event->pos()));
163 
164  // get the offset of how the screen moved
165  QPointF offset = pointBeforeScale - pointAfterScale;
166 
167  // adjust to the new center for correct zooming
168  QPointF newCenter = screenCenter + offset;
169  setCenter(newCenter);
170 
171  DEBUG(DBG_SRC) << "currentZoom=" << currentZoom();
172  UMLApp::app()->slotZoomSliderMoved(currentZoom());
173 }
174 
179 void UMLView::resizeEvent(QResizeEvent* event)
180 {
181  // get the rectangle of the visible area in scene coords
182  QRectF visibleArea = mapToScene(rect()).boundingRect();
183  setCenter(visibleArea.center());
184 
185  // call the subclass resize so the scrollbars are updated correctly
186  QGraphicsView::resizeEvent(event);
187 }
188 
192 void UMLView::showEvent(QShowEvent* se)
193 {
194  UMLApp* theApp = UMLApp::app();
195  WorkToolBar* tb = theApp->workToolBar();
196  UMLScene *us = umlScene();
197  connect(tb, SIGNAL(sigButtonChanged(int)), us, SLOT(slotToolBarChanged(int)));
198  connect(us, SIGNAL(sigResetToolBar()), tb, SLOT(slotResetToolBar()));
199 
200  umlScene()->showEvent(se);
201  us->resetToolbar();
202 }
203 
207 void UMLView::hideEvent(QHideEvent* he)
208 {
209  UMLApp* theApp = UMLApp::app();
210  WorkToolBar* tb = theApp->workToolBar();
211  UMLScene *us = umlScene();
212  disconnect(tb, SIGNAL(sigButtonChanged(int)), us, SLOT(slotToolBarChanged(int)));
213  disconnect(us, SIGNAL(sigResetToolBar()), tb, SLOT(slotResetToolBar()));
214 
215  us->hideEvent(he);
216 }
217 
221 void UMLView::closeEvent(QCloseEvent* ce)
222 {
223  QWidget::closeEvent(ce);
224 }
225 
233 void UMLView::setCenter(const QPointF& centerPoint)
234 {
235  // get the rectangle of the visible area in scene coords
236  QRectF visibleArea = mapToScene(rect()).boundingRect();
237 
238  // get the scene area
239  QRectF sceneBounds = sceneRect();
240 
241  double boundX = visibleArea.width() / 2.0;
242  double boundY = visibleArea.height() / 2.0;
243  double boundWidth = sceneBounds.width() - 2.0 * boundX;
244  double boundHeight = sceneBounds.height() - 2.0 * boundY;
245 
246  // the max boundary that the centerPoint can be to
247  QRectF bounds(boundX, boundY, boundWidth, boundHeight);
248 
249  if (bounds.contains(centerPoint)) {
250  // we are within the bounds
251  m_currentCenterPoint = centerPoint;
252  } else {
253  // we need to clamp or use the center of the screen
254  if(visibleArea.contains(sceneBounds)) {
255  // use the center of scene ie. we can see the whole scene
256  m_currentCenterPoint = sceneBounds.center();
257  } else {
258 
259  m_currentCenterPoint = centerPoint;
260 
261  // we need to clamp the center. The centerPoint is too large
262  if (centerPoint.x() > bounds.x() + bounds.width()) {
263  m_currentCenterPoint.setX(bounds.x() + bounds.width());
264  } else if (centerPoint.x() < bounds.x()) {
265  m_currentCenterPoint.setX(bounds.x());
266  }
267 
268  if (centerPoint.y() > bounds.y() + bounds.height()) {
269  m_currentCenterPoint.setY(bounds.y() + bounds.height());
270  } else if (centerPoint.y() < bounds.y()) {
271  m_currentCenterPoint.setY(bounds.y());
272  }
273 
274  }
275  }
276  // update the scrollbars
277  centerOn(m_currentCenterPoint);
278 }
279 
283 QPointF UMLView::center()
284 {
285  return m_currentCenterPoint;
286 }
287 
288 #include "umlview.moc"
UMLView::closeEvent
virtual void closeEvent(QCloseEvent *ce)
Override standard method.
Definition: umlview.cpp:221
UMLView::m_nZoom
int m_nZoom
zoom level in percent, default 100
Definition: umlview.h:64
UMLScene::resizeSceneToItems
void resizeSceneToItems()
Sets the size of the scene to just fit on all the items.
Definition: umlscene.cpp:3700
UMLView::zoomOut
void zoomOut()
Definition: umlview.cpp:119
UMLView::resizeEvent
virtual void resizeEvent(QResizeEvent *event)
Need to update the center so there is no jolt in the interaction after resizing the widget...
Definition: umlview.cpp:179
umlview.h
umlscene.h
UMLView
UMLView instances represent diagrams.
Definition: umlview.h:32
UMLApp::app
static UMLApp * app()
Get the last created instance of this class.
Definition: uml.cpp:206
UMLView::setCenter
void setCenter(const QPointF &centerPoint)
Sets the current centerpoint.
Definition: umlview.cpp:233
UMLView::wheelEvent
virtual void wheelEvent(QWheelEvent *event)
Zoom the view in and out.
Definition: umlview.cpp:139
UMLView::showEvent
virtual void showEvent(QShowEvent *se)
Overrides the standard operation.
Definition: umlview.cpp:192
UMLView::m_currentCenterPoint
QPointF m_currentCenterPoint
holds the current centerpoint for the view, used for panning and zooming
Definition: umlview.h:62
UMLView::center
QPointF center()
Get the center.
Definition: umlview.cpp:283
umlviewdialog.h
UMLScene::hideEvent
void hideEvent(QHideEvent *he)
Overrides the standard operation.
Definition: umlscene.cpp:561
model_utils.h
debug_utils.h
UMLView::hideEvent
virtual void hideEvent(QHideEvent *he)
Overrides the standard operation.
Definition: umlview.cpp:207
UMLView::~UMLView
virtual ~UMLView()
Destructor.
Definition: umlview.cpp:49
docwindow.h
notewidget.h
UMLScene::showEvent
void showEvent(QShowEvent *se)
Overrides the standard operation.
Definition: umlscene.cpp:548
umlwidget.h
umldragdata.h
DEBUG
#define DEBUG(src)
Definition: debug_utils.h:101
UMLApp
The base class for UML application windows.
Definition: uml.h:81
UMLViewDialog
Definition: umlviewdialog.h:39
UMLFolder
This class manages the UMLObjects and UMLViews of a Folder.
Definition: folder.h:34
UMLView::show
void show()
Overrides standard method from QWidget to resize scene when it's shown.
Definition: umlview.cpp:130
UMLView::setZoom
void setZoom(int zoom)
Sets the zoom of the diagram.
Definition: umlview.cpp:74
UMLApp::slotZoomSliderMoved
void slotZoomSliderMoved(int value)
Connected to by the zoomAction, a value of between 300 and 2200 is scaled to zoom to between 9% and 5...
Definition: uml.cpp:567
umldoc.h
UMLView::umlScene
UMLScene * umlScene() const
Getter for the scene.
Definition: umlview.cpp:58
WorkToolBar
This is the toolbar that is displayed on the right-hand side of the program window.
Definition: worktoolbar.h:40
UMLView::zoom
int zoom() const
Returns the zoom of the diagram.
Definition: umlview.cpp:66
UMLApp::workToolBar
WorkToolBar * workToolBar() const
Returns the toolbar being used.
Definition: uml.cpp:1663
QGraphicsView
DEBUG_REGISTER
#define DEBUG_REGISTER(src)
Definition: debug_utils.h:102
UMLView::showPropDialog
bool showPropDialog()
Shows the properties dialog for the view.
Definition: umlview.cpp:101
UMLScene::resetToolbar
void resetToolbar()
Reset the toolbar.
Definition: umlscene.cpp:2949
UMLView::currentZoom
int currentZoom()
Return the current zoom factor.
Definition: umlview.cpp:93
UMLScene
UMLScene instances represent diagrams.
Definition: umlscene.h:70
uml.h
DBG_SRC
#define DBG_SRC
Definition: import_utils.cpp:42
UMLView::zoomIn
void zoomIn()
Definition: umlview.cpp:112
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:06:01 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