E5Graphics/E5GraphicsView.py

changeset 2027
144463496a54
parent 2026
18f2b30ed046
child 2302
f29e9405c851
diff -r 18f2b30ed046 -r 144463496a54 E5Graphics/E5GraphicsView.py
--- a/E5Graphics/E5GraphicsView.py	Sat Sep 08 13:02:43 2012 +0200
+++ b/E5Graphics/E5GraphicsView.py	Sat Sep 08 17:36:14 2012 +0200
@@ -29,18 +29,14 @@
         super().__init__(scene, parent)
         self.setObjectName("E5GraphicsView")
         
+        self.__initialSceneSize = self.scene().sceneRect().size()
         self.setBackgroundBrush(QBrush(Qt.white))
         self.setRenderHint(QPainter.Antialiasing, True)
         self.setDragMode(QGraphicsView.RubberBandDrag)
         self.setAlignment(Qt.Alignment(Qt.AlignLeft | Qt.AlignTop))
         self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
         self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
-        
-        # available as of Qt 4.3
-        try:
-            self.setViewportUpdateMode(QGraphicsView.SmartViewportUpdate)
-        except AttributeError:
-            pass
+        self.setViewportUpdateMode(QGraphicsView.SmartViewportUpdate)
         
         self.setWhatsThis(self.trUtf8("<b>Graphics View</b>\n"
             "<p>This graphics view is used to show a diagram. \n"
@@ -119,13 +115,29 @@
         """
         Public method to set the scene size.
         
-        @param width width for the scene (integer)
-        @param height height for the scene (integer)
+        @param width width for the scene (real)
+        @param height height for the scene (real)
         """
         rect = self.scene().sceneRect()
         rect.setHeight(height)
         rect.setWidth(width)
-        self.setSceneRect(rect)
+        self.scene().setSceneRect(rect)
+        
+    def autoAdjustSceneSize(self, limit=False):
+        """
+        Public method to adjust the scene size to the diagram size.
+        
+        @param limit flag indicating to limit the scene to the
+            initial size (boolean)
+        """
+        size = self._getDiagramSize(10)
+        if limit:
+            newWidth = max(size.width(), self.__initialSceneSize.width())
+            newHeight = max(size.height(), self.__initialSceneSize.height())
+        else:
+            newWidth = size.width()
+            newHeight = size.height()
+        self.setSceneSize(newWidth, newHeight)
         
     def _getDiagramRect(self, border=0):
         """

eric ide

mercurial