eric6/E5Graphics/E5GraphicsView.py

Wed, 30 Dec 2020 11:00:44 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 30 Dec 2020 11:00:44 +0100
branch
maintenance
changeset 7924
8a96736d465e
parent 7780
41420f82c0ac
child 8143
2c730d5fd177
permissions
-rw-r--r--

Updated copyright for 2021.

51
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
7924
8a96736d465e Updated copyright for 2021.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7780
diff changeset
3 # Copyright (c) 2007 - 2021 Detlev Offenbach <detlev@die-offenbachs.de>
51
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing a canvas view class.
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10 import sys
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11
3656
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
12 from PyQt5.QtCore import pyqtSignal, QRectF, QSize, QSizeF, Qt
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
13 from PyQt5.QtGui import QBrush, QPainter, QPixmap, QFont, QColor
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
14 from PyQt5.QtWidgets import QGraphicsView
51
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15
7529
2b8a0d8ba12a UML Diagrams: added support for dark color scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7525
diff changeset
16 from E5Gui.E5Application import e5App
2b8a0d8ba12a UML Diagrams: added support for dark color scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7525
diff changeset
17
51
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18 import Preferences
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
20
51
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 class E5GraphicsView(QGraphicsView):
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 """
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 Class implementing a graphics view.
2334
fc69ad77e18a Introduced a zoom widget in the status bar of several windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
24
fc69ad77e18a Introduced a zoom widget in the status bar of several windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
25 @signal zoomValueChanged(int) emitted to signal a change of the zoom value
51
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 """
2334
fc69ad77e18a Introduced a zoom widget in the status bar of several windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
27 zoomValueChanged = pyqtSignal(int)
fc69ad77e18a Introduced a zoom widget in the status bar of several windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
28
fc69ad77e18a Introduced a zoom widget in the status bar of several windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
29 ZoomLevels = [
fc69ad77e18a Introduced a zoom widget in the status bar of several windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
30 1, 3, 5, 7, 9,
fc69ad77e18a Introduced a zoom widget in the status bar of several windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
31 10, 20, 30, 50, 67, 80, 90,
fc69ad77e18a Introduced a zoom widget in the status bar of several windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
32 100,
fc69ad77e18a Introduced a zoom widget in the status bar of several windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
33 110, 120, 133, 150, 170, 200, 240, 300, 400,
fc69ad77e18a Introduced a zoom widget in the status bar of several windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
34 500, 600, 700, 800, 900, 1000,
fc69ad77e18a Introduced a zoom widget in the status bar of several windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
35 ]
fc69ad77e18a Introduced a zoom widget in the status bar of several windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
36 ZoomLevelDefault = 100
fc69ad77e18a Introduced a zoom widget in the status bar of several windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
37
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
38 def __init__(self, scene, parent=None):
51
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 """
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 Constructor
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 @param scene reference to the scene object (QGraphicsScene)
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 @param parent parent widget (QWidget)
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 """
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2334
diff changeset
45 super(E5GraphicsView, self).__init__(scene, parent)
51
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 self.setObjectName("E5GraphicsView")
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47
2027
144463496a54 A few fixes for issues with the graphics dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2026
diff changeset
48 self.__initialSceneSize = self.scene().sceneRect().size()
7529
2b8a0d8ba12a UML Diagrams: added support for dark color scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7525
diff changeset
49 self.setBackgroundBrush(QBrush(self.getBackgroundColor()))
51
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 self.setRenderHint(QPainter.Antialiasing, True)
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 self.setDragMode(QGraphicsView.RubberBandDrag)
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 self.setAlignment(Qt.Alignment(Qt.AlignLeft | Qt.AlignTop))
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
2027
144463496a54 A few fixes for issues with the graphics dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2026
diff changeset
55 self.setViewportUpdateMode(QGraphicsView.SmartViewportUpdate)
51
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
57 self.setWhatsThis(self.tr(
2990
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
58 "<b>Graphics View</b>\n"
51
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 "<p>This graphics view is used to show a diagram. \n"
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 "There are various actions available to manipulate the \n"
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 "shown items.</p>\n"
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 "<ul>\n"
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 "<li>Clicking on an item selects it.</li>\n"
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64 "<li>Ctrl-clicking adds an item to the selection.</li>\n"
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 "<li>Ctrl-clicking a selected item deselects it.</li>\n"
2990
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
66 "<li>Clicking on an empty spot of the canvas resets the selection."
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
67 "</li>\n"
51
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 "<li>Dragging the mouse over the canvas spans a rubberband to \n"
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 "select multiple items.</li>\n"
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 "<li>Dragging the mouse over a selected item moves the \n"
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 "whole selection.</li>\n"
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 "</ul>\n"
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 ))
7529
2b8a0d8ba12a UML Diagrams: added support for dark color scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7525
diff changeset
74
2b8a0d8ba12a UML Diagrams: added support for dark color scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7525
diff changeset
75 def getDrawingColors(self):
2b8a0d8ba12a UML Diagrams: added support for dark color scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7525
diff changeset
76 """
2b8a0d8ba12a UML Diagrams: added support for dark color scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7525
diff changeset
77 Public method to get the configured drawing colors.
51
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78
7529
2b8a0d8ba12a UML Diagrams: added support for dark color scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7525
diff changeset
79 @return tuple containing the foreground and background colors
2b8a0d8ba12a UML Diagrams: added support for dark color scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7525
diff changeset
80 @rtype tuple of (QColor, QColor)
2b8a0d8ba12a UML Diagrams: added support for dark color scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7525
diff changeset
81 """
2b8a0d8ba12a UML Diagrams: added support for dark color scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7525
diff changeset
82 drawingMode = Preferences.getGraphics("DrawingMode")
2b8a0d8ba12a UML Diagrams: added support for dark color scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7525
diff changeset
83 if drawingMode == "automatic":
2b8a0d8ba12a UML Diagrams: added support for dark color scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7525
diff changeset
84 if e5App().usesDarkPalette():
2b8a0d8ba12a UML Diagrams: added support for dark color scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7525
diff changeset
85 drawingMode = "white_black"
2b8a0d8ba12a UML Diagrams: added support for dark color scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7525
diff changeset
86 else:
2b8a0d8ba12a UML Diagrams: added support for dark color scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7525
diff changeset
87 drawingMode = "black_white"
2b8a0d8ba12a UML Diagrams: added support for dark color scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7525
diff changeset
88
2b8a0d8ba12a UML Diagrams: added support for dark color scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7525
diff changeset
89 if drawingMode == "white_black":
2b8a0d8ba12a UML Diagrams: added support for dark color scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7525
diff changeset
90 return (QColor("#ffffff"), QColor("#262626"))
2b8a0d8ba12a UML Diagrams: added support for dark color scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7525
diff changeset
91 else:
2b8a0d8ba12a UML Diagrams: added support for dark color scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7525
diff changeset
92 return (QColor("#000000"), QColor("#ffffff"))
2b8a0d8ba12a UML Diagrams: added support for dark color scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7525
diff changeset
93
2b8a0d8ba12a UML Diagrams: added support for dark color scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7525
diff changeset
94 def getForegroundColor(self):
2b8a0d8ba12a UML Diagrams: added support for dark color scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7525
diff changeset
95 """
2b8a0d8ba12a UML Diagrams: added support for dark color scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7525
diff changeset
96 Public method to get the configured foreground color.
2b8a0d8ba12a UML Diagrams: added support for dark color scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7525
diff changeset
97
2b8a0d8ba12a UML Diagrams: added support for dark color scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7525
diff changeset
98 @return foreground color
2b8a0d8ba12a UML Diagrams: added support for dark color scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7525
diff changeset
99 @rtype QColor
2b8a0d8ba12a UML Diagrams: added support for dark color scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7525
diff changeset
100 """
2b8a0d8ba12a UML Diagrams: added support for dark color scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7525
diff changeset
101 return self.getDrawingColors()[0]
2b8a0d8ba12a UML Diagrams: added support for dark color scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7525
diff changeset
102
2b8a0d8ba12a UML Diagrams: added support for dark color scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7525
diff changeset
103 def getBackgroundColor(self):
2b8a0d8ba12a UML Diagrams: added support for dark color scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7525
diff changeset
104 """
2b8a0d8ba12a UML Diagrams: added support for dark color scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7525
diff changeset
105 Public method to get the configured background color.
2b8a0d8ba12a UML Diagrams: added support for dark color scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7525
diff changeset
106
2b8a0d8ba12a UML Diagrams: added support for dark color scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7525
diff changeset
107 @return background color
2b8a0d8ba12a UML Diagrams: added support for dark color scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7525
diff changeset
108 @rtype QColor
2b8a0d8ba12a UML Diagrams: added support for dark color scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7525
diff changeset
109 """
2b8a0d8ba12a UML Diagrams: added support for dark color scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7525
diff changeset
110 return self.getDrawingColors()[1]
2b8a0d8ba12a UML Diagrams: added support for dark color scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7525
diff changeset
111
2334
fc69ad77e18a Introduced a zoom widget in the status bar of several windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
112 def __levelForZoom(self, zoom):
fc69ad77e18a Introduced a zoom widget in the status bar of several windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
113 """
fc69ad77e18a Introduced a zoom widget in the status bar of several windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
114 Private method determining the zoom level index given a zoom factor.
fc69ad77e18a Introduced a zoom widget in the status bar of several windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
115
fc69ad77e18a Introduced a zoom widget in the status bar of several windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
116 @param zoom zoom factor (integer)
fc69ad77e18a Introduced a zoom widget in the status bar of several windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
117 @return index of zoom factor (integer)
fc69ad77e18a Introduced a zoom widget in the status bar of several windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
118 """
fc69ad77e18a Introduced a zoom widget in the status bar of several windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
119 try:
fc69ad77e18a Introduced a zoom widget in the status bar of several windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
120 index = E5GraphicsView.ZoomLevels.index(zoom)
fc69ad77e18a Introduced a zoom widget in the status bar of several windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
121 except ValueError:
fc69ad77e18a Introduced a zoom widget in the status bar of several windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
122 for index in range(len(E5GraphicsView.ZoomLevels)):
fc69ad77e18a Introduced a zoom widget in the status bar of several windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
123 if zoom <= E5GraphicsView.ZoomLevels[index]:
fc69ad77e18a Introduced a zoom widget in the status bar of several windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
124 break
fc69ad77e18a Introduced a zoom widget in the status bar of several windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
125 return index
fc69ad77e18a Introduced a zoom widget in the status bar of several windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
126
51
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
127 def zoomIn(self):
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
128 """
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
129 Public method to zoom in.
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
130 """
2334
fc69ad77e18a Introduced a zoom widget in the status bar of several windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
131 index = self.__levelForZoom(self.zoom())
fc69ad77e18a Introduced a zoom widget in the status bar of several windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
132 if index < len(E5GraphicsView.ZoomLevels) - 1:
fc69ad77e18a Introduced a zoom widget in the status bar of several windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
133 self.setZoom(E5GraphicsView.ZoomLevels[index + 1])
51
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
134
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
135 def zoomOut(self):
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
136 """
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
137 Public method to zoom out.
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
138 """
2334
fc69ad77e18a Introduced a zoom widget in the status bar of several windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
139 index = self.__levelForZoom(self.zoom())
fc69ad77e18a Introduced a zoom widget in the status bar of several windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
140 if index > 0:
fc69ad77e18a Introduced a zoom widget in the status bar of several windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
141 self.setZoom(E5GraphicsView.ZoomLevels[index - 1])
51
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
142
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
143 def zoomReset(self):
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
144 """
2334
fc69ad77e18a Introduced a zoom widget in the status bar of several windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
145 Public method to handle the reset the zoom value.
51
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
146 """
2990
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
147 self.setZoom(
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
148 E5GraphicsView.ZoomLevels[E5GraphicsView.ZoomLevelDefault])
51
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
149
2334
fc69ad77e18a Introduced a zoom widget in the status bar of several windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
150 def setZoom(self, value):
51
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
151 """
2334
fc69ad77e18a Introduced a zoom widget in the status bar of several windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
152 Public method to set the zoom value in percent.
51
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
153
2334
fc69ad77e18a Introduced a zoom widget in the status bar of several windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
154 @param value zoom value in percent (integer)
51
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
155 """
2334
fc69ad77e18a Introduced a zoom widget in the status bar of several windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
156 if value != self.zoom():
3781
a27433350e5f Fixed an issue with obsolete Qt class methods in E5GraphicsView.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3656
diff changeset
157 self.resetTransform()
2334
fc69ad77e18a Introduced a zoom widget in the status bar of several windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
158 factor = value / 100.0
fc69ad77e18a Introduced a zoom widget in the status bar of several windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
159 self.scale(factor, factor)
fc69ad77e18a Introduced a zoom widget in the status bar of several windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
160 self.zoomValueChanged.emit(value)
51
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
161
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
162 def zoom(self):
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
163 """
2334
fc69ad77e18a Introduced a zoom widget in the status bar of several windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
164 Public method to get the current zoom factor in percent.
51
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
165
2334
fc69ad77e18a Introduced a zoom widget in the status bar of several windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
166 @return current zoom factor in percent (integer)
51
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
167 """
3781
a27433350e5f Fixed an issue with obsolete Qt class methods in E5GraphicsView.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3656
diff changeset
168 return int(self.transform().m11() * 100.0)
51
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
169
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
170 def resizeScene(self, amount, isWidth=True):
51
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
171 """
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
172 Public method to resize the scene.
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
173
2953
703452a2876f Started correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2334
diff changeset
174 @param amount size increment (integer)
51
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
175 @param isWidth flag indicating width is to be resized (boolean)
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
176 """
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
177 sceneRect = self.scene().sceneRect()
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
178 width = sceneRect.width()
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
179 height = sceneRect.height()
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
180 if isWidth:
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
181 width += amount
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
182 else:
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
183 height += amount
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
184 rect = self._getDiagramRect(10)
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
185 if width < rect.width():
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
186 width = rect.width()
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
187 if height < rect.height():
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
188 height = rect.height()
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
189
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
190 self.setSceneSize(width, height)
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
191
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
192 def setSceneSize(self, width, height):
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
193 """
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
194 Public method to set the scene size.
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
195
2027
144463496a54 A few fixes for issues with the graphics dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2026
diff changeset
196 @param width width for the scene (real)
144463496a54 A few fixes for issues with the graphics dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2026
diff changeset
197 @param height height for the scene (real)
51
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
198 """
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
199 rect = self.scene().sceneRect()
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
200 rect.setHeight(height)
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
201 rect.setWidth(width)
2027
144463496a54 A few fixes for issues with the graphics dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2026
diff changeset
202 self.scene().setSceneRect(rect)
144463496a54 A few fixes for issues with the graphics dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2026
diff changeset
203
144463496a54 A few fixes for issues with the graphics dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2026
diff changeset
204 def autoAdjustSceneSize(self, limit=False):
144463496a54 A few fixes for issues with the graphics dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2026
diff changeset
205 """
144463496a54 A few fixes for issues with the graphics dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2026
diff changeset
206 Public method to adjust the scene size to the diagram size.
144463496a54 A few fixes for issues with the graphics dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2026
diff changeset
207
144463496a54 A few fixes for issues with the graphics dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2026
diff changeset
208 @param limit flag indicating to limit the scene to the
144463496a54 A few fixes for issues with the graphics dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2026
diff changeset
209 initial size (boolean)
144463496a54 A few fixes for issues with the graphics dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2026
diff changeset
210 """
144463496a54 A few fixes for issues with the graphics dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2026
diff changeset
211 size = self._getDiagramSize(10)
144463496a54 A few fixes for issues with the graphics dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2026
diff changeset
212 if limit:
144463496a54 A few fixes for issues with the graphics dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2026
diff changeset
213 newWidth = max(size.width(), self.__initialSceneSize.width())
144463496a54 A few fixes for issues with the graphics dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2026
diff changeset
214 newHeight = max(size.height(), self.__initialSceneSize.height())
144463496a54 A few fixes for issues with the graphics dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2026
diff changeset
215 else:
144463496a54 A few fixes for issues with the graphics dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2026
diff changeset
216 newWidth = size.width()
144463496a54 A few fixes for issues with the graphics dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2026
diff changeset
217 newHeight = size.height()
144463496a54 A few fixes for issues with the graphics dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2026
diff changeset
218 self.setSceneSize(newWidth, newHeight)
51
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
219
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
220 def _getDiagramRect(self, border=0):
51
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
221 """
2990
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
222 Protected method to calculate the minimum rectangle fitting the
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
223 diagram.
51
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
224
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
225 @param border border width to include in the calculation (integer)
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
226 @return the minimum rectangle (QRectF)
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
227 """
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
228 startx = sys.maxsize
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
229 starty = sys.maxsize
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
230 endx = 0
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
231 endy = 0
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
232 items = self.filteredItems(list(self.scene().items()))
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
233 for itm in items:
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
234 rect = itm.sceneBoundingRect()
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
235 itmEndX = rect.x() + rect.width()
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
236 itmEndY = rect.y() + rect.height()
51
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
237 itmStartX = rect.x()
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
238 itmStartY = rect.y()
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
239 if startx >= itmStartX:
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
240 startx = itmStartX
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
241 if starty >= itmStartY:
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
242 starty = itmStartY
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
243 if endx <= itmEndX:
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
244 endx = itmEndX
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
245 if endy <= itmEndY:
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
246 endy = itmEndY
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
247 if border:
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
248 startx -= border
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
249 starty -= border
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
250 endx += border
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
251 endy += border
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
252
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
253 return QRectF(startx, starty, endx - startx + 1, endy - starty + 1)
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
254
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
255 def _getDiagramSize(self, border=0):
51
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
256 """
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
257 Protected method to calculate the minimum size fitting the diagram.
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
258
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
259 @param border border width to include in the calculation (integer)
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
260 @return the minimum size (QSizeF)
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
261 """
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
262 endx = 0
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
263 endy = 0
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
264 items = self.filteredItems(list(self.scene().items()))
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
265 for itm in items:
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
266 rect = itm.sceneBoundingRect()
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
267 itmEndX = rect.x() + rect.width()
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
268 itmEndY = rect.y() + rect.height()
51
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
269 if endx <= itmEndX:
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
270 endx = itmEndX
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
271 if endy <= itmEndY:
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
272 endy = itmEndY
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
273 if border:
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
274 endx += border
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
275 endy += border
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
276
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
277 return QSizeF(endx + 1, endy + 1)
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
278
5587
ea526b78ee6c Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
279 def __getDiagram(self, rect, imageFormat="PNG", filename=None):
51
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
280 """
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
281 Private method to retrieve the diagram from the scene fitting it
51
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
282 in the minimum rectangle.
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
283
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
284 @param rect minimum rectangle fitting the diagram (QRectF)
5587
ea526b78ee6c Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
285 @param imageFormat format for the image file (string)
51
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
286 @param filename name of the file for non pixmaps (string)
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
287 @return diagram pixmap to receive the diagram (QPixmap)
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
288 """
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
289 selectedItems = self.scene().selectedItems()
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
290
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
291 # step 1: deselect all widgets
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
292 if selectedItems:
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
293 for item in selectedItems:
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
294 item.setSelected(False)
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
295
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
296 # step 2: grab the diagram
5587
ea526b78ee6c Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
297 if imageFormat == "PNG":
51
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
298 paintDevice = QPixmap(int(rect.width()), int(rect.height()))
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
299 paintDevice.fill(self.backgroundBrush().color())
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
300 else:
3656
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
301 from PyQt5.QtSvg import QSvgGenerator
51
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
302 paintDevice = QSvgGenerator()
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
303 paintDevice.setResolution(100) # 100 dpi
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
304 paintDevice.setSize(QSize(int(rect.width()), int(rect.height())))
2334
fc69ad77e18a Introduced a zoom widget in the status bar of several windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
305 paintDevice.setViewBox(rect)
51
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
306 paintDevice.setFileName(filename)
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
307 painter = QPainter(paintDevice)
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
308 painter.setRenderHint(QPainter.Antialiasing, True)
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
309 self.scene().render(painter, QRectF(), rect)
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
310
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
311 # step 3: reselect the widgets
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
312 if selectedItems:
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
313 for item in selectedItems:
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
314 item.setSelected(True)
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
315
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
316 return paintDevice
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
317
5587
ea526b78ee6c Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
318 def saveImage(self, filename, imageFormat="PNG"):
51
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
319 """
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
320 Public method to save the scene to a file.
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
321
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
322 @param filename name of the file to write the image to (string)
5587
ea526b78ee6c Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
323 @param imageFormat format for the image file (string)
51
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
324 @return flag indicating success (boolean)
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
325 """
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
326 rect = self._getDiagramRect(self.border)
5587
ea526b78ee6c Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
327 if imageFormat == "SVG":
ea526b78ee6c Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
328 self.__getDiagram(rect, imageFormat=imageFormat, filename=filename)
51
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
329 return True
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
330 else:
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
331 pixmap = self.__getDiagram(rect)
5587
ea526b78ee6c Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
332 return pixmap.save(filename, imageFormat)
51
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
333
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
334 def printDiagram(self, printer, diagramName=""):
51
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
335 """
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
336 Public method to print the diagram.
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
337
2990
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
338 @param printer reference to a ready configured printer object
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
339 (QPrinter)
51
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
340 @param diagramName name of the diagram (string)
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
341 """
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
342 painter = QPainter()
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
343 painter.begin(printer)
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
344 offsetX = 0
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
345 offsetY = 0
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
346 widthX = 0
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
347 heightY = 0
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
348 font = QFont("times", 10)
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
349 painter.setFont(font)
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
350 fm = painter.fontMetrics()
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
351 fontHeight = fm.lineSpacing()
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
352 marginX = printer.pageRect().x() - printer.paperRect().x()
7252
c5e3705073eb Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
353 marginX = (
c5e3705073eb Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
354 Preferences.getPrinter("LeftMargin") *
c5e3705073eb Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
355 int(printer.resolution() / 2.54) - marginX
c5e3705073eb Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
356 )
51
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
357 marginY = printer.pageRect().y() - printer.paperRect().y()
7252
c5e3705073eb Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
358 marginY = (
c5e3705073eb Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
359 Preferences.getPrinter("TopMargin") *
c5e3705073eb Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
360 int(printer.resolution() / 2.54) - marginY
c5e3705073eb Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
361 )
51
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
362
7252
c5e3705073eb Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
363 width = (
c5e3705073eb Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
364 printer.width() - marginX -
c5e3705073eb Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
365 Preferences.getPrinter("RightMargin") *
c5e3705073eb Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
366 int(printer.resolution() / 2.54)
c5e3705073eb Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
367 )
c5e3705073eb Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
368 height = (
c5e3705073eb Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
369 printer.height() - fontHeight - 4 - marginY -
c5e3705073eb Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
370 Preferences.getPrinter("BottomMargin") *
c5e3705073eb Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
371 int(printer.resolution() / 2.54)
c5e3705073eb Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
372 )
51
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
373
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
374 border = self.border == 0 and 5 or self.border
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
375 rect = self._getDiagramRect(border)
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
376 diagram = self.__getDiagram(rect)
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
377
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
378 finishX = False
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
379 finishY = False
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
380 page = 0
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
381 pageX = 0
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
382 pageY = 1
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
383 while not finishX or not finishY:
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
384 if not finishX:
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
385 offsetX = pageX * width
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
386 pageX += 1
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
387 elif not finishY:
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
388 offsetY = pageY * height
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
389 offsetX = 0
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
390 pageY += 1
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
391 finishX = False
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
392 pageX = 1
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
393 if (width + offsetX) > diagram.width():
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
394 finishX = True
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
395 widthX = diagram.width() - offsetX
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
396 else:
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
397 widthX = width
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
398 if diagram.width() < width:
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
399 widthX = diagram.width()
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
400 finishX = True
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
401 offsetX = 0
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
402 if (height + offsetY) > diagram.height():
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
403 finishY = True
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
404 heightY = diagram.height() - offsetY
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
405 else:
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
406 heightY = height
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
407 if diagram.height() < height:
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
408 finishY = True
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
409 heightY = diagram.height()
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
410 offsetY = 0
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
411
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
412 painter.drawPixmap(marginX, marginY, diagram,
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
413 offsetX, offsetY, widthX, heightY)
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
414 # write a foot note
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
415 s = self.tr("{0}, Page {1}").format(diagramName, page + 1)
51
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
416 tc = QColor(50, 50, 50)
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
417 painter.setPen(tc)
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
418 painter.drawRect(marginX, marginY, width, height)
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
419 painter.drawLine(marginX, marginY + height + 2,
3022
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2990
diff changeset
420 marginX + width, marginY + height + 2)
51
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
421 painter.setFont(font)
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
422 painter.drawText(marginX, marginY + height + 4, width,
3022
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2990
diff changeset
423 fontHeight, Qt.AlignRight, s)
51
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
424 if not finishX or not finishY:
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
425 printer.newPage()
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
426 page += 1
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
427
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
428 painter.end()
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
429
2990
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
430 ###########################################################################
51
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
431 ## The methods below should be overridden by subclasses to get special
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
432 ## behavior.
2990
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
433 ###########################################################################
51
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
434
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
435 def filteredItems(self, items):
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
436 """
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
437 Public method to filter a list of items.
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
438
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
439 @param items list of items as returned by the scene object
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
440 (QGraphicsItem)
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
441 @return list of interesting collision items (QGraphicsItem)
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
442 """
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
443 # just return the list unchanged
96
9624a110667d Started to clean up the code supported by py3flakes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 51
diff changeset
444 return items

eric ide

mercurial