6 """ |
6 """ |
7 Module implementing a subclass of E5GraphicsView for our diagrams. |
7 Module implementing a subclass of E5GraphicsView for our diagrams. |
8 """ |
8 """ |
9 |
9 |
10 from PyQt4.QtCore import pyqtSignal, Qt, QSignalMapper, QFileInfo, QEvent |
10 from PyQt4.QtCore import pyqtSignal, Qt, QSignalMapper, QFileInfo, QEvent |
11 from PyQt4.QtGui import QAction, QToolBar, QDialog, QPrinter, QPrintDialog |
11 from PyQt4.QtGui import QGraphicsView, QAction, QToolBar, QDialog, QPrinter, QPrintDialog |
12 |
12 |
13 from E5Graphics.E5GraphicsView import E5GraphicsView |
13 from E5Graphics.E5GraphicsView import E5GraphicsView |
14 |
14 |
15 from E5Gui import E5MessageBox, E5FileDialog |
15 from E5Gui import E5MessageBox, E5FileDialog |
16 |
16 |
43 @param name name of the view widget (string) |
43 @param name name of the view widget (string) |
44 """ |
44 """ |
45 E5GraphicsView.__init__(self, scene, parent) |
45 E5GraphicsView.__init__(self, scene, parent) |
46 if name: |
46 if name: |
47 self.setObjectName(name) |
47 self.setObjectName(name) |
|
48 self.setViewportUpdateMode(QGraphicsView.FullViewportUpdate) |
48 |
49 |
49 self.diagramName = diagramName |
50 self.diagramName = diagramName |
50 |
51 |
51 self.border = 10 |
52 self.border = 10 |
52 self.deltaSize = 100.0 |
53 self.deltaSize = 100.0 |
178 """ |
179 """ |
179 Private slot to set the enabled state of the size actions. |
180 Private slot to set the enabled state of the size actions. |
180 """ |
181 """ |
181 diagramSize = self._getDiagramSize(10) |
182 diagramSize = self._getDiagramSize(10) |
182 sceneRect = self.scene().sceneRect() |
183 sceneRect = self.scene().sceneRect() |
183 if (sceneRect.width() - self.deltaSize) <= diagramSize.width(): |
184 if (sceneRect.width() - self.deltaSize) < diagramSize.width(): |
184 self.decWidthAct.setEnabled(False) |
185 self.decWidthAct.setEnabled(False) |
185 else: |
186 else: |
186 self.decWidthAct.setEnabled(True) |
187 self.decWidthAct.setEnabled(True) |
187 if (sceneRect.height() - self.deltaSize) <= diagramSize.height(): |
188 if (sceneRect.height() - self.deltaSize) < diagramSize.height(): |
188 self.decHeightAct.setEnabled(False) |
189 self.decHeightAct.setEnabled(False) |
189 else: |
190 else: |
190 self.decHeightAct.setEnabled(True) |
191 self.decHeightAct.setEnabled(True) |
191 |
192 |
192 def __sceneChanged(self, areas): |
193 def __sceneChanged(self, areas): |
197 """ |
198 """ |
198 if len(self.scene().selectedItems()) > 0: |
199 if len(self.scene().selectedItems()) > 0: |
199 self.deleteShapeAct.setEnabled(True) |
200 self.deleteShapeAct.setEnabled(True) |
200 else: |
201 else: |
201 self.deleteShapeAct.setEnabled(False) |
202 self.deleteShapeAct.setEnabled(False) |
|
203 |
|
204 sceneRect = self.scene().sceneRect() |
|
205 newWidth = width = sceneRect.width() |
|
206 newHeight = height = sceneRect.height() |
|
207 rect = self._getDiagramRect(10) |
|
208 if width < rect.width(): |
|
209 newWidth = rect.width() |
|
210 if height < rect.height(): |
|
211 newHeight = rect.height() |
|
212 |
|
213 if newHeight != height or newWidth != width: |
|
214 self.setSceneSize(newWidth, newHeight) |
|
215 self.__checkSizeActions() |
202 |
216 |
203 def initToolBar(self): |
217 def initToolBar(self): |
204 """ |
218 """ |
205 Public method to populate a toolbar with our actions. |
219 Public method to populate a toolbar with our actions. |
206 |
220 |
317 dlg = UMLSceneSizeDialog(sceneRect.width(), sceneRect.height(), |
331 dlg = UMLSceneSizeDialog(sceneRect.width(), sceneRect.height(), |
318 rect.width(), rect.height(), self) |
332 rect.width(), rect.height(), self) |
319 if dlg.exec_() == QDialog.Accepted: |
333 if dlg.exec_() == QDialog.Accepted: |
320 width, height = dlg.getData() |
334 width, height = dlg.getData() |
321 self.setSceneSize(width, height) |
335 self.setSceneSize(width, height) |
|
336 self.__checkSizeActions() |
|
337 |
|
338 def autoAdjustSceneSize(self, limit=False): |
|
339 """ |
|
340 Public method to adjust the scene size to the diagram size. |
|
341 |
|
342 @param limit flag indicating to limit the scene to the |
|
343 initial size (boolean) |
|
344 """ |
|
345 super().autoAdjustSceneSize(limit=limit) |
322 self.__checkSizeActions() |
346 self.__checkSizeActions() |
323 |
347 |
324 def __saveImage(self): |
348 def __saveImage(self): |
325 """ |
349 """ |
326 Private method to handle the save context menu entry. |
350 Private method to handle the save context menu entry. |
358 def __relayout(self): |
382 def __relayout(self): |
359 """ |
383 """ |
360 Private method to handle the re-layout context menu entry. |
384 Private method to handle the re-layout context menu entry. |
361 """ |
385 """ |
362 scene = self.scene() |
386 scene = self.scene() |
363 for itm in list(scene.items())[:]: |
387 scene.clear() |
364 if itm.scene() == scene: |
|
365 scene.removeItem(itm) |
|
366 self.relayout.emit() |
388 self.relayout.emit() |
367 |
389 |
368 def __printDiagram(self): |
390 def __printDiagram(self): |
369 """ |
391 """ |
370 Private slot called to print the diagram. |
392 Private slot called to print the diagram. |