Mercurial > lcfOS
comparison applications/lab/diagrameditor.py @ 51:b3a65e154ab2
Added fancy arrow head
author | windel |
---|---|
date | Thu, 05 Apr 2012 08:01:41 +0200 |
parents | 38ff8e178fe4 |
children | 67056de5da0f |
comparison
equal
deleted
inserted
replaced
50:38ff8e178fe4 | 51:b3a65e154ab2 |
---|---|
17 """ | 17 """ |
18 def __init__(self, fromPort, toPort): | 18 def __init__(self, fromPort, toPort): |
19 super(Connection, self).__init__() | 19 super(Connection, self).__init__() |
20 self.pos1 = None | 20 self.pos1 = None |
21 self.pos2 = None | 21 self.pos2 = None |
22 pen = QPen() | 22 #self.setFlags(self.ItemIsSelectable | self.ItemIsMovable) |
23 self.setFlags(self.ItemIsSelectable) | |
24 pen = QPen(Qt.blue) | |
23 pen.setWidth(2) | 25 pen.setWidth(2) |
24 pen.setColor(Qt.blue) | |
25 pen.setCapStyle(Qt.RoundCap) | 26 pen.setCapStyle(Qt.RoundCap) |
26 self.setPen(pen) | 27 self.setPen(pen) |
28 arrowPath = QPainterPath(QPointF(0.0, 0.0)) | |
29 arrowPath.lineTo(-6.0, 10.0) | |
30 arrowPath.lineTo(6.0, 10.0) | |
31 arrowPath.lineTo(0.0, 0.0) | |
32 self.arrowhead = QGraphicsPathItem(arrowPath, self) | |
33 self.arrowhead.setPen(pen) | |
34 self.arrowhead.setBrush(QBrush(pen.color())) | |
27 self.setFromPort(fromPort) | 35 self.setFromPort(fromPort) |
28 self.setToPort(toPort) | 36 self.setToPort(toPort) |
37 def shape(self): | |
38 return self.path() | |
29 def setFromPort(self, fromPort): | 39 def setFromPort(self, fromPort): |
30 self.fromPort = fromPort | 40 self.fromPort = fromPort |
31 if self.fromPort: | 41 if self.fromPort: |
32 self.setBeginPos(fromPort.scenePos()) | 42 self.setBeginPos(fromPort.scenePos()) |
33 self.fromPort.posCallbacks.append(self.setBeginPos) | 43 self.fromPort.posCallbacks.append(self.setBeginPos) |
49 """ | 59 """ |
50 if self.pos1 is None or self.pos2 is None: | 60 if self.pos1 is None or self.pos2 is None: |
51 return | 61 return |
52 # TODO: do not get the scene here? | 62 # TODO: do not get the scene here? |
53 ds = editor.diagramScene | 63 ds = editor.diagramScene |
64 self.arrowhead.setPos(self.pos2) | |
54 | 65 |
55 # TODO: create pieces of lines. | 66 # TODO: create pieces of lines. |
56 | 67 |
57 # Determine the begin and end positions: | 68 # Determine the begin and end positions: |
58 p1 = self.pos1 | 69 p1 = self.pos1 |
85 else: | 96 else: |
86 pAB = pAB1 | 97 pAB = pAB1 |
87 return [pAB] | 98 return [pAB] |
88 | 99 |
89 # Determine left or right: | 100 # Determine left or right: |
90 dx = QPointF(10, 0) | 101 dx = QPointF(20, 0) |
91 if len(stripHits(ds.items(p1 + dx))) > len(stripHits(ds.items(p1 - dx))): | 102 if len(stripHits(ds.items(p1 + dx))) > len(stripHits(ds.items(p1 - dx))): |
92 p2 = p1 - dx | 103 p2 = p1 - dx |
93 else: | 104 else: |
94 p2 = p1 + dx | 105 p2 = p1 + dx |
95 | 106 |
96 if len(stripHits(ds.items(p4 + dx))) > len(stripHits(ds.items(p4 - dx))): | 107 if len(stripHits(ds.items(p4 + dx))) > len(stripHits(ds.items(p4 - dx))): |
97 p3 = p4 - dx | 108 p3 = p4 - dx |
109 self.arrowhead.setRotation(90) | |
98 else: | 110 else: |
99 p3 = p4 + dx | 111 p3 = p4 + dx |
112 self.arrowhead.setRotation(-90) | |
100 | 113 |
101 path = QPainterPath(p1) | 114 path = QPainterPath(p1) |
102 path.lineTo(p2) | 115 path.lineTo(p2) |
103 # Now move from p2 to p3 without hitting blocks: | 116 # Now move from p2 to p3 without hitting blocks: |
104 pts = viaPoints(p2, p3) | 117 pts = viaPoints(p2, p3) |
119 super(ParameterDialog, self).__init__(parent) | 132 super(ParameterDialog, self).__init__(parent) |
120 self.block = block | 133 self.block = block |
121 self.button = QPushButton('Ok', self) | 134 self.button = QPushButton('Ok', self) |
122 l = QGridLayout(self) | 135 l = QGridLayout(self) |
123 l.addWidget(QLabel('Name:', self), 0, 0) | 136 l.addWidget(QLabel('Name:', self), 0, 0) |
124 self.nameEdit = QLineEdit(self.block.getName()) | 137 self.nameEdit = QLineEdit(self.block.name) |
125 l.addWidget(self.nameEdit, 0, 1) | 138 l.addWidget(self.nameEdit, 0, 1) |
126 l.addWidget(self.button, 1, 0) | 139 l.addWidget(self.button, 1, 0) |
127 self.button.clicked.connect(self.OK) | 140 self.button.clicked.connect(self.OK) |
128 def OK(self): | 141 def OK(self): |
129 self.block.setName(self.nameEdit.text()) | 142 self.block.setName(self.nameEdit.text()) |