def set_coords_on_widgets(self, widgets: list or tuple, event: QtGui.QDragMoveEvent, x: int, y: int): """ sets label for widgets with distance to some widget :param widgets: widgets that need label :param event: event for position of mouse :param x: x coordinate of main widget :param y: y coordinate of main widget """ [widget.hide_size_or_pos_label() for widget in self.get_all_widgets()] for widget, (way_x, way_y) in widgets.items(): if way_x or way_y: widget.show_size_or_pos_label() widget.set_size_or_pos_label( "{} {}".format(str(str(abs((x + event.source().width() // 2) - way_x) if way_x else '') + '↔') if way_x else '', str(str(abs((y + event.source().height() // 2) - way_y) if way_y else '') + '↕') if way_y else '') )
def dragMoveEvent(self, event: QtGui.QDragMoveEvent) -> None: obj: TextWidget = event.source() modifier_pressed = QtWidgets.QApplication.keyboardModifiers() shift_pressed = (int(modifier_pressed) & QtCore.Qt.ShiftModifier) == QtCore.Qt.ShiftModifier if self.manager.widget_manager.get_dor() == DRAG: obj.move(event.pos().x() - self.manager.widget_manager.drag_dot[0], event.pos().y() - self.manager.widget_manager.drag_dot[1]) x, y, _, _, x_mod, y_mod, widgets = self.manager.widget_manager.drag_magnet_checker( obj) if shift_pressed: if not x_mod: x = x - (x - self.manager.grid_manager.zero_point_dot.get_pos()[0]) \ % (OFFSET_MAGNET * 2) if not y_mod: y = y - (y - self.manager.grid_manager.zero_point_dot.get_pos()[1]) \ % (OFFSET_MAGNET * 2) x, y = max(x, 0), max(y, 0) if self.manager.grid_manager.grid.show: x, y, widgets = \ self.manager.grid_manager.check_and_set_grid_magnet_lines_for_resizing( obj, x, y, x_mod, y_mod, widgets ) self.manager.widget_manager.set_coords_on_widgets( widgets, event, x, y) obj.move_event(x, y) obj.update_arrows() elif self.manager.widget_manager.get_dor() == RESIZE: obj_x1, obj_y1, obj_x2, obj_y2, x_mod, y_mod, widgets = \ self.manager.widget_manager.resize_magnet_checker(obj, event.pos()) x, y = obj_x2 - obj_x1, obj_y2 - obj_y1 if shift_pressed: if not x_mod: x = max(x - x % (OFFSET_MAGNET * 2), 0) if not y_mod: y = max(y - y % (OFFSET_MAGNET * 2), 0) self.manager.widget_manager.set_coords_on_widgets( widgets, event, x, y) obj.resize_event(x, y) self.update()