5 |
5 |
6 """ |
6 """ |
7 Module implementing a graphics item subclass for an arrow. |
7 Module implementing a graphics item subclass for an arrow. |
8 """ |
8 """ |
9 |
9 |
10 from math import * |
10 import math |
11 |
11 |
12 from PyQt4.QtCore import * |
12 from PyQt4.QtCore import QPointF, QRectF, QSizeF, QLineF, Qt |
13 from PyQt4.QtGui import * |
13 from PyQt4.QtGui import QAbstractGraphicsShapeItem, QGraphicsItem, QStyle, QPen, QPolygonF |
14 |
14 |
15 NormalArrow = 1 |
15 NormalArrow = 1 |
16 WideArrow = 2 |
16 WideArrow = 2 |
17 |
17 |
18 ArrowheadAngleFactor = 0.26179938779914941 # 0.5 * atan(sqrt(3.0) / 3.0) |
18 ArrowheadAngleFactor = 0.26179938779914941 # 0.5 * math.atan(math.sqrt(3.0) / 3.0) |
19 |
19 |
20 |
20 |
21 class E5ArrowItem(QAbstractGraphicsShapeItem): |
21 class E5ArrowItem(QAbstractGraphicsShapeItem): |
22 """ |
22 """ |
23 Class implementing an arrow graphics item subclass. |
23 Class implementing an arrow graphics item subclass. |
111 painter.setPen(QPen(Qt.black, width, Qt.SolidLine, Qt.FlatCap, Qt.MiterJoin)) |
111 painter.setPen(QPen(Qt.black, width, Qt.SolidLine, Qt.FlatCap, Qt.MiterJoin)) |
112 painter.drawLine(line) |
112 painter.drawLine(line) |
113 |
113 |
114 # draw the arrow head |
114 # draw the arrow head |
115 arrowAngle = self._type * ArrowheadAngleFactor |
115 arrowAngle = self._type * ArrowheadAngleFactor |
116 slope = atan2(line.dy(), line.dx()) |
116 slope = math.atan2(line.dy(), line.dx()) |
117 |
117 |
118 # Calculate left arrow point |
118 # Calculate left arrow point |
119 arrowSlope = slope + arrowAngle |
119 arrowSlope = slope + arrowAngle |
120 a1 = QPointF(self._end.x() - self._halfLength * cos(arrowSlope), |
120 a1 = QPointF(self._end.x() - self._halfLength * math.cos(arrowSlope), |
121 self._end.y() - self._halfLength * sin(arrowSlope)) |
121 self._end.y() - self._halfLength * math.sin(arrowSlope)) |
122 |
122 |
123 # Calculate right arrow point |
123 # Calculate right arrow point |
124 arrowSlope = slope - arrowAngle |
124 arrowSlope = slope - arrowAngle |
125 a2 = QPointF(self._end.x() - self._halfLength * cos(arrowSlope), |
125 a2 = QPointF(self._end.x() - self._halfLength * math.cos(arrowSlope), |
126 self._end.y() - self._halfLength * sin(arrowSlope)) |
126 self._end.y() - self._halfLength * math.sin(arrowSlope)) |
127 |
127 |
128 if self._filled: |
128 if self._filled: |
129 painter.setBrush(Qt.black) |
129 painter.setBrush(Qt.black) |
130 else: |
130 else: |
131 painter.setBrush(Qt.white) |
131 painter.setBrush(Qt.white) |