Graphics/UMLGraphicsView.py

changeset 945
8cd4d08fa9f6
parent 882
34b86be88bf0
child 1112
8a7d1b9d18db
equal deleted inserted replaced
944:1b59c4ba121e 945:8cd4d08fa9f6
20 20
21 import UI.Config 21 import UI.Config
22 import UI.PixmapCache 22 import UI.PixmapCache
23 23
24 import Preferences 24 import Preferences
25
25 26
26 class UMLGraphicsView(E5GraphicsView): 27 class UMLGraphicsView(E5GraphicsView):
27 """ 28 """
28 Class implementing a specialized E5GraphicsView for our diagrams. 29 Class implementing a specialized E5GraphicsView for our diagrams.
29 30
30 @signal relayout() emitted to indicate a relayout of the diagram 31 @signal relayout() emitted to indicate a relayout of the diagram
31 is requested 32 is requested
32 """ 33 """
33 relayout = pyqtSignal() 34 relayout = pyqtSignal()
34 35
35 def __init__(self, scene, diagramName = "Unnamed", parent = None, name = None): 36 def __init__(self, scene, diagramName="Unnamed", parent=None, name=None):
36 """ 37 """
37 Constructor 38 Constructor
38 39
39 @param scene reference to the scene object (QGraphicsScene) 40 @param scene reference to the scene object (QGraphicsScene)
40 @param diagramName name of the diagram (string) 41 @param diagramName name of the diagram (string)
101 self.trUtf8("Zoom reset"), self) 102 self.trUtf8("Zoom reset"), self)
102 self.zoomResetAct.triggered[()].connect(self.zoomReset) 103 self.zoomResetAct.triggered[()].connect(self.zoomReset)
103 104
104 self.incWidthAct = \ 105 self.incWidthAct = \
105 QAction(UI.PixmapCache.getIcon("sceneWidthInc.png"), 106 QAction(UI.PixmapCache.getIcon("sceneWidthInc.png"),
106 self.trUtf8("Increase width by {0} points").format(self.deltaSize), 107 self.trUtf8("Increase width by {0} points").format(self.deltaSize),
107 self) 108 self)
108 self.incWidthAct.triggered[()].connect(self.__incWidth) 109 self.incWidthAct.triggered[()].connect(self.__incWidth)
109 110
110 self.incHeightAct = \ 111 self.incHeightAct = \
111 QAction(UI.PixmapCache.getIcon("sceneHeightInc.png"), 112 QAction(UI.PixmapCache.getIcon("sceneHeightInc.png"),
112 self.trUtf8("Increase height by {0} points").format(self.deltaSize), 113 self.trUtf8("Increase height by {0} points").format(self.deltaSize),
113 self) 114 self)
114 self.incHeightAct.triggered[()].connect(self.__incHeight) 115 self.incHeightAct.triggered[()].connect(self.__incHeight)
115 116
116 self.decWidthAct = \ 117 self.decWidthAct = \
117 QAction(UI.PixmapCache.getIcon("sceneWidthDec.png"), 118 QAction(UI.PixmapCache.getIcon("sceneWidthDec.png"),
118 self.trUtf8("Decrease width by {0} points").format(self.deltaSize), 119 self.trUtf8("Decrease width by {0} points").format(self.deltaSize),
119 self) 120 self)
120 self.decWidthAct.triggered[()].connect(self.__decWidth) 121 self.decWidthAct.triggered[()].connect(self.__decWidth)
121 122
122 self.decHeightAct = \ 123 self.decHeightAct = \
123 QAction(UI.PixmapCache.getIcon("sceneHeightDec.png"), 124 QAction(UI.PixmapCache.getIcon("sceneHeightDec.png"),
124 self.trUtf8("Decrease height by {0} points").format(self.deltaSize), 125 self.trUtf8("Decrease height by {0} points").format(self.deltaSize),
125 self) 126 self)
126 self.decHeightAct.triggered[()].connect(self.__decHeight) 127 self.decHeightAct.triggered[()].connect(self.__decHeight)
127 128
128 self.setSizeAct = \ 129 self.setSizeAct = \
129 QAction(UI.PixmapCache.getIcon("sceneSize.png"), 130 QAction(UI.PixmapCache.getIcon("sceneSize.png"),
134 QAction(UI.PixmapCache.getIcon("reload.png"), 135 QAction(UI.PixmapCache.getIcon("reload.png"),
135 self.trUtf8("Re-Layout"), self) 136 self.trUtf8("Re-Layout"), self)
136 self.relayoutAct.triggered[()].connect(self.__relayout) 137 self.relayoutAct.triggered[()].connect(self.__relayout)
137 138
138 self.alignLeftAct = \ 139 self.alignLeftAct = \
139 QAction(UI.PixmapCache.getIcon("shapesAlignLeft.png"), 140 QAction(UI.PixmapCache.getIcon("shapesAlignLeft.png"),
140 self.trUtf8("Align Left"), self) 141 self.trUtf8("Align Left"), self)
141 self.alignMapper.setMapping(self.alignLeftAct, Qt.AlignLeft) 142 self.alignMapper.setMapping(self.alignLeftAct, Qt.AlignLeft)
142 self.alignLeftAct.triggered[()].connect(self.alignMapper.map) 143 self.alignLeftAct.triggered[()].connect(self.alignMapper.map)
143 144
144 self.alignHCenterAct = \ 145 self.alignHCenterAct = \
145 QAction(UI.PixmapCache.getIcon("shapesAlignHCenter.png"), 146 QAction(UI.PixmapCache.getIcon("shapesAlignHCenter.png"),
146 self.trUtf8("Align Center Horizontal"), self) 147 self.trUtf8("Align Center Horizontal"), self)
147 self.alignMapper.setMapping(self.alignHCenterAct, Qt.AlignHCenter) 148 self.alignMapper.setMapping(self.alignHCenterAct, Qt.AlignHCenter)
148 self.alignHCenterAct.triggered[()].connect(self.alignMapper.map) 149 self.alignHCenterAct.triggered[()].connect(self.alignMapper.map)
149 150
150 self.alignRightAct = \ 151 self.alignRightAct = \
151 QAction(UI.PixmapCache.getIcon("shapesAlignRight.png"), 152 QAction(UI.PixmapCache.getIcon("shapesAlignRight.png"),
152 self.trUtf8("Align Right"), self) 153 self.trUtf8("Align Right"), self)
153 self.alignMapper.setMapping(self.alignRightAct, Qt.AlignRight) 154 self.alignMapper.setMapping(self.alignRightAct, Qt.AlignRight)
154 self.alignRightAct.triggered[()].connect(self.alignMapper.map) 155 self.alignRightAct.triggered[()].connect(self.alignMapper.map)
155 156
156 self.alignTopAct = \ 157 self.alignTopAct = \
157 QAction(UI.PixmapCache.getIcon("shapesAlignTop.png"), 158 QAction(UI.PixmapCache.getIcon("shapesAlignTop.png"),
158 self.trUtf8("Align Top"), self) 159 self.trUtf8("Align Top"), self)
159 self.alignMapper.setMapping(self.alignTopAct, Qt.AlignTop) 160 self.alignMapper.setMapping(self.alignTopAct, Qt.AlignTop)
160 self.alignTopAct.triggered[()].connect(self.alignMapper.map) 161 self.alignTopAct.triggered[()].connect(self.alignMapper.map)
161 162
162 self.alignVCenterAct = \ 163 self.alignVCenterAct = \
163 QAction(UI.PixmapCache.getIcon("shapesAlignVCenter.png"), 164 QAction(UI.PixmapCache.getIcon("shapesAlignVCenter.png"),
164 self.trUtf8("Align Center Vertical"), self) 165 self.trUtf8("Align Center Vertical"), self)
165 self.alignMapper.setMapping(self.alignVCenterAct, Qt.AlignVCenter) 166 self.alignMapper.setMapping(self.alignVCenterAct, Qt.AlignVCenter)
166 self.alignVCenterAct.triggered[()].connect(self.alignMapper.map) 167 self.alignVCenterAct.triggered[()].connect(self.alignMapper.map)
167 168
168 self.alignBottomAct = \ 169 self.alignBottomAct = \
169 QAction(UI.PixmapCache.getIcon("shapesAlignBottom.png"), 170 QAction(UI.PixmapCache.getIcon("shapesAlignBottom.png"),
170 self.trUtf8("Align Bottom"), self) 171 self.trUtf8("Align Bottom"), self)
171 self.alignMapper.setMapping(self.alignBottomAct, Qt.AlignBottom) 172 self.alignMapper.setMapping(self.alignBottomAct, Qt.AlignBottom)
172 self.alignBottomAct.triggered[()].connect(self.alignMapper.map) 173 self.alignBottomAct.triggered[()].connect(self.alignMapper.map)
173 174
174 def __checkSizeActions(self): 175 def __checkSizeActions(self):
339 if QFileInfo(fname).exists(): 340 if QFileInfo(fname).exists():
340 res = E5MessageBox.yesNo(self, 341 res = E5MessageBox.yesNo(self,
341 self.trUtf8("Save Diagram"), 342 self.trUtf8("Save Diagram"),
342 self.trUtf8("<p>The file <b>{0}</b> already exists." 343 self.trUtf8("<p>The file <b>{0}</b> already exists."
343 " Overwrite it?</p>").format(fname), 344 " Overwrite it?</p>").format(fname),
344 icon = E5MessageBox.Warning) 345 icon=E5MessageBox.Warning)
345 if not res: 346 if not res:
346 return 347 return
347 348
348 success = self.saveImage(fname, QFileInfo(fname).suffix().upper()) 349 success = self.saveImage(fname, QFileInfo(fname).suffix().upper())
349 if not success: 350 if not success:
364 365
365 def __printDiagram(self): 366 def __printDiagram(self):
366 """ 367 """
367 Private slot called to print the diagram. 368 Private slot called to print the diagram.
368 """ 369 """
369 printer = QPrinter(mode = QPrinter.ScreenResolution) 370 printer = QPrinter(mode=QPrinter.ScreenResolution)
370 printer.setFullPage(True) 371 printer.setFullPage(True)
371 if Preferences.getPrinter("ColorMode"): 372 if Preferences.getPrinter("ColorMode"):
372 printer.setColorMode(QPrinter.Color) 373 printer.setColorMode(QPrinter.Color)
373 else: 374 else:
374 printer.setColorMode(QPrinter.GrayScale) 375 printer.setColorMode(QPrinter.GrayScale)
386 """ 387 """
387 Private slot called to show a print preview of the diagram. 388 Private slot called to show a print preview of the diagram.
388 """ 389 """
389 from PyQt4.QtGui import QPrintPreviewDialog 390 from PyQt4.QtGui import QPrintPreviewDialog
390 391
391 printer = QPrinter(mode = QPrinter.ScreenResolution) 392 printer = QPrinter(mode=QPrinter.ScreenResolution)
392 printer.setFullPage(True) 393 printer.setFullPage(True)
393 if Preferences.getPrinter("ColorMode"): 394 if Preferences.getPrinter("ColorMode"):
394 printer.setColorMode(QPrinter.Color) 395 printer.setColorMode(QPrinter.Color)
395 else: 396 else:
396 printer.setColorMode(QPrinter.GrayScale) 397 printer.setColorMode(QPrinter.GrayScale)

eric ide

mercurial