def mouseMoveEvent(self, event): if self.m_mouse_down: if not self.m_cursor_moving: self.setCursor(QCursor(Qt.SizeAllCursor)) self.m_cursor_moving = True self.repaintLines() QGraphicsItem.mouseMoveEvent(self, event)
def mouseMoveEvent(self, event): """ All mouseMoveEvents are passed to the group if it's in a group Args: event (TYPE): Description """ MOVE_THRESHOLD = 0.01 # ignore small moves selection_group = self.group() if selection_group is not None: selection_group.mousePressEvent(event) elif self._right_mouse_move: new_pos = event.scenePos() delta = new_pos - self.drag_last_position dx = int(floor(delta.x() / _BASE_WIDTH))*_BASE_WIDTH x = self.handle_start.x() + dx if abs(dx) > MOVE_THRESHOLD or dx == 0.0: old_x = self.x() self.setX(x) self._virtual_helix_item.setX(x + _VH_XOFFSET) self._part_item.updateXoverItems(self._virtual_helix_item) dz = self._part_item.convertToModelZ(x - old_x) self._model_part.translateVirtualHelices([self.idNum()], 0, 0, dz, False, use_undostack=False) else: QGraphicsItem.mouseMoveEvent(self, event)
def mouseMoveEvent(self, event): #pos = self.mapFromGlobal(event.globalPos()) self.graphics_view._is_cursor_moved = True QGraphicsItem.mouseMoveEvent(self, event) if event.buttons() == Qt.LeftButton: max_y_pos = self._minimap_height - self.height() # fix vertical self.setX(0) if self.y() < 0: self.setY(0) elif self.y() > max_y_pos and max_y_pos < 0: self.setY(0) elif self.y() > max_y_pos and max_y_pos > 0: self.setY(max_y_pos) # move textedit's scrollbar elif self.pos_ratio > 0: print("self.y()", self.y()) print("self.pos_ratio", self.pos_ratio) print("/", int(self.y() / self.pos_ratio)) cursor_ratio = self.y() / self._minimap_height print("cursor_ratio", cursor_ratio) r = self.y() + self.height() * cursor_ratio print("r", r) self.graphics_view._change_scrollbar_value( int(r / self.pos_ratio))
def mouseMoveEvent(self, event: 'QGraphicsSceneMouseEvent') -> None: """ :param event: :return: """ self.is_left_mouse_move = self.is_left_mouse_press QGraphicsItem.mouseMoveEvent(self, event)
def mouseMoveEvent(self, event): """ All mouseMoveEvents are passed to the group if it's in a group Args: event (TYPE): Description """ MOVE_THRESHOLD = 0.01 # ignore small moves selection_group = self.group() if selection_group is not None: selection_group.mousePressEvent(event) elif self._right_mouse_move: new_pos = event.scenePos() delta = new_pos - self.drag_last_position dx = int(floor(delta.x() / _BASE_WIDTH)) * _BASE_WIDTH x = self.handle_start.x() + dx if abs(dx) > MOVE_THRESHOLD or dx == 0.0: old_x = self.x() self.setX(x) self._virtual_helix_item.setX(x + _VH_XOFFSET) self._part_item.updateXoverItems(self._virtual_helix_item) dz = self._part_item.convertToModelZ(x - old_x) self._model_part.translateVirtualHelices([self.idNum()], 0, 0, dz, False, use_undostack=False) else: QGraphicsItem.mouseMoveEvent(self, event)
def mouseMoveEvent(self, event): #pos = self.mapFromGlobal(event.globalPos()) if self.graphics_view == None: return self.graphics_view._is_cursor_moved = True QGraphicsItem.mouseMoveEvent(self, event) if event.buttons() == Qt.LeftButton: max_y_pos = self._minimap_height - self.height() # fix vertical self.setX(0) if self.y() < 0: self.setY(0) elif self.y() > max_y_pos and max_y_pos < 0: self.setY(0) elif self.y() > max_y_pos and max_y_pos > 0: self.setY(max_y_pos) # move textedit's scrollbar elif self.pos_ratio > 0: print("self.y()", self.y()) print("self.pos_ratio", self.pos_ratio) print("/", int(self.y() / self.pos_ratio)) cursor_ratio = self.y() / self._minimap_height print("cursor_ratio", cursor_ratio) r = self.y() + self.height() * cursor_ratio print("r", r) self.graphics_view._change_scrollbar_value( int(r / self.pos_ratio))
def mouseMoveEvent(self, event): if not self.m_mouse_down: QGraphicsItem.mouseMoveEvent(self, event) return event.accept() if not self.m_cursor_moving: self.setCursor(QCursor(Qt.CrossCursor)) self.m_cursor_moving = True for connection in canvas.connection_list: if ((connection.group_out_id == self.m_group_id and connection.port_out_id == self.m_port_id) or (connection.group_in_id == self.m_group_id and connection.port_in_id == self.m_port_id)): connection.widget.setLocked(True) if not self.m_line_mov: if options.use_bezier_lines: self.m_line_mov = CanvasBezierLineMov(self.m_port_mode, self.m_port_type, self) else: self.m_line_mov = CanvasLineMov(self.m_port_mode, self.m_port_type, self) canvas.last_z_value += 1 self.m_line_mov.setZValue(canvas.last_z_value) canvas.last_z_value += 1 self.parentItem().setZValue(canvas.last_z_value) item = None items = canvas.scene.items(event.scenePos(), Qt.ContainsItemShape, Qt.AscendingOrder) #for i in range(len(items)): for _, itemx in enumerate(items): if itemx.type() != CanvasPortType: continue if itemx == self: continue if item is None or itemx.parentItem().zValue() > item.parentItem( ).zValue(): item = itemx if self.m_hover_item and self.m_hover_item != item: self.m_hover_item.setSelected(False) if item is not None: if item.getPortMode() != self.m_port_mode and item.getPortType( ) == self.m_port_type: item.setSelected(True) self.m_hover_item = item else: self.m_hover_item = None else: self.m_hover_item = None self.m_line_mov.updateLinePos(event.scenePos())
def mouseMoveEvent(self, event): """ All mouseMoveEvents are passed to the group if it's in a group """ selection_group = self.group() if selection_group != None: selection_group.mousePressEvent(event) else: QGraphicsItem.mouseMoveEvent(self, event)
def mouseMoveEvent(self, event): if event.buttons() == Qt.LeftButton: rect = self.scene().parent().mapToScene( self.scene().parent().viewport().rect()).boundingRect() restrictedRect = QRectF( rect.x() + (rect.width() - self.scene().roomWidth) * .5, rect.y() + (rect.height() - self.scene().roomHeight) * .5, self.scene().roomWidth, self.scene().roomHeight) if restrictedRect.contains(event.scenePos()): self.scene().update() QGraphicsItem.mouseMoveEvent(self, event)
def mouseMoveEvent(self, event): if event.modifiers() & Qt.ShiftModifier: QGraphicsItem.mouseMoveEvent(self, event) else: drag = QDrag(event.widget()) drag.setMimeData(env.strips.mkMimeDez(self.strip)) pixmap = self.toPixmap() drag.setPixmap(pixmap) drag.setHotSpot(pixmap.rect().center()) self.setVisible(False) if drag.exec() != Qt.MoveAction: self.setVisible(True)
def mouseMoveEvent(self, event): '''Handle mouse move event. Argument(s): event (QGraphicsSceneMouseEvent): Graphics scene mouse event ''' # Only move the node if CTRL button pressed if event.modifiers() == Qt.AltModifier: QGraphicsItem.mouseMoveEvent(self, event) # Update coordinates of the line elif self.semiEdge is not None: self.semiEdge.update(event.scenePos())
def mouseMoveEvent(self, event): """Handle mouse move event. Argument(s): event (QGraphicsSceneMouseEvent): Graphics scene mouse event """ # Only move the node if CTRL button pressed if event.modifiers() == Qt.ControlModifier: QGraphicsItem.mouseMoveEvent(self, event) # Update coordinates of the line elif self.semiEdge is not None: self.semiEdge.update(event.scenePos())
def mouseMoveEvent(self, event): parent = self.parentItem() if self.model_bounds: xTL, yTL, xBR, yBR = self.model_bounds ct = self.corner_type epos = event.scenePos() # print(epos, self.item_start) # print(xTL, self.item_start.x()) new_pos = self.item_start + epos - self.event_start_position new_x = new_pos.x() new_y = new_pos.y() hwidth = self.half_width if ct == TOP_LEFT: new_x_TL = xTL - hwidth if new_x + hwidth > xTL else new_x new_y_TL = yTL - hwidth if new_y + hwidth > yTL else new_y tl, _ = parent.reconfigureRect((new_x_TL + hwidth, new_y_TL + hwidth), (), do_grid=True) self.alignPos(*tl) elif ct == BOTTOM_RIGHT: new_x_BR = xBR + hwidth if new_x + hwidth < xBR else new_x new_y_BR = yBR + hwidth if new_y + hwidth < yBR else new_y _, br = parent.reconfigureRect((), (new_x_BR + hwidth, new_y_BR + hwidth), do_grid=True) self.alignPos(*br) elif ct == TOP_RIGHT: pass elif ct == BOTTOM_LEFT: pass else: raise NotImplementedError("corner_type %d not supported" % (ct)) else: res = QGraphicsItem.mouseMoveEvent(parent, event) return res
def mouseMoveEvent(self, ev): if self.mode == MODE_MOVE: return QGraphicsItem.mouseMoveEvent(self, ev) center = self.transform().map(self.boundingRect().center()) origToCenter = self.origin - center originScale = vectorLength(origToCenter) origAngle = math.atan2(origToCenter.y(), origToCenter.x()) newPt = self.transform().map(ev.pos()) newToCenter = newPt - center newScale = vectorLength(newToCenter) newAngle = math.atan2(newToCenter.y(), newToCenter.x()) # build transform t = QTransform() t.translate(center.x(), center.y()) if self.mode == MODE_ROT: self._angle = math.degrees(newAngle - origAngle) t.rotate(self._angle) if self.mode == MODE_ZOOM: self._scale = newScale / originScale t.scale(self._scale, self._scale) t.translate(-center.x(), -center.y()) self.setTransform(t)
def mouseMoveEvent(self, event): parent = self.parentItem() if self.model_bounds: xTL, yTL, xBR, yBR = self.model_bounds ct = self.corner_type epos = event.scenePos() # print(epos, self.item_start) # print(xTL, self.item_start.x()) new_pos = self.item_start + epos - self.event_start_position new_x = new_pos.x() new_y = new_pos.y() hwidth = self.half_width if ct == TOP_LEFT: new_x_TL = xTL - hwidth if new_x + hwidth > xTL else new_x new_y_TL = yTL - hwidth if new_y + hwidth > yTL else new_y tl, _ = parent.reconfigureRect( (new_x_TL + hwidth, new_y_TL + hwidth), (), do_grid=True) self.alignPos(*tl) elif ct == BOTTOM_RIGHT: new_x_BR = xBR + hwidth if new_x + hwidth < xBR else new_x new_y_BR = yBR + hwidth if new_y + hwidth < yBR else new_y _, br = parent.reconfigureRect( (), (new_x_BR + hwidth, new_y_BR + hwidth), do_grid=True) self.alignPos(*br) elif ct == TOP_RIGHT: pass elif ct == BOTTOM_LEFT: pass else: raise NotImplementedError("corner_type %d not supported" % (ct)) else: res = QGraphicsItem.mouseMoveEvent(parent, event) return res
def mouseMoveEvent(self, event): parent = self.parentItem() epos = event.scenePos() h_w = self.half_width if self.model_bounds: mTLx, mTLy, mBRx, mBRy = self.model_bounds poTL = parent.outline.rect().topLeft() poBR = parent.outline.rect().bottomRight() poTLx, poTLy = poTL.x(), poTL.y() poBRx, poBRy = poBR.x(), poBR.y() new_pos = self.item_start + epos - self.event_start_position new_x = new_pos.x() + h_w new_y = new_pos.y() + h_w ht = self._handle_type if ht == HandleType.TOP_LEFT: new_x_TL = mTLx if new_x > mTLx else new_x new_y_TL = mTLy if new_y > mTLy else new_y r = parent.reconfigureRect((new_x_TL, new_y_TL), ()) self._group.alignHandles(r) elif ht == HandleType.TOP: new_y_TL = mTLy if new_y > mTLy else new_y r = parent.reconfigureRect((poTLx, new_y_TL), ()) self._group.alignHandles(r) elif ht == HandleType.TOP_RIGHT: new_y_TL = mTLy if new_y > mTLy else new_y new_x_BR = mBRx if new_x < mBRx else new_x r = parent.reconfigureRect((poTLx, new_y_TL), (new_x_BR, poBRy)) self._group.alignHandles(r) elif ht == HandleType.RIGHT: new_x_BR = mBRx if new_x < mBRx else new_x r = parent.reconfigureRect((), (new_x_BR, poBRy)) self._group.alignHandles(r) elif ht == HandleType.BOTTOM_RIGHT: new_x_BR = mBRx if new_x < mBRx else new_x new_y_BR = mBRy if new_y < mBRy else new_y r = parent.reconfigureRect((), (new_x_BR, new_y_BR)) self._group.alignHandles(r) elif ht == HandleType.BOTTOM: new_y_BR = mBRy if new_y < mBRy else new_y r = parent.reconfigureRect((), (poBRx, new_y_BR)) self._group.alignHandles(r) elif ht == HandleType.BOTTOM_LEFT: new_x_TL = mTLx if new_x > mTLx else new_x new_y_BR = mBRy if new_y < mBRy else new_y r = parent.reconfigureRect((new_x_TL, poTLy), (poBRx, new_y_BR)) self._group.alignHandles(r) elif ht == HandleType.LEFT: new_x_TL = mTLx if new_x > mTLx else new_x r = parent.reconfigureRect((new_x_TL, poTLy), ()) self._group.alignHandles(r) else: raise NotImplementedError("handle_type %d not supported" % (ht)) else: res = QGraphicsItem.mouseMoveEvent(parent, event) return res
def mouseMoveEvent(self, event): parent = self.parentItem() epos = event.scenePos() h_w = self.half_width if self.model_bounds: mTLx, mTLy, mBRx, mBRy = self.model_bounds po_rect = parent.outline.rect() poTL = po_rect.topLeft() poBR = po_rect.bottomRight() poTLx, poTLy = poTL.x(), poTL.y() poBRx, poBRy = poBR.x(), poBR.y() new_pos = self.item_start + epos - self.event_start_position new_x = new_pos.x()+h_w new_y = new_pos.y()+h_w ht = self._handle_type if ht == HandleEnum.TOP_LEFT: new_x_TL = mTLx if new_x > mTLx else new_x new_y_TL = mTLy if new_y > mTLy else new_y r = parent.reconfigureRect((new_x_TL, new_y_TL), ()) self._group.alignHandles(r) elif ht == HandleEnum.TOP: new_y_TL = mTLy if new_y > mTLy else new_y r = parent.reconfigureRect((poTLx, new_y_TL), ()) self._group.alignHandles(r) elif ht == HandleEnum.TOP_RIGHT: new_y_TL = mTLy if new_y > mTLy else new_y new_x_BR = mBRx if new_x < mBRx else new_x r = parent.reconfigureRect((poTLx, new_y_TL), (new_x_BR, poBRy)) self._group.alignHandles(r) elif ht == HandleEnum.RIGHT: new_x_BR = mBRx if new_x < mBRx else new_x r = parent.reconfigureRect((), (new_x_BR, poBRy)) self._group.alignHandles(r) elif ht == HandleEnum.BOTTOM_RIGHT: new_x_BR = mBRx if new_x < mBRx else new_x new_y_BR = mBRy if new_y < mBRy else new_y r = parent.reconfigureRect((), (new_x_BR, new_y_BR)) self._group.alignHandles(r) elif ht == HandleEnum.BOTTOM: new_y_BR = mBRy if new_y < mBRy else new_y r = parent.reconfigureRect((), (poBRx, new_y_BR)) self._group.alignHandles(r) elif ht == HandleEnum.BOTTOM_LEFT: new_x_TL = mTLx if new_x > mTLx else new_x new_y_BR = mBRy if new_y < mBRy else new_y r = parent.reconfigureRect((new_x_TL, poTLy), (poBRx, new_y_BR)) self._group.alignHandles(r) elif ht == HandleEnum.LEFT: new_x_TL = mTLx if new_x > mTLx else new_x r = parent.reconfigureRect((new_x_TL, poTLy), ()) self._group.alignHandles(r) else: raise NotImplementedError("handle_type %d not supported" % (ht)) event.setAccepted(True) else: res = QGraphicsItem.mouseMoveEvent(parent, event) return res
def mouseMoveEvent(self, event): """ called when mouse is pressed and moved, calls the move, drag or resize function according to selected handle """ if self.handle_selected == HANDLE_MIDDLE: self.setCursor(Qt.ClosedHandCursor) # start drag event only when cursor leaves current track if event.pos().y() < 0 or event.pos().y() > self.height: self.start_drag(event) else: pos = event.scenePos().x() - self.mouse_press_pos self.move_on_track(pos) else: self.resize(event.pos().x()) QGraphicsItem.mouseMoveEvent(self, event)
def mouseMoveEvent(self, event: QGraphicsSceneMouseEvent): """Converts event coords into an idx delta and updates if changed. """ delta = int(floor((self.x()+event.pos().x()) / BASE_WIDTH)) - self._offset_idx delta = util.clamp(delta, self._low_drag_bound-self._start_idx_low, self._high_drag_bound-self._start_idx_high+self.width()) if self._delta != delta: self._idx_low = int(self._start_idx_low + delta) self._idx_high = int(self._start_idx_high + delta) self._delta = delta self.reconfigureRect((), ()) self.resize_handle_group.updateText(HandleEnum.LEFT, self._idx_low) self.resize_handle_group.updateText(HandleEnum.RIGHT, self._idx_high) return QGraphicsItem.mouseMoveEvent(self, event)
def mouseMoveEvent(self, event: QGraphicsSceneMouseEvent): """Converts event coords into an idx delta and updates if changed. """ delta = int(floor( (self.x() + event.pos().x()) / BASE_WIDTH)) - self._offset_idx delta = util.clamp( delta, self._low_drag_bound - self._start_idx_low, self._high_drag_bound - self._start_idx_high + self.width()) if self._delta != delta: self._idx_low = int(self._start_idx_low + delta) self._idx_high = int(self._start_idx_high + delta) self._delta = delta self.reconfigureRect((), ()) self.resize_handle_group.updateText(HandleEnum.LEFT, self._idx_low) self.resize_handle_group.updateText(HandleEnum.RIGHT, self._idx_high) return QGraphicsItem.mouseMoveEvent(self, event)
def mouseMoveEvent(self, e): if self.mapper.tagSet: self.mapper.clearTagGroup() QGraphicsItem.mouseMoveEvent(self, e)
def mouseMoveEvent(self, event): if not self.m_mouse_down: QGraphicsItem.mouseMoveEvent(self, event) return event.accept() if not self.m_cursor_moving: self.setCursor(QCursor(Qt.CrossCursor)) self.m_cursor_moving = True for connection in canvas.connection_list: if CanvasConnectionConcerns(connection, self.m_group_id, [self.m_port_id]): connection.widget.setLocked(True) if not self.m_line_mov_list: if options.use_bezier_lines: line_mov = CanvasBezierLineMov(self.m_port_mode, self.m_port_type, 0, 1, self) else: line_mov = CanvasLineMov(self.m_port_mode, self.m_port_type, 0, 1, self) self.m_line_mov_list.append(line_mov) line_mov.setZValue(canvas.last_z_value) canvas.last_z_value += 1 canvas.is_line_mov = True self.m_last_rclick_item = None self.parentItem().setZValue(canvas.last_z_value) item = None items = canvas.scene.items(event.scenePos(), Qt.ContainsItemShape, Qt.AscendingOrder) for _, itemx in enumerate(items): if not itemx.type() in (CanvasPortType, CanvasPortGroupType): continue if itemx == self: continue if (item is None or itemx.parentItem().zValue() > item.parentItem().zValue()): item = itemx if self.m_hover_item and self.m_hover_item != item: self.m_hover_item.setSelected(False) if (item is not None and item.getPortType() == self.m_port_type and item.getPortMode() == self.m_port_mode): # check if item can cut/paste connections item_valid = False if self.m_has_connections: if item.type() == CanvasPortType: for connection in canvas.connection_list: if CanvasConnectionConcerns(connection, item.getGroupId(), [item.getPortId()]): break else: item_valid = True if not item_valid: item = None if item is not None and not self.is_connectable_to( item, accept_same_port_mode=True): # prevent connection from an out CV port to a non CV port input # because it is very dangerous for monitoring pass elif (item is not None and item.getPortType() == self.m_port_type): item.setSelected(True) if item == self.m_hover_item: pass elif item.type() == CanvasPortGroupType: self.m_hover_item = item self.resetLineMovPositions() self.resetDotLines() if len(self.m_line_mov_list) <= 1: # make original line going to first port of the hover portgrp for line_mov in self.m_line_mov_list: line_mov.setDestinationPortGroupPosition( 0, self.m_hover_item.getPortLength()) port_pos, portgrp_len = CanvasGetPortGroupPosition( self.m_group_id, self.m_port_id, self.m_portgrp_id) # create one line for each port of the hover portgrp for i in range(1, self.m_hover_item.getPortLength()): if options.use_bezier_lines: line_mov = CanvasBezierLineMov( self.m_port_mode, self.m_port_type, port_pos, portgrp_len, self) else: line_mov = CanvasLineMov(self.m_port_mode, self.m_port_type, port_pos, portgrp_len, self) line_mov.setDestinationPortGroupPosition( i, self.m_hover_item.getPortLength()) self.m_line_mov_list.append(line_mov) for connection in canvas.connection_list: if CanvasConnectionMatches( connection, self.m_group_id, [self.m_port_id], self.m_hover_item.getGroupId(), self.m_hover_item.getPortsList()): self.m_dotcon_list.append(connection) if (len(self.m_dotcon_list) == len( self.m_hover_item.getPortsList())): for connection in self.m_dotcon_list: connection.widget.setReadyToDisc(True) connection.widget.updateLineGradient() for line_mov in self.m_line_mov_list: line_mov.setReadyToDisc(True) elif item.type() == CanvasPortType: self.m_hover_item = item self.resetLineMovPositions() self.resetDotLines() if item.getPortMode() == self.m_port_mode: # situation of cut and paste existing connections for connection in canvas.connection_list: if CanvasConnectionConcerns(connection, self.m_group_id, [self.m_port_id]): connection.widget.setReadyToDisc(True) connection.widget.updateLineGradient() self.m_dotcon_list.append(connection) for line_mov in self.m_line_mov_list: line_mov.setReadyToDisc(True) else: for connection in canvas.connection_list: if CanvasConnectionMatches( connection, self.m_group_id, [self.m_port_id], self.m_hover_item.getGroupId(), [self.m_hover_item.getPortId()]): for line_mov in self.m_line_mov_list: line_mov.setReadyToDisc(True) connection.widget.setReadyToDisc(True) connection.widget.updateLineGradient() self.m_dotcon_list.append(connection) elif connection.widget.isReadyToDisc(): connection.widget.setReadyToDisc(False) connection.widget.updateLineGradient() else: self.m_hover_item = None self.resetLineMovPositions() self.resetDotLines() self.m_last_rclick_item = None for line_mov in self.m_line_mov_list: line_mov.updateLinePos(event.scenePos()) return event.accept() QGraphicsItem.mouseMoveEvent(self, event)
def mouseMoveEvent(self, event): # move object QGraphicsItem.mouseMoveEvent(self, event)
def mouseMoveEvent(self, event): print(self.pos()) QGraphicsItem.mouseMoveEvent(self, event)
def mouseMoveEvent(self, event): QGraphicsItem.mouseMoveEvent(self, event) self.scene().update()
def mouseMoveEvent(self, event): if not self.m_mouse_down: QGraphicsItem.mouseMoveEvent(self, event) return if not self.m_cursor_moving: self.setCursor(QCursor(Qt.CrossCursor)) self.m_cursor_moving = True for connection in canvas.connection_list: if CanvasConnectionConcerns(connection, self.m_group_id, self.m_port_id_list): connection.widget.setLocked(True) if not self.m_line_mov_list: self.m_last_rclick_item = None canvas.last_z_value += 1 self.setZValue(canvas.last_z_value) canvas.last_z_value += 1 for port in canvas.port_list: if (port.group_id == self.m_group_id and port.port_id in self.m_port_id_list): port.widget.setZValue(canvas.last_z_value) for i in range(len(self.m_port_id_list)): if options.use_bezier_lines: line_mov = CanvasBezierLineMov(self.m_port_mode, self.m_port_type, i, len(self.m_port_id_list), self) else: line_mov = CanvasLineMov(self.m_port_mode, self.m_port_type, i, len(self.m_port_id_list), self) self.m_line_mov_list.append(line_mov) canvas.is_line_mov = True canvas.last_z_value += 1 self.parentItem().setZValue(canvas.last_z_value) item = None items = canvas.scene.items(event.scenePos(), Qt.ContainsItemShape, Qt.AscendingOrder) for i in range(len(items)): if items[i].type() in (CanvasPortType, CanvasPortGroupType): if items[i] != self: if not item: item = items[i] elif (items[i].parentItem().zValue() > item.parentItem().zValue()): item = items[i] if self.m_hover_item and self.m_hover_item != item: self.m_hover_item.setSelected(False) # if item has same port mode # verify we can use it for cut and paste connections if (item is not None and item.getPortType() == self.m_port_type and item.getPortMode() == self.m_port_mode): item_valid = False if (self.m_has_connections and item.type() == CanvasPortGroupType and len(item.getPortsList()) == len(self.m_port_id_list)): for connection in canvas.connection_list: if CanvasConnectionConcerns(connection, item.getGroupId(), item.getPortsList()): break else: item_valid = True if not item_valid: item = None if item is not None and not self.is_connectable_to( item, accept_same_port_mode=True): # prevent connection from an out CV port to a non CV port input # because it is very dangerous for monitoring pass elif (item is not None and self.m_hover_item != item and item.getPortType() == self.m_port_type): item.setSelected(True) if item == self.m_hover_item: # prevent unneeded operations pass elif item.type() == CanvasPortType: self.m_hover_item = item self.resetDotLines() self.resetLineMovPositions() for line_mov in self.m_line_mov_list: line_mov.setDestinationPortGroupPosition(0, 1) self.m_dotcon_list.clear() for connection in canvas.connection_list: if CanvasConnectionMatches( connection, self.m_group_id, self.m_port_id_list, self.m_hover_item.getGroupId(), [self.m_hover_item.getPortId()]): self.m_dotcon_list.append(connection) if len(self.m_dotcon_list) == len(self.m_port_id_list): for connection in self.m_dotcon_list: connection.widget.setReadyToDisc(True) connection.widget.updateLineGradient() for line_mov in self.m_line_mov_list: line_mov.setReadyToDisc(True) elif item.type() == CanvasPortGroupType: self.m_hover_item = item self.resetDotLines() self.resetLineMovPositions() if item.getPortMode() == self.m_port_mode: for connection in canvas.connection_list: if CanvasConnectionConcerns(connection, self.m_group_id, self.m_port_id_list): connection.widget.setReadyToDisc(True) connection.widget.updateLineGradient() self.m_dotcon_list.append(connection) for line_mov in self.m_line_mov_list: line_mov.setReadyToDisc(True) else: if (self.m_hover_item.getPortLength() <= len( self.m_line_mov_list)): for i in range(len(self.m_line_mov_list)): line_mov = self.m_line_mov_list[i] line_mov.setDestinationPortGroupPosition( i % self.m_hover_item.getPortLength(), self.m_hover_item.getPortLength()) else: start_n_linemov = len(self.m_line_mov_list) for i in range(self.m_hover_item.getPortLength()): if i < start_n_linemov: line_mov = self.m_line_mov_list[i] line_mov.setDestinationPortGroupPosition( i, self.m_hover_item.getPortLength()) else: port_posinportgrp = i % len( self.m_port_id_list) if options.use_bezier_lines: line_mov = CanvasBezierLineMov( self.m_port_mode, self.m_port_type, port_posinportgrp, self.m_hover_item.getPortLength(), self) else: line_mov = CanvasLineMov( self.m_port_mode, self.m_port_type, port_posinportgrp, self.m_hover_item.getPortLength(), self) line_mov.setDestinationPortGroupPosition( i, self.m_hover_item.getPortLength()) self.m_line_mov_list.append(line_mov) self.m_dotcon_list.clear() symetric_con_list = [] for portself_id in self.m_port_id_list: for porthover_id in self.m_hover_item.getPortsList(): for connection in canvas.connection_list: if CanvasConnectionMatches( connection, self.m_group_id, [portself_id], self.m_hover_item.getGroupId(), [porthover_id]): if (self.m_port_id_list.index(portself_id) % len(self.m_hover_item.getPortsList( )) == ( self.m_hover_item.getPortsList( ).index(porthover_id) % len(self.m_port_id_list))): self.m_dotcon_list.append(connection) symetric_con_list.append(connection) else: self.m_dotcon_list.append(connection) connection.widget.setReadyToDisc(True) connection.widget.updateLineGradient() biggest_list = self.m_hover_item.getPortsList() if (len(self.m_port_id_list) >= len( self.m_hover_item.getPortsList())): biggest_list = self.m_port_id_list if len(symetric_con_list) == len(biggest_list): for connection in self.m_dotcon_list: connection.widget.setReadyToDisc(True) connection.widget.updateLineGradient() for line_mov in self.m_line_mov_list: line_mov.setReadyToDisc(True) else: if item != self.m_hover_item: self.m_hover_item = None self.m_last_rclick_item = None self.resetDotLines() self.resetLineMovPositions() for line_mov in self.m_line_mov_list: line_mov.updateLinePos(event.scenePos()) return event.accept() QGraphicsItem.mouseMoveEvent(self, event)