61 |
61 |
62 def __init__(self, scene, parent=None): |
62 def __init__(self, scene, parent=None): |
63 """ |
63 """ |
64 Constructor |
64 Constructor |
65 |
65 |
66 @param scene reference to the scene object (QGraphicsScene) |
66 @param scene reference to the scene object |
67 @param parent parent widget (QWidget) |
67 @type QGraphicsScene |
|
68 @param parent parent widget |
|
69 @type QWidget |
68 """ |
70 """ |
69 super().__init__(scene, parent) |
71 super().__init__(scene, parent) |
70 self.setObjectName("EricGraphicsView") |
72 self.setObjectName("EricGraphicsView") |
71 |
73 |
72 self.__initialSceneSize = self.scene().sceneRect().size() |
74 self.__initialSceneSize = self.scene().sceneRect().size() |
137 |
139 |
138 def __levelForZoom(self, zoom): |
140 def __levelForZoom(self, zoom): |
139 """ |
141 """ |
140 Private method determining the zoom level index given a zoom factor. |
142 Private method determining the zoom level index given a zoom factor. |
141 |
143 |
142 @param zoom zoom factor (integer) |
144 @param zoom zoom factor |
143 @return index of zoom factor (integer) |
145 @type int |
|
146 @return index of zoom factor |
|
147 @rtype int |
144 """ |
148 """ |
145 try: |
149 try: |
146 index = EricGraphicsView.ZoomLevels.index(zoom) |
150 index = EricGraphicsView.ZoomLevels.index(zoom) |
147 except ValueError: |
151 except ValueError: |
148 for index in range(len(EricGraphicsView.ZoomLevels)): |
152 for index in range(len(EricGraphicsView.ZoomLevels)): |
174 |
178 |
175 def setZoom(self, value): |
179 def setZoom(self, value): |
176 """ |
180 """ |
177 Public method to set the zoom value in percent. |
181 Public method to set the zoom value in percent. |
178 |
182 |
179 @param value zoom value in percent (integer) |
183 @param value zoom value in percent |
|
184 @type int |
180 """ |
185 """ |
181 if value != self.zoom(): |
186 if value != self.zoom(): |
182 self.resetTransform() |
187 self.resetTransform() |
183 factor = value / 100.0 |
188 factor = value / 100.0 |
184 self.scale(factor, factor) |
189 self.scale(factor, factor) |
186 |
191 |
187 def zoom(self): |
192 def zoom(self): |
188 """ |
193 """ |
189 Public method to get the current zoom factor in percent. |
194 Public method to get the current zoom factor in percent. |
190 |
195 |
191 @return current zoom factor in percent (integer) |
196 @return current zoom factor in percent |
|
197 @rtype int |
192 """ |
198 """ |
193 return int(self.transform().m11() * 100.0) |
199 return int(self.transform().m11() * 100.0) |
194 |
200 |
195 def resizeScene(self, amount, isWidth=True): |
201 def resizeScene(self, amount, isWidth=True): |
196 """ |
202 """ |
197 Public method to resize the scene. |
203 Public method to resize the scene. |
198 |
204 |
199 @param amount size increment (integer) |
205 @param amount size increment |
200 @param isWidth flag indicating width is to be resized (boolean) |
206 @type int |
|
207 @param isWidth flag indicating width is to be resized |
|
208 @type bool |
201 """ |
209 """ |
202 sceneRect = self.scene().sceneRect() |
210 sceneRect = self.scene().sceneRect() |
203 width = sceneRect.width() |
211 width = sceneRect.width() |
204 height = sceneRect.height() |
212 height = sceneRect.height() |
205 if isWidth: |
213 if isWidth: |
216 |
224 |
217 def setSceneSize(self, width, height): |
225 def setSceneSize(self, width, height): |
218 """ |
226 """ |
219 Public method to set the scene size. |
227 Public method to set the scene size. |
220 |
228 |
221 @param width width for the scene (real) |
229 @param width width for the scene |
222 @param height height for the scene (real) |
230 @type float |
|
231 @param height height for the scene |
|
232 @type float |
223 """ |
233 """ |
224 rect = self.scene().sceneRect() |
234 rect = self.scene().sceneRect() |
225 rect.setHeight(height) |
235 rect.setHeight(height) |
226 rect.setWidth(width) |
236 rect.setWidth(width) |
227 self.scene().setSceneRect(rect) |
237 self.scene().setSceneRect(rect) |
229 def autoAdjustSceneSize(self, limit=False): |
239 def autoAdjustSceneSize(self, limit=False): |
230 """ |
240 """ |
231 Public method to adjust the scene size to the diagram size. |
241 Public method to adjust the scene size to the diagram size. |
232 |
242 |
233 @param limit flag indicating to limit the scene to the |
243 @param limit flag indicating to limit the scene to the |
234 initial size (boolean) |
244 initial size |
|
245 @type bool |
235 """ |
246 """ |
236 size = self._getDiagramSize(10) |
247 size = self._getDiagramSize(10) |
237 if limit: |
248 if limit: |
238 newWidth = max(size.width(), self.__initialSceneSize.width()) |
249 newWidth = max(size.width(), self.__initialSceneSize.width()) |
239 newHeight = max(size.height(), self.__initialSceneSize.height()) |
250 newHeight = max(size.height(), self.__initialSceneSize.height()) |
278 |
291 |
279 def _getDiagramSize(self, border=0): |
292 def _getDiagramSize(self, border=0): |
280 """ |
293 """ |
281 Protected method to calculate the minimum size fitting the diagram. |
294 Protected method to calculate the minimum size fitting the diagram. |
282 |
295 |
283 @param border border width to include in the calculation (integer) |
296 @param border border width to include in the calculation |
284 @return the minimum size (QSizeF) |
297 @type int |
|
298 @return the minimum size |
|
299 @rtype QSizeF |
285 """ |
300 """ |
286 endx = 0 |
301 endx = 0 |
287 endy = 0 |
302 endy = 0 |
288 for itm in self.filteredItems(self.scene().items()): |
303 for itm in self.filteredItems(self.scene().items()): |
289 rect = itm.sceneBoundingRect() |
304 rect = itm.sceneBoundingRect() |
307 @param rect minimum rectangle fitting the diagram |
322 @param rect minimum rectangle fitting the diagram |
308 @type QRectF |
323 @type QRectF |
309 @param imageFormat format for the image file |
324 @param imageFormat format for the image file |
310 @type str |
325 @type str |
311 @param filename name of the file for non pixmaps |
326 @param filename name of the file for non pixmaps |
312 str |
327 @type str |
313 @return paint device containing the diagram |
328 @return paint device containing the diagram |
314 @rtype QPixmap or QSvgGenerator |
329 @rtype QPixmap or QSvgGenerator |
315 """ |
330 """ |
316 selectedItems = self.scene().selectedItems() |
331 selectedItems = self.scene().selectedItems() |
317 |
332 |
343 |
358 |
344 def saveImage(self, filename, imageFormat="PNG"): |
359 def saveImage(self, filename, imageFormat="PNG"): |
345 """ |
360 """ |
346 Public method to save the scene to a file. |
361 Public method to save the scene to a file. |
347 |
362 |
348 @param filename name of the file to write the image to (string) |
363 @param filename name of the file to write the image to |
349 @param imageFormat format for the image file (string) |
364 @type float |
350 @return flag indicating success (boolean) |
365 @param imageFormat format for the image file |
|
366 @type float |
|
367 @return flag indicating success |
|
368 @rtype bool |
351 """ |
369 """ |
352 rect = self._getDiagramRect(self.border) |
370 rect = self._getDiagramRect(self.border) |
353 if imageFormat == "SVG": |
371 if imageFormat == "SVG": |
354 self.__getDiagram(rect, imageFormat=imageFormat, filename=filename) |
372 self.__getDiagram(rect, imageFormat=imageFormat, filename=filename) |
355 return True |
373 return True |
360 def printDiagram(self, printer, diagramName=""): |
378 def printDiagram(self, printer, diagramName=""): |
361 """ |
379 """ |
362 Public method to print the diagram. |
380 Public method to print the diagram. |
363 |
381 |
364 @param printer reference to a ready configured printer object |
382 @param printer reference to a ready configured printer object |
365 (QPrinter) |
383 @type QPrinter |
366 @param diagramName name of the diagram (string) |
384 @param diagramName name of the diagram |
|
385 @type float |
367 """ |
386 """ |
368 painter = QPainter(printer) |
387 painter = QPainter(printer) |
369 |
388 |
370 font = QFont(["times"], 10) |
389 font = QFont(["times"], 10) |
371 painter.setFont(font) |
390 painter.setFont(font) |
430 def filteredItems(self, items): |
449 def filteredItems(self, items): |
431 """ |
450 """ |
432 Public method to filter a list of items. |
451 Public method to filter a list of items. |
433 |
452 |
434 @param items list of items as returned by the scene object |
453 @param items list of items as returned by the scene object |
435 (QGraphicsItem) |
454 @type QGraphicsItem |
436 @return list of interesting collision items (QGraphicsItem) |
455 @return list of interesting collision items |
|
456 @rtype QGraphicsItem |
437 """ |
457 """ |
438 # just return the list unchanged |
458 # just return the list unchanged |
439 return list(items) |
459 return list(items) |