# HG changeset patch # User windel # Date 1333605701 -7200 # Node ID b3a65e154ab2961f8fdedb0cc7239272bfc3d5b7 # Parent 38ff8e178fe4ab5c6ad146f501b8be648ede40df Added fancy arrow head diff -r 38ff8e178fe4 -r b3a65e154ab2 applications/lab/diagrameditor.py --- 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)