eric6/E5Graphics/E5GraphicsView.py

changeset 7529
2b8a0d8ba12a
parent 7525
6d1f954947bc
child 7780
41420f82c0ac
diff -r 0345f54d3959 -r 2b8a0d8ba12a eric6/E5Graphics/E5GraphicsView.py
--- a/eric6/E5Graphics/E5GraphicsView.py	Sun Apr 12 15:03:27 2020 +0200
+++ b/eric6/E5Graphics/E5GraphicsView.py	Sun Apr 12 18:40:37 2020 +0200
@@ -14,6 +14,8 @@
 from PyQt5.QtGui import QBrush, QPainter, QPixmap, QFont, QColor
 from PyQt5.QtWidgets import QGraphicsView
 
+from E5Gui.E5Application import e5App
+
 import Preferences
 
 
@@ -45,8 +47,7 @@
         self.setObjectName("E5GraphicsView")
         
         self.__initialSceneSize = self.scene().sceneRect().size()
-        # TODO: set background according to user selected color
-        self.setBackgroundBrush(QBrush(Qt.white))
+        self.setBackgroundBrush(QBrush(self.getBackgroundColor()))
         self.setRenderHint(QPainter.Antialiasing, True)
         self.setDragMode(QGraphicsView.RubberBandDrag)
         self.setAlignment(Qt.Alignment(Qt.AlignLeft | Qt.AlignTop))
@@ -71,7 +72,44 @@
             "whole selection.</li>\n"
             "</ul>\n"
         ))
+    
+    def getDrawingColors(self):
+        """
+        Public method to get the configured drawing colors.
         
+        @return tuple containing the foreground and background colors
+        @rtype tuple of (QColor, QColor)
+        """
+        drawingMode = Preferences.getGraphics("DrawingMode")
+        if drawingMode == "automatic":
+            if e5App().usesDarkPalette():
+                drawingMode = "white_black"
+            else:
+                drawingMode = "black_white"
+        
+        if drawingMode == "white_black":
+            return (QColor("#ffffff"), QColor("#262626"))
+        else:
+            return (QColor("#000000"), QColor("#ffffff"))
+    
+    def getForegroundColor(self):
+        """
+        Public method to get the configured foreground color.
+        
+        @return foreground color
+        @rtype QColor
+        """
+        return self.getDrawingColors()[0]
+    
+    def getBackgroundColor(self):
+        """
+        Public method to get the configured background color.
+        
+        @return background color
+        @rtype QColor
+        """
+        return self.getDrawingColors()[1]
+    
     def __levelForZoom(self, zoom):
         """
         Private method determining the zoom level index given a zoom factor.

eric ide

mercurial