Example #1
0
    def mousePressEvent(self, event: QMouseEvent) -> None:
        x, y, z = [event.pos().x(), event.pos().y(), 0]
        origin = self.viewer.origin_from_click(x, y, z)
        ray = self.viewer.ray_from_click(x, y, z)

        self.viewer.signal_screen_clicked.emit([x, y, z])
        self.viewer.signal_ray_generated.emit({'origin': origin, 'ray': ray})
Example #2
0
    def mouseMoveEvent(self, qevent: QtGui.QMouseEvent) -> None:
        self.lastPoint = qevent.pos()

        if self.active_drag:
            self.active_drag.move(QPoint_to_point(qevent.pos()))

        elif self.active_drag is None and not self.mouse_wheel_emu:
            if self.interactionDelegate is not None:

                pos = QPoint_to_point(qevent.pos())

                # TODO - revisit behaviour?
                potential_actions = []
                for (event_id, modifiers), act in self.id_actions_map.items():
                    if event_id.mouse_triggered():
                        potential_actions.append(act)

                event = MoveEvent(
                    pos,
                    self.viewState.tfV2W(pos),
                    potential_actions)

                self.interactionDelegate.mouseMoveEvent(event)

        self.update()
    def mousePressEvent(self, event: QMouseEvent) -> None:
        super().mousePressEvent(event)

        x, y, z = [event.pos().x(), event.pos().y(), 1]
        origin = self.viewer.origin_from_click(x, y, z)
        ray = self.viewer.ray_from_click(x, y, z)

        self.viewer.intersect_elements(origin, ray)
Example #4
0
    def detect_rays(self, event: QMouseEvent) -> None:
        x, y, z = [event.pos().x(), event.pos().y(), 1.0]
        self.rays.append(self.viewer.ray_from_click(x, y, z))
        self.origins.append(self.viewer.origin_from_click(x, y, z))

        if len(self.rays) == 2:
            self.viewer.generate_slice_description(self.origins, self.rays)
            self.origins.clear()
            self.rays.clear()
Example #5
0
    def mousePressEvent(self, event: QtGui.QMouseEvent) -> None:
        self.lastPoint = event.pos()

        event_id = EventID.from_mouse_event(event)
        modifiers = Modifier.from_qevent(event)

        self.dispatchActionEvent(event.pos(), event_id, modifiers)

        self.update()
Example #6
0
    def mousePressEvent(self, e: QtGui.QMouseEvent):
        opt = QtWidgets.QStyleOptionSpinBox()
        self.initStyleOption(opt)

        if self.style().subControlRect(QtWidgets.QStyle.CC_SpinBox, opt, QtWidgets.QStyle.SC_SpinBoxUp).contains(
                e.pos()):
            self.setValue(self.value() + 1)
            self.valueChanged.emit()
        elif self.style().subControlRect(QtWidgets.QStyle.CC_SpinBox, opt, QtWidgets.QStyle.SC_SpinBoxDown).contains(
                e.pos()):
            self.setValue(self.value() - 1)
            self.valueChanged.emit()
Example #7
0
    def mouseMoveEvent(self, ev: QMouseEvent):
        '''
        Mousemoveevent

        Parameters
        ----------
        ev : QMouseEvent
        '''
        if (not (ev.buttons() & Qt.LeftButton)
                or self.d.is_dragging_state(DragState.inactive)):
            self.d.drag_state = DragState.inactive
            return super().mouseMoveEvent(ev)

        # move floating window
        if self.d.is_dragging_state(DragState.floating_widget):
            self.d.floating_widget.move_floating()
            return super().mouseMoveEvent(ev)

        # move tab
        if self.d.is_dragging_state(DragState.tab):
            # Moving the tab is always allowed because it does not mean moving
            # the dock widget around
            self.d.move_tab(ev)

        # Maybe a fixed drag distance is better here ?
        drag_distance_y = abs(self.d.drag_start_mouse_position.y() -
                              ev.pos().y())
        start_dist = start_drag_distance()
        if drag_distance_y >= start_dist:
            # If this is the last dock area in a dock container with only
            # one single dock widget it does not make  sense to move it to a new
            # floating widget and leave this one empty
            if (self.d.dock_area.dock_container().is_floating()
                    and self.d.dock_area.open_dock_widgets_count() == 1
                    and self.d.dock_area.dock_container(
                    ).visible_dock_area_count() == 1):
                return

            # Floating is only allowed for widgets that are movable
            if self.d.floatable:
                self.d.start_floating()
        elif (self.d.dock_area.open_dock_widgets_count() > 1 and
              (ev.pos() - self.d.drag_start_mouse_position).manhattanLength()
              >= start_dist):
            # Wait a few pixels before start moving
            self.d.drag_state = DragState.tab
        else:
            return super().mouseMoveEvent(ev)
Example #8
0
    def mouseReleaseEvent(self, event: QtGui.QMouseEvent) -> None:
        event_id = EventID.from_mouse_event(event)
        modifiers = Modifier.from_qevent(event)

        self.dispatchActionEvent(event.pos(), event_id, modifiers)

        self.update()
Example #9
0
    def mouseMoveEvent(self, ev: QtGui.QMouseEvent) -> None:
        x_pos = ev.pos().x()
        y_pos = ev.pos().y()

        # Check if the mouse position is inside the effective level grid image
        x_grid = x_pos - self.x_pixmap
        y_grid = y_pos - self.y_pixmap
        if 0 <= x_grid < self.pixmap().width() and 0 <= y_grid < self.pixmap(
        ).height():
            self.setCursor(Qt.CrossCursor)

            # Converts the widget coordinates into grid coordinates
            grid_size = self._level_model.get_level_size()
            row = math.floor(y_grid * grid_size[0] / self.pixmap().height())
            col = math.floor(x_grid * grid_size[1] / self.pixmap().width())

            # Check if we are drawing (the mouse is pressed and dragged)
            if self._drawing:
                # Check if the event was already handled for this tile (the mouse is moved over the same tile)
                if row != self._last_tile_drawn_row or col != self._last_tile_drawn_col:
                    self.tile_clicked.emit(row, col)
                    self._last_tile_drawn_row = row
                    self._last_tile_drawn_col = col
            else:
                # Check if the highlightinh event was already handled for this tile
                # (the mouse is moved over the same tile)
                if row != self._last_tile_drawn_row or col != self._last_tile_drawn_col:
                    self.tile_over.emit(row, col)
                    self._last_tile_over_row = row
                    self._last_tile_drawn_col = col
        else:
            self.unsetCursor()
            self.tile_over.emit(-1, -1)
            self._last_tile_over_row = -1
            self._last_tile_drawn_col = -1
    def mouseMoveEvent(self, ev: QMouseEvent):
        '''
        Starts floating the complete docking area including all dock widgets,
        if it is not the last dock area in a floating widget

        Parameters
        ----------
        ev : QMouseEvent
        '''
        super().mouseMoveEvent(ev)
        if ev.buttons() != Qt.LeftButton:
            return
        if self.d.floating_widget:
            self.d.floating_widget.move_floating()
            return

        # If this is the last dock area in a dock container it does not make
        # sense to move it to a new floating widget and leave this one empty
        container = self.d.dock_area.dock_container()
        if container.is_floating() and container.visible_dock_area_count(
        ) == 1:
            return

        drag_distance = (self.d.drag_start_mouse_pos -
                         ev.pos()).manhattanLength()
        if drag_distance >= start_drag_distance():
            logger.debug('DockAreaTabBar.startFloating')
            self.start_floating(self.d.drag_start_mouse_pos)
            overlay = self.d.dock_area.dock_manager().container_overlay()
            overlay.set_allowed_areas(DockWidgetArea.outer_dock_areas)
Example #11
0
    def mousePressEvent(self, event):
        """Reimplement Qt method"""

        # mouse buttons for forward and backward navigation
        if event.button() == Qt.XButton1:
            self.sig_prev_cursor.emit()
        elif event.button() == Qt.XButton2:
            self.sig_next_cursor.emit()

        if sys.platform.startswith('linux') and event.button() == Qt.MidButton:
            self.calltip_widget.hide()
            self.setFocus()
            event = QMouseEvent(QEvent.MouseButtonPress, event.pos(),
                                Qt.LeftButton, Qt.LeftButton, Qt.NoModifier)
            QPlainTextEdit.mousePressEvent(self, event)
            QPlainTextEdit.mouseReleaseEvent(self, event)
            # Send selection text to clipboard to be able to use
            # the paste method and avoid the strange spyder-ide/spyder#1445.
            # NOTE: This issue seems a focusing problem but it
            # seems really hard to track
            mode_clip = QClipboard.Clipboard
            mode_sel = QClipboard.Selection
            text_clip = QApplication.clipboard().text(mode=mode_clip)
            text_sel = QApplication.clipboard().text(mode=mode_sel)
            QApplication.clipboard().setText(text_sel, mode=mode_clip)
            self.paste()
            QApplication.clipboard().setText(text_clip, mode=mode_clip)
        else:
            self.calltip_widget.hide()
            QPlainTextEdit.mousePressEvent(self, event)
Example #12
0
    def mousePressEvent(self, ev: QtGui.QMouseEvent) -> None:
        x_click = ev.pos().x()
        y_click = ev.pos().y()

        # Converts the widget coordinates into grid coordinates
        x_grid = x_click - self.x_pixmap
        y_grid = y_click - self.y_pixmap
        if 0 <= x_grid < self.pixmap().width() and 0 <= y_grid < self.pixmap(
        ).height():
            # Converts the widget coordinates into grid coordinates
            grid_size = self._level_model.get_level_size()
            row = math.floor(y_grid * grid_size[0] / self.pixmap().height())
            col = math.floor(x_grid * grid_size[1] / self.pixmap().width())

            self.tile_clicked.emit(row, col)
            self._last_tile_drawn_row = row
            self._last_tile_drawn_col = col

            # Start continuous drawing
            self._drawing = True

            # Disable cell highlighting when drawing
            self._last_tile_over_row = -1
            self._last_tile_over_col = -1
            self.tile_over.emit(-1, -1)
Example #13
0
 def mousePressEvent(self, event):
     if event.button() == Qt.RightButton:
         # Rewrite the mouse event to a left button event so the cursor is
         # moved to the location of the pointer.
         event = QMouseEvent(QEvent.MouseButtonPress, event.pos(),
                             Qt.LeftButton, Qt.LeftButton, Qt.NoModifier)
     HintedTextEdit.mousePressEvent(self, event)
Example #14
0
    def mouseMoveEvent(self, event: QMouseEvent) -> None:
        if self.lastPos is None:
            return

        dx = event.x() - self.lastPos.x()
        dy = event.y() - self.lastPos.y()
        smoothness = max(self.viewer.smoothness, 0.1)

        # viewer.world.setToIdentity()
        if event.buttons() == Qt.LeftButton:
            self.viewer.rotate(alpha=dy / smoothness,
                               beta=0,
                               gamma=dx / smoothness)

        elif event.buttons() == Qt.RightButton:
            self.viewer.rotate(alpha=dy / smoothness,
                               beta=dx / smoothness,
                               gamma=0)

        elif event.buttons() == Qt.MiddleButton:
            off_center = self.viewer.off_center[2]
            distance_x = off_center / self.viewer.width()
            distance_y = off_center / self.viewer.height()

            self.viewer.translate(x=-distance_x * dx, y=distance_y * dy, z=0)

        self.lastPos = QPoint(event.pos())
Example #15
0
    def mousePressEvent(self, ev: QMouseEvent):
        if ev.button() == Qt.LeftButton:
            self.d.drag_state = DragState.floating_widget
            self.d.floating_widget.start_dragging(
                ev.pos(), self.d.floating_widget.size(), self)
            return

        super().mousePressEvent(ev)
Example #16
0
 def mousePressEvent(self, event):
     if event.button() == Qt.RightButton:
         # Rewrite the mouse event to a left button event so the cursor is
         # moved to the location of the pointer.
         event = QMouseEvent(QEvent.MouseButtonPress,
                             event.pos(),
                             Qt.LeftButton,
                             Qt.LeftButton,
                             Qt.NoModifier)
     HintedTextEdit.mousePressEvent(self, event)
Example #17
0
    def mousePressEvent(self, event: QMouseEvent):
        """
        mousePressEvent

        Parameters
        ----------
        event : QMouseEvent
        """
        super().mousePressEvent(event)
        if event.button() == Qt.LeftButton:
            self._click_pos = self.mapToScene(event.pos())
    def mousePressEvent(self, ev: QMouseEvent):
        '''
        Stores mouse position to detect dragging

        Parameters
        ----------
        ev : QMouseEvent
        '''
        if ev.button() == Qt.LeftButton:
            ev.accept()
            self.d.drag_start_mouse_pos = ev.pos()
            return

        super().mousePressEvent(ev)
Example #19
0
 def mouseMoveEvent(self, event: QtGui.QMouseEvent):
     if event.buttons() != QtCore.Qt.LeftButton:
         event.ignore()
         return
     if (sub(event.pos(), self.dragStartPos)
         ).manhattanLength() < QtWidgets.QApplication.startDragDistance():
         event.ignore()
         return
     self.move_me.emit(self)
     mime_data = QtCore.QMimeData()
     mime_data.setObjectName('frame')
     drag = QtGui.QDrag(self)
     drag.setMimeData(mime_data)
     drop_action = drag.exec_(QtCore.Qt.MoveAction)
    def mouseDoubleClickEvent(self, event: QMouseEvent):
        '''
        Double clicking the title bar also starts floating of the complete area

        Parameters
        ----------
        event : QMouseEvent
        '''
        # If this is the last dock area in a dock container it does not make
        # sense to move it to a new floating widget and leave this one empty
        container = self.d.dock_area.dock_container()
        if container.is_floating() and container.dock_area_count() == 1:
            return

        self.make_area_floating(event.pos(), DragState.inactive)
Example #21
0
    def mousePressEvent(self, ev: QMouseEvent):
        '''
        Mousepressevent

        Parameters
        ----------
        ev : QMouseEvent
        '''
        if ev.button() == Qt.LeftButton:
            ev.accept()
            self.d.drag_start_mouse_position = ev.pos()
            self.d.drag_state = DragState.mouse_pressed
            self.clicked.emit()
            return

        super().mousePressEvent(ev)
Example #22
0
    def move_tab(self, ev: QMouseEvent):
        '''
        Moves the tab depending on the position in the given mouse event

        Parameters
        ----------
        ev : QMouseEvent
        '''
        ev.accept()
        # left, top, right, bottom = self.public.getContentsMargins()
        move_to_pos = self.public.mapToParent(
            ev.pos()) - self.drag_start_mouse_position
        move_to_pos.setY(0)

        self.public.move(move_to_pos)
        self.public.raise_()
Example #23
0
    def mouseMoveEvent(self, event: QMouseEvent):
        """
        mouseMoveEvent

        Parameters
        ----------
        event : QMouseEvent
        """
        super().mouseMoveEvent(event)
        if self._scene.mouseGrabberItem() is None and event.buttons(
        ) == Qt.LeftButton:
            # Make sure shift is not being pressed
            if not (event.modifiers() & Qt.ShiftModifier):
                difference = self._click_pos - self.mapToScene(event.pos())
                self.setSceneRect(self.sceneRect().translated(
                    difference.x(), difference.y()))
    def mouseDoubleClickEvent(self, event: QMouseEvent):
        '''
        Double clicking the tab widget makes the assigned dock widget floating

        Parameters
        ----------
        event : QMouseEvent
        '''
        # If this is the last dock area in a dock container it does not make
        # sense to move it to a new floating widget and leave this one
        # empty
        if not self.d.dock_area.dock_container().is_floating(
        ) or self.d.dock_area.dock_widgets_count() > 1:
            self.d.drag_start_mouse_position = event.pos()
            self.d.start_floating(DragState.inactive)

        super().mouseDoubleClickEvent(event)
Example #25
0
    def mouseReleaseEvent(self, ev: QtGui.QMouseEvent) -> None:
        if ev.button() == QtCore.Qt.LeftButton and self.current and self.tracingActive:
            if len(self.current.points) > 1:
                self.mouseDoubleClickEvent(QtCore.QEvent(QtCore.QEvent.MouseButtonDblClick))
                self.tracingActive = False

        if ev.button() == QtCore.Qt.RightButton:
            menu = self.menus[len(self.selectedShapesCopy) > 0]
            self.restoreCursor()
            if (
                not menu.exec_(self.mapToGlobal(ev.pos()))
                and self.selectedShapesCopy
            ):
                # Cancel the move by deleting the shadow copy.
                self.selectedShapesCopy = []
                self.repaint()
        elif ev.button() == QtCore.Qt.LeftButton and self.selectedShapes:
            self.overrideCursor(CURSOR_GRAB)
            if (
                self.editing()
                and int(ev.modifiers()) == QtCore.Qt.ShiftModifier
            ):
                # Add point to line if: left-click + SHIFT on a line segment
                self.addPointToEdge()
        elif ev.button() == QtCore.Qt.LeftButton and self.selectedVertex():
            if (
                self.editing()
                and int(ev.modifiers()) == QtCore.Qt.ShiftModifier
            ):
                # Delete point if: left-click + SHIFT on a point
                self.removeSelectedPoint()

        if self.movingShape and self.hShape:
            index = self.shapes.index(self.hShape)
            if (
                self.shapesBackups[-1][index].points
                != self.shapes[index].points
            ):
                self.storeShapes()
                self.shapeMoved.emit()

            self.movingShape = False
Example #26
0
 def mousePressEvent(self, event):
     """Reimplement Qt method"""
     if sys.platform.startswith('linux') and event.button() == Qt.MidButton:
         self.calltip_widget.hide()
         self.setFocus()
         event = QMouseEvent(QEvent.MouseButtonPress, event.pos(),
                             Qt.LeftButton, Qt.LeftButton, Qt.NoModifier)
         QPlainTextEdit.mousePressEvent(self, event)
         QPlainTextEdit.mouseReleaseEvent(self, event)
         # Send selection text to clipboard to be able to use
         # the paste method and avoid the strange Issue 1445
         # NOTE: This issue seems a focusing problem but it
         # seems really hard to track
         mode_clip = QClipboard.Clipboard
         mode_sel = QClipboard.Selection
         text_clip = QApplication.clipboard().text(mode=mode_clip)
         text_sel = QApplication.clipboard().text(mode=mode_sel)
         QApplication.clipboard().setText(text_sel, mode=mode_clip)
         self.paste()
         QApplication.clipboard().setText(text_clip, mode=mode_clip)
     else:
         self.calltip_widget.hide()
         QPlainTextEdit.mousePressEvent(self, event)
Example #27
0
 def mousePressEvent(self, event: QMouseEvent):
     if event.x() > self.width() - 20:
         self.last_point = event.pos()
Example #28
0
    def mouseDoubleClickEvent(self, event: QMouseEvent) -> None:
        x, y, z = [event.pos().x(), event.pos().y(), 1]
        origin = self.viewer.origin_from_click(x, y, z)
        ray = self.viewer.ray_from_click(x, y, z)

        self.viewer.intersect_elements(origin, ray)
Example #29
0
 def mousePressEvent(self, event: QMouseEvent):
     self.drag = True
     self.drag_start = event.pos()
     super(MapView, self).mousePressEvent(event)
Example #30
0
 def mousePressEvent(self, event: QMouseEvent) -> None:
     super().mousePressEvent(event)
     self.lastPos = QPoint(event.pos())
Example #31
0
 def mousePressEvent(self, e: QMouseEvent):
     child = self.childAt(e.pos())
     if not isinstance(child, ColorShow):
         self.chosen = None
         return
     self.chosen = child
Example #32
0
 def mousePressEvent(self, event: QtGui.QMouseEvent):
     if event.button() == QtCore.Qt.LeftButton:
         self.dragStartPos = event.pos()