def mousePressEvent(self, event: QtWidgets.QGraphicsSceneMouseEvent):
     if event.button() == Qt.MidButton:
         self.clear()
     elif event.button() == Qt.LeftButton:
         self.addEllipse(event.scenePos().x() - self.LINE_RADIUS_PX, event.scenePos().y() - self.LINE_RADIUS_PX,
                         self.LINE_RADIUS_PX * 2, self.LINE_RADIUS_PX * 2,
                         QPen(Qt.NoPen),
                         QBrush(Qt.black))
         self.previousPoint = event.scenePos()
Example #2
0
 def mousePressEvent(self, evt: QGraphicsSceneMouseEvent):
     if evt.button() == Qt.LeftButton:
         pos = (evt.scenePos().x(), evt.scenePos().y())
         self.relative_pos = (pos[0] - self.x(), pos[1] - self.y())
         self.port_clicked.emit(self)
     elif evt.button() == Qt.RightButton:
         pass
     elif evt.button() == Qt.MidButton:
         pass
Example #3
0
 def mousePressEvent(self, evt: QGraphicsSceneMouseEvent):
     if evt.button() == Qt.LeftButton:
         pos = (evt.scenePos().x(), evt.scenePos().y())
         self.relative_pos = (pos[0] - self.x(), pos[1] - self.y())
         if not evt.modifiers() == Qt.ControlModifier:
             self.scene().signal_clear_selection.emit()
         self.scene().select_item(self)
         self.color = COLOR_SELECTED
     elif evt.button() == Qt.RightButton:
         pass
     elif evt.button() == Qt.MidButton:
         pass
Example #4
0
    def mousePressEvent(self, event: QGraphicsSceneMouseEvent):
        """Parses a :meth:`mousePressEvent` to extract strand_set and base index,
        forwarding them to approproate tool method as necessary.

        Args:
            event: Description
        """
        # 1. Check if we are doing a Z translation
        if event.button() == Qt.RightButton:
            viewroot = self._viewroot
            current_filter_set = viewroot.selectionFilterSet()
            if self.FILTER_NAME in current_filter_set and self.part().isZEditable():
                self._right_mouse_move = True
                self.drag_last_position = event.scenePos()
                self.handle_start = self.pos()
            return

        self.scene().views()[0].addToPressList(self)
        strand_set, idx = self.baseAtPoint(event.pos())
        self._model_part.setActiveVirtualHelix(self._id_num, strand_set.isForward(), idx)
        tool = self._getActiveTool()
        tool_method_name = tool.methodPrefix() + "MousePress"

        if hasattr(self, tool_method_name):
            self._last_strand_set, self._last_idx = strand_set, idx
            getattr(self, tool_method_name)(strand_set, idx, event.modifiers())
        else:
            event.setAccepted(False)
Example #5
0
    def mouseReleaseEvent(self, event: QGraphicsSceneMouseEvent):
        if event.button() == Qt.LeftButton:
            trans = self.parent().transform()

            item = self.itemAt(event.scenePos(), trans)
            if isinstance(item, NamedArrow) and \
                self._source_y is not None and \
                    self._accepts_hover:

                interval = np.unique(
                    self._hot_str.loc[:, [STFCFM.TIN.name, STFCFM.TOUT.
                                          name]].values)

                source_inter = self._px_to_interval(self._source_y, interval)
                dest_inter = self._px_to_interval(event.scenePos().y(),
                                                  interval)

                if source_inter == dest_inter:
                    # if the intervals of the clicks are the same, prompt user
                    summary = self._setup.summary
                    pinch = self._setup.pinch
                    if self._des_type == 'abv':
                        summary_indexer = summary[SFM.TOUT.name] >= pinch
                    else:
                        summary_indexer = summary[SFM.TIN.name] <= pinch
                    summary = summary.loc[summary_indexer, :].reset_index(
                        drop=True)
                    inter = summary.at[source_inter, SFM.INTERVAL.name]
                    dialog = ExchangerInputDialog('process', self._des_type,
                                                  inter, self._source_item,
                                                  item.name, self._setup)
                    dialog.exec_()

        return super().mouseReleaseEvent(event)
    def mousePressEvent(self, event: QGraphicsSceneMouseEvent):
        """Event handler for when the mouse button is pressed inside
        this item. If a tool-specific mouse press method is defined, it will be
        called for the currently active tool. Otherwise, the default
        QGraphicsItem.mousePressEvent will be called.

        Note:
            Only applies the event if the clicked item is in the part
            item's active filter set.

        Args:
            event (QMouseEvent): contains parameters that describe the mouse event.
        """
        if self.FILTER_NAME not in self._part_item.getFilterSet():
            self._doc_controller.showFilterHints(True,
                                                 filter_name=self.FILTER_NAME)
            return
        if event.button() == Qt.RightButton:
            return
        part_item = self._part_item
        tool = part_item._getActiveTool()
        tool_method_name = tool.methodPrefix() + "MousePress"
        if hasattr(self, tool_method_name):
            getattr(self, tool_method_name)(tool, part_item, event)
        else:
            QGraphicsItem.mousePressEvent(self, event)
    def mousePressEvent(self, event: QGraphicsSceneMouseEvent):
        """Parses a :meth:`mousePressEvent` to extract strand_set and base index,
        forwarding them to approproate tool method as necessary.

        Args:
            event: Description
        """
        # 1. Check if we are doing a Z translation
        if event.button() == Qt.RightButton:
            viewroot = self._viewroot
            current_filter_set = viewroot.selectionFilterSet()
            if self.FILTER_NAME in current_filter_set and self.part(
            ).isZEditable():
                self._right_mouse_move = True
                self.drag_last_position = event.scenePos()
                self.handle_start = self.pos()
            return

        self.scene().views()[0].addToPressList(self)
        strand_set, idx = self.baseAtPoint(event.pos())
        self._model_part.setActiveVirtualHelix(self._id_num,
                                               strand_set.isForward(), idx)
        tool = self._getActiveTool()
        tool_method_name = tool.methodPrefix() + "MousePress"

        if hasattr(self, tool_method_name):
            self._last_strand_set, self._last_idx = strand_set, idx
            getattr(self, tool_method_name)(strand_set, idx, event.modifiers())
        else:
            event.setAccepted(False)
Example #8
0
    def mousePressEvent(self, event: QGraphicsSceneMouseEvent):
        """Handler for user mouse press.

        Args:
            event: Contains item, scene, and screen
            coordinates of the the event, and previous event.
        """
        # self.show()
        if event.button() != Qt.LeftButton:
            return QGraphicsItemGroup.mousePressEvent(self, event)
        else:
            self._drag_enable = True

            # required to get the itemChanged event to work
            # correctly for this
            self.setSelected(True)

            # self.selectionbox.resetTransform()
            self.selectionbox.resetPosition()
            self.selectionbox.refreshPath()

            # self.selectionbox.resetTransform()
            self.selectionbox.resetPosition()
            self.selectionbox.show()

            # for some reason we need to skip the first mouseMoveEvent
            self._dragged = False

            if self._added_to_press_list is False:
                self._added_to_press_list = True
                self.scene().views()[0].addToPressList(self)
            return QGraphicsItemGroup.mousePressEvent(self, event)
Example #9
0
 def mousePressEvent(self, event: QGraphicsSceneMouseEvent) -> None:
     if event.button() == 1:
         item = self.itemAt(event.scenePos(), QTransform())
         if isinstance(item, Region):
             self.rebuild_sprite_signal.emit(item.region_id)
             self.current_item = item
             self.pressed = True
Example #10
0
    def mousePressEvent(self, event: QGraphicsSceneMouseEvent):
        """Handler for user mouse press.

        Args:
            event: Contains item, scene, and screen
            coordinates of the the event, and previous event.
        """
        # self.show()
        if event.button() != Qt.LeftButton:
            return QGraphicsItemGroup.mousePressEvent(self, event)
        else:
            self._drag_enable = True

            # required to get the itemChanged event to work
            # correctly for this
            self.setSelected(True)

            # self.selectionbox.resetTransform()
            self.selectionbox.resetPosition()
            self.selectionbox.refreshPath()

            # self.selectionbox.resetTransform()
            self.selectionbox.resetPosition()
            self.selectionbox.show()

            # for some reason we need to skip the first mouseMoveEvent
            self._dragged = False

            if self._added_to_press_list is False:
                self._added_to_press_list = True
                self.scene().views()[0].addToPressList(self)
            return QGraphicsItemGroup.mousePressEvent(self, event)
Example #11
0
    def mousePressEvent(self, event: QGraphicsSceneMouseEvent):
        """Handler for user mouse press.

        Args:
            event: Contains item, scene, and screen coordinates of the
                event, and previous event.
        """
        # print("GridSelectionGroup mousePress")
        tool = self.tool
        if event.button() != Qt.LeftButton:
            """ do context menu?
            """
            # slice_graphics_view = self.tool.slice_graphics_view
            # print(slice_graphics_view)
            # tool.getCustomContextMenu(event.screenPos())
            tool.individual_pick = False
            return QGraphicsItemGroup.mousePressEvent(self, event)
        else:
            # print("the right event")
            modifiers = event.modifiers()
            is_shift = modifiers == Qt.ShiftModifier
            # print("Is_shift is %s" % is_shift)
            # check to see if we are clicking on a previously selected item
            if tool.is_selection_active:
                # print("clicking the box")
                pos = event.scenePos()
                for item in tool.slice_graphics_view.scene().items(pos):
                    if isinstance(item, GridVirtualHelixItem):
                        doc = tool.manager.document
                        part = item.part()
                        if is_shift:
                            id_num = item.idNum()
                            if doc.isVirtualHelixSelected(
                                    part,
                                    id_num):  # maybe should ask the model?
                                doc.removeVirtualHelicesFromSelection(
                                    part, [id_num])
                        else:
                            origin_id_num = item.idNum()
                            is_alt = modifiers == Qt.AltModifier
                            if (doc.isVirtualHelixSelected(
                                    part, origin_id_num) and not is_alt):
                                # print("origin", origin_id_num)
                                if tool.snap_origin_item is not None:
                                    tool.snap_origin_item.setSnapOrigin(False)
                                tool.snap_origin_item = item
                                item.setSnapOrigin(True)
                                break
                            else:
                                item.mousePressEvent(event)
            self.drag_start_position = sp = self.pos()
            self.drag_last_position = sp

            return QGraphicsItemGroup.mousePressEvent(self, event)
Example #12
0
 def mousePressEvent(self, event: QtWidgets.QGraphicsSceneMouseEvent):
     main_window = self.scene().parent()
     if main_window.state == main_window.State.INIT:
         if event.button() == QtCore.Qt.MiddleButton:
             self.active = not self.active
             if self.has_button:
                 self.scene().reset_button()
             main_window.update_buttons()
         if event.button() == QtCore.Qt.RightButton:
             self.stack_item.mousePressEvent(event)
         elif event.button() == QtCore.Qt.LeftButton:
             self.scene().give_button(self)
             main_window.update_buttons()
         return
     if self.active:
         item = self._identify_item(event)
         if item is not self:
             try:
                 item.mousePressEvent(event)
             except (RuntimeError, AttributeError):
                 pass
Example #13
0
    def mousePressEvent(self, event: QGraphicsSceneMouseEvent):
        """Handler for user mouse press.

        Args:
            event: Contains item, scene, and screen coordinates of the
                event, and previous event.
        """
        # print("GridSelectionGroup mousePress")
        tool = self.tool
        if event.button() != Qt.LeftButton:
            """ do context menu?
            """
            # slice_graphics_view = self.tool.slice_graphics_view
            # print(slice_graphics_view)
            # tool.getCustomContextMenu(event.screenPos())
            tool.individual_pick = False
            return QGraphicsItemGroup.mousePressEvent(self, event)
        else:
            # print("the right event")
            modifiers = event.modifiers()
            is_shift = modifiers == Qt.ShiftModifier
            # print("Is_shift is %s" % is_shift)
            # check to see if we are clicking on a previously selected item
            if tool.is_selection_active:
                # print("clicking the box")
                pos = event.scenePos()
                for item in tool.slice_graphics_view.scene().items(pos):
                    if isinstance(item, GridVirtualHelixItem):
                        doc = tool.manager.document
                        part = item.part()
                        if is_shift:
                            id_num = item.idNum()
                            if doc.isVirtualHelixSelected(part, id_num):    # maybe should ask the model?
                                doc.removeVirtualHelicesFromSelection(part, [id_num])
                        else:
                            origin_id_num = item.idNum()
                            is_alt = modifiers == Qt.AltModifier
                            if (doc.isVirtualHelixSelected(part, origin_id_num) and
                                    not is_alt):
                                # print("origin", origin_id_num)
                                if tool.snap_origin_item is not None:
                                    tool.snap_origin_item.setSnapOrigin(False)
                                tool.snap_origin_item = item
                                item.setSnapOrigin(True)
                                break
                            else:
                                item.mousePressEvent(event)
            self.drag_start_position = sp = self.pos()
            self.drag_last_position = sp

            return QGraphicsItemGroup.mousePressEvent(self, event)
Example #14
0
 def mouseReleaseEvent(self, event: qw.QGraphicsSceneMouseEvent) -> None:
     """Start drawing arena"""
     logging.debug(f'Number of items {len(self.items())}')
     if event.button() == qc.Qt.RightButton:
         self.points = []
         self._clearIncomplete()
         return
     pos = event.scenePos().toPoint()
     pos = np.array((pos.x(), pos.y()), dtype=int)
     if self.geom == DrawingGeom.rectangle:
         if len(self.points) > 0:
             rect = util.points2rect(self.points[0], pos)                
             rect = qg.QPolygonF([qc.QPointF(*p) for p in rect])
             self.points = []
             if self.geom == DrawingGeom.arena:
                 self.setArena(rect)
             else:
                 # logging.debug('DDDD %r', len(self.items()))
                 self._clearIncomplete()
                 # logging.debug('EEEE %r', len(self.items()))
                 self._addItem(rect)
                 # logging.debug('FFFF %r', len(self.items()))
         else:
             self.points = [pos]
             logging.debug(f'XXXX Number of items {len(self.items())}\n'
                           f'pos: {pos}')
             return
     elif self.geom == DrawingGeom.polygon or \
             self.geom == DrawingGeom.arena:
         if len(self.points) > 0:
             dvec = pos - self.points[0]
             if max(abs(dvec)) < self.snap_dist and \
                     len(self.points) > 2:
                 if self.geom == DrawingGeom.polygon:
                     self._addItem(np.array(self.points))
                 elif self.geom == DrawingGeom.arena:
                     poly = qg.QPolygonF([qc.QPointF(*p) for p in self.points])
                     self.setArena(poly)
                 self._clearIncomplete()
                 self.points = []
                 logging.debug(f'YYYY Number of items {len(self.items())}')
                 return
         self.points.append(pos)
         path = qg.QPainterPath(qc.QPointF(*self.points[0]))
         for point in self.points[1:]:
             path.lineTo(qc.QPointF(*point))
         self.addIncompletePath(path)
     else:
         raise NotImplementedError(
             f'Drawing geometry {self.geom} not implemented')
     logging.debug(f'ZZZZ Number of items {len(self.items())}')
Example #15
0
    def mousePressEvent(self, event: QGraphicsSceneMouseEvent):
        """
        Override method of a mouse click event in QGraphicsView.
        - Left button provides the cropping feature.
        - Right button provides the pixel value.
        """
        if self.__displayed_image is None:
            return

        xy = event.scenePos().toPoint()

        height = self.ui.image_display.sceneRect().height()
        width = self.ui.image_display.sceneRect().width()

        if event.button() == ImageDisplay.CROP_IMAGE:
            self.__button_clicked_type = ImageDisplay.CROP_IMAGE

            # cursor location
            self.__orig_pos_scene = xy
            self.__orig_pos_screen = event.screenPos()

            # rubber band for zoom feature
            self.__current_rubber_band = QRubberBand(QRubberBand.Rectangle)
            self.__current_rubber_band.setGeometry(
                QRect(self.__orig_pos_screen, self.__orig_pos_screen))
            self.__current_rubber_band.show()

        elif event.button() == ImageDisplay.PIXEL_FETCH:
            self.__button_clicked_type = ImageDisplay.PIXEL_FETCH

            # return if click is not in image scene
            if xy.x() < 0 or xy.x() >= width or xy.y() < 0 or xy.y() >= height:
                return

            self.stream_display.append_row(
                'Pixel: row[{0:.2f}], col[{1:.2f}]'.format(xy.y(), xy.x()))

        return
Example #16
0
 def mousePressEvent(self, event: QGraphicsSceneMouseEvent
                     ):  # отслеживание нажатия кнопки мыши
     if self.i != 0 and self.j != 0 and self.i != self.a - 1 and self.j != self.b - 1:
         self.X0 = event.screenPos().x()
         self.Y0 = event.screenPos().y()
         if event.button() == 2:  # отслеживание нажатия правой кнопки мыши
             if not self.clicked:
                 self.color = QtGui.QColor(150, 0, 0)
                 self.clicked = True
             else:
                 self.color = QtGui.QColor(0, 0, 0)
                 self.clicked = False
             self.setBrush(
                 QtGui.QBrush(self.color, style=QtCore.Qt.SolidPattern))
Example #17
0
 def mouseReleaseEvent(self, event: QGraphicsSceneMouseEvent):
     """
     Args:
         event: Description
     """
     MOVE_THRESHOLD = 0.01   # ignore small moves
     if self._right_mouse_move and event.button() == Qt.RightButton:
         self._right_mouse_move = False
         delta = self.pos() - self.handle_start
         dz = delta.x()
         if abs(dz) > MOVE_THRESHOLD:
             dz = self._part_item.convertToModelZ(dz)
             self._model_part.translateVirtualHelices([self.idNum()],
                                                      0, 0, dz, True,
                                                      use_undostack=True)
Example #18
0
    def mousePressEvent(self, event: QGraphicsSceneMouseEvent):
        if event.button() == Qt.LeftButton:
            trans = self.parent().transform()

            item = self.itemAt(event.scenePos(), trans)
            if isinstance(item, LiveArrowItem):
                self._source_item = item.name
                self._source_y = event.scenePos().y()
                self._accepts_hover = True
            else:
                self._source_item = None
                self._source_y = None
                self._accepts_hover = False

        return super().mousePressEvent(event)
 def _handle_mouse_press_draw_mode(self, event: QGraphicsSceneMouseEvent):
     if event.button() == Qt.LeftButton and self.new_selection_view is None:
         self.new_selection_origin = event.scenePos()
         self._restrict_to_scene_space(self.new_selection_origin)
         scene_logger.info(
             f"Beginning to draw a new selection: "
             f"X={self.new_selection_origin.x()}, Y={self.new_selection_origin.y()}"
         )
         self.new_selection_view = QGraphicsRectItem(
             self.new_selection_origin.x(), self.new_selection_origin.y(),
             0, 0)
         self.new_selection_view.setPen(self.default_border_pen)
         self.new_selection_view.setBrush(self.default_fill_brush)
         self.addItem(self.new_selection_view)
         event.accept()
Example #20
0
    def mousePressEvent(self, event: QGraphicsSceneMouseEvent):
        """All mousePressEvents are passed to the group if it's in a group

        Args:
            event: Description
        """
        selection_group = self.group()
        if selection_group is not None:
            selection_group.mousePressEvent(event)
        elif event.button() == Qt.RightButton:
            current_filter_set = self._viewroot.selectionFilterSet()
            if self.FILTER_NAME in current_filter_set and self.part().isZEditable():
                self._right_mouse_move = True
                self.drag_last_position = event.scenePos()
                self.handle_start = self.pos()
        else:
            QGraphicsItem.mousePressEvent(self, event)
Example #21
0
    def mousePressEvent(self, event: QGraphicsSceneMouseEvent):
        if event.button() != Qt.LeftButton:
            return

        if self.mode == self.insert_item:
            layers = frameworks_utils.get_framework_layers(self.framework_name)
            item = DiagramItem(layers[self.item_type](), self.context_menu)
            item.setBrush(self.item_color)
            item.setPos(event.scenePos())
            self.addItem(item)
            self.item_inserted.emit(item)
        elif self.mode == self.insert_line:
            self.line = QGraphicsLineItem(
                QLineF(event.scenePos(), event.scenePos()))
            self.line.setPen(QPen(self.line_color, 2))
            self.addItem(self.line)

        super(DiagramScene, self).mousePressEvent(event)
 def _handle_mouse_release_draw_mode(self, event: QGraphicsSceneMouseEvent):
     self.new_selection_view: QGraphicsRectItem
     if event.button(
     ) == Qt.LeftButton and self.new_selection_view is not None:
         absolute_rectangle = self.new_selection_view.mapRectFromScene(
             self.new_selection_view.rect())
         if self.is_rectangle_valid_selection(absolute_rectangle):
             self.selection_drawing_finished.emit(absolute_rectangle)
         else:
             scene_logger.info(
                 f"Discarding invalid selection: "
                 f"x={absolute_rectangle.x()}, y={absolute_rectangle.y()}, "
                 f"width={absolute_rectangle.width()}, height={absolute_rectangle.height()}"
             )
             self.removeItem(self.new_selection_view)
         self.new_selection_origin = None
         self.new_selection_view = None
         event.accept()
Example #23
0
    def mouseReleaseEvent(self, event: QGraphicsSceneMouseEvent):
        """because :class:`GridSelectionGroup` has the flag
        ``QGraphicsItem.ItemIsMovable`` we need only get the position of the
        item to figure out what to submit to the model

        Args:
            event: the mouse event
        """
        MOVE_THRESHOLD = 0.01   # ignore small moves
        # print("mouse mouseReleaseEvent", self.tool.individual_pick)
        if not self.tool.individual_pick and event.button() == Qt.LeftButton:
            delta = self.pos() - self.drag_start_position
            dx, dy = delta.x(), delta.y()
            # print(abs(dx), abs(dy))
            if abs(dx) > MOVE_THRESHOLD or abs(dy) > MOVE_THRESHOLD:
                # print("finalizling", dx, dy)
                self.tool.moveSelection(dx, dy, True)
        self.tool.individual_pick = False
        return QGraphicsItemGroup.mouseReleaseEvent(self, event)
Example #24
0
 def mousePressEvent(self, event: QtWidgets.QGraphicsSceneMouseEvent):
     mw = self.scene().parent()
     if mw.state != mw.State.ACTIONS:
         return
     if event.button() != QtCore.Qt.LeftButton:
         return
     log.debug("Left click on card")
     if self.rank is None:
         self.rank = Rank.DEUCE
     if self.suit is None:
         self.suit = Suit.CLUBS
     elif self.suit is Suit.CLUBS:
         self.suit = Suit.DIAMONDS
     elif self.suit is Suit.DIAMONDS:
         self.suit = Suit.HEARTS
     elif self.suit is Suit.HEARTS:
         self.suit = Suit.SPADES
     else:
         self.suit = None
Example #25
0
    def mouseReleaseEvent(self, event: QGraphicsSceneMouseEvent):
        """because :class:`GridSelectionGroup` has the flag
        ``QGraphicsItem.ItemIsMovable`` we need only get the position of the
        item to figure out what to submit to the model

        Args:
            event: the mouse event
        """
        MOVE_THRESHOLD = 0.01  # ignore small moves
        # print("mouse mouseReleaseEvent", self.tool.individual_pick)
        if not self.tool.individual_pick and event.button() == Qt.LeftButton:
            delta = self.pos() - self.drag_start_position
            dx, dy = delta.x(), delta.y()
            # print(abs(dx), abs(dy))
            if abs(dx) > MOVE_THRESHOLD or abs(dy) > MOVE_THRESHOLD:
                # print("finalizling", dx, dy)
                self.tool.moveSelection(dx, dy, True)
        self.tool.individual_pick = False
        return QGraphicsItemGroup.mouseReleaseEvent(self, event)
Example #26
0
    def mousePressEvent(self, event: qt.QGraphicsSceneMouseEvent):
        if event.button() != Qt.LeftButton:
            return

        pos = event.scenePos()

        if self.state is EditorState.INSERT_AUGMENT_ITEM:
            self._item_start_point = (pos.x(), pos.y())
        elif self.state is EditorState.NONE:
            item = self.itemAt(event.scenePos(), gui.QTransform())
            item = item if item and isinstance(
                item, InterestPointAugmentGraphic) else None
            self._dragging = item
            if self._selected and item != self._selected:
                self._selected.selected = False
            self._selected = item
            if self._selected:
                self._selected.selected = True
            self.update()
        event.accept()
 def mousePressEvent(self, event: qt.QGraphicsSceneMouseEvent):
     if event.button() != Qt.LeftButton:
         return
     pos = event.scenePos()
     if self.state is EntryEditorState.SELECT_FEATURES:
         self._clicked = list(filter(lambda i: type(i) is FeatureItem, self.items(pos)))
         self._selection_rect = {'from': (pos.x(), pos.y()), 'to': (pos.x(), pos.y())}
     elif self.state is EntryEditorState.INSERT_AUGMENT_ITEM:
         self._item_start_point = (pos.x(), pos.y())
     elif self.state is EntryEditorState.NONE:
         item = self.itemAt(event.scenePos(), gui.QTransform())
         item = item if item and isinstance(item, AugmentItem) else None
         self._dragging = item
         if self._selected and item != self._selected:
             self._selected.selected = False
         self._selected = item
         if self._selected:
             self._selected.selected = True
         self.update()
     event.accept()
Example #28
0
    def mouseReleaseEvent(self, event: QGraphicsSceneMouseEvent
                          ):  #отслеживание отнажатия кнопки мыши
        if self.i != 0 and self.j != 0 and self.i != self.a - 1 and self.j != self.b - 1:
            if event.button() == 1:
                self.dx = event.screenPos().x() - self.X0
                self.dy = event.screenPos().y() - self.Y0
                self.ell.x += self.dx
                self.ell.y += self.dy
                self.setFlag(QtWidgets.QGraphicsItem.ItemIsMovable, False)
                if self.moved:
                    self.ell.x -= self.dx
                    self.ell.y -= self.dy
                self.moved = True
                self.parent.window.btn_start.setEnabled(True)

                for i in self.parent.lines:
                    self.parent.window.scene.removeItem(i)
                self.parent.lines = self.parent.create_lines()
                for i in self.parent.lines:
                    self.parent.window.scene.addItem(i)
    def mousePressEvent(self, event: QGraphicsSceneMouseEvent):
        """Handler for user mouse press.

        Args:
            event: Contains item, scene, and screen
            coordinates of the the event, and previous event.
        """
        if event.button() == Qt.RightButton:
            return
        part = self._model_part
        part.setSelected(True)
        if self.isMovable():
            return QGraphicsItem.mousePressEvent(self, event)
        tool = self._getActiveTool()
        if tool.FILTER_NAME not in part.document().filter_set:
            return
        tool_method_name = tool.methodPrefix() + "MousePress"
        if hasattr(self, tool_method_name):
            getattr(self, tool_method_name)(tool, event)
        else:
            event.setAccepted(False)
            QGraphicsItem.mousePressEvent(self, event)
Example #30
0
    def mousePressEvent(self, event: QGraphicsSceneMouseEvent):
        """Handler for user mouse press.

        Args:
            event: Contains item, scene, and screen
            coordinates of the the event, and previous event.
        """
        if event.button() == Qt.RightButton:
            return
        part = self._model_part
        part.setSelected(True)
        if self.isMovable():
            return QGraphicsItem.mousePressEvent(self, event)
        tool = self._getActiveTool()
        if tool.FILTER_NAME not in part.document().filter_set:
            return
        tool_method_name = tool.methodPrefix() + "MousePress"
        if hasattr(self, tool_method_name):
            getattr(self, tool_method_name)(tool, event)
        else:
            event.setAccepted(False)
            QGraphicsItem.mousePressEvent(self, event)
Example #31
0
    def mousePressEvent(self, event: QGraphicsSceneMouseEvent):
        """Event handler for when the mouse button is pressed inside
        this item. If a tool-specific mouse press method is defined, it will be
        called for the currently active tool. Otherwise, the default
        :meth:`QGraphicsItem.mousePressEvent` will be called.

        Note:
            Only applies the event if the clicked item is in the part
            item's active filter set.

        Args:
            event: contains parameters that describe the mouse event.
        """
        if self.FILTER_NAME not in self._part_item.getFilterSet():
            return
        if event.button() == Qt.RightButton:
            return
        part_item = self._part_item
        tool = part_item._getActiveTool()
        tool_method_name = tool.methodPrefix() + "MousePress"
        if hasattr(self, tool_method_name):
            getattr(self, tool_method_name)(tool, part_item, event)
        else:
            QGraphicsItem.mousePressEvent(self, event)
Example #32
0
    def mouseReleaseEvent(self, event: QGraphicsSceneMouseEvent) -> None:
        if self._mode is None and self._item_to_draw is not None and event.button(
        ) == Qt.LeftButton:
            if isinstance(self._item_old_line_or_rect, QRectF):
                line_or_rect = self._item_to_draw.rect()
            elif isinstance(self._item_old_line_or_rect, QLineF):
                line_or_rect = self._item_to_draw.line()
            else:
                line_or_rect = None

            if line_or_rect is None or self._item_old_line_or_rect == line_or_rect:
                if self._item_old_pos != self._item_to_draw.pos():
                    self._undo_stack.push(
                        MoveCommand(self._item_to_draw, self._item_old_pos,
                                    self.scene()))
            else:
                self._undo_stack.push(
                    ResizeCommand(self._item_to_draw, self._item_old_pos,
                                  self._item_old_line_or_rect, self.scene()))
        self._item_old_pos = None
        self._item_old_line_or_rect = None
        self._item_to_draw = None
        self._orig_point = None
        super().mouseReleaseEvent(event)
 def mouseReleaseEvent(self, event: QtWidgets.QGraphicsSceneMouseEvent):
     if event.button() == Qt.RightButton:
         self.communication.doneDrawing.emit()
Example #34
0
File: ui.py Project: xmye/games
 def mouseReleaseEvent(self, sceneMouseEvent: QGraphicsSceneMouseEvent):
     if sceneMouseEvent.button() == Qt.LeftButton:
         self.tetris.drop()
     if sceneMouseEvent.button() == Qt.RightButton:
         self.tetris.rotate()
Example #35
0
 def mouseReleaseEvent(self, event: QGraphicsSceneMouseEvent):
     if self.on_rect_end and event.button() & Qt.MouseButton.LeftButton:
         end = normalize_pos(self, event.pos())
         if self._start:
             self.on_rect_end(QRectF(self._start, end).normalized())
Example #36
0
 def mousePressEvent(self, ev: QGraphicsSceneMouseEvent):
     if ev.button() == Qt.RightButton:
         self._page._net._window._main.tabChanged.emit()
         return
     self._lastPos = ev.scenePos()
     self._lastItemClicked = self.itemAt(ev.scenePos(), QTransform())
     print(ev.scenePos())
     if self._parentState._sPasting:
         self._page._net.pasteItems(self._lastPos)
         self.inserted.emit()
     if self._parentState._sDistributor:
         pos = ev.scenePos()
         elem = PFSDistributor(self._page._net.requestId(PFSDistributor),
                               pos.x(), pos.y())
         self._page._net.addItem(elem, self._page)
         if int(ev.modifiers()) & Qt.ShiftModifier == 0:
             self.inserted.emit()
         return
     if self._parentState._sActivity:
         pos = ev.scenePos()
         elem = PFSActivity(self._page._net.requestId(PFSActivity), pos.x(),
                            pos.y(), "Activity")
         self._page._net.addItem(elem, self._page)
         if int(ev.modifiers()) & Qt.ShiftModifier == 0:
             self.inserted.emit()
         return
     if self._parentState._sRelationS:
         it = self._lastItemClicked
         if it is not None:
             self._tempSource = it
             self.inserted.emit()
         return
     if self._parentState._sSFlowS:
         it = self._lastItemClicked
         if it is not None:
             self._tempSource = it
             self.inserted.emit()
         return
     if self._parentState._sRelationT:
         it = self._lastItemClicked
         if it is not None:
             elem = PFSRelation.createRelation(
                 self._page._net.requestId(PFSRelation), self._tempSource,
                 it)
             if elem is not None:
                 self._page._net.addItem(elem, self._page)
         if int(ev.modifiers()) & Qt.ShiftModifier == 0:
             self.inserted.emit()
         else:
             self.shiftInserted.emit()
         self._tempSource = None
         return
     if self._parentState._sSFlowT:
         it = self._lastItemClicked
         if it is not None:
             elem = PFSSecondaryFlow.createSecondaryFlow(
                 self._page._net.requestId(PFSRelation), self._tempSource,
                 it)
             if elem is not None:
                 self._page._net.addItem(elem, self._page)
         if int(ev.modifiers()) & Qt.ShiftModifier == 0:
             self.inserted.emit()
         else:
             self.shiftInserted.emit()
         self._tempSource = None
         return
     if self._parentState._sNormal:
         self._page._net._prop.clear()
         it = self._lastItemClicked
         if int(ev.modifiers()) & Qt.ControlModifier == Qt.ControlModifier:
             if isinstance(it, PFSActivity):
                 if not it.hasSubPage():
                     self._page._net.createPage(it)
                 self._page._net.openPage(it)
             elif isinstance(it, PFSRelation):
                 if not it.closeMiddlePoint(ev.scenePos()):
                     it.createMiddlePoint(ev.scenePos())
         return
     if self._parentState._sTiping:
         it = self._lastItemClicked
         if it is None or not isinstance(it, QGraphicsProxyWidget):
             if self._tempActivity is not None:
                 x = PFSUndoSetText(self._tempActivity,
                                    self._line.widget().toPlainText(), self)
                 self._page._net.undoStack.push(x)
             self.removeItem(self._line)
             self.inserted.emit()
         QGraphicsScene.mousePressEvent(self, ev)
         return
     QGraphicsScene.mousePressEvent(self, ev)