27 @param parent parent widget (QWidget) |
27 @param parent parent widget (QWidget) |
28 """ |
28 """ |
29 super().__init__(scene, parent) |
29 super().__init__(scene, parent) |
30 self.setObjectName("E5GraphicsView") |
30 self.setObjectName("E5GraphicsView") |
31 |
31 |
|
32 self.__initialSceneSize = self.scene().sceneRect().size() |
32 self.setBackgroundBrush(QBrush(Qt.white)) |
33 self.setBackgroundBrush(QBrush(Qt.white)) |
33 self.setRenderHint(QPainter.Antialiasing, True) |
34 self.setRenderHint(QPainter.Antialiasing, True) |
34 self.setDragMode(QGraphicsView.RubberBandDrag) |
35 self.setDragMode(QGraphicsView.RubberBandDrag) |
35 self.setAlignment(Qt.Alignment(Qt.AlignLeft | Qt.AlignTop)) |
36 self.setAlignment(Qt.Alignment(Qt.AlignLeft | Qt.AlignTop)) |
36 self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOn) |
37 self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOn) |
37 self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn) |
38 self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn) |
38 |
39 self.setViewportUpdateMode(QGraphicsView.SmartViewportUpdate) |
39 # available as of Qt 4.3 |
|
40 try: |
|
41 self.setViewportUpdateMode(QGraphicsView.SmartViewportUpdate) |
|
42 except AttributeError: |
|
43 pass |
|
44 |
40 |
45 self.setWhatsThis(self.trUtf8("<b>Graphics View</b>\n" |
41 self.setWhatsThis(self.trUtf8("<b>Graphics View</b>\n" |
46 "<p>This graphics view is used to show a diagram. \n" |
42 "<p>This graphics view is used to show a diagram. \n" |
47 "There are various actions available to manipulate the \n" |
43 "There are various actions available to manipulate the \n" |
48 "shown items.</p>\n" |
44 "shown items.</p>\n" |
117 |
113 |
118 def setSceneSize(self, width, height): |
114 def setSceneSize(self, width, height): |
119 """ |
115 """ |
120 Public method to set the scene size. |
116 Public method to set the scene size. |
121 |
117 |
122 @param width width for the scene (integer) |
118 @param width width for the scene (real) |
123 @param height height for the scene (integer) |
119 @param height height for the scene (real) |
124 """ |
120 """ |
125 rect = self.scene().sceneRect() |
121 rect = self.scene().sceneRect() |
126 rect.setHeight(height) |
122 rect.setHeight(height) |
127 rect.setWidth(width) |
123 rect.setWidth(width) |
128 self.setSceneRect(rect) |
124 self.scene().setSceneRect(rect) |
|
125 |
|
126 def autoAdjustSceneSize(self, limit=False): |
|
127 """ |
|
128 Public method to adjust the scene size to the diagram size. |
|
129 |
|
130 @param limit flag indicating to limit the scene to the |
|
131 initial size (boolean) |
|
132 """ |
|
133 size = self._getDiagramSize(10) |
|
134 if limit: |
|
135 newWidth = max(size.width(), self.__initialSceneSize.width()) |
|
136 newHeight = max(size.height(), self.__initialSceneSize.height()) |
|
137 else: |
|
138 newWidth = size.width() |
|
139 newHeight = size.height() |
|
140 self.setSceneSize(newWidth, newHeight) |
129 |
141 |
130 def _getDiagramRect(self, border=0): |
142 def _getDiagramRect(self, border=0): |
131 """ |
143 """ |
132 Protected method to calculate the minimum rectangle fitting the diagram. |
144 Protected method to calculate the minimum rectangle fitting the diagram. |
133 |
145 |