src/eric7/EricGraphics/EricArrowItem.py

branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9473
3f23dbf37dbe
diff -r e9e7eca7efee -r bf71ee032bb4 src/eric7/EricGraphics/EricArrowItem.py
--- a/src/eric7/EricGraphics/EricArrowItem.py	Wed Jul 13 11:16:20 2022 +0200
+++ b/src/eric7/EricGraphics/EricArrowItem.py	Wed Jul 13 14:55:47 2022 +0200
@@ -22,6 +22,7 @@
     """
     Class defining the arrow types.
     """
+
     NORMAL = 1
     WIDE = 2
 
@@ -30,12 +31,19 @@
     """
     Class implementing an arrow graphics item subclass.
     """
-    def __init__(self, origin=None, end=None,
-                 filled=False, arrowType=EricArrowType.NORMAL, colors=None,
-                 parent=None):
+
+    def __init__(
+        self,
+        origin=None,
+        end=None,
+        filled=False,
+        arrowType=EricArrowType.NORMAL,
+        colors=None,
+        parent=None,
+    ):
         """
         Constructor
-        
+
         @param origin origin of the arrow
         @type QPointF
         @param end end point of the arrow
@@ -50,29 +58,28 @@
         @type QGraphicsItem
         """
         super().__init__(parent)
-        
+
         self._origin = QPointF() if origin is None else QPointF(origin)
         self._end = QPointF() if end is None else QPointF(end)
         self._filled = filled
         self.__type = arrowType
-        
+
         if colors is None:
-            self._colors = (QColor(Qt.GlobalColor.black),
-                            QColor(Qt.GlobalColor.white))
+            self._colors = (QColor(Qt.GlobalColor.black), QColor(Qt.GlobalColor.white))
         else:
             self._colors = colors
-        
+
         self._halfLength = 13.0
-        
+
         self.setFlag(QGraphicsItem.GraphicsItemFlag.ItemIsMovable, True)
         self.setFlag(QGraphicsItem.GraphicsItemFlag.ItemIsSelectable, True)
-        
+
     def setPoints(self, xa, ya, xb, yb):
         """
         Public method to set the start and end points of the line.
-        
+
         <b>Note:</b> This method does not redraw the item.
-        
+
         @param xa x-coordinate of the start point (float)
         @param ya y-coordinate of the start point (float)
         @param xb x-coordinate of the end point (float)
@@ -80,78 +87,99 @@
         """
         self._origin = QPointF(xa, ya)
         self._end = QPointF(xb, yb)
-        
+
     def setStartPoint(self, x, y):
         """
         Public method to set the start point.
-        
+
         <b>Note:</b> This method does not redraw the item.
-        
+
         @param x x-coordinate of the start point (float)
         @param y y-coordinate of the start point (float)
         """
         self._origin = QPointF(x, y)
-        
+
     def setEndPoint(self, x, y):
         """
         Public method to set the end point.
-        
+
         <b>Note:</b> This method does not redraw the item.
-        
+
         @param x x-coordinate of the end point (float)
         @param y y-coordinate of the end point (float)
         """
         self._end = QPointF(x, y)
-        
+
     def boundingRect(self):
         """
         Public method to return the bounding rectangle.
-        
+
         @return bounding rectangle (QRectF)
         """
         extra = self._halfLength / 2.0
-        return QRectF(self._origin, QSizeF(self._end.x() - self._origin.x(),
-                                           self._end.y() - self._origin.y())
-                      ).normalized().adjusted(-extra, -extra, extra, extra)
-        
+        return (
+            QRectF(
+                self._origin,
+                QSizeF(
+                    self._end.x() - self._origin.x(), self._end.y() - self._origin.y()
+                ),
+            )
+            .normalized()
+            .adjusted(-extra, -extra, extra, extra)
+        )
+
     def paint(self, painter, option, widget=None):
         """
         Public method to paint the item in local coordinates.
-        
+
         @param painter reference to the painter object (QPainter)
         @param option style options (QStyleOptionGraphicsItem)
         @param widget optional reference to the widget painted on (QWidget)
         """
-        width = 2 if (
-            (option.state & QStyle.StateFlag.State_Selected) ==
-            QStyle.StateFlag.State_Selected
-        ) else 1
-        
+        width = (
+            2
+            if (
+                (option.state & QStyle.StateFlag.State_Selected)
+                == QStyle.StateFlag.State_Selected
+            )
+            else 1
+        )
+
         # draw the line first
         line = QLineF(self._origin, self._end)
         painter.setPen(
-            QPen(self._colors[0], width, Qt.PenStyle.SolidLine,
-                 Qt.PenCapStyle.FlatCap, Qt.PenJoinStyle.MiterJoin))
+            QPen(
+                self._colors[0],
+                width,
+                Qt.PenStyle.SolidLine,
+                Qt.PenCapStyle.FlatCap,
+                Qt.PenJoinStyle.MiterJoin,
+            )
+        )
         painter.drawLine(line)
-        
+
         # draw the arrow head
         arrowAngle = (
             ArrowheadAngleFactor
-            if self.__type == EricArrowType.NORMAL else
-            2 * ArrowheadAngleFactor
+            if self.__type == EricArrowType.NORMAL
+            else 2 * ArrowheadAngleFactor
         )
         slope = math.atan2(line.dy(), line.dx())
-        
+
         # Calculate left arrow point
         arrowSlope = slope + arrowAngle
-        a1 = QPointF(self._end.x() - self._halfLength * math.cos(arrowSlope),
-                     self._end.y() - self._halfLength * math.sin(arrowSlope))
-        
+        a1 = QPointF(
+            self._end.x() - self._halfLength * math.cos(arrowSlope),
+            self._end.y() - self._halfLength * math.sin(arrowSlope),
+        )
+
         # Calculate right arrow point
         arrowSlope = slope - arrowAngle
-        a2 = QPointF(self._end.x() - self._halfLength * math.cos(arrowSlope),
-                     self._end.y() - self._halfLength * math.sin(arrowSlope))
-        
+        a2 = QPointF(
+            self._end.x() - self._halfLength * math.cos(arrowSlope),
+            self._end.y() - self._halfLength * math.sin(arrowSlope),
+        )
+
         if self._filled:
             painter.setBrush(self._colors[0])
         else:

eric ide

mercurial