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