def mousePressEvent(self, event): self.point_edited = self.point_at_cursor(event.pos()) shift_is_pressed = (event.modifiers() == Qt.ShiftModifier) # Determine if cursor is near to the center self.moving = (geometry.distance2_qt(self.mass_center, event.pos()) <= 16) # Determine if cursor is near to a point if self.point_edited is None: if self.moving and shift_is_pressed: # Erase the whole roi self.scene().ROIs.remove(self) self.scene().removeItem(self) # Determine if cursor is near to a segment add_point_in_segment_n = self.near_segment(event.pos()) if add_point_in_segment_n is not None: pol = self.polygon() pol.insert(add_point_in_segment_n, event.pos()) self.setPolygon(pol) self.set_outer_polygon() self.update() self.point_edited = add_point_in_segment_n self.setCursor(QCursor(Qt.SizeAllCursor)) else: if shift_is_pressed: pol = self.polygon() pol.remove(self.point_edited) self.setPolygon(pol) self.set_outer_polygon() self.update() self.setCursor(self.DEFAULT_CURSOR) super(RoiPol, self).mousePressEvent(event)
def mousePressEvent(self, event): self.point_edited = self.point_at_cursor(event.pos()) shift_is_pressed = (event.modifiers() == Qt.ShiftModifier) # Determine if cursor is near to the center self.moving = (geometry.distance2_qt(self.mass_center, event.pos()) <= 16) # Determine if cursor is near to a point if self.moving and shift_is_pressed: # Erase the whole roi self.scene().ROIs.remove(self) self.scene().removeItem(self) super(RoiCirc, self).mousePressEvent(event)
def hoverMoveEvent(self, event): if self.is_editing() and self.isSelected(): shift_is_pressed = (event.modifiers() == Qt.ShiftModifier) near_center = (geometry.distance2_qt(self.mass_center, event.pos()) <= 9) near_vertex = self.point_at_cursor(event.pos()) if near_center or near_vertex: if near_center and shift_is_pressed: self.setCursor(QCursor(self.DEL_POINT_CURSOR)) else: self.setCursor(QCursor(Qt.SizeAllCursor)) else: self.setCursor(self.DEFAULT_CURSOR)
def point_at_cursor(self, point): for p in self.polygon(): if geometry.distance2_qt(point, p) <= 16: return self.polygon().indexOf(p) return None
def point_at_cursor(self, point): r = self.boundingRect() p = r.bottomRight() return geometry.distance2_qt(point, p) <= 16