개정판 c51f31bd
fixed a routine to select area by using rubberband
DTI_PID/DTI_PID/Commands/AreaOcrCommand.py | ||
---|---|---|
28 | 28 |
super(AreaOcrCommand, self).__init__(imageViewer) |
29 | 29 |
self.name = 'AreaOcr' |
30 | 30 |
self.imageViewer.setCursor(QCursor(Qt.CrossCursor)) |
31 |
self._shape = None |
|
31 |
self._rubberBand = QRubberBand(QRubberBand.Rectangle, self.imageViewer) |
|
32 |
self._origin = QPoint() |
|
33 |
|
|
32 | 34 |
|
33 | 35 |
''' |
34 | 36 |
@brief pan image by left click and drag |
... | ... | |
39 | 41 |
Jeongwoo 2018.04.25 Add if state with QEngineeringNoteItem |
40 | 42 |
Jeongwoo 2018.04.26 Change method to create TextItem with TextItemFactory |
41 | 43 |
Jeongwoo 2018.05.02 Add Checking imageViewer has image if-statement, when mouseReleaseEvent happen |
44 |
humkyung 2018.08.29 use rubberband for selection text area |
|
42 | 45 |
''' |
43 | 46 |
def execute(self, param): |
44 | 47 |
event = param[1] |
45 | 48 |
scenePos = param[2] |
46 | 49 |
if 'mousePressEvent' == param[0]: |
47 | 50 |
if event.button() == Qt.LeftButton: |
48 |
if self._shape is None: |
|
49 |
self._shape = QGraphicsBoundingBoxItem(scenePos.x(), scenePos.y(), 0, 0) |
|
50 |
pen = QPen(Qt.DotLine) |
|
51 |
pen.setColor(Qt.red) |
|
52 |
pen.setWidthF(1) |
|
53 |
hilightColor = QColor(255, 0, 0, 127) |
|
54 |
self._shape.setBrush(QBrush(hilightColor)) |
|
55 |
self._shape.setPen(pen) |
|
56 |
self._shape._vertices.append(scenePos) |
|
57 |
self._shape.setSelected(True) |
|
58 |
self.imageViewer.scene.addItem(self._shape) |
|
59 |
self._shape.update() |
|
51 |
self._origin = event.pos() |
|
52 |
self._rubberBand.setGeometry(QRect(self._origin, QSize())) |
|
53 |
self._rubberBand.show() |
|
60 | 54 |
|
61 | 55 |
self.imageViewer.leftMouseButtonPressed.emit(scenePos.x(), scenePos.y()) |
62 |
elif 'mouseMoveEvent' == param[0] and event.buttons() == Qt.LeftButton and self._shape is not None: |
|
63 |
self._shape.process(param) |
|
56 |
elif 'mouseMoveEvent' == param[0] and event.buttons() == Qt.LeftButton: |
|
57 |
if self._rubberBand.isVisible(): |
|
58 |
self._rubberBand.setGeometry(QRect(self._origin, event.pos()).normalized()) |
|
64 | 59 |
elif 'mouseReleaseEvent' == param[0]: |
65 | 60 |
QGraphicsView.mouseReleaseEvent(self.imageViewer, event) |
66 | 61 |
try: |
67 | 62 |
if self.imageViewer.canZoom and event.button() == Qt.LeftButton and self._shape is not None: |
68 |
rect = self._shape.rect() |
|
63 |
self._rubberBand.hide() |
|
64 |
topLeft = self.imageViewer.mapToScene(self._rubberBand.geometry().topLeft()) |
|
65 |
bottomRight = self.imageViewer.mapToScene(self._rubberBand.geometry().bottomRight()) |
|
66 |
rect = QRectF(topLeft, bottomRight) |
|
69 | 67 |
if rect.isValid(): |
70 | 68 |
if self.imageViewer.hasImage(): |
71 | 69 |
rect = rect.toAlignedRect() |
... | ... | |
75 | 73 |
elif event.button() == Qt.RightButton: |
76 | 74 |
self.onRejected.emit(self) |
77 | 75 |
finally: |
78 |
self.imageViewer.scene.removeItem(self._shape) |
|
79 |
self._shape = None |
|
76 |
pass |
|
80 | 77 |
|
81 | 78 |
self.isTreated = False |
82 | 79 |
|
DTI_PID/DTI_PID/Commands/FenceCommand.py | ||
---|---|---|
19 | 19 |
super(FenceCommand, self).__init__(imageViewer) |
20 | 20 |
self.name = 'Fence' |
21 | 21 |
self.imageViewer.setCursor(QCursor(Qt.CrossCursor)) |
22 |
self._shape = None |
|
22 |
#self._shape = None |
|
23 |
self._rubberBand = QRubberBand(QRubberBand.Rectangle, self.imageViewer) |
|
24 |
self._origin = QPoint() |
|
25 |
|
|
23 | 26 |
self._vertices = [] |
24 | 27 |
|
25 | 28 |
''' |
... | ... | |
31 | 34 |
event = param[1] |
32 | 35 |
scenePos = param[2] |
33 | 36 |
if 'mousePressEvent' == param[0] and event.button() == Qt.LeftButton: |
34 |
if self._shape is None: |
|
35 |
self._shape = QGraphicsBoundingBoxItem(scenePos.x(), scenePos.y(), 0, 0) |
|
36 |
pen = QPen(Qt.DotLine) |
|
37 |
pen.setColor(Qt.red) |
|
38 |
pen.setWidthF(1) |
|
39 |
hilightColor = QColor(255, 0, 0, 127) |
|
40 |
self._shape.setBrush(QBrush(hilightColor)) |
|
41 |
self._shape.setPen(pen) |
|
42 |
self._shape._vertices.append(scenePos) |
|
43 |
self._shape.setSelected(True) |
|
44 |
self.imageViewer.scene.addItem(self._shape) |
|
45 |
self._shape.update() |
|
46 |
elif 'mouseMoveEvent' == param[0] and event.buttons() == Qt.LeftButton and self._shape is not None: |
|
47 |
self._shape.process(param) |
|
48 |
elif 'mouseReleaseEvent' == param[0] and event.button() == Qt.LeftButton and self._shape is not None: |
|
37 |
self._origin = event.pos() |
|
38 |
self._rubberBand.setGeometry(QRect(self._origin, QSize())) |
|
39 |
self._rubberBand.show() |
|
40 |
elif 'mouseMoveEvent' == param[0] and event.buttons() == Qt.LeftButton: |
|
41 |
if self._rubberBand.isVisible(): |
|
42 |
self._rubberBand.setGeometry(QRect(self._origin, event.pos()).normalized()) |
|
43 |
elif 'mouseReleaseEvent' == param[0] and event.button() == Qt.LeftButton: |
|
49 | 44 |
try: |
50 |
rect = self._shape.rect() |
|
45 |
self._rubberBand.hide() |
|
46 |
topLeft = self.imageViewer.mapToScene(self._rubberBand.geometry().topLeft()) |
|
47 |
bottomRight = self.imageViewer.mapToScene(self._rubberBand.geometry().bottomRight()) |
|
48 |
rect = QRectF(topLeft, bottomRight) |
|
51 | 49 |
if rect.isValid(): |
52 | 50 |
if self.imageViewer.hasImage(): |
53 | 51 |
rect = rect.toAlignedRect() |
... | ... | |
55 | 53 |
|
56 | 54 |
QGraphicsView.mouseReleaseEvent(self.imageViewer, event) |
57 | 55 |
finally: |
58 |
self.imageViewer.scene.removeItem(self._shape) |
|
59 |
self._shape = None |
|
56 |
pass |
|
60 | 57 |
|
61 | 58 |
''' |
62 | 59 |
@brief return vertices selected by user |
DTI_PID/DTI_PID/Shapes/EngineeringLineItem.py | ||
---|---|---|
35 | 35 |
|
36 | 36 |
try: |
37 | 37 |
QGraphicsLineItem.__init__(self, parent) |
38 |
self.setPen(QPen(Qt.blue, 4, Qt.SolidLine)) # set default pen |
|
38 | 39 |
self.isCreated = True |
39 | 40 |
|
40 | 41 |
self.connectors = [] |
내보내기 Unified diff