コード例 #1
0
    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)
コード例 #2
0
ファイル: Connectors.py プロジェクト: afesteves/opengeode
    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)
コード例 #3
0
ファイル: TextInteraction.py プロジェクト: Kampbell/opengeode
 def set_text_alignment(self):
     ''' Apply the required text alignment within the text box '''
     alignment = self.parent.text_alignment
     self.setTextWidth(self.boundingRect().width())
     fmt = QTextBlockFormat()
     fmt.setAlignment(alignment)
     cursor = self.textCursor()
     cursor.select(QTextCursor.Document)
     cursor.mergeBlockFormat(fmt)
     cursor.clearSelection()
     self.setTextCursor(cursor)
コード例 #4
0
ファイル: TextInteraction.py プロジェクト: BlasTJSN/BIPEditor
 def set_text_alignment(self):
     ''' Apply the required text alignment within the text box '''
     alignment = self.parent.text_alignment
     self.setTextWidth(self.boundingRect().width())
     fmt = QTextBlockFormat()
     fmt.setAlignment(alignment)
     cursor = self.textCursor()
     cursor.select(QTextCursor.Document)
     cursor.mergeBlockFormat(fmt)
     cursor.clearSelection()
     self.setTextCursor(cursor)
コード例 #5
0
class QtReduceFormat(object):
    GRAY = QColor(qRgb(235,235,238))
    #    red = QColor(qRgb(250,220,220))
    RED = QColor(qRgb(250,230,230))
    DARKRED = QColor(qRgb(0xb0,0,0))
    DARKBLUE = QColor(qRgb(0,0,0xb0))
    DARKGRAY = QColor(qRgb(0xa0,0xa0,0xa0))

    def __init__(self):
        self.blockFormat = QTextBlockFormat()
        self.blockFormat.setAlignment(Qt.AlignLeft)
        self.charFormat = QTextCharFormat()
        self.frameFormat = QTextFrameFormat()
        self.frameFormat.setTopMargin(0)
        self.frameFormat.setBottomMargin(0)
        self.frameFormat.setLeftMargin(0)
        self.frameFormat.setPosition(QTextFrameFormat.InFlow)