def mouseMoveEvent(self, event: QtGui.QMouseEvent) -> None: x, y = event.pos().x(), event.pos().y() x, y = self.gr_field.pixel_to_norm_coord(x, y) for zone in self.gr_field.zones: if zone.coordinates_are_in_zone(x, y): if not zone.activated: zone.mouse_enter.emit() zone.activated = True else: if zone.activated: zone.mouse_leave.emit() zone.activated = False
def mouseMoveEvent(self, event: QtGui.QMouseEvent) -> None: x, y = event.pos().x(), event.pos().y() if self.__mode == 'select' and self.__mouse_is_pressed: self.__select_end = (x, y) self.update() elif self.__mode == 'grab' and self.__mouse_is_pressed: end = (x, y) dx = end[0] - self.__move_start[0] dy = end[1] - self.__move_start[1] self.zoom_x = self.__zoom_x0 - self.pixel_to_norm_rel(dx) self.zoom_y = self.__zoom_y0 - self.pixel_to_norm_rel(dy) self.zoomed.emit()
def mousePressEvent(self, event: QtGui.QMouseEvent) -> None: x, y = event.pos().x(), event.pos().y() if self.__mode == 'select': self.__select = True self.__select_start = (x, y) self.__select_end = (x, y) elif self.__mode == 'grab': self.setCursor(Qt.CursorShape.ClosedHandCursor) self.__move_start = (x, y) self.__zoom_x0 = self.zoom_x self.__zoom_y0 = self.zoom_y else: x, y = self.pixel_to_norm_coord(x, y) for zone in self.zones: if zone.coordinates_are_in_zone(x, y): zone.clicked.emit() self.__mouse_is_pressed = True
def mouseReleaseEvent(self, event: QtGui.QMouseEvent) -> None: self.__mouse_is_pressed = False if self.__mode == 'select': self.__select_end = (event.pos().x(), event.pos().y()) width = self.__select_end[0] - self.__select_start[0] height = self.__select_end[1] - self.__select_start[1] self.zoom_x, self.zoom_y = self.pixel_to_norm_coord( self.__select_start[0], self.__select_start[1]) self.zoom_x += self.margin self.zoom_y += self.margin if width < 0: width = abs(width) self.zoom_x -= self.pixel_to_norm_rel(width) if height < 0: height = abs(height) self.zoom_y -= self.pixel_to_norm_rel(height) if width <= height * self.x_range / self.y_range: self.zoom_w = self.pixel_to_norm_rel(width) else: self.zoom_w = self.pixel_to_norm_rel(height * self.x_range / self.y_range) if self.zoom_w <= 2 * self.margin: self.zoom_w = 0 else: self.zoom_w -= 2 * self.margin self.__select = False self.zoomed.emit() elif self.__mode == 'grab': self.setCursor(Qt.CursorShape.OpenHandCursor)
def mouseDoubleClickEvent(self, event: QtGui.QMouseEvent) -> None: x, y = self.pixel_to_norm_coord(event.pos().x(), event.pos().y()) for zone in self.zones: if zone.coordinates_are_in_zone(x, y): zone.double_clicked.emit()