8 """ |
8 """ |
9 |
9 |
10 import math |
10 import math |
11 |
11 |
12 from PyQt4.QtCore import QPointF, QRectF, QSizeF, QLineF, Qt |
12 from PyQt4.QtCore import QPointF, QRectF, QSizeF, QLineF, Qt |
13 from PyQt4.QtGui import QAbstractGraphicsShapeItem, QGraphicsItem, QStyle, QPen, QPolygonF |
13 from PyQt4.QtGui import QAbstractGraphicsShapeItem, QGraphicsItem, QStyle, \ |
|
14 QPen, QPolygonF |
14 |
15 |
15 NormalArrow = 1 |
16 NormalArrow = 1 |
16 WideArrow = 2 |
17 WideArrow = 2 |
17 |
18 |
18 ArrowheadAngleFactor = 0.26179938779914941 # 0.5 * math.atan(math.sqrt(3.0) / 3.0) |
19 ArrowheadAngleFactor = 0.26179938779914941 |
|
20 # 0.5 * math.atan(math.sqrt(3.0) / 3.0) |
19 |
21 |
20 |
22 |
21 class E5ArrowItem(QAbstractGraphicsShapeItem): |
23 class E5ArrowItem(QAbstractGraphicsShapeItem): |
22 """ |
24 """ |
23 Class implementing an arrow graphics item subclass. |
25 Class implementing an arrow graphics item subclass. |
99 |
101 |
100 @param painter reference to the painter object (QPainter) |
102 @param painter reference to the painter object (QPainter) |
101 @param option style options (QStyleOptionGraphicsItem) |
103 @param option style options (QStyleOptionGraphicsItem) |
102 @param widget optional reference to the widget painted on (QWidget) |
104 @param widget optional reference to the widget painted on (QWidget) |
103 """ |
105 """ |
104 if (option.state & QStyle.State_Selected) == QStyle.State(QStyle.State_Selected): |
106 if (option.state & QStyle.State_Selected) == \ |
|
107 QStyle.State(QStyle.State_Selected): |
105 width = 2 |
108 width = 2 |
106 else: |
109 else: |
107 width = 1 |
110 width = 1 |
108 |
111 |
109 # draw the line first |
112 # draw the line first |
110 line = QLineF(self._origin, self._end) |
113 line = QLineF(self._origin, self._end) |
111 painter.setPen(QPen(Qt.black, width, Qt.SolidLine, Qt.FlatCap, Qt.MiterJoin)) |
114 painter.setPen( |
|
115 QPen(Qt.black, width, Qt.SolidLine, Qt.FlatCap, Qt.MiterJoin)) |
112 painter.drawLine(line) |
116 painter.drawLine(line) |
113 |
117 |
114 # draw the arrow head |
118 # draw the arrow head |
115 arrowAngle = self._type * ArrowheadAngleFactor |
119 arrowAngle = self._type * ArrowheadAngleFactor |
116 slope = math.atan2(line.dy(), line.dx()) |
120 slope = math.atan2(line.dy(), line.dx()) |