12 |
12 |
13 |
13 |
14 class SnapshotPreview(QLabel): |
14 class SnapshotPreview(QLabel): |
15 """ |
15 """ |
16 Class implementing the snapshot preview label. |
16 Class implementing the snapshot preview label. |
17 |
17 |
18 @signal startDrag() emitted to indicate the start of a drag operation |
18 @signal startDrag() emitted to indicate the start of a drag operation |
19 """ |
19 """ |
|
20 |
20 startDrag = pyqtSignal() |
21 startDrag = pyqtSignal() |
21 |
22 |
22 def __init__(self, parent=None): |
23 def __init__(self, parent=None): |
23 """ |
24 """ |
24 Constructor |
25 Constructor |
25 |
26 |
26 @param parent reference to the parent widget (QWidget) |
27 @param parent reference to the parent widget (QWidget) |
27 """ |
28 """ |
28 super().__init__(parent) |
29 super().__init__(parent) |
29 |
30 |
30 self.setAlignment(Qt.AlignmentFlag.AlignHCenter | |
31 self.setAlignment(Qt.AlignmentFlag.AlignHCenter | Qt.AlignmentFlag.AlignCenter) |
31 Qt.AlignmentFlag.AlignCenter) |
|
32 self.setCursor(Qt.CursorShape.OpenHandCursor) |
32 self.setCursor(Qt.CursorShape.OpenHandCursor) |
33 |
33 |
34 self.__mouseClickPoint = QPoint(0, 0) |
34 self.__mouseClickPoint = QPoint(0, 0) |
35 |
35 |
36 def setPreview(self, preview): |
36 def setPreview(self, preview): |
37 """ |
37 """ |
38 Public slot to set the preview picture. |
38 Public slot to set the preview picture. |
39 |
39 |
40 @param preview preview picture to be shown (QPixmap) |
40 @param preview preview picture to be shown (QPixmap) |
41 """ |
41 """ |
42 pixmap = ( |
42 pixmap = ( |
43 preview.scaled( |
43 preview.scaled( |
44 self.width(), self.height(), |
44 self.width(), |
|
45 self.height(), |
45 Qt.AspectRatioMode.KeepAspectRatio, |
46 Qt.AspectRatioMode.KeepAspectRatio, |
46 Qt.TransformationMode.SmoothTransformation) |
47 Qt.TransformationMode.SmoothTransformation, |
47 if not preview.isNull() else |
48 ) |
48 preview |
49 if not preview.isNull() |
|
50 else preview |
49 ) |
51 ) |
50 self.setPixmap(pixmap) |
52 self.setPixmap(pixmap) |
51 |
53 |
52 def mousePressEvent(self, evt): |
54 def mousePressEvent(self, evt): |
53 """ |
55 """ |
54 Protected method to handle mouse button presses. |
56 Protected method to handle mouse button presses. |
55 |
57 |
56 @param evt mouse button press event (QMouseEvent) |
58 @param evt mouse button press event (QMouseEvent) |
57 """ |
59 """ |
58 if evt.button() == Qt.MouseButton.LeftButton: |
60 if evt.button() == Qt.MouseButton.LeftButton: |
59 self.__mouseClickPoint = evt.position().toPoint() |
61 self.__mouseClickPoint = evt.position().toPoint() |
60 |
62 |
61 def mouseReleaseEvent(self, evt): |
63 def mouseReleaseEvent(self, evt): |
62 """ |
64 """ |
63 Protected method to handle mouse button releases. |
65 Protected method to handle mouse button releases. |
64 |
66 |
65 @param evt mouse button release event (QMouseEvent) |
67 @param evt mouse button release event (QMouseEvent) |
66 """ |
68 """ |
67 self.__mouseClickPoint = QPoint(0, 0) |
69 self.__mouseClickPoint = QPoint(0, 0) |
68 |
70 |
69 def mouseMoveEvent(self, evt): |
71 def mouseMoveEvent(self, evt): |
70 """ |
72 """ |
71 Protected method to handle mouse moves. |
73 Protected method to handle mouse moves. |
72 |
74 |
73 @param evt mouse move event (QMouseEvent) |
75 @param evt mouse move event (QMouseEvent) |
74 """ |
76 """ |
75 if ( |
77 if ( |
76 self.__mouseClickPoint != QPoint(0, 0) and ( |
78 self.__mouseClickPoint != QPoint(0, 0) |
77 evt.position().toPoint() - self.__mouseClickPoint |
79 and (evt.position().toPoint() - self.__mouseClickPoint).manhattanLength() |
78 ).manhattanLength() > QApplication.startDragDistance() |
80 > QApplication.startDragDistance() |
79 ): |
81 ): |
80 self.__mouseClickPoint = QPoint(0, 0) |
82 self.__mouseClickPoint = QPoint(0, 0) |
81 self.startDrag.emit() |
83 self.startDrag.emit() |