82 |
83 |
83 def setWidth(self, width): |
84 def setWidth(self, width): |
84 """ |
85 """ |
85 Public method to set the widget width. |
86 Public method to set the widget width. |
86 |
87 |
87 @param width widget width (integer) |
88 @param width widget width |
|
89 @type int |
88 """ |
90 """ |
89 if width != self.__width: |
91 if width != self.__width: |
90 self.__width = max(6, width) # minimum width 6 pixels |
92 self.__width = max(6, width) # minimum width 6 pixels |
91 self.__updateControllerViewportWidth() |
93 self.__updateControllerViewportWidth() |
92 self.update() |
94 self.update() |
93 |
95 |
94 def width(self): |
96 def width(self): |
95 """ |
97 """ |
96 Public method to get the widget's width. |
98 Public method to get the widget's width. |
97 |
99 |
98 @return widget width (integer) |
100 @return widget width |
|
101 @rtype int |
99 """ |
102 """ |
100 return self.__width |
103 return self.__width |
101 |
104 |
102 def setMapPosition(self, onRight): |
105 def setMapPosition(self, onRight): |
103 """ |
106 """ |
126 |
129 |
127 def setLineDimensions(self, border, height): |
130 def setLineDimensions(self, border, height): |
128 """ |
131 """ |
129 Public method to set the line (indicator) dimensions. |
132 Public method to set the line (indicator) dimensions. |
130 |
133 |
131 @param border border width on each side in x-direction (integer) |
134 @param border border width on each side in x-direction |
132 @param height height of the line in pixels (integer) |
135 @type int |
|
136 @param height height of the line in pixels |
|
137 @type int |
133 """ |
138 """ |
134 if border != self.__lineBorder or height != self.__lineHeight: |
139 if border != self.__lineBorder or height != self.__lineHeight: |
135 self.__lineBorder = max(1, border) # min border 1 pixel |
140 self.__lineBorder = max(1, border) # min border 1 pixel |
136 self.__lineHeight = max(1, height) # min height 1 pixel |
141 self.__lineHeight = max(1, height) # min height 1 pixel |
137 self.update() |
142 self.update() |
138 |
143 |
139 def lineDimensions(self): |
144 def lineDimensions(self): |
140 """ |
145 """ |
141 Public method to get the line (indicator) dimensions. |
146 Public method to get the line (indicator) dimensions. |
142 |
147 |
143 @return tuple with border width (integer) and line height (integer) |
148 @return tuple with border width (integer) and line height |
|
149 @rtype int |
144 """ |
150 """ |
145 return self.__lineBorder, self.__lineHeight |
151 return self.__lineBorder, self.__lineHeight |
146 |
152 |
147 def setEnabled(self, enable): |
153 def setEnabled(self, enable): |
148 """ |
154 """ |
149 Public method to set the enabled state. |
155 Public method to set the enabled state. |
150 |
156 |
151 @param enable flag indicating the enabled state (boolean) |
157 @param enable flag indicating the enabled state |
|
158 @type bool |
152 """ |
159 """ |
153 if enable != self.__enabled: |
160 if enable != self.__enabled: |
154 self.__enabled = enable |
161 self.__enabled = enable |
155 self.setVisible(enable) |
162 self.setVisible(enable) |
156 self.__updateControllerViewportWidth() |
163 self.__updateControllerViewportWidth() |
157 |
164 |
158 def isEnabled(self): |
165 def isEnabled(self): |
159 """ |
166 """ |
160 Public method to check the enabled state. |
167 Public method to check the enabled state. |
161 |
168 |
162 @return flag indicating the enabled state (boolean) |
169 @return flag indicating the enabled state |
|
170 @rtype bool |
163 """ |
171 """ |
164 return self.__enabled |
172 return self.__enabled |
165 |
173 |
166 def setBackgroundColor(self, color): |
174 def setBackgroundColor(self, color): |
167 """ |
175 """ |
168 Public method to set the widget background color. |
176 Public method to set the widget background color. |
169 |
177 |
170 @param color color for the background (QColor) |
178 @param color color for the background |
|
179 @type QColor |
171 """ |
180 """ |
172 if color != self.__backgroundColor: |
181 if color != self.__backgroundColor: |
173 self.__backgroundColor = color |
182 self.__backgroundColor = color |
174 self.__setSliderColor() |
183 self.__setSliderColor() |
175 self.update() |
184 self.update() |
176 |
185 |
177 def backgroundColor(self): |
186 def backgroundColor(self): |
178 """ |
187 """ |
179 Public method to get the background color. |
188 Public method to get the background color. |
180 |
189 |
181 @return background color (QColor) |
190 @return background color |
|
191 @rtype QColor |
182 """ |
192 """ |
183 return QColor(self.__backgroundColor) |
193 return QColor(self.__backgroundColor) |
184 |
194 |
185 def sizeHint(self): |
195 def sizeHint(self): |
186 """ |
196 """ |
187 Public method to give an indication about the preferred size. |
197 Public method to give an indication about the preferred size. |
188 |
198 |
189 @return preferred size (QSize) |
199 @return preferred size |
|
200 @rtype QSize |
190 """ |
201 """ |
191 return QSize(self.__width, 0) |
202 return QSize(self.__width, 0) |
192 |
203 |
193 def paintEvent(self, event): |
204 def paintEvent(self, event): |
194 """ |
205 """ |
195 Protected method to handle a paint event. |
206 Protected method to handle a paint event. |
196 |
207 |
197 @param event paint event (QPaintEvent) |
208 @param event paint event |
|
209 @type QPaintEvent |
198 """ |
210 """ |
199 # step 1: fill the whole painting area |
211 # step 1: fill the whole painting area |
200 painter = QPainter(self) |
212 painter = QPainter(self) |
201 painter.fillRect(event.rect(), self.__backgroundColor) |
213 painter.fillRect(event.rect(), self.__backgroundColor) |
202 |
214 |
217 """ |
229 """ |
218 Protected method for painting the widget's indicators. |
230 Protected method for painting the widget's indicators. |
219 |
231 |
220 Note: This method should be implemented by subclasses. |
232 Note: This method should be implemented by subclasses. |
221 |
233 |
222 @param painter reference to the painter object (QPainter) |
234 @param painter reference to the painter object |
|
235 @type QPainter |
223 """ |
236 """ |
224 pass |
237 pass |
225 |
238 |
226 def mousePressEvent(self, event): |
239 def mousePressEvent(self, event): |
227 """ |
240 """ |
228 Protected method to handle a mouse button press. |
241 Protected method to handle a mouse button press. |
229 |
242 |
230 @param event reference to the mouse event (QMouseEvent) |
243 @param event reference to the mouse event |
|
244 @type QMouseEvent |
231 """ |
245 """ |
232 if event.button() == Qt.MouseButton.LeftButton and self._controller: |
246 if event.button() == Qt.MouseButton.LeftButton and self._controller: |
233 vsb = self._controller.verticalScrollBar() |
247 vsb = self._controller.verticalScrollBar() |
234 value = self.position2Value(event.position().toPoint().y() - 1) |
248 value = self.position2Value(event.position().toPoint().y() - 1) |
235 vsb.setValue(int(value - 0.5 * vsb.pageStep())) # center on page |
249 vsb.setValue(int(value - 0.5 * vsb.pageStep())) # center on page |
237 |
251 |
238 def mouseMoveEvent(self, event): |
252 def mouseMoveEvent(self, event): |
239 """ |
253 """ |
240 Protected method to handle a mouse moves. |
254 Protected method to handle a mouse moves. |
241 |
255 |
242 @param event reference to the mouse event (QMouseEvent) |
256 @param event reference to the mouse event |
|
257 @type QMouseEvent |
243 """ |
258 """ |
244 if event.buttons() & Qt.MouseButton.LeftButton and self._controller: |
259 if event.buttons() & Qt.MouseButton.LeftButton and self._controller: |
245 vsb = self._controller.verticalScrollBar() |
260 vsb = self._controller.verticalScrollBar() |
246 value = self.position2Value(event.position().toPoint().y() - 1) |
261 value = self.position2Value(event.position().toPoint().y() - 1) |
247 vsb.setValue(int(value - 0.5 * vsb.pageStep())) # center on page |
262 vsb.setValue(int(value - 0.5 * vsb.pageStep())) # center on page |
248 |
263 |
249 def wheelEvent(self, event): |
264 def wheelEvent(self, event): |
250 """ |
265 """ |
251 Protected slot handling mouse wheel events. |
266 Protected slot handling mouse wheel events. |
252 |
267 |
253 @param event reference to the wheel event (QWheelEvent) |
268 @param event reference to the wheel event |
|
269 @type QWheelEvent |
254 """ |
270 """ |
255 isVertical = event.angleDelta().x() == 0 |
271 isVertical = event.angleDelta().x() == 0 |
256 if ( |
272 if ( |
257 self._controller |
273 self._controller |
258 and event.modifiers() == Qt.KeyboardModifier.NoModifier |
274 and event.modifiers() == Qt.KeyboardModifier.NoModifier |
322 |
341 |
323 def position2Value(self, position, slider=False): |
342 def position2Value(self, position, slider=False): |
324 """ |
343 """ |
325 Public method to convert a position into a scrollbar value. |
344 Public method to convert a position into a scrollbar value. |
326 |
345 |
327 @param position scrollbar position to convert (integer) |
346 @param position scrollbar position to convert |
|
347 @type int |
328 @param slider flag indicating to calculate the result for the slider |
348 @param slider flag indicating to calculate the result for the slider |
329 (boolean) |
349 |
330 @return scrollbar value (integer) |
350 @type bool |
|
351 @return scrollbar value |
|
352 @rtype int |
331 """ |
353 """ |
332 if self._controller: |
354 if self._controller: |
333 offset = 0 if slider else 1 |
355 offset = 0 if slider else 1 |
334 vsb = self._controller.verticalScrollBar() |
356 vsb = self._controller.verticalScrollBar() |
335 return vsb.minimum() + max( |
357 return vsb.minimum() + max( |