eric6/E5Graphics/E5ArrowItem.py

changeset 7529
2b8a0d8ba12a
parent 7360
9190402e4505
child 7780
41420f82c0ac
diff -r 0345f54d3959 -r 2b8a0d8ba12a eric6/E5Graphics/E5ArrowItem.py
--- a/eric6/E5Graphics/E5ArrowItem.py	Sun Apr 12 15:03:27 2020 +0200
+++ b/eric6/E5Graphics/E5ArrowItem.py	Sun Apr 12 18:40:37 2020 +0200
@@ -11,7 +11,7 @@
 import math
 
 from PyQt5.QtCore import QPointF, QRectF, QSizeF, QLineF, Qt
-from PyQt5.QtGui import QPen, QPolygonF
+from PyQt5.QtGui import QPen, QPolygonF, QColor
 from PyQt5.QtWidgets import QAbstractGraphicsShapeItem, QGraphicsItem, QStyle
 
 NormalArrow = 1
@@ -26,15 +26,23 @@
     Class implementing an arrow graphics item subclass.
     """
     def __init__(self, origin=None, end=None,
-                 filled=False, arrowType=NormalArrow, parent=None):
+                 filled=False, arrowType=NormalArrow, colors=None,
+                 parent=None):
         """
         Constructor
         
-        @param origin origin of the arrow (QPointF)
-        @param end end point of the arrow (QPointF)
-        @param filled flag indicating a filled arrow head (boolean)
-        @param arrowType arrow type (NormalArrow, WideArrow)
-        @keyparam parent reference to the parent object (QGraphicsItem)
+        @param origin origin of the arrow
+        @type QPointF
+        @param end end point of the arrow
+        @type QPointF
+        @param filled flag indicating a filled arrow head
+        @type bool
+        @param arrowType arrow type
+        @type int, one of NormalArrow, WideArrow
+        @param colors tuple containing the foreground and background colors
+        @type tuple of (QColor, QColor)
+        @param parent reference to the parent object
+        @type QGraphicsItem
         """
         super(E5ArrowItem, self).__init__(parent)
         
@@ -43,6 +51,11 @@
         self._filled = filled
         self._type = arrowType
         
+        if colors is None:
+            self._colors = (QColor(Qt.black), QColor(Qt.white))
+        else:
+            self._colors = colors
+        
         self._halfLength = 13.0
         
         self.setFlag(QGraphicsItem.ItemIsMovable, True)
@@ -114,7 +127,8 @@
         # draw the line first
         line = QLineF(self._origin, self._end)
         painter.setPen(
-            QPen(Qt.black, width, Qt.SolidLine, Qt.FlatCap, Qt.MiterJoin))
+            QPen(self._colors[0], width, Qt.SolidLine, Qt.FlatCap,
+                 Qt.MiterJoin))
         painter.drawLine(line)
         
         # draw the arrow head
@@ -132,9 +146,9 @@
                      self._end.y() - self._halfLength * math.sin(arrowSlope))
         
         if self._filled:
-            painter.setBrush(Qt.black)
+            painter.setBrush(self._colors[0])
         else:
-            painter.setBrush(Qt.white)
+            painter.setBrush(self._colors[1])
         polygon = QPolygonF()
         polygon.append(line.p2())
         polygon.append(a1)

eric ide

mercurial