changeset 73:191d70a0ed52

Removed arrowhead class
author windel
date Sat, 10 Nov 2012 11:53:55 +0100
parents b01311fb3be7
children f506f6b74697
files python/apps/diagrameditor.py
diffstat 1 files changed, 15 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/python/apps/diagrameditor.py	Sat Nov 10 11:26:50 2012 +0100
+++ b/python/apps/diagrameditor.py	Sat Nov 10 11:53:55 2012 +0100
@@ -13,32 +13,27 @@
   $ python [thisfile.py]
 """
 
-class ArrowHead(QGraphicsPathItem):
-   def __init__(self, parent):
-      super(ArrowHead, self).__init__(parent)
-      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.setPath(arrowPath)
-      pen = QPen(Qt.blue, 2)
-      self.setPen(pen)
-      self.setBrush(QBrush(pen.color()))
+def buildPath(pts):
+   path = QPainterPath(pts[0])
+   for pt in pts[1:]:
+      path.lineTo(pt)
+   return path
 
 class Connection(QGraphicsPathItem):
    """ Implementation of a connection between blocks """
    def __init__(self, fromPort, toPort):
       super(Connection, self).__init__()
-      self.pos1 = None
-      self.pos2 = None
-      self.fromPort = None
-      self.toPort = None
+      self.pos1, self.pos2 = None, None
+      self.fromPort, self.toPort = None, None
       self.setFlag(self.ItemIsSelectable, True)
       self.setFlag(self.ItemClipsToShape, True)
-      self.pen = QPen(Qt.blue, 2)
-      self.pen.setCapStyle(Qt.RoundCap)
-      self.setPen(self.pen)
-      self.arrowhead = ArrowHead(self)
+      pen = QPen(Qt.blue, 2)
+      pen.setCapStyle(Qt.RoundCap)
+      self.setPen(pen)
+      self.arrowhead = QGraphicsPathItem(self)
+      self.arrowhead.setPath(buildPath([QPointF(0.0, 0.0), QPointF(-6.0, 10.0), QPointF(6.0, 10.0), QPointF(0.0, 0.0)]))
+      self.arrowhead.setPen(pen)
+      self.arrowhead.setBrush(QBrush(pen.color()))
       self.vias = []
       self.setFromPort(fromPort)
       self.setToPort(toPort)
@@ -120,10 +115,7 @@
          self.arrowhead.setRotation(-90)
       else:
          self.arrowhead.setRotation(90)
-      path = QPainterPath(pts[0])
-      for pt in pts[1:]:
-         path.lineTo(pt)
-      self.setPath(path)
+      self.setPath(buildPath(pts))
       """ Create a shape outline using the path stroker """
       s = super(Connection, self).shape()
       pps = QPainterPathStroker()