eric6/E5Graphics/E5ArrowItem.py

changeset 8268
6b8128e0c9d1
parent 8257
28146736bbfc
--- a/eric6/E5Graphics/E5ArrowItem.py	Tue Apr 27 17:42:00 2021 +0200
+++ b/eric6/E5Graphics/E5ArrowItem.py	Wed Apr 28 19:42:28 2021 +0200
@@ -7,25 +7,31 @@
 Module implementing a graphics item subclass for an arrow.
 """
 
+import enum
 import math
 
 from PyQt5.QtCore import QPointF, QRectF, QSizeF, QLineF, Qt
 from PyQt5.QtGui import QPen, QPolygonF, QColor
 from PyQt5.QtWidgets import QAbstractGraphicsShapeItem, QGraphicsItem, QStyle
 
-NormalArrow = 1
-WideArrow = 2
-
 ArrowheadAngleFactor = 0.26179938779914941
 # That is: 0.5 * math.atan(math.sqrt(3.0) / 3.0)
 
 
+class E5ArrowType(enum.Enum):
+    """
+    Class defining the arrow types.
+    """
+    NORMAL = 1
+    WIDE = 2
+
+
 class E5ArrowItem(QAbstractGraphicsShapeItem):
     """
     Class implementing an arrow graphics item subclass.
     """
     def __init__(self, origin=None, end=None,
-                 filled=False, arrowType=NormalArrow, colors=None,
+                 filled=False, arrowType=E5ArrowType.NORMAL, colors=None,
                  parent=None):
         """
         Constructor
@@ -37,7 +43,7 @@
         @param filled flag indicating a filled arrow head
         @type bool
         @param arrowType arrow type
-        @type int, one of NormalArrow, WideArrow
+        @type E5ArrowType
         @param colors tuple containing the foreground and background colors
         @type tuple of (QColor, QColor)
         @param parent reference to the parent object
@@ -48,7 +54,7 @@
         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
+        self.__type = arrowType
         
         if colors is None:
             self._colors = (QColor(Qt.GlobalColor.black),
@@ -129,7 +135,11 @@
         painter.drawLine(line)
         
         # draw the arrow head
-        arrowAngle = self._type * ArrowheadAngleFactor
+        arrowAngle = (
+            ArrowheadAngleFactor
+            if self.__type == E5ArrowType.NORMAL else
+            2 * ArrowheadAngleFactor
+        )
         slope = math.atan2(line.dy(), line.dx())
         
         # Calculate left arrow point

eric ide

mercurial