Esempio n. 1
0
    def mouseReleaseEvent(self, event: qt.QGraphicsSceneMouseEvent):
        if self.state is EditorState.INSERT_AUGMENT_ITEM:
            if self._item:
                self._item.drawing = False
                dlg = ImageDlg()
                if dlg.exec():
                    name = dlg.name
                    images = dlg.images
                    self._item.setName(name)
                    self._item.setImages(images)
                else:
                    self._selected = self._item
                    self.delete_point_of_interest()

                    return
                self.augments.add(self._item)
                self._item_start_point = None
                self._item = None
                self.update()
        elif self.state is EditorState.NONE:
            if self._dragging:
                self._dragging.dragging = False
                self._dragging = None
                self.update()

        event.accept()
Esempio n. 2
0
 def mousePressEvent(self, event: QGraphicsSceneMouseEvent):
     """ Only accept mouse press events (i.e. ROI selection) if the mouse is near to the boundary.
         Prevents selection based on larger bounding rectangle.
         Overrides QGraphicsItem::mousePressEvent.
     @param event: mouse press event
     """
     if self.distance_to_boundary(event.pos(), increment=0.005) < 4:
         event.accept()
     else:
         event.ignore()
Esempio n. 3
0
 def mouseMoveEvent(self, event: QGraphicsSceneMouseEvent):
     if event.buttons() == Qt.MiddleButton:
         delta: QPointF = event.pos() - self._pan_last_pos
         new_x = self.horizontalScrollBar().value() - delta.x()
         new_y = self.verticalScrollBar().value() - delta.y()
         self.horizontalScrollBar().setValue(new_x)
         self.verticalScrollBar().setValue(new_y)
         self._pan_last_pos = event.pos()
         event.accept()
     else:
         super().mouseMoveEvent(event)
    def _handle_mouse_move_draw_mode(self, event: QGraphicsSceneMouseEvent):
        point2 = event.scenePos()
        self._restrict_to_scene_space(point2)
        if self.new_selection_origin is None:
            scene_logger.warning("Move event: Selection origin is None!")
            event.accept()
            return

        rectangle = QRectF(
            QPointF(min(self.new_selection_origin.x(), point2.x()),
                    min(self.new_selection_origin.y(), point2.y())),
            QPointF(max(self.new_selection_origin.x(), point2.x()),
                    max(self.new_selection_origin.y(), point2.y())))
        self.new_selection_view.setRect(rectangle)
        event.accept()
 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()
Esempio n. 6
0
    def mouseMoveEvent(self, event: QGraphicsSceneMouseEvent):
        if event.buttons() == Qt.LeftButton:
            if not self._moving_edge:
                if self.type() == self.INPUT:
                    edge = GEdge(destination=self)
                else:
                    edge = GEdge(source=self)
                self._current_edge = edge
                self._moving_edge = True
                self.edge_started.emit(edge)
            else:
                self._current_edge.set_tip_pos(event.scenePos())

            event.accept()
        else:
            event.ignore()
 def mouseMoveEvent(self, event: qt.QGraphicsSceneMouseEvent):
     if self.state is EntryEditorState.SELECT_FEATURES and self._selection_rect is not None:
         new_x, new_y = event.scenePos().x(), event.scenePos().y()
         self._selection_rect['to'] = (new_x, new_y)
         self.update_selection_rect()
     elif self.state is EntryEditorState.INSERT_AUGMENT_ITEM:
         if self.augment_type is AugmentType.BOX and self._item_start_point:
             if not self._item:
                 self._item = BoxAugmentItem(0, 0)
                 self._item.setPos(*self._item_start_point)
                 self._item.drawing = True
                 self.addItem(self._item)
             box = self._item
             box.width = event.scenePos().x() - self._item_start_point[0]
             box.height = event.scenePos().y() - self._item_start_point[1]
             self.update()
         elif self.augment_type is AugmentType.ARROW and self._item_start_point:
             if not self._item:
                 self._item = ArrowAugmentItem(0)
                 self._item.setPos(*self._item_start_point)
                 self._item.drawing = True
                 self.addItem(self._item)
             arrow = self._item
             vec = (event.scenePos().x() - self._item_start_point[0], event.scenePos().y() - self._item_start_point[1])
             arrow.length = math.sqrt(pow(vec[0], 2) +
                                      pow(vec[1], 2))
             arrow.setRotation(math.degrees(math.atan2(vec[1], vec[0])))
             self.update()
         elif self.augment_type is AugmentType.ELLIPSE and self._item_start_point:
             if not self._item:
                 self._item = EllipseAugmentItem(0, 0)
                 self._item.setPos(*self._item_start_point)
                 self._item.drawing = True
                 self.addItem(self._item)
             ellipse = self._item
             ellipse.width = event.scenePos().x() - self._item_start_point[0]
             ellipse.height = event.scenePos().y() - self._item_start_point[1]
             self.update()
     elif self.state is EntryEditorState.NONE and self._dragging is not None:
         curr = (event.scenePos().x(), event.scenePos().y())
         prev = (event.lastScenePos().x(), event.lastScenePos().y())
         delta = (curr[0] - prev[0], curr[1] - prev[1])
         self._dragging.dragging = True
         self._dragging.moveBy(*delta)
         self.update()
     event.accept()
 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()
Esempio n. 9
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()
Esempio n. 10
0
 def mouseMoveEvent(self, event: qt.QGraphicsSceneMouseEvent):
     if self.state is EditorState.INSERT_AUGMENT_ITEM:
         if self._item_start_point:
             if not self._item:
                 self._item = InterestPointAugmentGraphic(0, 0)
                 self._item.setPos(*self._item_start_point)
                 self._item.drawing = True
                 self.addItem(self._item)
             box = self._item
             box.width = event.scenePos().x() - self._item_start_point[0]
             box.height = event.scenePos().y() - self._item_start_point[1]
             self.update()
     elif self.state is EditorState.NONE and self._dragging is not None:
         curr = (event.scenePos().x(), event.scenePos().y())
         prev = (event.lastScenePos().x(), event.lastScenePos().y())
         delta = (curr[0] - prev[0], curr[1] - prev[1])
         self._dragging.dragging = True
         self._dragging.moveBy(*delta)
         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()
    def mouseReleaseEvent(self, event: qt.QGraphicsSceneMouseEvent):
        if (self.state is EntryEditorState.SELECT_FEATURES and
                self._selection_rect is not None):
            a, b = self._selection_rect['from'], self._selection_rect['to']
            top_left = qtc.QPointF(min(a[0], b[0]), min(a[1], b[1]))
            bottom_right = qtc.QPointF(max(a[0], b[0]), max(a[1], b[1]))
            rect = qtc.QRectF(top_left, bottom_right)
            in_selection = self.items(rect)
            in_selection.extend(self._clicked)
            self._clicked.clear()
            ctrl = event.modifiers() & Qt.ControlModifier
            shift = event.modifiers() & Qt.ShiftModifier
            if not ctrl:
                self.clear_selected_features()
            for item in in_selection:
                if type(item) is FeatureItem:
                    item.selected = not shift
                    if not shift:
                        self._selected_features.add(item)
                    else:
                        self._selected_features.discard(item)
            self._selection_rect = None
            self.removeItem(self._selection_rect_ui)
            self._selection_rect_ui = None
            self.update()
        elif self.state is EntryEditorState.INSERT_AUGMENT_ITEM:
            if self._item:
                self._item.drawing = False
                self.augments.add(self._item)
                self._item_start_point = None
                self._item = None
                self.update()
        elif self.state is EntryEditorState.NONE:
            if self._dragging:
                self._dragging.dragging = False
                self._dragging = None
                self.update()

        event.accept()
Esempio n. 13
0
 def mousePressEvent(self,
                     event: QtWidgets.QGraphicsSceneMouseEvent) -> None:
     # swallow mouse press events (which aren't handled by some other of the
     # node's items) to prevent the canvas from triggering a rubber band
     # selection.
     event.accept()
Esempio n. 14
0
 def mousePressEvent(self, event: QGraphicsSceneMouseEvent):
     # Needs to be reimplemented to be able to catch mouseMoveEvent, but it does not need to do anything
     event.accept()
Esempio n. 15
0
 def mouseDoubleClickEvent(self, event: QGraphicsSceneMouseEvent):
     if self.scene():
         event.accept()
         self.scene().addHandle(event.pos(), link=self)
     else:
         super().mouseDoubleClickEvent(event)
Esempio n. 16
0
 def mouseDoubleClickEvent(self, event: QGraphicsSceneMouseEvent):
     if self.scene():
         event.accept()
         self.scene().removeHandle(self)