Example #1
0
    def mouseMoveEvent(self, a0: QtGui.QMouseEvent):
        """
        Is called by PyQt5 library, when the mouse has moved over the OpenGLWidget.
        Used to update mouse position for the cursor and calling the drag functions.
        :param a0: mouse move event data
        :return:
        """

        self.setFocus()
        self.mouse_pos = [a0.x(), a0.y()]
        if self.ctrl:
            self.camera.update_mouse_position(self.mouse_pos)
            self.update_cursor_data()
            self.glDraw()
            self.update_info_frame()
        else:
            self.update_info_frame()
            if self.drag_state:
                drag_amount = [
                    self.last_position[0] - self.mouse_pos[0],
                    self.last_position[1] - self.mouse_pos[1]
                ]

                if int(
                        a0.buttons()
                ) & QtCore.Qt.LeftButton and self.world.grid.get_dimension_count(
                ) > 2:
                    self.rotate_view(drag_amount)

                if int(a0.buttons()) & QtCore.Qt.RightButton:
                    self.drag_view(drag_amount)

                self.last_position = self.mouse_pos
Example #2
0
    def mousePressEvent(self, event: QMouseEvent):
        if self.scene() is None:
            return

        cursor = self.cursor().shape()
        has_shift_modifier = event.modifiers() == Qt.ShiftModifier
        is_in_shift_mode = (has_shift_modifier and self.hold_shift_to_drag) \
                           or (not has_shift_modifier and not self.hold_shift_to_drag) \
                              and cursor != Qt.SplitHCursor and cursor != Qt.SplitVCursor

        if event.buttons() == Qt.LeftButton and is_in_shift_mode:
            self.setCursor(Qt.ClosedHandCursor)
            self.grab_start = event.pos()
        elif event.buttons() == Qt.LeftButton:
            if self.is_pos_in_separea(self.mapToScene(event.pos())):
                self.separation_area_moving = True
                self.setCursor(Qt.SplitVCursor)

            elif self.selection_area.is_empty or self.selection_area.selected_edge is None:
                # Create new selection
                self.mouse_press_pos = event.pos()
                self.mouse_pos = event.pos()
                scene_pos = self.mapToScene(self.mouse_press_pos)
                self.__set_selection_area(x=scene_pos.x(), y=scene_pos.y(), w=0, h=0)
                self.selection_area.finished = False

            elif self.selection_area.selected_edge is not None:
                self.selection_area.resizing = True
Example #3
0
    def _mouse_handler(self, qt_event: QtGui.QMouseEvent) -> None:
        """
        Mouse handling helper function.

        Parameters:
         qt_event: mouse event.
        """
        x = qt_event.x()
        y = qt_event.y()
        if qt_event.buttons() == QtCore.Qt.LeftButton:
            if (self._mouse_usage == self._MOUSE_MOVE_PLOT
                or self._mouse_usage == self._MOUSE_DEFAULT_ACTION):
                x, y = self._mouse_coordinates_transform(x, y)
                if self._prev_mouse_position != []:
                    x_prev, y_prev = self._prev_mouse_position
                    dx = x - x_prev
                    dy = y - y_prev
                    # self.setCursor()
                    self._ani.move_axes(self._ani.figure.get_axes()[0],
                                        -dx, -dy)
                    self._ani.on_plot_view_changed()
                else:
                    self._prev_mouse_position = [x, y]
            elif self._mouse_usage == self._MOUSE_EDIT_FUNCTION:
                x, y = self._mouse_coordinates_transform(x, y)
                self._ani.change_values(x, y)
        if qt_event.buttons() == QtCore.Qt.MidButton:
            pass
        if qt_event.buttons() == QtCore.Qt.RightButton:
            pass
Example #4
0
    def mouseMoveEvent(self, event: QMouseEvent):
        """Handle mouse move events."""
        coord = self._coord_from_event(event)

        # Return if the mouse wasn't moved to a different cell.
        if self._await_release_all_buttons or coord == self._mouse_coord:
            return

        self._mouse_coord = coord

        ## Double leftclick
        if self._was_double_left_click:
            if event.buttons() == Qt.LeftButton:
                self.left_button_double_move(coord)
            return

        ## Bothclick
        if event.buttons() & Qt.LeftButton and event.buttons(
        ) & Qt.RightButton:
            self.both_buttons_move(coord)
        elif not self._both_mouse_buttons_pressed or self._state.drag_select:
            ## Leftclick
            if event.buttons() & Qt.LeftButton:
                self.left_button_move(coord)
            ## Rightclick
            if event.buttons() & Qt.RightButton:
                self.right_button_move(coord)
Example #5
0
    def mouseReleaseEvent(self, event: QMouseEvent):
        """Handle mouse release events."""
        if self._await_release_all_buttons and not event.buttons():
            self._await_release_all_buttons = False
            return

        coord = self._coord_from_event(event)

        ## Bothclick (one of the buttons still down)
        if self._both_mouse_buttons_pressed:
            if event.buttons():
                logger.debug("Mouse button release on cell %s after both down",
                             coord)
                self.first_of_both_buttons_release(coord)
            if not self._state.drag_select or event.buttons(
            ) == Qt.RightButton:
                # Only right button down - no risk.
                self.no_risk_signal.emit()
        ## Left release
        elif event.button(
        ) == Qt.LeftButton and not self._was_double_left_click:
            logger.debug("Left mouse button release on cell %s", coord)
            self.left_button_release(coord)

        # Reset variables if neither of the mouse buttons are down.
        if not event.buttons():
            logger.debug("No mouse buttons down, reset variables")
            self.all_buttons_release()
 def __handle_mouse_press_event(self, event: QMouseEvent) -> None:
     if self.__image_widget.has_image():
         if ((event.button() == event.buttons() == Qt.LeftButton)
                 or (event.button() == event.buttons() == Qt.MiddleButton)):
             self.__last_move_pos = event.pos()
             return
     self.__last_move_pos = None
Example #7
0
    def mouseMoveEvent(self, a0: QtGui.QMouseEvent):
        if a0.buttons() == QtCore.Qt.RightButton:
            a0.ignore()
            return
        if a0.buttons() == QtCore.Qt.MiddleButton:
            # Drag the display
            a0.accept()
            if self.moveStartX != -1 and self.moveStartY != -1:
                dx = self.moveStartX - a0.x()
                dy = self.moveStartY - a0.y()
                self.zoomTo(self.leftMargin + dx, self.topMargin + dy,
                            self.leftMargin + self.chartWidth + dx,
                            self.topMargin + self.chartHeight + dy)

            self.moveStartX = a0.x()
            self.moveStartY = a0.y()
            return
        if a0.modifiers() == QtCore.Qt.ControlModifier:
            # Dragging a box
            if not self.draggedBox:
                self.draggedBoxStart = (a0.x(), a0.y())
            self.draggedBoxCurrent = (a0.x(), a0.y())
            self.update()
            a0.accept()
            return
        x = a0.x()
        f = self.frequencyAtPosition(x)
        if x == -1:
            a0.ignore()
            return
        a0.accept()
        m = self.getActiveMarker()
        if m is not None:
            m.setFrequency(str(f))
            m.frequencyInput.setText(str(f))
Example #8
0
 def mousePress(self, a0: QMouseEvent) -> bool:
     d, _ = self.parent.findCellUnder(a0)
     if not d:
         return False
     shift = a0.modifiers() & QtCore.Qt.KeyboardModifier.ShiftModifier
     ctrl = a0.modifiers() & QtCore.Qt.KeyboardModifier.ControlModifier
     if a0.buttons() & QtCore.Qt.MouseButton.LeftButton:
         if a0.x() < Ruler.Width: # quick row selection
             self.parent.selector.addRowCol(self.parent.data, shift or ctrl, ctrl, y=d.y)
             return True
         if a0.y() < Ruler.Width: # quick column selection
             self.parent.selector.addRowCol(self.parent.data, shift or ctrl, ctrl, x=d.x)
             return True
     if a0.buttons() & QtCore.Qt.MouseButton.RightButton:
         if not (a0.x() < Ruler.Width or a0.y() < Ruler.Width):
             return False
         m = QMenu(self.parent)
         if a0.x() < Ruler.Width: # add hline
             if d.y in self.hlines:
                 a = m.addAction(TR('Remove Line'))
                 a.triggered.connect(lambda v: self.hlines.remove(d.y))
             else:
                 a = m.addAction(TR('Add Line'))
                 a.triggered.connect(lambda v: self.hlines.add(d.y))
         else:
             if d.x in self.vlines:
                 a = m.addAction(TR('Remove Line'))
                 a.triggered.connect(lambda v: self.vlines.remove(d.x))
             else:
                 a = m.addAction(TR('Add Line'))
                 a.triggered.connect(lambda v: self.vlines.add(d.x))
         m.popup(self.parent.mapToGlobal(a0.pos()))
         return True
     return False
Example #9
0
    def mouseMoveEvent(self, a0: QtGui.QMouseEvent) -> None:

        x = a0.x()
        y = a0.y()

        self.dx = x - self.x0
        self.dy = y - self.y0
        self.x0 = x
        self.y0 = y

        if a0.buttons() == QtCore.Qt.LeftButton:

            self.ax = self.ax + self.dx
            self.ay = self.ay - self.dy
            if self.ax > 360: self.ax = self.ax - 360
            if self.ax < 0: self.ax = self.ax + 360

            if self.ay > 360: self.ay = self.ay - 360
            if self.ay < 0: self.ay = self.ay + 360

            self.repaint()

        elif a0.buttons() == QtCore.Qt.RightButton:

            self.x = self.x + self.dx / 300
            self.z = self.z - self.dy / 100

            self.repaint()
Example #10
0
    def mousePressEvent(self, event: QMouseEvent):
        if self.scene() is None:
            return

        cursor = self.cursor().shape()
        has_shift_modifier = event.modifiers() == Qt.ShiftModifier
        is_in_shift_mode = (has_shift_modifier and self.hold_shift_to_drag) \
                           or (not has_shift_modifier and not self.hold_shift_to_drag) \
                              and cursor != Qt.SplitHCursor and cursor != Qt.SplitVCursor

        if event.buttons() == Qt.LeftButton and is_in_shift_mode:
            self.setCursor(Qt.ClosedHandCursor)
            self.grab_start = event.pos()
        elif event.buttons() == Qt.LeftButton:
            if self.is_pos_in_separea(self.mapToScene(event.pos())):
                self.separation_area_moving = True
                self.setCursor(Qt.SplitVCursor)

            elif self.selection_area.is_empty or self.selection_area.selected_edge is None:
                # Neue ROI anlegen
                self.mouse_press_pos = event.pos()
                self.mouse_pos = event.pos()
                scene_pos = self.mapToScene(self.mouse_press_pos)
                x = scene_pos.x()
                self.set_selection_area(x=x, w=0)
                self.selection_area.finished = False

            elif self.selection_area.selected_edge is not None:
                self.selection_area.resizing = True
Example #11
0
 def mousePressEvent(self, event: QtGui.QMouseEvent) -> None:
     if event.buttons() == QtCore.Qt.RightButton:
         self.rmbPrevPos = [event.x(), event.y()]
         self.rmbPressed = True
     elif event.buttons() == QtCore.Qt.LeftButton:
         self.lmbPressed = True
         self.mouseCurX = self.mouseStartX = event.x()
         self.mouseCurY = self.mouseStartY = event.y()
Example #12
0
    def mouseMoveEvent(self, event: QMouseEvent):
        if self.scene() is None:
            return

        cursor = self.cursor().shape()

        if self.grab_start is not None:
            move = self.grab_start.x() - event.pos().x()
            self.horizontalScrollBar().setValue(self.horizontalScrollBar().value() + move)
            self.grab_start = event.pos()
            return

        if self.separation_area_moving:
            y_sep = self.mapToScene(event.pos()).y()
            y = self.sceneRect().y()
            h = self.sceneRect().height()
            if y < y_sep < y + h:
                self.scene().draw_sep_area(y_sep)
                self.sep_area_moving.emit(y_sep)
        elif self.is_pos_in_separea(self.mapToScene(event.pos())):
            self.setCursor(Qt.SplitVCursor)
        elif cursor == Qt.SplitVCursor:
            self.unsetCursor()

        if self.selection_area.finished and not self.selection_area.resizing:
            pos = self.mapToScene(event.pos())
            roi_edge = self.selection_area.get_selected_edge(pos, self.view_rect().width())
            if roi_edge is None and cursor == Qt.SplitHCursor:
                self.unsetCursor()
                return
            elif roi_edge == 0 or roi_edge == 1:
                self.setCursor(Qt.SplitHCursor)

        if event.buttons() == Qt.LeftButton and self.selection_area.resizing:

            if self.selection_area.selected_edge == 0:
                start = self.mapToScene(event.pos())
                self.set_selection_area(x=start.x())
                self.scroll_mouse(start.x())
                return

            if self.selection_area.selected_edge == 1:
                start = QPoint(self.selection_area.rect().x(), self.selection_area.rect().y())
                end = self.mapToScene(event.pos())

                self.set_selection_area(w=end.x() - start.x())
                self.scroll_mouse(end.x())
                return

        if self.mouse_press_pos is None:
            return

        self.mouse_pos = event.pos()
        if event.buttons() == Qt.LeftButton and not self.selection_area.finished:
            start = self.mapToScene(self.mouse_press_pos)
            end = self.mapToScene(self.mouse_pos)
            self.set_selection_area(w=end.x() - start.x())
            self.scroll_mouse(end.x())
Example #13
0
    def mouseMoveEvent(self, e: QtGui.QMouseEvent):
        QWidget.mouseMoveEvent(self, e)
        if not self.m_isEditing:
            return
        if not self.m_infocus:
            return
        if not e.buttons() and QtCore.Qt.LeftButton:
            p = QPoint(e.x() + self.geometry().x(), e.y() + self.geometry().y())
            self.setCursorShape(p)
            return

        if (self.mode == Mode.MOVE or self.mode == Mode.NONE) and e.buttons() and QtCore.Qt.LeftButton:
            toMove = e.globalPos() - self.position
            if toMove.x() < 0:return
            if toMove.y() < 0:return
            if toMove.x() > self.parentWidget().width() - self.width(): return
            self.move(toMove)
            self.newGeometry.emit(self.geometry())
            self.parentWidget().repaint()
            return
        if (self.mode != Mode.MOVE) and e.buttons() and QtCore.Qt.LeftButton:
            if self.mode == Mode.RESIZETL: # Left - Top
                newwidth = e.globalX() - self.position.x() - self.geometry().x()
                newheight = e.globalY() - self.position.y() - self.geometry().y()
                toMove = e.globalPos() - self.position
                self.resize(self.geometry().width() - newwidth, self.geometry().height() - newheight)
                self.move(toMove.x(), toMove.y())
            elif self.mode == Mode.RESIZETR: # Right - Top
                newheight = e.globalY() - self.position.y() - self.geometry().y()
                toMove = e.globalPos() - self.position
                self.resize(e.x(), self.geometry().height() - newheight)
                self.move(self.x(), toMove.y())
            elif self.mode== Mode.RESIZEBL: # Left - Bottom
                newwidth = e.globalX() - self.position.x() - self.geometry().x()
                toMove = e.globalPos() - self.position
                self.resize(self.geometry().width() - newwidth, e.y())
                self.move(toMove.x(), self.y())
            elif self.mode == Mode.RESIZEB: # Bottom
                self.resize(self.width(), e.y())
            elif self.mode == Mode.RESIZEL: # Left
                newwidth = e.globalX() - self.position.x() - self.geometry().x()
                toMove = e.globalPos() - self.position
                self.resize(self.geometry().width() - newwidth, self.height())
                self.move(toMove.x(), self.y())
            elif self.mode == Mode.RESIZET:# Top
                newheight = e.globalY() - self.position.y() - self.geometry().y()
                toMove = e.globalPos() - self.position
                self.resize(self.width(), self.geometry().height() - newheight)
                self.move(self.x(), toMove.y())
            elif self.mode == Mode.RESIZER: # Right
                self.resize(e.x(), self.height())
            elif self.mode == Mode.RESIZEBR:# Right - Bottom
                self.resize(e.x(), e.y())
            self.parentWidget().repaint()
        self.newGeometry.emit(self.geometry())
Example #14
0
    def mouseMoveEvent(self, event: QMouseEvent):
        repaint = False
        mx, my = self.posToWorldPos(event.x(), event.y())

        self.onCursorChange.emit(mx, my)

        if self.scroll_enabled and (event.buttons() & Qt.MiddleButton):
            self.x_offset -= self.prevX - event.x()
            self.y_offset -= self.prevY - event.y()
            repaint = True

        if self.clicked_object is None:
            if self.scroll_enabled and (event.buttons() & Qt.LeftButton):
                self.mouse_moved = True
                self.x_offset -= self.prevX - event.x()
                self.y_offset -= self.prevY - event.y()
                repaint = True

        else:
            if not self.move_objects:
                x, y = self.click_pos
                distance = math.hypot(x-event.x(), y-event.y())

                if distance > self.min_move_distance:
                    self.move_objects = True
                    click_x, click_y = self.posToWorldPos(x, y)
                    self.moved_rest = (mx - click_x, my - click_y)
            else:
                rest_x, rest_y = self.moved_rest
                cur_pos = self.posToWorldPos(event.x(), event.y())
                prev_pos = self.posToWorldPos(self.prevX, self.prevY)
                nx, ny = tuple(map(sub, cur_pos, prev_pos))

                snap = self.snap

                self.moved_rest = (math.fmod(rest_x + nx, snap),
                                   math.fmod(rest_y + ny, snap))

                move_x, move_y = ((
                    rest_x + nx - self.moved_rest[0]) / snap, (rest_y + ny - self.moved_rest[1]) / snap)

                for o in self.selectedObjects:
                    o.x += move_x * snap
                    o.y += move_y * snap

                self.emitSelectedObjects()
                repaint = True
            # self.scroll_view = True

        self.prevX = event.x()
        self.prevY = event.y()

        if repaint:
            self.repaint()
Example #15
0
    def mouseMoveEvent(self, event: QtGui.QMouseEvent):
        mouse_pos = event.globalPos()
        top_left = self.mapToGlobal(self.rect().topLeft())
        # top_left = self.pos
        bottom_right = self.mapToGlobal(self.rect().bottomRight())

        # print(self.LOCATION)

        # if event.buttons() and event.button() != Qt.LeftButton:  # 也不行
        if not event.buttons():
            self.cursor_location(event.pos())
        else:
            if event.buttons() == QtCore.Qt.LeftButton:
                # print('left press')
                if self.LOCATION is Const.CENTER:
                    pass
                    # print('center')
                    # self.move(event.globalPos() - self.dragPosition)  # 将窗口移动到指定位置
                else:
                    geo = QtCore.QRect(top_left, bottom_right)

                    if self.LOCATION == Const.LEFT:
                        # if bottom_right.x() - mouse_pos.x() > self.minimumWidth():#不需要,有setmin、max、fix决定
                        # geo.setWidth(bottom_right.x() - mouse_pos.x())  # 自动计算的
                        geo.setX(mouse_pos.x())
                    elif self.LOCATION is Const.RIGHT:
                        geo.setWidth(mouse_pos.x() - top_left.x())
                    elif self.LOCATION is Const.TOP:
                        geo.setY(mouse_pos.y())
                    elif self.LOCATION == Const.BOTTOM:
                        geo.setHeight(mouse_pos.y() - top_left.y())
                    elif self.LOCATION == Const.TL_CORNER:
                        geo.setX(mouse_pos.x())
                        geo.setY(mouse_pos.y())
                    elif self.LOCATION == Const.TR_CORNER:
                        geo.setWidth(mouse_pos.x() - top_left.x())
                        geo.setY(mouse_pos.y())
                    elif self.LOCATION == Const.BL_CORNER:
                        geo.setX(mouse_pos.x())
                        geo.setHeight(mouse_pos.y() - top_left.y())
                    elif self.LOCATION == Const.BR_CORNER:
                        geo.setWidth(mouse_pos.x() - top_left.x())
                        geo.setHeight(mouse_pos.y() - top_left.y())
                    # else:  # is Const.CENTER
                    #     pass
                    self.setGeometry(geo)  # 设置影子的父窗口的位置

            # else:
            #     print('other press')
        # QEvent的accept()和ignore()一般不会用到,因为不如直接调用QWidget类的事件处理函数直接,而且作用是一样的
        # 唯有在closeEvent()中必须调用accept()或ignore()。
        event.ignore()
Example #16
0
    def mouse_move_event(self, a0: QtGui.QMouseEvent):
        # Methods that use relative cursor movement
        self.curr_cursor_pos = a0.pos()

        # Methods that use absolute cursor position
        if self.drawing_mode.is_active() and (not self.ctrl_pressed):
            self.drawing_mode.register_point(a0.x(),
                                             a0.y(),
                                             correction=True,
                                             is_temporary=True)

        elif self.align_mode.is_active() and (not self.ctrl_pressed):
            self.align_mode.register_tmp_point(
                self.view.glWidget.get_world_coords(a0.x(),
                                                    a0.y(),
                                                    correction=False))

        if self.last_cursor_pos:
            dx = (self.last_cursor_pos.x() - a0.x()
                  ) / 5  # Calculate relative movement from last click position
            dy = (self.last_cursor_pos.y() - a0.y()) / 5

            if self.ctrl_pressed and (not self.drawing_mode.is_active()) and (
                    not self.align_mode.is_active()):
                if a0.buttons() & QtCore.Qt.LeftButton:  # bbox rotation
                    # self.bbox_controler.rotate_around_x(-dy)
                    # self.bbox_controler.rotate_around_y(-dx)
                    self.bbox_controler.rotate_with_mouse(-dx, -dy)
                elif a0.buttons() & QtCore.Qt.RightButton:  # bbox translation
                    # self.bbox_controler.translate_along_x(-dx / 30)
                    # self.bbox_controler.translate_along_y(dy / 30)
                    new_center = self.view.glWidget.get_world_coords(
                        a0.x(), a0.y(), correction=True)
                    self.bbox_controler.set_center(
                        *new_center)  # absolute positioning
            else:
                if a0.buttons() & QtCore.Qt.LeftButton:  # pcd rotation
                    self.pcd_controler.rotate_around_x(dy)
                    self.pcd_controler.rotate_around_z(dx)
                elif a0.buttons() & QtCore.Qt.RightButton:  # pcd translation
                    self.pcd_controler.translate_along_x(dx)
                    self.pcd_controler.translate_along_y(dy)

            if dx > 0.1 or dy > 0.1:  # Reset scroll locks if significant cursor movements
                if self.side_mode:
                    self.side_mode = False
                else:
                    self.scroll_mode = False
        self.last_cursor_pos = a0.pos()
Example #17
0
    def mouseMoveEvent(self, a0: QMouseEvent):
        delta = 0.01
        dx = delta * (a0.x() - self.LastMouseMove.x())
        dy = delta * (a0.y() - self.LastMouseMove.y())

        if(a0.buttons() & QtCore.Qt.LeftButton):
            self.YawStack[self.activeCamStackIdx] -= dx * (math.radians(30))
            self.PitchStack[self.activeCamStackIdx] -= dy * (math.radians(30))
        elif(a0.buttons() & QtCore.Qt.RightButton):
            RotationMatrix = self.makeRotationMatrix()
            self.TranslationStack[self.activeCamStackIdx] += RotationMatrix.dot(np.array([-dx, dy, 0])) * 300

        self.LastMouseMove = a0.pos()

        self.update()
Example #18
0
    def mousePressEvent(self, event: QMouseEvent):
        self.setFocus(Qt.ActiveWindowFocusReason)

        self.prevX = event.x()
        self.prevY = event.y()

        if event.buttons() & Qt.LeftButton:
            self.zoom_enabled = False
            self.left_clicked = True

            (mx, my) = self.posToWorldPos(event.x(), event.y())

            obj = self.state.getClickedObject(mx, my)
            self.clicked_object = obj

            if obj is not None:
                self.scroll_enabled = False
                if event.modifiers() & Qt.ControlModifier:
                    self.control_pressed = True
                    if obj in self.selectedObjects:
                        obj.selected = False
                        self.selectedObjects.remove(obj)
                    else:
                        obj.selected = True
                        self.selectedObjects.append(obj)
                else:
                    if obj not in self.selectedObjects:
                        for o in self.selectedObjects:
                            o.selected = False

                        self.selectedObjects.clear()
                        obj.selected = True
                        self.selectedObjects.append(obj)

                self.click_pos = (event.x(), event.y())

        elif event.buttons() & Qt.RightButton:
            (mx, my) = self.posToWorldPos(event.x(), event.y())

            obj = self.state.getClickedObject(mx, my)

            if isinstance(obj, Node):
                for o in self.selectedObjects:
                    if isinstance(o, Node):
                        self.state.toggleMember(obj, o, self.selected_material)

        self.emitSelectedObjects()
        self.repaint()
Example #19
0
    def mousePressEvent(self, event: QMouseEvent):
        if not self.start_coords and self.parent.is_edit_mode() and event.buttons() & Qt.LeftButton:
            pos = self.mapToScene(event.pos())
            self.start_coords = (pos.x(), pos.y())
            rect_item = GraphicsRectItem(
                QRectF(int(self.start_coords[0]), int(self.start_coords[1]), 1, 1))

            color = QColor(random.randint(0, 180), random.randint(100, 255),
                           random.randint(50, 200))
            self.pen.setColor(color)
            rect_item.setPen(self.pen)
            rect_item.main_view = self

            rect_item.setData(int(const.ITEM_DATA_KEY_FONT), 'Arial')
            rect_item.setData(int(const.ITEM_DATA_KEY_FONT_SIZE), 12)
            rect_item.setData(int(const.ITEM_DATA_KEY_FONT_ALIGN), 'center')
            rect_item.setData(int(const.ITEM_DATA_KEY_FONT_COLOR), (0, 0, 0))

            self.scene().addItem(rect_item)
            rect_item.setToolTip(f'Поле_{len(self.scene().items()) - 1}')
            self.current_item = rect_item

            self.scene().update()

        super(GraphicsView, self).mousePressEvent(event)
Example #20
0
    def mouseMoveEvent(self, a0: QtGui.QMouseEvent) -> None:
        d, pt = self.findCellUnder(a0)
        changed = False
        if d:  # update ruler
            xy = (d.x, d.y)
            changed = self.ruler.currentXY != xy and self.showRuler
            self.ruler.currentXY = xy

        if a0.buttons() & QtCore.Qt.MouseButton.MidButton:  # pan
            diff: QtCore.QPoint = a0.pos() - self.pressPos
            self.pressPos = a0.pos()
            self.pan(diff.x(), diff.y())
        elif a0.modifiers(
        ) & QtCore.Qt.KeyboardModifier.ShiftModifier and self.pressPosPath:  # circle select
            self._appendPressPath()
            self.pressPos = a0.pos()
            self.repaint()
        elif self.pressHoldSel:
            if d:
                if self.dragger.started:  # drag, show drag pointer
                    self.dragger.drag(a0.x(), a0.y(), pt)
                else:
                    if a0.modifiers(
                    ) & QtCore.Qt.KeyboardModifier.ShiftModifier:  # select
                        self.selector.addSelection(d)
                    elif a0.modifiers(
                    ) & QtCore.Qt.KeyboardModifier.ControlModifier:  # un-select
                        self.selector.delSelection(d)
            self.repaint()
        elif changed:
            self.repaint()
        return super().mouseMoveEvent(a0)
Example #21
0
    def mouseMoveEvent(self, a0: QtGui.QMouseEvent) -> None:
        if a0.buttons() == QtCore.Qt.RightButton:
            a0.ignore()
            return
        x = a0.x()
        y = a0.y()
        absx = x - (self.width() - self.dim.width) / 2
        absy = y - (self.height() - self.dim.height) / 2
        if absx < 0 or absx > self.dim.width or absy < 0 or absy > self.dim.height \
                or len(self.data) == len(self.reference) == 0:
            a0.ignore()
            return
        a0.accept()

        if len(self.data) > 0:
            target = self.data
        else:
            target = self.reference
        positions = []
        for d in target:
            thisx = self.width() / 2 + d.re * self.dim.width / 2
            thisy = self.height() / 2 + d.im * -1 * self.dim.height / 2
            positions.append(math.sqrt((x - thisx)**2 + (y - thisy)**2))

        minimum_position = positions.index(min(positions))
        m = self.getActiveMarker()
        if m is not None:
            m.setFrequency(str(round(target[minimum_position].freq)))
            m.frequencyInput.setText(str(round(target[minimum_position].freq)))
        return
Example #22
0
    def mouseMoveEvent(self, e: QtGui.QMouseEvent) -> None:
        if e.buttons() != Qt.LeftButton:
            return None
        #根据currentIndex获取数据行的名称
        mimeData = QMimeData()
        currentRow = self.currentIndex().row()
        index = self.model().index(currentRow, 0)
        itemName = self.model().data(index)
        mimeData.setText('{}:{}:{}'.format(self.type, self.address, itemName))

        #绘制拖动时的图像
        width = self.columnWidth(0)
        height = self.rowHeight(currentRow)
        pixmap = QPixmap(width, height)
        paint = QPainter()
        paint.begin(pixmap)
        paint.fillRect(pixmap.rect(), QColor(Qt.white))
        paint.drawRect(0, 0, width - 1, height - 1)
        paint.drawText(pixmap.rect(), Qt.AlignCenter, itemName)
        paint.end()

        #设定拖动项的数据和图标
        drag = QDrag(self)
        drag.setMimeData(mimeData)
        drag.setPixmap(pixmap)
        drag.exec_(Qt.MoveAction)
        super().mouseMoveEvent(e)
Example #23
0
    def mouseMoveEvent(self, a0: QtGui.QMouseEvent):
        if a0.buttons() == QtCore.Qt.RightButton:
            a0.ignore()
            return

        x = a0.x()
        y = a0.y()
        absx = x - (self.width() - self.dim.width) / 2
        absy = y - (self.height() - self.dim.height) / 2
        if absx < 0 or absx > self.dim.width or absy < 0 or absy > self.dim.height \
                or len(self.data) == len(self.reference) == 0:
            a0.ignore()
            return
        a0.accept()

        target = self.data or self.reference
        positions = []

        dim_x_2 = self.dim.width / 2
        dim_y_2 = self.dim.height / 2
        width_2 = self.width() / 2
        height_2 = self.height() / 2

        positions = [
            math.sqrt((x - (width_2 + d.re * dim_x_2))**2 +
                      (y - (height_2 - d.im * dim_y_2))**2) for d in target
        ]

        minimum_position = positions.index(min(positions))
        if m := self.getActiveMarker():
            m.setFrequency(str(round(target[minimum_position].freq)))
            m.frequencyInput.setText(str(round(target[minimum_position].freq)))
Example #24
0
 def mousePressEvent(self, event: QtGui.QMouseEvent):
     # if event.button() == Qt.LeftButton:#也可以
     if event.buttons() == QtCore.Qt.LeftButton:
         if self.LOCATION != Const.CENTER:
             self.mouseGrabber()  # 得到正在捕获键盘事件的窗口
         else:
             pass
Example #25
0
 def mousePressEvent(self, event: QtGui.QMouseEvent):
     if self.svgX < event.x() <= self.svgX + self.board_size and \
             self.svgY < event.y() <= self.svgY + self.board_size:
         if event.buttons() == Qt.LeftButton:
             if self.svgX + self.margin < event.x() < self.svgX + self.board_size - self.margin and \
                     self.svgY + self.margin < event.y() < self.svgY + self.board_size - self.margin and \
                     self.svg_clickable:
                 file = int((event.x() - (self.svgX + self.margin)) /
                            self.sqr_size)
                 rank = 7 - int((event.y() -
                                 (self.svgY + self.margin)) / self.sqr_size)
                 square = chess.square(file, rank)
                 piece = self.board.piece_at(square)
                 coordinates = '{}{}'.format(chr(file + 97), str(rank + 1))
                 if self.chosen_piece[0] is not None:
                     move = chess.Move.from_uci('{}{}'.format(
                         self.chosen_piece[1], coordinates))
                     if move in self.board.legal_moves:
                         self.board.push(move)
                         piece = None
                         coordinates = None
                         can_ai_move = self._can_next_player_move()
                         if can_ai_move:
                             cb_board = ChessBoard(self.board.fen())
                             ai_move, _ = self.ai_engine.choose_move(
                                 cb_board, flip=True)
                             ai_move = self._flip_move(ai_move)
                             self.board.push(ai_move)
                             self.last_ai_move = ai_move
                             self._can_next_player_move()
                 self.chosen_piece = [piece, coordinates]
         self.update()
     else:
         QWidget.mousePressEvent(self, event)
Example #26
0
    def mouseMoveEvent(self, a0: QMouseEvent) -> None:
        if (a0.buttons() == Qt.LeftButton) and abs(a0.pos().y()) > 30:
            globalPos = self.mapToGlobal(a0.pos())
            posInTab = self.mapFromGlobal(globalPos)

            TabBar.indexTabToDrag = self.currentIndex()

            tabRect = self.tabRect(self.indexTabToDrag)
            pixmap = QPixmap(tabRect.size())
            self.render(pixmap, QPoint(), QRegion(tabRect))

            mimeData = QMimeData()
            drag = QDrag(self)
            drag.setMimeData(mimeData)
            drag.setPixmap(pixmap)
            cursor = QCursor(Qt.OpenHandCursor)
            drag.setHotSpot(cursor.pos())
            drag.setHotSpot(a0.pos() - posInTab)
            drag.setDragCursor(cursor.pixmap(), Qt.MoveAction)
            dropAction = drag.exec(Qt.MoveAction)
            # If the drag completed outside of the tab bar, detach the tab and move
            # the content to the current cursor position
            if dropAction == Qt.IgnoreAction:
                a0.accept()
                self.detachTab(self.indexTabToDrag, self.cursor().pos())
        else:
            super(TabBar, self).mouseMoveEvent(a0)
 def mouseMoveEvent(self, e: QtGui.QMouseEvent) -> None:
     if self.draw_mode:
         if 0 <= e.x() < self.width and 0 <= e.y(
         ) < self.height and e.buttons():
             i, j = self.get_indexes_by_coords(e.x(), e.y())
             self.draw_point_in_coords(i, j)
             self.pictureChanged.emit()
Example #28
0
    def mousePressEvent(self, event: QMouseEvent) -> NoReturn:
        for wire in WorkspaceView.wires:
            if wire.point_on_line(
                    event.pos()) and WorkspaceView.wire_in_hand is None:
                if event.buttons() == Qt.LeftButton:
                    wire.selected = not wire.selected
                elif event.buttons() == Qt.RightButton:
                    wire.open_context_menu(event.globalPos())
                event.ignore()
                return

        if event.buttons() == Qt.LeftButton:
            if WorkspaceView.wire_in_hand is not None:
                WorkspaceView.wire_in_hand.delete()

        super().mousePressEvent(event)
 def mouseMoveEvent(self,evt: QtGui.QMouseEvent) -> None:
     mouse_pos=self.mapToScene(evt.pos())
     image_rect: QRectF=self._pixmap.boundingRect()
     if self.current_tool == SELECTION_TOOL.BOX:
         if not self._rectangle_tool_origin.isNull():
             geometry = QRect(self._rectangle_tool_origin,evt.pos()).normalized()
             self._rectangle_tool_picker.setGeometry(geometry)
     elif self.current_tool == SELECTION_TOOL.POLYGON:
         if self._current_polygon and image_rect.contains(mouse_pos):
             if self._current_polygon.count > 0:
                 last_point: QPointF=self._current_polygon.last_point
                 self._polygon_guide_line.setZValue(1)
                 self._polygon_guide_line.show()
                 mouse_pos=self.mapToScene(evt.pos())
                 self._polygon_guide_line.setLine(last_point.x(),last_point.y(),mouse_pos.x(),mouse_pos.y())
         else:
             self._polygon_guide_line.hide()
     elif self.current_tool == SELECTION_TOOL.ELLIPSE:
         if self._current_ellipse and image_rect.contains(mouse_pos):
             ellipse_rect=self._current_ellipse.rect()
             ellipse_pos=QPointF(ellipse_rect.x(),ellipse_rect.y())
             distance=math.hypot(mouse_pos.x()-ellipse_pos.x(),mouse_pos.y()-ellipse_pos.y())
             ellipse_rect.setWidth(distance)
             ellipse_rect.setHeight(distance)
             self._current_ellipse.setRect(ellipse_rect)
     elif self.current_tool == SELECTION_TOOL.FREE and evt.buttons() and QtCore.Qt.LeftButton:
         if self._current_free_path and image_rect.contains(mouse_pos):
             painter: QPainterPath=self._current_free_path.path()
             self._last_point_drawn=self.mapToScene(evt.pos())
             painter.lineTo(self._last_point_drawn)
             self._current_free_path.setPath(painter)
     super(ImageViewer, self).mouseMoveEvent(evt)
    def mousePressEvent(self, evt: QtGui.QMouseEvent) -> None:
        image_rect : QRectF=self._pixmap.boundingRect()
        mouse_pos = self.mapToScene(evt.pos())
        if evt.buttons() == QtCore.Qt.LeftButton:
            if self.current_tool == SELECTION_TOOL.BOX:
                # create rectangle
                self.setDragMode(QGraphicsView.NoDrag)
                self._rectangle_tool_origin=evt.pos()
                geometry = QRect(self._rectangle_tool_origin,QSize())
                self._rectangle_tool_picker.setGeometry(geometry)
                self._rectangle_tool_picker.show()
            elif self.current_tool == SELECTION_TOOL.POLYGON:
                if image_rect.contains(mouse_pos):
                    if self._current_polygon is None:
                        self._current_polygon=EditablePolygon()
                        self._current_polygon.label = self._current_label
                        self._current_polygon.tag = self._dataset
                        self._current_polygon.signals.deleted.connect(self.delete_polygon_slot)
                        self._scene.addItem(self._current_polygon)
                        self._current_polygon.addPoint(mouse_pos)
                    else:
                        self._current_polygon.addPoint(mouse_pos)
            elif self.current_tool == SELECTION_TOOL.ELLIPSE:
                if image_rect.contains(mouse_pos):
                    self.setDragMode(QGraphicsView.NoDrag)
                    ellipse_rec=QtCore.QRectF(mouse_pos.x(),mouse_pos.y(),0,0)
                    self._current_ellipse=EditableEllipse()
                    self._current_ellipse.tag = self.dataset
                    self._current_ellipse.label=self._current_label
                    self._current_ellipse.setRect(ellipse_rec)
                    self._scene.addItem(self._current_ellipse)

            elif self.current_tool == SELECTION_TOOL.FREE:
                # consider only the points into the image
                if image_rect.contains(mouse_pos):
                    self.setDragMode(QGraphicsView.NoDrag)
                    self._last_point_drawn=mouse_pos
                    self._current_free_path=QGraphicsPathItem()
                    self._current_free_path.setOpacity(0.6)
                    self._current_free_path.setPen(self._free_Path_pen)
                    painter=QPainterPath()
                    painter.moveTo(self._last_point_drawn)
                    self._current_free_path.setPath(painter)
                    self._scene.addItem(self._current_free_path)

            elif self.current_tool == SELECTION_TOOL.EXTREME_POINTS:
                if image_rect.contains(mouse_pos):
                    if not self._extreme_points.full():
                        def delete_point(idx):
                            del self._extreme_points.queue[idx]
                        idx=self._extreme_points.qsize()
                        editable_pt=EditablePolygonPoint(idx)
                        editable_pt.signals.deleted.connect(delete_point)
                        editable_pt.setPos(mouse_pos)
                        self._scene.addItem(editable_pt)
                        self._extreme_points.put(editable_pt)

        else:
            self.setDragMode(QGraphicsView.ScrollHandDrag)
        super(ImageViewer, self).mousePressEvent(evt)
Example #31
0
    def mouseMoveEvent(self, evt: QtGui.QMouseEvent) -> None:
        if self.selection_mode == SELECTION_MODE.BOX:
            if not self._box_origin.isNull():
                self._box_picker.setGeometry(
                    QRect(self._box_origin, evt.pos()).normalized())
        elif self.selection_mode == SELECTION_MODE.POLYGON:
            if self._current_polygon:
                if self._current_polygon.count > 0:
                    last_point: QPointF = self._current_polygon.last_point
                    self._polygon_guide_line.setZValue(1)
                    self._polygon_guide_line.show()
                    mouse_pos = self.mapToScene(evt.pos())
                    self._polygon_guide_line.setLine(last_point.x(),
                                                     last_point.y(),
                                                     mouse_pos.x(),
                                                     mouse_pos.y())
            else:
                self._polygon_guide_line.hide()

        elif self.selection_mode == SELECTION_MODE.FREE and evt.buttons(
        ) and QtCore.Qt.LeftButton:
            if self._current_free_path:
                painter: QPainterPath = self._current_free_path.path()
                self._last_point_drawn = self.mapToScene(evt.pos())
                painter.lineTo(self._last_point_drawn)
                self._current_free_path.setPath(painter)

        super(ImageViewer, self).mouseMoveEvent(evt)
Example #32
0
 def _redirectEvent(self, event, callback, transmuteMouseEvent=False):
     if transmuteMouseEvent:
         # construct a new event with pos in canvas coordinates
         canvasPos = self.mapToCanvas(event.localPos())
         event = QMouseEvent(
             event.type(),
             canvasPos,
             event.windowPos(),
             event.screenPos(),
             event.button(),
             event.buttons(),
             event.modifiers()
         )
     callback(event)
Example #33
0
 def mousePressEvent(self, event: QMouseEvent):
     """docstring for mousePressEvent"""
     if self._transform_enable and qApp.keyboardModifiers():
         which_buttons = event.buttons()
         if which_buttons in [self._button_pan, self._button_pan_alt]:
             self._panEnable()
             posf = event.localPos()
             self._x0 = posf.x()
             self._y0 = posf.y()
         elif which_buttons == self._button_zoom:
             self._dolly_zoom_enable = True
             self._last_scale_factor = 0
             # QMouseEvent.y() returns the position of the mouse cursor
             # relative to the widget
             self._y0 = event.localPos().y()
         else:
             QGraphicsView.mousePressEvent(self, event)
     else:
         QGraphicsView.mousePressEvent(self, event)
Example #34
0
    def mouseMoveEvent(self, event: QMouseEvent):
        if self.scene() is None:
            return

        cursor = self.cursor().shape()

        if self.grab_start is not None:
            move_x = self.grab_start.x() - event.pos().x()
            self.horizontalScrollBar().setValue(self.horizontalScrollBar().value() + move_x)

            if self.move_y_with_drag:
                move_y = self.grab_start.y() - event.pos().y()
                self.verticalScrollBar().setValue(self.verticalScrollBar().value() + move_y)

            self.grab_start = event.pos()
            return

        if self.separation_area_moving:
            y_sep = self.mapToScene(event.pos()).y()
            y = self.sceneRect().y()
            h = self.sceneRect().height()
            if y < y_sep < y + h:
                self.scene().draw_sep_area(y_sep)
                self.sep_area_moving.emit(y_sep)
        elif self.is_pos_in_separea(self.mapToScene(event.pos())):
            self.setCursor(Qt.SplitVCursor)
        elif cursor == Qt.SplitVCursor and self.has_horizontal_selection:
            self.unsetCursor()

        if self.selection_area.finished and not self.selection_area.resizing:
            pos = self.mapToScene(event.pos())
            roi_edge = self.selection_area.get_selected_edge(pos, self.transform())
            if roi_edge is None:
                if (cursor == Qt.SplitHCursor and self.has_horizontal_selection) \
                        or (cursor == Qt.SplitVCursor and not self.has_horizontal_selection):
                    self.unsetCursor()
                    return
            elif roi_edge == 0 or roi_edge == 1:
                if self.has_horizontal_selection:
                    self.setCursor(Qt.SplitHCursor)
                else:
                    self.setCursor(Qt.SplitVCursor)

        if event.buttons() == Qt.LeftButton and self.selection_area.resizing:

            if self.selection_area.selected_edge == 0:
                start = self.mapToScene(event.pos())
                self.__set_selection_area(x=start.x(), y=start.y())
                if self.has_horizontal_selection:
                    self.scroll_mouse(start.x())
                return

            if self.selection_area.selected_edge == 1:
                start = QPoint(self.selection_area.x, self.selection_area.y)
                end = self.mapToScene(event.pos())

                self.__set_selection_area(w=end.x() - start.x(), h=end.y() - start.y())

                if self.has_horizontal_selection:
                    self.scroll_mouse(end.x())

                return

        if self.mouse_press_pos is None:
            return

        self.mouse_pos = event.pos()
        if event.buttons() == Qt.LeftButton and not self.selection_area.finished:
            start = self.mapToScene(self.mouse_press_pos)
            end = self.mapToScene(self.mouse_pos)
            self.__set_selection_area(w=end.x() - start.x(), h=end.y() - start.y())
            if self.has_horizontal_selection:
                self.scroll_mouse(end.x())