Mercurial > lcfOS
comparison python/apps/diagrameditor.py @ 73:191d70a0ed52
Removed arrowhead class
author | windel |
---|---|
date | Sat, 10 Nov 2012 11:53:55 +0100 |
parents | b01311fb3be7 |
children | f506f6b74697 |
comparison
equal
deleted
inserted
replaced
72:b01311fb3be7 | 73:191d70a0ed52 |
---|---|
11 Description: This script implements a diagram editor. | 11 Description: This script implements a diagram editor. |
12 run with python 3.x as: | 12 run with python 3.x as: |
13 $ python [thisfile.py] | 13 $ python [thisfile.py] |
14 """ | 14 """ |
15 | 15 |
16 class ArrowHead(QGraphicsPathItem): | 16 def buildPath(pts): |
17 def __init__(self, parent): | 17 path = QPainterPath(pts[0]) |
18 super(ArrowHead, self).__init__(parent) | 18 for pt in pts[1:]: |
19 arrowPath = QPainterPath(QPointF(0.0, 0.0)) | 19 path.lineTo(pt) |
20 arrowPath.lineTo(-6.0, 10.0) | 20 return path |
21 arrowPath.lineTo(6.0, 10.0) | |
22 arrowPath.lineTo(0.0, 0.0) | |
23 self.setPath(arrowPath) | |
24 pen = QPen(Qt.blue, 2) | |
25 self.setPen(pen) | |
26 self.setBrush(QBrush(pen.color())) | |
27 | 21 |
28 class Connection(QGraphicsPathItem): | 22 class Connection(QGraphicsPathItem): |
29 """ Implementation of a connection between blocks """ | 23 """ Implementation of a connection between blocks """ |
30 def __init__(self, fromPort, toPort): | 24 def __init__(self, fromPort, toPort): |
31 super(Connection, self).__init__() | 25 super(Connection, self).__init__() |
32 self.pos1 = None | 26 self.pos1, self.pos2 = None, None |
33 self.pos2 = None | 27 self.fromPort, self.toPort = None, None |
34 self.fromPort = None | |
35 self.toPort = None | |
36 self.setFlag(self.ItemIsSelectable, True) | 28 self.setFlag(self.ItemIsSelectable, True) |
37 self.setFlag(self.ItemClipsToShape, True) | 29 self.setFlag(self.ItemClipsToShape, True) |
38 self.pen = QPen(Qt.blue, 2) | 30 pen = QPen(Qt.blue, 2) |
39 self.pen.setCapStyle(Qt.RoundCap) | 31 pen.setCapStyle(Qt.RoundCap) |
40 self.setPen(self.pen) | 32 self.setPen(pen) |
41 self.arrowhead = ArrowHead(self) | 33 self.arrowhead = QGraphicsPathItem(self) |
34 self.arrowhead.setPath(buildPath([QPointF(0.0, 0.0), QPointF(-6.0, 10.0), QPointF(6.0, 10.0), QPointF(0.0, 0.0)])) | |
35 self.arrowhead.setPen(pen) | |
36 self.arrowhead.setBrush(QBrush(pen.color())) | |
42 self.vias = [] | 37 self.vias = [] |
43 self.setFromPort(fromPort) | 38 self.setFromPort(fromPort) |
44 self.setToPort(toPort) | 39 self.setToPort(toPort) |
45 def mouseDoubleClickEvent(self, event): | 40 def mouseDoubleClickEvent(self, event): |
46 pos = event.scenePos() | 41 pos = event.scenePos() |
118 self.arrowhead.setPos(self.pos2) | 113 self.arrowhead.setPos(self.pos2) |
119 if pts[-1].x() < pts[-2].x(): | 114 if pts[-1].x() < pts[-2].x(): |
120 self.arrowhead.setRotation(-90) | 115 self.arrowhead.setRotation(-90) |
121 else: | 116 else: |
122 self.arrowhead.setRotation(90) | 117 self.arrowhead.setRotation(90) |
123 path = QPainterPath(pts[0]) | 118 self.setPath(buildPath(pts)) |
124 for pt in pts[1:]: | |
125 path.lineTo(pt) | |
126 self.setPath(path) | |
127 """ Create a shape outline using the path stroker """ | 119 """ Create a shape outline using the path stroker """ |
128 s = super(Connection, self).shape() | 120 s = super(Connection, self).shape() |
129 pps = QPainterPathStroker() | 121 pps = QPainterPathStroker() |
130 pps.setWidth(10) | 122 pps.setWidth(10) |
131 self.myshape = pps.createStroke(s).simplified() | 123 self.myshape = pps.createStroke(s).simplified() |