def hoverMoveEvent(self, event: QtWidgets.QGraphicsSceneHoverEvent): """Handles hover event by showing hover price line.""" event.setAccepted(True) pos = self.mapToParent(event.pos()) val = self.mapToValue(pos) self.hoverLine.clear() self.hoverLine.append(0, val.y()) self.hoverLine.append(1, val.y()) if val.y() > 0: precision = min(abs(int(math.log10(val.y())) - 4), 8) else: precision = 1 # TODO calculate offsets instead of hard coding it self.hoverLinePriceTag.setPos(self.plotArea().getCoords()[2] + 5, pos.y() - 7) self.hoverLinePriceTag.setText('{:.{prec}f}'.format(val.y(), prec=min( precision, 8))) # self.hoverLinePriceTag.setText(f'{val.y():.{min(precision, 8)}f}') font = self.hoverLinePriceTag.font() font.setPointSize(8) self.hoverLinePriceTag.setFont(font) y_axes = self.hoverLine.attachedAxes()[0] if y_axes.min() < val.y() < y_axes.max(): self.hoverLinePriceTag.show() else: self.hoverLinePriceTag.hide()
def hoverLeaveEvent(self, event: QGraphicsSceneHoverEvent): # self._circle_brush = self._circle_connected_brush if self.connected else self._circle_disconnected_brush if not self.is_connected(): self._border_brush = self._border_disconnected_brush self.update() event.accept()
def createToolHoverMoveEvent(self, tool: CreateSliceToolT, part_item: SliceNucleicAcidPartItemT, event: QGraphicsSceneHoverEvent): if self.grid.grid_type == GridEnum.HONEYCOMB: positionToLatticeCoord = HoneycombDnaPart.positionModelToLatticeCoord else: positionToLatticeCoord = SquareDnaPart.positionModelToLatticeCoord coordinates = positionToLatticeCoord( part_item.part().radius(), event.scenePos().x(), event.scenePos().y(), scale_factor=part_item.scale_factor) latticeCoordToXY = HoneycombDnaPart.latticeCoordToQtXY if self.grid.grid_type is GridEnum.HONEYCOMB \ else SquareDnaPart.latticeCoordToQtXY coordinate_string = '(%s, %s)' % coordinates coordiate_scaled_pos = '(%s, %s)' % latticeCoordToXY( DEFAULT_RADIUS, coordinates[0], coordinates[1], part_item.scale_factor) coordiate_pos = '(%s, %s)' % latticeCoordToXY( DEFAULT_RADIUS, coordinates[0], coordinates[1]) position_string = '(%s, %s)' % (event.scenePos().x(), event.scenePos().y()) part_item.updateStatusBar('%s @ %s (%s) - %s' % (coordinate_string, coordiate_scaled_pos, coordiate_pos, position_string)) part_item.createToolHoverMove(tool, event)
def hoverMoveEvent(self, event: QGraphicsSceneHoverEvent): """Summary Args: event: Description """ tool = self._getActiveTool() tool_method_name = tool.methodPrefix() + "HoverMove" if hasattr(self, tool_method_name): getattr(self, tool_method_name)(tool, event) else: event.setAccepted(False) QGraphicsItem.hoverMoveEvent(self, event)
def hoverMoveEvent(self, event: QGraphicsSceneHoverEvent): """Parses a :meth:`hoverMoveEvent` to extract strand_set and base index, forwarding them to approproate tool method as necessary. Args: event: Description """ base_idx = int(floor(event.pos().x() / _BASE_WIDTH)) loc = "%d[%d]" % (self._id_num, base_idx) self._part_item.updateStatusBar(loc) active_tool = self._getActiveTool() tool_method_name = active_tool.methodPrefix() + "HoverMove" if hasattr(self, tool_method_name): is_fwd, idx_x, idx_y = active_tool.baseAtPoint(self, event.pos()) getattr(self, tool_method_name)(is_fwd, idx_x, idx_y)
def hoverEnterEvent(self, event: QGraphicsSceneHoverEvent): if event.modifiers() & Qt.ShiftModifier: self.setCursor(Qt.OpenHandCursor) else: self.setCursor(Qt.ArrowCursor) self._part_item.updateStatusBar("{}–{}".format(self._idx_low, self._idx_high)) QGraphicsItem.hoverEnterEvent(self, event)
def hoverMoveEvent(self, event: QGraphicsSceneHoverEvent): """Parses a mouseMoveEvent to extract strandSet and base index, forwarding them to approproate tool method as necessary. Args: event: Description """ active_tool = self._getActiveTool() tool_method_name = active_tool.methodPrefix() + "HoverMove" if hasattr(self, tool_method_name): getattr(self, tool_method_name)(event.pos())
def createToolHoverMoveEvent(self, tool: CreateSliceToolT, part_item: SliceNucleicAcidPartItemT, event: QGraphicsSceneHoverEvent): if self.grid.grid_type == GridEnum.HONEYCOMB: positionToLatticeCoord = HoneycombDnaPart.positionModelToLatticeCoord else: positionToLatticeCoord = SquareDnaPart.positionModelToLatticeCoord coordinates = positionToLatticeCoord(part_item.part().radius(), event.scenePos().x(), event.scenePos().y(), scale_factor=part_item.scale_factor) latticeCoordToXY = HoneycombDnaPart.latticeCoordToQtXY if self.grid.grid_type is GridEnum.HONEYCOMB \ else SquareDnaPart.latticeCoordToQtXY coordinate_string = '(%s, %s)' % coordinates coordiate_scaled_pos = '(%s, %s)' % latticeCoordToXY(DEFAULT_RADIUS, coordinates[0], coordinates[1], part_item.scale_factor) coordiate_pos = '(%s, %s)' % latticeCoordToXY(DEFAULT_RADIUS, coordinates[0], coordinates[1]) position_string = '(%s, %s)' % (event.scenePos().x(), event.scenePos().y()) part_item.updateStatusBar('%s @ %s (%s) - %s' % (coordinate_string, coordiate_scaled_pos, coordiate_pos, position_string)) part_item.createToolHoverMove(tool, event)
def hoverMove(self, item: PathVirtualHelixItemT, event: QGraphicsSceneHoverEvent, flag: bool = None): """flag is for the case where an item in the path also needs to implement the hover method Args: item (TYPE): Description event (TYPE): Description flag (None, optional): Description """ self.show() self.updateLocation(item, item.mapToScene(QPointF(event.pos()))) pos_scene = item.mapToScene(QPointF(event.pos())) pos_item = item.mapFromScene(pos_scene) self.setTopStrand(self.helixIndex(pos_item)[1] == 0) new_position = self.helixPos(pos_item) if new_position is not None: self.setPos(new_position)
def hoverMoveEvent(self, event: QGraphicsSceneHoverEvent): if self.mode != StickMode.EditDelete and self.mode != StickMode.Edit and self.mode != StickMode.Measurement: return if self.mode == StickMode.Measurement: self.proposed_snow_height = max(self.line.p2().y() - event.pos().y(), 0) self.update() return hovered_handle = list(filter(lambda h: h.rect().contains(event.pos()), self.handles)) if len(hovered_handle) == 0: if self.hovered_handle is not None: self.hovered_handle.setBrush(self.handle_idle_brush) self.hovered_handle = None return if self.hovered_handle is not None and self.hovered_handle != hovered_handle[0]: self.hovered_handle.setBrush(self.handle_idle_brush) self.hovered_handle = hovered_handle[0] if self.hovered_handle == self.top_handle: self.top_handle.setBrush(self.handle_hover_brush) elif self.hovered_handle == self.bottom_handle: self.bottom_handle.setBrush(self.handle_hover_brush) else: self.mid_handle.setBrush(self.handle_hover_brush) self.scene().update()
def hoverMoveEvent(self, event: QGraphicsSceneHoverEvent): """Parses a :class:`QGraphicsSceneHoverEvent` to extract a base index, forwarding them to approproate tool method as necessary. Updates the status bar Args: event: """ vhi_num = self._virtual_helix_item.idNum() idx = int(floor((event.pos().x()) / _BASE_WIDTH)) oligo_length = self._model_strand.oligo().length() self.partItem().updateStatusBar("%d[%d]\tlength: %d" % (vhi_num, idx, oligo_length)) tool_method_name = self._getActiveTool().methodPrefix() + "HoverMove" if hasattr(self, tool_method_name): getattr(self, tool_method_name)(event, idx)
def hoverMoveEvent(self, event: QGraphicsSceneHoverEvent) -> None: if self.current_link_item is not None: return found: List[Tuple[float, StickLink, float]] = [] for stick_link in self.stick_links_list: if stick_link == self.current_link_item: continue stick_link.btn_break_link.setVisible(False) stick_link.fade_out(False) e1 = stick_link.line_item.line().unitVector() e1 = e1.p2() - e1.p1() e2 = stick_link.line_item.line().normalVector().unitVector() e2 = e2.p2() - e2.p1() sp = event.scenePos() - stick_link.line_item.line().p1() proj = QPointF.dotProduct(sp, e1) * e1 perp = sp - proj dist = math.sqrt(QPointF.dotProduct(perp, perp)) if dist < 50: t = math.sqrt(QPointF.dotProduct(proj, proj)) / stick_link.line_item.line().length() if 0.1 < t < 0.9 and QPointF.dotProduct(proj, e1) > 0.0: found.append((dist, stick_link, t)) if len(found) > 0: found.sort(key=lambda tup: tup[0]) dist_stick_link_t = found[0] stick_link = dist_stick_link_t[1] stick_link.fade_out(False) t = dist_stick_link_t[2] p = stick_link.line_item.line().pointAt(t) q = stick_link.line_item.mapFromScene(p) stick_link.btn_break_link.setPos(q - QPointF(stick_link.btn_break_link.boundingRect().width() * 0.5, stick_link.btn_break_link.boundingRect().height() * 0.5)) stick_link.btn_break_link.setVisible(True) for stick_link_ in self.stick_links_list: if stick_link_ == stick_link: continue stick_link_.fade_out(True)
def hoverEnterEvent(self, event: QGraphicsSceneHoverEvent): # self._circle_brush = self._circle_hover_brush self._border_brush = self._border_connected_brush self.update() event.accept()
def hoverMoveEvent(self, event: QGraphicsSceneHoverEvent): if event.modifiers() & Qt.ShiftModifier: self.setCursor(Qt.OpenHandCursor) else: self.setCursor(Qt.ArrowCursor) QGraphicsItem.hoverMoveEvent(self, event)
def hoverMoveEvent(self, event: QGraphicsSceneHoverEvent) -> None: pt = event.pos() x = math.floor(pt.x()) y = math.floor(pt.y()) self.signals.hoverMoveEventSgn.emit(event, x, y) super(ImagePixmap, self).hoverMoveEvent(event)