Mercurial > lcfOS
changeset 51:b3a65e154ab2
Added fancy arrow head
author | windel |
---|---|
date | Thu, 05 Apr 2012 08:01:41 +0200 |
parents | 38ff8e178fe4 |
children | 67056de5da0f |
files | applications/lab/diagrameditor.py |
diffstat | 1 files changed, 17 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/applications/lab/diagrameditor.py Wed Apr 04 18:08:48 2012 +0200 +++ b/applications/lab/diagrameditor.py Thu Apr 05 08:01:41 2012 +0200 @@ -19,13 +19,23 @@ super(Connection, self).__init__() self.pos1 = None self.pos2 = None - pen = QPen() + #self.setFlags(self.ItemIsSelectable | self.ItemIsMovable) + self.setFlags(self.ItemIsSelectable) + pen = QPen(Qt.blue) pen.setWidth(2) - pen.setColor(Qt.blue) pen.setCapStyle(Qt.RoundCap) self.setPen(pen) + arrowPath = QPainterPath(QPointF(0.0, 0.0)) + arrowPath.lineTo(-6.0, 10.0) + arrowPath.lineTo(6.0, 10.0) + arrowPath.lineTo(0.0, 0.0) + self.arrowhead = QGraphicsPathItem(arrowPath, self) + self.arrowhead.setPen(pen) + self.arrowhead.setBrush(QBrush(pen.color())) self.setFromPort(fromPort) self.setToPort(toPort) + def shape(self): + return self.path() def setFromPort(self, fromPort): self.fromPort = fromPort if self.fromPort: @@ -51,6 +61,7 @@ return # TODO: do not get the scene here? ds = editor.diagramScene + self.arrowhead.setPos(self.pos2) # TODO: create pieces of lines. @@ -87,7 +98,7 @@ return [pAB] # Determine left or right: - dx = QPointF(10, 0) + dx = QPointF(20, 0) if len(stripHits(ds.items(p1 + dx))) > len(stripHits(ds.items(p1 - dx))): p2 = p1 - dx else: @@ -95,8 +106,10 @@ if len(stripHits(ds.items(p4 + dx))) > len(stripHits(ds.items(p4 - dx))): p3 = p4 - dx + self.arrowhead.setRotation(90) else: p3 = p4 + dx + self.arrowhead.setRotation(-90) path = QPainterPath(p1) path.lineTo(p2) @@ -121,7 +134,7 @@ self.button = QPushButton('Ok', self) l = QGridLayout(self) l.addWidget(QLabel('Name:', self), 0, 0) - self.nameEdit = QLineEdit(self.block.getName()) + self.nameEdit = QLineEdit(self.block.name) l.addWidget(self.nameEdit, 0, 1) l.addWidget(self.button, 1, 0) self.button.clicked.connect(self.OK)