11 from PyQt4.QtGui import QGraphicsView, 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 from E5Gui.E5ZoomWidget import E5ZoomWidget |
16 |
17 |
17 from .UMLItem import UMLItem |
18 from .UMLItem import UMLItem |
18 from .AssociationItem import AssociationItem |
19 from .AssociationItem import AssociationItem |
19 from .ClassItem import ClassItem |
20 from .ClassItem import ClassItem |
20 from .ModuleItem import ModuleItem |
21 from .ModuleItem import ModuleItem |
21 from .PackageItem import PackageItem |
22 from .PackageItem import PackageItem |
22 from .UMLSceneSizeDialog import UMLSceneSizeDialog |
23 from .UMLSceneSizeDialog import UMLSceneSizeDialog |
23 from .ZoomDialog import ZoomDialog |
|
24 |
24 |
25 import UI.Config |
25 import UI.Config |
26 import UI.PixmapCache |
26 import UI.PixmapCache |
27 |
27 |
28 import Preferences |
28 import Preferences |
52 self.__itemId = -1 |
52 self.__itemId = -1 |
53 |
53 |
54 self.border = 10 |
54 self.border = 10 |
55 self.deltaSize = 100.0 |
55 self.deltaSize = 100.0 |
56 |
56 |
|
57 self.__zoomWidget = E5ZoomWidget(UI.PixmapCache.getPixmap("zoomOut.png"), |
|
58 UI.PixmapCache.getPixmap("zoomIn.png"), |
|
59 UI.PixmapCache.getPixmap("zoomReset.png"), self) |
|
60 parent.statusBar().addPermanentWidget(self.__zoomWidget) |
|
61 self.__zoomWidget.setMapping( |
|
62 E5GraphicsView.ZoomLevels, E5GraphicsView.ZoomLevelDefault) |
|
63 self.__zoomWidget.valueChanged.connect(self.setZoom) |
|
64 self.zoomValueChanged.connect(self.__zoomWidget.setValue) |
|
65 |
57 self.__initActions() |
66 self.__initActions() |
58 |
67 |
59 scene.changed.connect(self.__sceneChanged) |
68 scene.changed.connect(self.__sceneChanged) |
60 |
69 |
61 self.grabGesture(Qt.PinchGesture) |
70 self.grabGesture(Qt.PinchGesture) |
69 |
78 |
70 self.deleteShapeAct = \ |
79 self.deleteShapeAct = \ |
71 QAction(UI.PixmapCache.getIcon("deleteShape.png"), |
80 QAction(UI.PixmapCache.getIcon("deleteShape.png"), |
72 self.trUtf8("Delete shapes"), self) |
81 self.trUtf8("Delete shapes"), self) |
73 self.deleteShapeAct.triggered[()].connect(self.__deleteShape) |
82 self.deleteShapeAct.triggered[()].connect(self.__deleteShape) |
74 |
|
75 self.zoomInAct = \ |
|
76 QAction(UI.PixmapCache.getIcon("zoomIn.png"), |
|
77 self.trUtf8("Zoom in"), self) |
|
78 self.zoomInAct.triggered[()].connect(self.zoomIn) |
|
79 |
|
80 self.zoomOutAct = \ |
|
81 QAction(UI.PixmapCache.getIcon("zoomOut.png"), |
|
82 self.trUtf8("Zoom out"), self) |
|
83 self.zoomOutAct.triggered[()].connect(self.zoomOut) |
|
84 |
|
85 self.zoomAct = \ |
|
86 QAction(UI.PixmapCache.getIcon("zoomTo.png"), |
|
87 self.trUtf8("Zoom..."), self) |
|
88 self.zoomAct.triggered[()].connect(self.__zoom) |
|
89 |
|
90 self.zoomResetAct = \ |
|
91 QAction(UI.PixmapCache.getIcon("zoomReset.png"), |
|
92 self.trUtf8("Zoom reset"), self) |
|
93 self.zoomResetAct.triggered[()].connect(self.zoomReset) |
|
94 |
83 |
95 self.incWidthAct = \ |
84 self.incWidthAct = \ |
96 QAction(UI.PixmapCache.getIcon("sceneWidthInc.png"), |
85 QAction(UI.PixmapCache.getIcon("sceneWidthInc.png"), |
97 self.trUtf8("Increase width by {0} points").format(self.deltaSize), |
86 self.trUtf8("Increase width by {0} points").format(self.deltaSize), |
98 self) |
87 self) |
214 @return the populated toolBar (QToolBar) |
203 @return the populated toolBar (QToolBar) |
215 """ |
204 """ |
216 toolBar = QToolBar(self.trUtf8("Graphics"), self) |
205 toolBar = QToolBar(self.trUtf8("Graphics"), self) |
217 toolBar.setIconSize(UI.Config.ToolBarIconSize) |
206 toolBar.setIconSize(UI.Config.ToolBarIconSize) |
218 toolBar.addAction(self.deleteShapeAct) |
207 toolBar.addAction(self.deleteShapeAct) |
219 toolBar.addSeparator() |
|
220 toolBar.addAction(self.zoomInAct) |
|
221 toolBar.addAction(self.zoomOutAct) |
|
222 toolBar.addAction(self.zoomAct) |
|
223 toolBar.addAction(self.zoomResetAct) |
|
224 toolBar.addSeparator() |
208 toolBar.addSeparator() |
225 toolBar.addAction(self.alignLeftAct) |
209 toolBar.addAction(self.alignLeftAct) |
226 toolBar.addAction(self.alignHCenterAct) |
210 toolBar.addAction(self.alignHCenterAct) |
227 toolBar.addAction(self.alignRightAct) |
211 toolBar.addAction(self.alignRightAct) |
228 toolBar.addAction(self.alignTopAct) |
212 toolBar.addAction(self.alignTopAct) |
464 """ |
448 """ |
465 Private slot to generate a print preview. |
449 Private slot to generate a print preview. |
466 """ |
450 """ |
467 super().printDiagram(printer, self.diagramName) |
451 super().printDiagram(printer, self.diagramName) |
468 |
452 |
469 def __zoom(self): |
|
470 """ |
|
471 Private method to handle the zoom context menu action. |
|
472 """ |
|
473 dlg = ZoomDialog(self.zoom(), self) |
|
474 if dlg.exec_() == QDialog.Accepted: |
|
475 zoom = dlg.getZoomSize() |
|
476 self.setZoom(zoom) |
|
477 |
|
478 def setDiagramName(self, name): |
453 def setDiagramName(self, name): |
479 """ |
454 """ |
480 Public slot to set the diagram name. |
455 Public slot to set the diagram name. |
481 |
456 |
482 @param name diagram name (string) |
457 @param name diagram name (string) |
639 @param evt reference to the gesture event (QGestureEvent |
614 @param evt reference to the gesture event (QGestureEvent |
640 """ |
615 """ |
641 pinch = evt.gesture(Qt.PinchGesture) |
616 pinch = evt.gesture(Qt.PinchGesture) |
642 if pinch: |
617 if pinch: |
643 if pinch.state() == Qt.GestureStarted: |
618 if pinch.state() == Qt.GestureStarted: |
644 pinch.setScaleFactor(self.zoom()) |
619 pinch.setScaleFactor(self.zoom() / 100.0) |
645 else: |
620 else: |
646 self.setZoom(pinch.scaleFactor()) |
621 self.setZoom(int(pinch.scaleFactor() * 100)) |
647 evt.accept() |
622 evt.accept() |
648 |
623 |
649 def getItemId(self): |
624 def getItemId(self): |
650 """ |
625 """ |
651 Public method to get the ID to be assigned to an item. |
626 Public method to get the ID to be assigned to an item. |