def mouseReleaseEvent(self, event_data: QMouseEvent):
     if self._ignoring_mouse_events:
         return
     if 0 <= event_data.x() <= self.width() and 0 <= event_data.y(
     ) <= self.height():
         event_data.accept()
         self.set_checked(not self.is_checked)
Beispiel #2
0
	def mousePressEvent(self, ev: QtGui.QMouseEvent) -> None:
		# if mouse on handle : grab and move it
		# else : move handle to the correct pos
		# print("cursor on bar :", self.barRect.contains(ev.pos()))
		if self.barRect.contains(ev.pos()):
			pos = self.getMousePositionInSteps(ev.pos())
			self.setValue(pos)
Beispiel #3
0
 def mousePressEvent(self, e: QMouseEvent) -> None:
     if self.actual_selection.value == 1:
         super(CustomQGraphicsView, self).mousePressEvent(e)
     elif self.actual_selection.value in [2, 3, 4, 5]:
         self.drawing = True
         self.previous_point = QPoint(int(e.position().x()),
                                      int(e.position().y()))
     elif self.actual_selection.value == 6:
         self.previous_point = self.mapToScene(
             QPoint(int(e.position().x()), int(e.position().y())))
         if not self.preparing:
             self.preparing = True
             self.prepare_points = list()
             self.prepare_points.append(self.previous_point)
         else:
             below_point: float = 5 / self.transform().m11()
             DrawTools.draw_simple_shape_to_scene(self,
                                                  self.prepare_points[-1],
                                                  self.previous_point,
                                                  to_gim=False)
             if fabs(self.previous_point.x() - self.prepare_points[0].x()) < below_point and \
                     fabs(self.previous_point.y() - self.prepare_points[0].y()) < below_point:
                 if len(self.prepare_points) <= 2:
                     items = self.scene().items()
                     for i in range(len(self.prepare_points)):
                         self.scene().removeItem(items[i])
                     self.preparing = False
                     return
                 DrawTools.draw_polygon(self, self.prepare_points)
                 self.preparing = False
             else:
                 self.prepare_points.append(self.previous_point)
Beispiel #4
0
 def wheelEvent(self, event: QMouseEvent):
     if self.hasMouseTracking():
         self.reset()
     elif self.annotation:
         self.annotation = False
         self.unsetCursor()
     else:
         event.ignore()
Beispiel #5
0
    def mouseReleaseEvent(self, event: QtGui.QMouseEvent):
        if event.button() == QtCore.Qt.MouseButton.MiddleButton:
            index = self.indexAt(event.pos())
            model = index.model()
            if model:
                self.middle_clicked.emit(index)
                return

        super().mouseReleaseEvent(event)
Beispiel #6
0
 def mouseMoveEvent(self, event: QtGui.QMouseEvent) -> None:
     # print("mouse move    detected", self._text)
     if event.buttons() == Qt.LeftButton and self.hasPcGrabbed:
         # send mouse position to pb
         # set pc loos end to mouse pos
         self.parent().moveLastPC(self.mapToParent(event.pos()))
     else:
         # set pc to hevered if the mouse in on the pp
         self.setPcToHoveredIfCursorOnPp(event)
Beispiel #7
0
 def mousePressEvent(self, event: QMouseEvent):  # pylint: disable=invalid-name
     """Mouse event handler; begins a crop action"""
     self.mouse_down = True
     self.mouse_pos = self.mapToScene(event.pos()).toPoint()
     if self.crop_btn.isChecked() or self.annotation:
         self.crop_rect.setTopLeft(self.mapToScene(event.pos()).toPoint())
         self.scene().addItem(self.g_rect)
     if self.annotation:
         self.g_rect.setPen(QPen(Qt.magenta, 1, Qt.SolidLine))
         self.g_rect.setBrush(QBrush(Qt.magenta, Qt.Dense4Pattern))
     elif self.hasMouseTracking() and self.g_rect.isUnderMouse:
         self.adjustment = self.edge(event.pos)[1]
     else:
         QGraphicsView.mousePressEvent(self, event)
Beispiel #8
0
 def mouseReleaseEvent(self, e: QMouseEvent) -> None:
     super(CustomQGraphicsView, self).mouseReleaseEvent(e)
     if self.drawing:
         self.drawing = False
         p_prev: QPointF = self.mapToScene(self.previous_point)
         p_act: QPointF = self.mapToScene(
             QPoint(int(e.position().x()), int(e.position().y())))
         if p_prev.x() != p_act.x() and p_act.y() != p_prev.y():
             if self.actual_selection.value in [
                     2, 3, 4
             ] and DrawTools.is_two_dimensional(p_prev, p_act):
                 DrawTools.draw_simple_shape_to_scene(self, p_prev, p_act)
             elif self.actual_selection.value == 5:
                 DrawTools.draw_simple_shape_to_scene(self, p_prev, p_act)
             self.changed.emit()
Beispiel #9
0
    def mousePressEvent(self, event: QtGui.QMouseEvent):
        """
        Event for pressing certain mouse buttons on this widget

        """
        if event.button() == QtCore.Qt.MouseButton.RightButton:
            self._signalSenderPressed.sgn2adder.emit([self._x, self._y])
Beispiel #10
0
 def eventFilter(self, source: QTextEdit, event: QMouseEvent):
     if event.type() == QEvent.MouseButtonDblClick:
         # 格式化组件中的内容
         # 或者尝试解析从浏览器中直接复制过来的 request headers
         formatted_content = ''
         content = source.toPlainText()
         try:
             formatted_content = json.dumps(json.loads(content), ensure_ascii=False, indent=4)
         except Exception:
             try:
                 tmp_config = {}
                 for line in content.split('\n'):
                     line = line.strip()
                     if line == '':
                         continue
                     if line.startswith(':'):
                         continue
                     kv = line.split(':', maxsplit=1)
                     if len(kv) == 1:
                         tmp_config[kv[0].strip()] = ''
                     else:
                         tmp_config[kv[0].strip()] = kv[1].strip()
                 formatted_content = json.dumps(tmp_config, ensure_ascii=False, indent=4)
             except Exception:
                 pass
         if formatted_content != '':
             source.setText(formatted_content)
             self.refresh.emit()
         return True
     return super(HeadersQTextEdit, self).eventFilter(source, event)
Beispiel #11
0
 def mouseReleaseEvent(
         self,
         event: QMouseEvent
 ) -> None:
     if event.button() == Qt.LeftButton:
         self.func()
     super().mouseReleaseEvent(event)
Beispiel #12
0
 def mouseReleaseEvent(self, me: QtGui.QMouseEvent) -> None:
     if distance(me.pos(), self.center) < self.radius:
         if not self.doubleClick:
             # print("mouse event type = ", me.flags == QtCore.Qt.MouseEventCreatedDoubleClick)
             super(Knob, self).mouseReleaseEvent(me)
         else:
             self.doubleClick = False
     else:
         pass
Beispiel #13
0
 def mouseReleaseEvent(self, event: QMouseEvent):  # pylint: disable=invalid-name
     """Completes the crop rectangle."""
     self.mouse_down = False
     if self.crop_btn.isChecked() | self.annotation:
         self.crop_rect.setBottomRight(
             self.mapToScene(event.pos()).toPoint())
         self.g_rect.setRect(self.crop_rect)
         self.setMouseTracking(True)
         self.crop_btn.setChecked(False)
         self.annotation = False
         self.unsetCursor()
Beispiel #14
0
 def mouseMoveEvent(self, event: QMouseEvent):  # pylint: disable=invalid-name
     """Expand crop rectangle"""
     if self.crop_btn.isChecked() | self.annotation and self.mouse_down:
         self.crop_rect.setBottomRight(
             self.mapToScene(event.pos()).toPoint())
         self.g_rect.setRect(self.crop_rect)
     if self.hasMouseTracking():
         self.setCursor((Qt.ArrowCursor, self.edge(
             event.pos)[0])[self.is_under_mouse(self.g_rect.rect())])
         if self.mouse_down:
             self.move_rect(event.pos)
Beispiel #15
0
    def mouse_move_event(self, event: QtGui.QMouseEvent) -> None:
        """Show the value tooltip on hover."""
        super().mouse_move_event(event)
        on_handle = self._handle_rect().contains(event.position().to_point())

        if on_handle and not self._mouse_on_handle:
            self._mouse_on_handle = True
            self._display_value_tooltip(start_hide_timer=False)
        elif not on_handle and self._mouse_on_handle:
            self._mouse_on_handle = False
            if not self._value_spinbox.focus and not self._tooltip_hide_timer.active:
                self._hide_value_tooltip_if_not_hover()
Beispiel #16
0
    def mousePressEvent(self, event: QtGui.QMouseEvent) -> None:
        # cprint("mouse press   detected", self._text)

        # if self has no PC or ctrl is pressed :
        if self.pcs.is_empty() or event.modifiers() == Qt.ControlModifier:
            # pb create PC ( anchored end = self, loose end = pouse pos)
            self.parent().createPC(self)
            self.hasPcGrabbed = True
        elif not self.pcs.is_empty():
            # elif self has a pc, disconnect it from self
            pc = self.pcs.last()
            self.pcs.remove(pc)
            self.parent().movePC(pc, self)
            self.hasPcGrabbed = True
Beispiel #17
0
    def mouseReleaseEvent(self, event: QMouseEvent):
        super().mouseReleaseEvent(event)
        if self._state == State.PANNING:
            if event.button() == Qt.RightButton:
                self._state = State.IDLE
        elif self._state == State.SELECTING:
            if event.button() == Qt.LeftButton:
                self._state = State.IDLE
                if self.GetSelectionMode() is SelectionMode.MODIFY:
                    for item in self._hoveredItems:
                        self.ToggleSelectItem(item)
                else:
                    self.DeselectAll()
                    for item in self._hoveredItems:
                        self.SelectItem(item)
                self.selectionChanged.emit(self._selectedItems)
        elif self._state == State.MOVING:
            if event.button() == Qt.LeftButton:
                self._state = State.IDLE

        self.UpdateView()

        super().mouseReleaseEvent(event)
Beispiel #18
0
    def mousePressEvent(self, event: QMouseEvent) -> None:
        if event.button() == Qt.LeftButton:

            # TODO handle click on label, etc
            offset = self.xy_to_offset(event.x(), event.y())
            if offset is not None:

                ctrl = event.modifiers(
                ) & Qt.ControlModifier == Qt.ControlModifier
                shift = event.modifiers(
                ) & Qt.ShiftModifier == Qt.ShiftModifier

                if ctrl:
                    # Go to pointer
                    self.signal_go_to_pointer_at_offset.emit(offset)
                    return

                if shift:
                    # Move selection instead of cursor
                    self.signal_selection_updated.emit(offset)
                    self.is_dragging_to_select = True
                    return
                self.signal_cursor_changed.emit(offset)
                self.is_dragging_to_select = True
Beispiel #19
0
    def mouseDoubleClickEvent(self, event: QtGui.QMouseEvent) -> None:
        local_pos = QPointF(self.mapFromGlobal(event.globalPos()))
        local_pos -= self.get_area_canvas_offset()

        nodes_at_mouse = self._nodes_at_position(local_pos)
        if nodes_at_mouse:
            if len(nodes_at_mouse) == 1:
                self.SelectNodeRequest.emit(nodes_at_mouse[0])
            return

        areas_at_mouse = self._other_areas_at_position(local_pos)
        if areas_at_mouse:
            if len(areas_at_mouse) == 1:
                self.SelectAreaRequest.emit(areas_at_mouse[0])
            return
Beispiel #20
0
    def mouseMoveEvent(self, event: QMouseEvent):
        # Update position movement
        newCursorPosition = event.localPos()
        if self._currentCursorPosition is None:
            deltaScene = QPointF()
        else:
            deltaScene = (self.mapToScene(newCursorPosition.toPoint()) -
                          self.mapToScene(self._currentCursorPosition.toPoint()))
        self._currentCursorPosition = newCursorPosition

        if self._state is State.PANNING:
            self._offset -= deltaScene
            self.UpdateView()
        elif self._state is State.MOVING:
            for selectedItem in self._selectedItems:
                selectedItem.Move(deltaScene)

        self.UpdateView()

        super().mouseMoveEvent(event)
Beispiel #21
0
    def mouseMoveEvent(self, event: QtGui.QMouseEvent):
        if (event.buttons() & QtGui.Qt.MiddleButton and (not(event.modifiers() & QtGui.Qt.ShiftModifier))) or event.buttons() & QtCore.Qt.LeftButton:

            self.stopViewAnimation()

            self.m_yRot = self.normalizeAngle(self.m_yLastRot - (event.pos().x() - self.m_lastPos.x()) * 0.5)
            self.m_xRot = self.m_xLastRot + (event.pos().y() - self.m_lastPos.y()) * 0.5

            if self.m_xRot < -90:
                self.m_xRot = -90
            if self.m_xRot > 90:
                self.m_xRot = 90

            self.updateView()
            self.rotationChanged.emit()
    

        if (event.buttons() & QtCore.Qt.MiddleButton and event.modifiers() & QtGui.Qt.ShiftModifier) or event.buttons() & QtCore.Qt.RightButton:
            self.m_xPan = self.m_xLastPan - (event.pos().x() - self.m_lastPos.x()) * 1 / (float)(self.width())
            self.m_yPan = self.m_yLastPan + (event.pos().y() - self.m_lastPos.y()) * 1 / (float)(self.height())

            self.updateProjection()
Beispiel #22
0
 def mousePressEvent(self, event: QtGui.QMouseEvent):
     self.m_lastPos = event.pos()
     self.m_xLastRot = self.m_xRot
     self.m_yLastRot = self.m_yRot
     self.m_xLastPan = self.m_xPan
     self.m_yLastPan = self.m_yPan
Beispiel #23
0
 def mouseReleaseEvent(self, event: QtGui.QMouseEvent) -> None:
     if self.hasPcGrabbed:
         # cprint("mouse release detected", self._text)
         # send mouse release to pb
         self.hasPcGrabbed = False
         self.parent().findReleasePp(self.mapToParent(event.pos()))
Beispiel #24
0
 def mousePressEvent(self, me: QtGui.QMouseEvent) -> None:
     if distance(me.pos(), self.center) < self.radius:
         super(Knob, self).mousePressEvent(me)
     else:
         pass
Beispiel #25
0
 def mousePressEvent(self, event: QMouseEvent) -> None:  # pylint: disable=invalid-name
     """Event handler for mouse button presses."""
     if event.button() == Qt.MouseButton.ForwardButton:
         self.next()
     elif event.button() == Qt.MouseButton.BackButton:
         self.previous()
Beispiel #26
0
 def mousePressEvent(self, e: QtGui.QMouseEvent) -> None:
     if (distance(self.center, e.pos()) <
             self.radius) or self.textRect.contains(e.pos()):
         self.setChecked(True)
Beispiel #27
0
 def mouseMoveEvent(self, event: QMouseEvent) -> None:
     self.hoverIndexRow = self.indexAt(event.pos()).row()
     return super().mouseMoveEvent(event)
Beispiel #28
0
 def mousePressEvent(self, event: QtGui.QMouseEvent) -> None:
     self.__last_pos = event.globalPos()
Beispiel #29
0
 def mouseMoveEvent(self, event: QtGui.QMouseEvent) -> None:
     dx = event.globalX() - self.__last_pos.x()
     dy = event.globalY() - self.__last_pos.y()
     self.__last_pos = event.globalPos()
     self.move(self.x() + dx, self.y() + dy)
Beispiel #30
0
 def mouseMoveEvent(self, event: QMouseEvent) -> None:
     if self.is_dragging_to_select:
         offset = self.xy_to_offset(event.x(), event.y())
         if offset is not None:
             self.signal_selection_updated.emit(offset)