11 import sys |
11 import sys |
12 |
12 |
13 from PyQt5.QtCore import pyqtSignal, QRectF, QSize, QSizeF, Qt |
13 from PyQt5.QtCore import pyqtSignal, QRectF, QSize, QSizeF, Qt |
14 from PyQt5.QtGui import QBrush, QPainter, QPixmap, QFont, QColor |
14 from PyQt5.QtGui import QBrush, QPainter, QPixmap, QFont, QColor |
15 from PyQt5.QtWidgets import QGraphicsView |
15 from PyQt5.QtWidgets import QGraphicsView |
|
16 |
|
17 from E5Gui.E5Application import e5App |
16 |
18 |
17 import Preferences |
19 import Preferences |
18 |
20 |
19 |
21 |
20 class E5GraphicsView(QGraphicsView): |
22 class E5GraphicsView(QGraphicsView): |
43 """ |
45 """ |
44 super(E5GraphicsView, self).__init__(scene, parent) |
46 super(E5GraphicsView, self).__init__(scene, parent) |
45 self.setObjectName("E5GraphicsView") |
47 self.setObjectName("E5GraphicsView") |
46 |
48 |
47 self.__initialSceneSize = self.scene().sceneRect().size() |
49 self.__initialSceneSize = self.scene().sceneRect().size() |
48 # TODO: set background according to user selected color |
50 self.setBackgroundBrush(QBrush(self.getBackgroundColor())) |
49 self.setBackgroundBrush(QBrush(Qt.white)) |
|
50 self.setRenderHint(QPainter.Antialiasing, True) |
51 self.setRenderHint(QPainter.Antialiasing, True) |
51 self.setDragMode(QGraphicsView.RubberBandDrag) |
52 self.setDragMode(QGraphicsView.RubberBandDrag) |
52 self.setAlignment(Qt.Alignment(Qt.AlignLeft | Qt.AlignTop)) |
53 self.setAlignment(Qt.Alignment(Qt.AlignLeft | Qt.AlignTop)) |
53 self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOn) |
54 self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOn) |
54 self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn) |
55 self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn) |
69 "select multiple items.</li>\n" |
70 "select multiple items.</li>\n" |
70 "<li>Dragging the mouse over a selected item moves the \n" |
71 "<li>Dragging the mouse over a selected item moves the \n" |
71 "whole selection.</li>\n" |
72 "whole selection.</li>\n" |
72 "</ul>\n" |
73 "</ul>\n" |
73 )) |
74 )) |
74 |
75 |
|
76 def getDrawingColors(self): |
|
77 """ |
|
78 Public method to get the configured drawing colors. |
|
79 |
|
80 @return tuple containing the foreground and background colors |
|
81 @rtype tuple of (QColor, QColor) |
|
82 """ |
|
83 drawingMode = Preferences.getGraphics("DrawingMode") |
|
84 if drawingMode == "automatic": |
|
85 if e5App().usesDarkPalette(): |
|
86 drawingMode = "white_black" |
|
87 else: |
|
88 drawingMode = "black_white" |
|
89 |
|
90 if drawingMode == "white_black": |
|
91 return (QColor("#ffffff"), QColor("#262626")) |
|
92 else: |
|
93 return (QColor("#000000"), QColor("#ffffff")) |
|
94 |
|
95 def getForegroundColor(self): |
|
96 """ |
|
97 Public method to get the configured foreground color. |
|
98 |
|
99 @return foreground color |
|
100 @rtype QColor |
|
101 """ |
|
102 return self.getDrawingColors()[0] |
|
103 |
|
104 def getBackgroundColor(self): |
|
105 """ |
|
106 Public method to get the configured background color. |
|
107 |
|
108 @return background color |
|
109 @rtype QColor |
|
110 """ |
|
111 return self.getDrawingColors()[1] |
|
112 |
75 def __levelForZoom(self, zoom): |
113 def __levelForZoom(self, zoom): |
76 """ |
114 """ |
77 Private method determining the zoom level index given a zoom factor. |
115 Private method determining the zoom level index given a zoom factor. |
78 |
116 |
79 @param zoom zoom factor (integer) |
117 @param zoom zoom factor (integer) |