def reset(self): """ Remove temporary/state information from node, eg. remove touch areas. """ Movable.reset(self) self.update_bounding_rect() ctrl.ui.remove_touch_areas_for(self)
def __init__(self, img, box=QtCore.QRectF(0, 0, 480, 400)): pixmap = QtGui.QPixmap(img) # pixmap=pixmap.scaledToHeight(int(box.height())) QtWidgets.QGraphicsPixmapItem.__init__(self, pixmap) Movable.__init__(self) self.setFlag(QtWidgets.QGraphicsRectItem.ItemIsMovable) self.setTransformationMode(QtCore.Qt.SmoothTransformation)
def __init__(self, img, box=QtCore.QRectF(0, 0, 480, 400), forest=None): pixmap = QtGui.QPixmap(img) # pixmap=pixmap.scaledToHeight(int(box.height())) QtWidgets.QGraphicsPixmapItem.__init__(self, pixmap) Movable.__init__(self, forest=forest) self.setFlag(QtWidgets.QGraphicsRectItem.ItemIsMovable) self.setTransformationMode(QtCore.Qt.SmoothTransformation)
def mouseReleaseEvent(self, event): """ Either we are finishing dragging or clicking the node. If clicking a node with editable label, the click has to be replayed to Label (QGraphicsTextItem) when it has toggled the edit mode on, to let its inaccessible method for positioning cursor on click position to do its work. :param event: :return: """ replay_click = False shift = event.modifiers() == QtCore.Qt.ShiftModifier if ctrl.pressed is self: ctrl.release(self) if ctrl.dragged_set: x, y = to_tuple(event.scenePos()) self.drop_to(int(x), int(y), recipient=ctrl.drag_hovering_on, shift_down=shift) ctrl.graph_scene.kill_dragging() ctrl.ui.update_selections() # drag operation may have changed visible affordances else: # This is a regular click on 'pressed' object self.select(adding=shift, select_area=False) if self.label_object.is_quick_editing(): replay_click = True self.update() Movable.mouseReleaseEvent(self, event) if replay_click and False: ctrl.graph_view.replay_mouse_press() self.label_object.mouseReleaseEvent(event) ctrl.release(self)
def mouseMoveEvent(self, e): # mouseMoveEvents only happen between mousePressEvents and mouseReleaseEvents scene_pos_pf = e.scenePos() if ctrl.dragged_focus is self: self.drag(e) ctrl.graph_scene.dragging_over(scene_pos_pf) elif (e.buttonDownScenePos(QtCore.Qt.LeftButton) - scene_pos_pf).manhattanLength() > 6: scene_pos = to_tuple(scene_pos_pf) self.start_dragging(scene_pos) self.drag(e) ctrl.graph_scene.dragging_over(scene_pos_pf) Movable.mouseMoveEvent(self, e)
def __init__(self, forest=None): """ Node is an abstract class that shouldn't be used by itself, though it should contain all methods to make it work. Inherit and modify this for Constituents, Features etc. """ self.label_object = None Movable.__init__(self, forest=forest) Draggable.__init__(self) self.settings = NodeSettings(self) self.label_object = SimpleLabel(parent=self) self.syntactic_object = None self.label = '' self.selected = False self._label_visible = True self.label_rect = None self._gravity = 0 self.drag_data = None self.user_size = None self.invert_colors = False self.text_parse_mode = 1 self._magnets = [] self.is_syntactically_valid = False self.width = 0 self.height = 0 self.is_trace = False self.inner_rect = None self._cached_child_rect = None self.anim = None self.magnet_mapper = None self.halo = False self.halo_item = None self.in_scene = False self.edges_up = [] self.edges_down = [] self.triangle_stack = [] # you can always unfold only the outermost triangle, so stack self.color_key = None self.invert_colors = False self._editing_template = {} self.label_display_data = {} self.setFiltersChildEvents(False) self.setAcceptHoverEvents(True) self.setAcceptDrops(True) self.setCacheMode(QtWidgets.QGraphicsItem.DeviceCoordinateCache) self.setFlag(QtWidgets.QGraphicsObject.ItemSendsGeometryChanges) # self.setFlag(QtWidgets.QGraphicsObject.ItemIsMovable) self.setFlag(QtWidgets.QGraphicsObject.ItemIsSelectable) self.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor)) # self.fade_in() self.update_visibility()
def __init__(self, text='', box=QtCore.QRectF(0, 0, 480, 400), forest=None): QtWidgets.QGraphicsTextItem.__init__(self) Movable.__init__(self, forest=forest) self.setFlag(QtWidgets.QGraphicsRectItem.ItemIsMovable) # self.setFlag(QtGui.QGraphicsRectItem.ItemIsSelectable) self.setTextInteractionFlags(QtCore.Qt.TextEditorInteraction) self.prepareGeometryChange() # self.setFont(qt_prefs.get_font) # self.setTextWidth(box.width()) self.set_position(box.x(), box.y(), 0) self.host_tree = None if text: self.setPlainText(text)
def dragged_to(self, scene_pos): """ Dragged focus is in scene_pos. Move there or to position relative to that :param scene_pos: current pos of drag pointer (tuple x,y) :return: """ Movable.dragged_to(self, scene_pos) edge_list = [self.edges_up, self.edges_down] for item in self.childItems(): if isinstance(item, Movable): edge_list.append(item.edges_up) edge_list.append(item.edges_down) for edge in itertools.chain.from_iterable(edge_list): edge.make_path() edge.update()
def __init__(self, top=None, numeration=False): Movable.__init__(self) self.top = top if is_constituent(top): self.sorted_constituents = [top] else: self.sorted_constituents = [] if top: self.sorted_nodes = [top] else: self.sorted_nodes = [] self.numeration = numeration self.current_position = 100, 100 self.drag_data = None self.tree_changed = True self._cached_bounding_rect = None self.setZValue(100)
def __init__(self, top=None, numeration=False): Movable.__init__(self) self.top = top if is_constituent(top): self.sorted_constituents = [top] else: self.sorted_constituents = [] if top: self.sorted_nodes = [top] else: self.sorted_nodes = [] self.numeration = numeration self.current_position = 100, 100 self.drag_data = None self.tree_changed = True self._cached_bounding_rect = None self.deleted_nodes = set() self.setZValue(100)
def mousePressEvent(self, event): ctrl.press(self) Movable.mousePressEvent(self, event)
def lock(self): Movable.lock(self) if self.is_visible(): ctrl.main.ui_manager.show_anchor(self)