def reshape(self): ''' Update the shape of the edge (redefined function) ''' path = QPainterPath() # If there is a starting point, draw a line to the first curve point if self.start_point: path.moveTo(self.source_connection.center) path.lineTo(self.bezier[0]) else: path.moveTo(self.source_connection.center) # Loop over the curve points: for group in self.bezier[1:]: path.cubicTo(*[point.center for point in group]) # If there is an ending point, draw a line to it if self.end_point: path.lineTo(self.end_connection.center) end_point = path.currentPosition() arrowhead = self.angle_arrow(path) path.lineTo(arrowhead[0]) path.moveTo(end_point) path.lineTo(arrowhead[1]) path.moveTo(end_point) try: # Add the transition label, if any (none for the START edge) font = QFont('arial', pointSize=8) metrics = QFontMetrics(font) label = self.edge.get('label', '') or '' lines = label.split('\n') width = metrics.width(max(lines)) # longest line height = metrics.height() * len(lines) # lp is the position of the center of the text pos = self.mapFromScene(*self.edge['lp']) if not self.text_label: self.text_label = QGraphicsTextItem(self.edge.get('label', ''), parent=self) self.text_label.setX(pos.x() - width / 2) self.text_label.setY(pos.y() - height / 2) self.text_label.setFont(font) # Make horizontal center alignment, as dot does self.text_label.setTextWidth( self.text_label.boundingRect().width()) fmt = QTextBlockFormat() fmt.setAlignment(Qt.AlignHCenter) cursor = self.text_label.textCursor() cursor.select(QTextCursor.Document) cursor.mergeBlockFormat(fmt) cursor.clearSelection() self.text_label.setTextCursor(cursor) self.text_label.show() except KeyError: # no label pass self.setPath(path)
def __init__(self, process): ''' Set generic parameters from Connection class ''' super(Channel, self).__init__(process, process) self.label_in = QGraphicsTextItem('[]', parent=self) self.label_out = QGraphicsTextItem('[]', parent=self) if not Channel.in_sig: # keep at class level as long as only one process is supported # when copy-pasting a process the challel in/out signal lists # are not parsed. Workaround is to keep the list "global" # to allow a copy of both process and channel # Needed for the image exporter, that copies the scene to a # temporary one Channel.in_sig = '[{}]'.format(',\n'.join( sig['name'] for sig in process.input_signals)) Channel.out_sig = '[{}]'.format(',\n'.join( sig['name'] for sig in process.output_signals)) font = QFont('Ubuntu', pointSize=8) for each in (self.label_in, self.label_out): each.setFont(font) each.show() self.process = process self.reshape()
def __init__(self, image, employee, text=u""): super(EmployeePictureItem, self).__init__(image) self.employee = employee # FIXME Clear ownership issues if any name = QGraphicsTextItem(self.employee.fullname + u" " + text, self) if image: name.setPos((image.width() - name.boundingRect().width()) / 2, image.height()) self.boundingBox = QRectF(0, 0, image.width(), 180) else: self.boundingBox = QRectF(0, 0, name.boundingRect().width(), name.boundingRect().height())
def reshape(self): ''' Update the shape of the edge (redefined function) ''' path = QPainterPath() # If there is a starting point, draw a line to the first curve point if self.start_point: path.moveTo(self.source_connection.center) path.lineTo(self.bezier[0]) else: path.moveTo(self.source_connection.center) # Loop over the curve points: for group in self.bezier[1:]: path.cubicTo(*[point.center for point in group]) # If there is an ending point, draw a line to it if self.end_point: path.lineTo(self.end_connection.center) end_point = path.currentPosition() arrowhead = self.angle_arrow(path) path.lineTo(arrowhead[0]) path.moveTo(end_point) path.lineTo(arrowhead[1]) path.moveTo(end_point) try: # Add the transition label, if any (none for the START edge) font = QFont('arial', pointSize=8) width = QFontMetrics(font).width(self.edge.get('label', 0)) pos = self.mapFromScene(*self.edge['lp']) #path.addText(pos.x() - width/2, pos.y(), # font, self.edge['label']) if not self.text_label: self.text_label = QGraphicsTextItem(self.edge.get('label', ''), parent=self) self.text_label.setX(pos.x() - width / 2) self.text_label.setY(pos.y()) self.text_label.setFont(font) self.text_label.show() except KeyError: # no label pass self.setPath(path)
def __init__(self, parent): super(QNEPort, self).__init__(parent) self.label = QGraphicsTextItem(self) self.radius_ = 4 self.margin = 3 path = QPainterPath() path.addEllipse(-self.radius_, -self.radius_, 2*self.radius_, 2*self.radius_); self.setPath(path) self.setPen(QPen(Qt.darkRed)) self.setBrush(Qt.red) self.setFlag(QGraphicsItem.ItemSendsScenePositionChanges) self.m_portFlags = 0 self.isOutput_ = False self.m_block = None self.m_connections = []
def __init__(self, parent): super(QNEPort, self).__init__(parent) self.label = QGraphicsTextItem(self) self.radius_ = 4 self.margin = 3 self.widgetWidth = 50 self.setPen(QPen(QApplication.palette().text().color(), 1)) self.setBrush(QApplication.palette().highlight()) self.setFlag(QGraphicsItem.ItemSendsScenePositionChanges) self.valueText = QNEValue(self) self.valueText.setPort(self) self.outputPort = QNEOutputPort(self) self.m_portFlags = 0 self.hasInput_ = False self.hasOutput_ = False self.m_block = None self.m_connections = []
def graphicsTextItem(label): item = QGraphicsTextItem(label) item.setFont(Branding.figureFont()) return item