Example #1
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)
Example #2
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()
Example #3
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()