38 |
38 |
39 def __init__(self, pixmap, parent=None, name=None): |
39 def __init__(self, pixmap, parent=None, name=None): |
40 """ |
40 """ |
41 Constructor |
41 Constructor |
42 |
42 |
43 @param pixmap filename of a graphics file to show (string) |
43 @param pixmap filename of a graphics file to show |
44 @param parent parent widget of the view (QWidget) |
44 @type str |
45 @param name name of the view widget (string) |
45 @param parent parent widget of the view |
|
46 @type QWidget |
|
47 @param name name of the view widget |
|
48 @type str |
46 """ |
49 """ |
47 super().__init__(parent) |
50 super().__init__(parent) |
48 if name: |
51 if name: |
49 self.setObjectName(name) |
52 self.setObjectName(name) |
50 else: |
53 else: |
120 |
123 |
121 def __showContextMenu(self, coord): |
124 def __showContextMenu(self, coord): |
122 """ |
125 """ |
123 Private slot to show the context menu of the listview. |
126 Private slot to show the context menu of the listview. |
124 |
127 |
125 @param coord the position of the mouse pointer (QPoint) |
128 @param coord the position of the mouse pointer |
|
129 @type QPoint |
126 """ |
130 """ |
127 self.__menu.popup(self.mapToGlobal(coord)) |
131 self.__menu.popup(self.mapToGlobal(coord)) |
128 |
132 |
129 def __initToolBars(self): |
133 def __initToolBars(self): |
130 """ |
134 """ |
144 |
148 |
145 def __showPixmap(self, filename): |
149 def __showPixmap(self, filename): |
146 """ |
150 """ |
147 Private method to show a file. |
151 Private method to show a file. |
148 |
152 |
149 @param filename name of the file to be shown (string) |
153 @param filename name of the file to be shown |
150 @return flag indicating success (boolean) |
154 @type str |
|
155 @return flag indicating success |
|
156 @rtype bool |
151 """ |
157 """ |
152 image = QImage(filename) |
158 image = QImage(filename) |
153 if image.isNull(): |
159 if image.isNull(): |
154 E5MessageBox.warning( |
160 E5MessageBox.warning( |
155 self, |
161 self, |
166 def getDiagramName(self): |
172 def getDiagramName(self): |
167 """ |
173 """ |
168 Public method to retrieve a name for the diagram. |
174 Public method to retrieve a name for the diagram. |
169 |
175 |
170 @return name for the diagram |
176 @return name for the diagram |
|
177 @rtype str |
171 """ |
178 """ |
172 return self.pixmapfile |
179 return self.pixmapfile |
173 |
180 |
174 def getStatus(self): |
181 def getStatus(self): |
175 """ |
182 """ |
176 Public method to retrieve the status of the canvas. |
183 Public method to retrieve the status of the canvas. |
177 |
184 |
178 @return flag indicating a successful pixmap loading (boolean) |
185 @return flag indicating a successful pixmap loading |
|
186 @rtype bool |
179 """ |
187 """ |
180 return self.status |
188 return self.status |
181 |
189 |
182 def wheelEvent(self, evt): |
190 def wheelEvent(self, evt): |
183 """ |
191 """ |
184 Protected method to handle wheel events. |
192 Protected method to handle wheel events. |
185 |
193 |
186 @param evt reference to the wheel event (QWheelEvent) |
194 @param evt reference to the wheel event |
|
195 @type QWheelEvent |
187 """ |
196 """ |
188 if evt.modifiers() & Qt.KeyboardModifier.ControlModifier: |
197 if evt.modifiers() & Qt.KeyboardModifier.ControlModifier: |
189 delta = evt.angleDelta().y() |
198 delta = evt.angleDelta().y() |
190 if delta < 0: |
199 if delta < 0: |
191 self.__zoomOut() |
200 self.__zoomOut() |
198 |
207 |
199 def event(self, evt): |
208 def event(self, evt): |
200 """ |
209 """ |
201 Public method handling events. |
210 Public method handling events. |
202 |
211 |
203 @param evt reference to the event (QEvent) |
212 @param evt reference to the event |
204 @return flag indicating, if the event was handled (boolean) |
213 @type QEvent |
|
214 @return flag indicating, if the event was handled |
|
215 @rtype bool |
205 """ |
216 """ |
206 if evt.type() == QEvent.Type.Gesture: |
217 if evt.type() == QEvent.Type.Gesture: |
207 self.gestureEvent(evt) |
218 self.gestureEvent(evt) |
208 return True |
219 return True |
209 |
220 |
211 |
222 |
212 def gestureEvent(self, evt): |
223 def gestureEvent(self, evt): |
213 """ |
224 """ |
214 Protected method handling gesture events. |
225 Protected method handling gesture events. |
215 |
226 |
216 @param evt reference to the gesture event (QGestureEvent |
227 @param evt reference to the gesture event |
|
228 @type QGestureEvent |
217 """ |
229 """ |
218 pinch = evt.gesture(Qt.GestureType.PinchGesture) |
230 pinch = evt.gesture(Qt.GestureType.PinchGesture) |
219 if pinch: |
231 if pinch: |
220 if pinch.state() == Qt.GestureState.GestureStarted: |
232 if pinch.state() == Qt.GestureState.GestureStarted: |
221 pinch.setTotalScaleFactor(self.__zoom() / 100) |
233 pinch.setTotalScaleFactor(self.__zoom() / 100) |
229 |
241 |
230 def __adjustScrollBar(self, scrollBar, factor): |
242 def __adjustScrollBar(self, scrollBar, factor): |
231 """ |
243 """ |
232 Private method to adjust a scrollbar by a certain factor. |
244 Private method to adjust a scrollbar by a certain factor. |
233 |
245 |
234 @param scrollBar reference to the scrollbar object (QScrollBar) |
246 @param scrollBar reference to the scrollbar object |
235 @param factor factor to adjust by (float) |
247 @type QScrollBar |
|
248 @param factor factor to adjust by |
|
249 @type float |
236 """ |
250 """ |
237 scrollBar.setValue(int(factor * scrollBar.value() + |
251 scrollBar.setValue(int(factor * scrollBar.value() + |
238 ((factor - 1) * scrollBar.pageStep() / 2))) |
252 ((factor - 1) * scrollBar.pageStep() / 2))) |
239 |
253 |
240 def __levelForZoom(self, zoom): |
254 def __levelForZoom(self, zoom): |
241 """ |
255 """ |
242 Private method determining the zoom level index given a zoom factor. |
256 Private method determining the zoom level index given a zoom factor. |
243 |
257 |
244 @param zoom zoom factor (integer) |
258 @param zoom zoom factor |
245 @return index of zoom factor (integer) |
259 @type int |
|
260 @return index of zoom factor |
|
261 @rtype int |
246 """ |
262 """ |
247 try: |
263 try: |
248 index = PixmapDiagram.ZoomLevels.index(zoom) |
264 index = PixmapDiagram.ZoomLevels.index(zoom) |
249 except ValueError: |
265 except ValueError: |
250 for index in range(len(PixmapDiagram.ZoomLevels)): |
266 for index in range(len(PixmapDiagram.ZoomLevels)): |
254 |
270 |
255 def __doZoom(self, value): |
271 def __doZoom(self, value): |
256 """ |
272 """ |
257 Private method to set the zoom value in percent. |
273 Private method to set the zoom value in percent. |
258 |
274 |
259 @param value zoom value in percent (integer) |
275 @param value zoom value in percent |
|
276 @type int |
260 """ |
277 """ |
261 oldValue = self.__zoom() |
278 oldValue = self.__zoom() |
262 if value != oldValue: |
279 if value != oldValue: |
263 self.pixmapLabel.resize( |
280 self.pixmapLabel.resize( |
264 value / 100 * self.pixmapLabel.pixmap().size()) |
281 value / 100 * self.pixmapLabel.pixmap().size()) |
295 |
312 |
296 def __zoom(self): |
313 def __zoom(self): |
297 """ |
314 """ |
298 Private method to get the current zoom factor in percent. |
315 Private method to get the current zoom factor in percent. |
299 |
316 |
300 @return current zoom factor in percent (integer) |
317 @return current zoom factor in percent |
|
318 @rtype int |
301 """ |
319 """ |
302 return int(self.pixmapLabel.width() / |
320 return int(self.pixmapLabel.width() / |
303 self.pixmapLabel.pixmap().width() * 100.0) |
321 self.pixmapLabel.pixmap().width() * 100.0) |
304 |
322 |
305 def __printDiagram(self): |
323 def __printDiagram(self): |
353 |
371 |
354 def __print(self, printer): |
372 def __print(self, printer): |
355 """ |
373 """ |
356 Private slot to the actual printing. |
374 Private slot to the actual printing. |
357 |
375 |
358 @param printer reference to the printer object (QPrinter) |
376 @param printer reference to the printer object |
|
377 @type QPrinter |
359 """ |
378 """ |
360 painter = QPainter() |
379 painter = QPainter() |
361 painter.begin(printer) |
380 painter.begin(printer) |
362 |
381 |
363 # calculate margin and width of printout |
382 # calculate margin and width of printout |