eric6/E5Graphics/E5ArrowItem.py

Mon, 12 Oct 2020 19:28:42 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Mon, 12 Oct 2020 19:28:42 +0200
changeset 7781
607a6098cb44
parent 7780
41420f82c0ac
child 7923
91e843545d9a
permissions
-rw-r--r--

Performed some more code cleanup.

51
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
7360
9190402e4505 Updated copyright for 2020.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7252
diff changeset
3 # Copyright (c) 2007 - 2020 Detlev Offenbach <detlev@die-offenbachs.de>
51
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing a graphics item subclass for an arrow.
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
1112
8a7d1b9d18db Improved code quality by getting rid of star imports. That way pyflakes can do its job. A few bugs fixed found by flakes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
10 import math
51
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11
3656
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3178
diff changeset
12 from PyQt5.QtCore import QPointF, QRectF, QSizeF, QLineF, Qt
7529
2b8a0d8ba12a UML Diagrams: added support for dark color scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
13 from PyQt5.QtGui import QPen, QPolygonF, QColor
3656
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3178
diff changeset
14 from PyQt5.QtWidgets import QAbstractGraphicsShapeItem, QGraphicsItem, QStyle
51
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16 NormalArrow = 1
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17 WideArrow = 2
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18
2990
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
19 ArrowheadAngleFactor = 0.26179938779914941
7249
0bf517e60f54 Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
20 # That is: 0.5 * math.atan(math.sqrt(3.0) / 3.0)
51
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
22
51
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 class E5ArrowItem(QAbstractGraphicsShapeItem):
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 """
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 Class implementing an arrow graphics item subclass.
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 """
5653
c023821bb25f Fixed a few code style issues related to the usage of class instances for default arguments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5587
diff changeset
27 def __init__(self, origin=None, end=None,
7529
2b8a0d8ba12a UML Diagrams: added support for dark color scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
28 filled=False, arrowType=NormalArrow, colors=None,
2b8a0d8ba12a UML Diagrams: added support for dark color scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
29 parent=None):
51
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 """
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 Constructor
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32
7529
2b8a0d8ba12a UML Diagrams: added support for dark color scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
33 @param origin origin of the arrow
2b8a0d8ba12a UML Diagrams: added support for dark color scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
34 @type QPointF
2b8a0d8ba12a UML Diagrams: added support for dark color scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
35 @param end end point of the arrow
2b8a0d8ba12a UML Diagrams: added support for dark color scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
36 @type QPointF
2b8a0d8ba12a UML Diagrams: added support for dark color scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
37 @param filled flag indicating a filled arrow head
2b8a0d8ba12a UML Diagrams: added support for dark color scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
38 @type bool
2b8a0d8ba12a UML Diagrams: added support for dark color scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
39 @param arrowType arrow type
2b8a0d8ba12a UML Diagrams: added support for dark color scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
40 @type int, one of NormalArrow, WideArrow
2b8a0d8ba12a UML Diagrams: added support for dark color scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
41 @param colors tuple containing the foreground and background colors
2b8a0d8ba12a UML Diagrams: added support for dark color scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
42 @type tuple of (QColor, QColor)
2b8a0d8ba12a UML Diagrams: added support for dark color scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
43 @param parent reference to the parent object
2b8a0d8ba12a UML Diagrams: added support for dark color scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
44 @type QGraphicsItem
51
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 """
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2302
diff changeset
46 super(E5ArrowItem, self).__init__(parent)
51
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47
5653
c023821bb25f Fixed a few code style issues related to the usage of class instances for default arguments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5587
diff changeset
48 self._origin = QPointF() if origin is None else QPointF(origin)
c023821bb25f Fixed a few code style issues related to the usage of class instances for default arguments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5587
diff changeset
49 self._end = QPointF() if end is None else QPointF(end)
51
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 self._filled = filled
5587
ea526b78ee6c Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
51 self._type = arrowType
51
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52
7529
2b8a0d8ba12a UML Diagrams: added support for dark color scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
53 if colors is None:
2b8a0d8ba12a UML Diagrams: added support for dark color scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
54 self._colors = (QColor(Qt.black), QColor(Qt.white))
2b8a0d8ba12a UML Diagrams: added support for dark color scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
55 else:
2b8a0d8ba12a UML Diagrams: added support for dark color scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
56 self._colors = colors
2b8a0d8ba12a UML Diagrams: added support for dark color scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
57
51
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 self._halfLength = 13.0
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 self.setFlag(QGraphicsItem.ItemIsMovable, True)
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 self.setFlag(QGraphicsItem.ItemIsSelectable, True)
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 def setPoints(self, xa, ya, xb, yb):
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64 """
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 Public method to set the start and end points of the line.
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 <b>Note:</b> This method does not redraw the item.
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 @param xa x-coordinate of the start point (float)
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 @param ya y-coordinate of the start point (float)
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 @param xb x-coordinate of the end point (float)
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 @param yb y-coordinate of the end point (float)
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 """
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 self._origin = QPointF(xa, ya)
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 self._end = QPointF(xb, yb)
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 def setStartPoint(self, x, y):
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78 """
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 Public method to set the start point.
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 <b>Note:</b> This method does not redraw the item.
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 @param x x-coordinate of the start point (float)
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 @param y y-coordinate of the start point (float)
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 """
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 self._origin = QPointF(x, y)
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88 def setEndPoint(self, x, y):
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89 """
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90 Public method to set the end point.
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92 <b>Note:</b> This method does not redraw the item.
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 @param x x-coordinate of the end point (float)
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95 @param y y-coordinate of the end point (float)
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96 """
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97 self._end = QPointF(x, y)
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99 def boundingRect(self):
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
100 """
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101 Public method to return the bounding rectangle.
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
102
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
103 @return bounding rectangle (QRectF)
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
104 """
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
105 extra = self._halfLength / 2.0
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
106 return QRectF(self._origin, QSizeF(self._end.x() - self._origin.x(),
7252
c5e3705073eb Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
107 self._end.y() - self._origin.y())
c5e3705073eb Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
108 ).normalized().adjusted(-extra, -extra, extra, extra)
51
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
109
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
110 def paint(self, painter, option, widget=None):
51
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
111 """
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
112 Public method to paint the item in local coordinates.
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
113
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
114 @param painter reference to the painter object (QPainter)
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
115 @param option style options (QStyleOptionGraphicsItem)
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
116 @param widget optional reference to the widget painted on (QWidget)
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
117 """
7252
c5e3705073eb Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
118 if (
c5e3705073eb Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
119 (option.state & QStyle.State_Selected) ==
c5e3705073eb Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
120 QStyle.State(QStyle.State_Selected)
c5e3705073eb Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
121 ):
51
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
122 width = 2
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
123 else:
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
124 width = 1
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
125
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
126 # draw the line first
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
127 line = QLineF(self._origin, self._end)
2990
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
128 painter.setPen(
7529
2b8a0d8ba12a UML Diagrams: added support for dark color scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
129 QPen(self._colors[0], width, Qt.SolidLine, Qt.FlatCap,
2b8a0d8ba12a UML Diagrams: added support for dark color scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
130 Qt.MiterJoin))
51
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
131 painter.drawLine(line)
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
132
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
133 # draw the arrow head
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
134 arrowAngle = self._type * ArrowheadAngleFactor
1112
8a7d1b9d18db Improved code quality by getting rid of star imports. That way pyflakes can do its job. A few bugs fixed found by flakes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
135 slope = math.atan2(line.dy(), line.dx())
51
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
136
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
137 # Calculate left arrow point
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
138 arrowSlope = slope + arrowAngle
1112
8a7d1b9d18db Improved code quality by getting rid of star imports. That way pyflakes can do its job. A few bugs fixed found by flakes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
139 a1 = QPointF(self._end.x() - self._halfLength * math.cos(arrowSlope),
8a7d1b9d18db Improved code quality by getting rid of star imports. That way pyflakes can do its job. A few bugs fixed found by flakes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
140 self._end.y() - self._halfLength * math.sin(arrowSlope))
51
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
141
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
142 # Calculate right arrow point
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
143 arrowSlope = slope - arrowAngle
1112
8a7d1b9d18db Improved code quality by getting rid of star imports. That way pyflakes can do its job. A few bugs fixed found by flakes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
144 a2 = QPointF(self._end.x() - self._halfLength * math.cos(arrowSlope),
8a7d1b9d18db Improved code quality by getting rid of star imports. That way pyflakes can do its job. A few bugs fixed found by flakes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
145 self._end.y() - self._halfLength * math.sin(arrowSlope))
51
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
146
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
147 if self._filled:
7529
2b8a0d8ba12a UML Diagrams: added support for dark color scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
148 painter.setBrush(self._colors[0])
51
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
149 else:
7529
2b8a0d8ba12a UML Diagrams: added support for dark color scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
150 painter.setBrush(self._colors[1])
51
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
151 polygon = QPolygonF()
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
152 polygon.append(line.p2())
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
153 polygon.append(a1)
7d80b0f20ca6 Renamed E4Graphics to E5Graphics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
154 polygon.append(a2)
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
155 painter.drawPolygon(polygon)

eric ide

mercurial