51 self.setAlignment(Qt.Alignment(Qt.AlignLeft | Qt.AlignTop)) |
51 self.setAlignment(Qt.Alignment(Qt.AlignLeft | Qt.AlignTop)) |
52 self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOn) |
52 self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOn) |
53 self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn) |
53 self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn) |
54 self.setViewportUpdateMode(QGraphicsView.SmartViewportUpdate) |
54 self.setViewportUpdateMode(QGraphicsView.SmartViewportUpdate) |
55 |
55 |
56 self.setWhatsThis(self.trUtf8("<b>Graphics View</b>\n" |
56 self.setWhatsThis(self.trUtf8( |
|
57 "<b>Graphics View</b>\n" |
57 "<p>This graphics view is used to show a diagram. \n" |
58 "<p>This graphics view is used to show a diagram. \n" |
58 "There are various actions available to manipulate the \n" |
59 "There are various actions available to manipulate the \n" |
59 "shown items.</p>\n" |
60 "shown items.</p>\n" |
60 "<ul>\n" |
61 "<ul>\n" |
61 "<li>Clicking on an item selects it.</li>\n" |
62 "<li>Clicking on an item selects it.</li>\n" |
62 "<li>Ctrl-clicking adds an item to the selection.</li>\n" |
63 "<li>Ctrl-clicking adds an item to the selection.</li>\n" |
63 "<li>Ctrl-clicking a selected item deselects it.</li>\n" |
64 "<li>Ctrl-clicking a selected item deselects it.</li>\n" |
64 "<li>Clicking on an empty spot of the canvas resets the selection.</li>\n" |
65 "<li>Clicking on an empty spot of the canvas resets the selection." |
|
66 "</li>\n" |
65 "<li>Dragging the mouse over the canvas spans a rubberband to \n" |
67 "<li>Dragging the mouse over the canvas spans a rubberband to \n" |
66 "select multiple items.</li>\n" |
68 "select multiple items.</li>\n" |
67 "<li>Dragging the mouse over a selected item moves the \n" |
69 "<li>Dragging the mouse over a selected item moves the \n" |
68 "whole selection.</li>\n" |
70 "whole selection.</li>\n" |
69 "</ul>\n" |
71 "</ul>\n" |
128 |
131 |
129 def resizeScene(self, amount, isWidth=True): |
132 def resizeScene(self, amount, isWidth=True): |
130 """ |
133 """ |
131 Public method to resize the scene. |
134 Public method to resize the scene. |
132 |
135 |
|
136 @param amount size increment (integer) |
133 @param isWidth flag indicating width is to be resized (boolean) |
137 @param isWidth flag indicating width is to be resized (boolean) |
134 @param amount size increment (integer) |
|
135 """ |
138 """ |
136 sceneRect = self.scene().sceneRect() |
139 sceneRect = self.scene().sceneRect() |
137 width = sceneRect.width() |
140 width = sceneRect.width() |
138 height = sceneRect.height() |
141 height = sceneRect.height() |
139 if isWidth: |
142 if isWidth: |
176 newHeight = size.height() |
179 newHeight = size.height() |
177 self.setSceneSize(newWidth, newHeight) |
180 self.setSceneSize(newWidth, newHeight) |
178 |
181 |
179 def _getDiagramRect(self, border=0): |
182 def _getDiagramRect(self, border=0): |
180 """ |
183 """ |
181 Protected method to calculate the minimum rectangle fitting the diagram. |
184 Protected method to calculate the minimum rectangle fitting the |
|
185 diagram. |
182 |
186 |
183 @param border border width to include in the calculation (integer) |
187 @param border border width to include in the calculation (integer) |
184 @return the minimum rectangle (QRectF) |
188 @return the minimum rectangle (QRectF) |
185 """ |
189 """ |
186 startx = sys.maxsize |
190 startx = sys.maxsize |
291 |
295 |
292 def printDiagram(self, printer, diagramName=""): |
296 def printDiagram(self, printer, diagramName=""): |
293 """ |
297 """ |
294 Public method to print the diagram. |
298 Public method to print the diagram. |
295 |
299 |
296 @param printer reference to a ready configured printer object (QPrinter) |
300 @param printer reference to a ready configured printer object |
|
301 (QPrinter) |
297 @param diagramName name of the diagram (string) |
302 @param diagramName name of the diagram (string) |
298 """ |
303 """ |
299 painter = QPainter() |
304 painter = QPainter() |
300 painter.begin(printer) |
305 painter.begin(printer) |
301 offsetX = 0 |
306 offsetX = 0 |
306 painter.setFont(font) |
311 painter.setFont(font) |
307 fm = painter.fontMetrics() |
312 fm = painter.fontMetrics() |
308 fontHeight = fm.lineSpacing() |
313 fontHeight = fm.lineSpacing() |
309 marginX = printer.pageRect().x() - printer.paperRect().x() |
314 marginX = printer.pageRect().x() - printer.paperRect().x() |
310 marginX = \ |
315 marginX = \ |
311 Preferences.getPrinter("LeftMargin") * int(printer.resolution() / 2.54) \ |
316 Preferences.getPrinter("LeftMargin") * int( |
312 - marginX |
317 printer.resolution() / 2.54) - marginX |
313 marginY = printer.pageRect().y() - printer.paperRect().y() |
318 marginY = printer.pageRect().y() - printer.paperRect().y() |
314 marginY = \ |
319 marginY = \ |
315 Preferences.getPrinter("TopMargin") * int(printer.resolution() / 2.54) \ |
320 Preferences.getPrinter("TopMargin") * int( |
316 - marginY |
321 printer.resolution() / 2.54) - marginY |
317 |
322 |
318 width = printer.width() - marginX \ |
323 width = printer.width() - marginX \ |
319 - Preferences.getPrinter("RightMargin") * int(printer.resolution() / 2.54) |
324 - Preferences.getPrinter("RightMargin") * int( |
|
325 printer.resolution() / 2.54) |
320 height = printer.height() - fontHeight - 4 - marginY \ |
326 height = printer.height() - fontHeight - 4 - marginY \ |
321 - Preferences.getPrinter("BottomMargin") * int(printer.resolution() / 2.54) |
327 - Preferences.getPrinter("BottomMargin") * int( |
|
328 printer.resolution() / 2.54) |
322 |
329 |
323 border = self.border == 0 and 5 or self.border |
330 border = self.border == 0 and 5 or self.border |
324 rect = self._getDiagramRect(border) |
331 rect = self._getDiagramRect(border) |
325 diagram = self.__getDiagram(rect) |
332 diagram = self.__getDiagram(rect) |
326 |
333 |
374 printer.newPage() |
381 printer.newPage() |
375 page += 1 |
382 page += 1 |
376 |
383 |
377 painter.end() |
384 painter.end() |
378 |
385 |
379 ############################################################################ |
386 ########################################################################### |
380 ## The methods below should be overridden by subclasses to get special |
387 ## The methods below should be overridden by subclasses to get special |
381 ## behavior. |
388 ## behavior. |
382 ############################################################################ |
389 ########################################################################### |
383 |
390 |
384 def filteredItems(self, items): |
391 def filteredItems(self, items): |
385 """ |
392 """ |
386 Public method to filter a list of items. |
393 Public method to filter a list of items. |
387 |
394 |