Exemplo n.º 1
0
    def paint(self, painter, option, index):
        txt = index.model().data(index, qt.Qt.DisplayRole)
        if txt == '':
            return
        if txt.startswith('no'):
            super(SymbolDelegate, self).paint(painter, option, index)
            return
        lineSymbol = lineSymbols[lineSymbolsText[txt]]
        painter.save()
        painter.setRenderHint(qt.QPainter.Antialiasing, True)
        rect = option.rect
        rect.adjust(+5, 0, -5, 0)

        symbolFC = qt.QColor(self.parent().color)
        symbolEC = qt.QColor(self.parent().color)
        # symbolSize = self.parent().sizeSpinBox.value() * 2
        symbolSize = (self.parent().sizeSpinBox.value() + 1) * 1.75
        symbolPath = qt.QPainterPath(lineSymbol)
        scale = symbolSize
        painter.scale(scale, scale)
        symbolOffset = qt.QPointF(
            (rect.left() + rect.right() - symbolSize) * 0.5 / scale,
            (rect.top() + rect.bottom() - symbolSize) * 0.5 / scale)
        symbolPath.translate(symbolOffset)
        symbolBrush = qt.QBrush(symbolFC, qt.Qt.SolidPattern)
        symbolPen = qt.QPen(symbolEC, 1. / scale, qt.Qt.SolidLine)
        painter.setPen(symbolPen)
        painter.setBrush(symbolBrush)
        painter.drawPath(symbolPath)
        painter.restore()
Exemplo n.º 2
0
 def paintCheckBox(self, painter, rect):
     for coords in [self.coords1, self.coords2]:
         pointerPath = qt.QPainterPath()
         pointerPath.moveTo(*coords[0])
         for xy in coords[1:]:
             if isinstance(xy, tuple):
                 pointerPath.lineTo(*xy)
             if isinstance(xy, type('')):
                 end = xy.split(',')
                 if end[0] == 'close':
                     pointerPath.closeSubpath()
                 symbolPen = qt.QPen(qt.Qt.black, float(end[1].strip()))
         symbolBrush = qt.QBrush(qt.Qt.white)
         painter.setPen(symbolPen)
         painter.setBrush(symbolBrush)
         pointerPath.translate(rect.x() + 12, rect.y() + 16)
         painter.drawPath(pointerPath)
Exemplo n.º 3
0
    def paintEvent(self, e):
        txt = self.currentText()
        if txt == '':
            return
        if txt.startswith('no'):
            super(SymbolComboBox, self).paintEvent(e)
            return
        lineSymbol = lineSymbols[lineSymbolsText[txt]]
        p = qt.QStylePainter(self)
        p.setPen(self.palette().color(qt.QPalette.Text))
        opt = qt.QStyleOptionComboBox()
        self.initStyleOption(opt)
        p.drawComplexControl(qt.QStyle.CC_ComboBox, opt)
        painter = qt.QPainter(self)
        painter.save()
        painter.setRenderHint(qt.QPainter.Antialiasing, True)
        rect = p.style().subElementRect(qt.QStyle.SE_ComboBoxFocusRect, opt,
                                        self)
        rect.adjust(+5, 0, -5, 0)

        symbolFC = qt.QColor(self.parent().color)
        symbolEC = qt.QColor(self.parent().color)
        symbolSize = self.parent().sizeSpinBox.value() * 2
        symbolPath = qt.QPainterPath(lineSymbol)
        scale = symbolSize
        painter.scale(scale, scale)
        symbolOffset = qt.QPointF(
            (rect.left() + rect.right() - symbolSize) * 0.5 / scale,
            (rect.top() + rect.bottom() - symbolSize) * 0.5 / scale)
        symbolPath.translate(symbolOffset)
        symbolBrush = qt.QBrush(symbolFC, qt.Qt.SolidPattern)
        symbolPen = qt.QPen(symbolEC, 1. / scale, qt.Qt.SolidLine)
        painter.setPen(symbolPen)
        painter.setBrush(symbolBrush)
        painter.drawPath(symbolPath)
        painter.restore()
Exemplo n.º 4
0
    'none': qt.Qt.NoPen,
    '': qt.Qt.NoPen,
    ' ': qt.Qt.NoPen,
    '-': qt.Qt.SolidLine,
    '--': qt.Qt.DashLine,
    '.': qt.Qt.DotLine,
    ':': qt.Qt.DotLine,
    '-.': qt.Qt.DashDotLine
}

lineStylesText = OrderedDict([('no line', ' '), ('solid', '-'),
                              ('dashed', '--'), ('dash-dot', '-.'),
                              ('dotted', ':'), ('', '')])

# Build all lineSymbols, from pyqtgraph
lineSymbols = dict([(name, qt.QPainterPath())
                    for name in ['o', 's', 't', 'd', '+', 'x', '.', ',']])
lineSymbols['o'].addEllipse(qt.QRectF(.1, .1, .8, .8))
lineSymbols['.'].addEllipse(qt.QRectF(.3, .3, .4, .4))
lineSymbols[','].addEllipse(qt.QRectF(.4, .4, .2, .2))
lineSymbols['s'].addRect(qt.QRectF(.1, .1, .8, .8))

coords = {
    't': [(0.5, 0.), (.1, .8), (.9, .8)],
    'd': [(0.1, 0.5), (0.5, 0.), (0.9, 0.5), (0.5, 1.)],
    '+': [(0.0, 0.40), (0.40, 0.40), (0.40, 0.), (0.60, 0.), (0.60, 0.40),
          (1., 0.40), (1., 0.60), (0.60, 0.60), (0.60, 1.), (0.40, 1.),
          (0.40, 0.60), (0., 0.60)],
    'x': [(0.0, 0.40), (0.40, 0.40), (0.40, 0.), (0.60, 0.), (0.60, 0.40),
          (1., 0.40), (1., 0.60), (0.60, 0.60), (0.60, 1.), (0.40, 1.),
          (0.40, 0.60), (0., 0.60)]
Exemplo n.º 5
0
    def paint(self, painter, option, index):
        data = index.data(qt.Qt.DisplayRole)
        if data is None:
            return
        bknd = index.data(qt.Qt.BackgroundRole)

        rect = option.rect
        painter.save()
        painter.setRenderHint(qt.QPainter.Antialiasing, False)
        painter.setPen(qt.Qt.NoPen)
        if ((option.state & qt.QStyle.State_Selected
             or option.state & qt.QStyle.State_MouseOver)) and bknd not in [
                 BAD_BKGND, UNDEFINED_BKGND, NOTFOUND_BKGND, MATHERROR_BKGND
             ]:
            color = self.parent().palette().highlight().color()
            color.setAlphaF(0.1)
        else:
            color = bknd
        if color is not None:
            painter.setBrush(color)
        painter.drawRect(rect)

        if (type(data) is tuple and bknd not in [
                BAD_BKGND, UNDEFINED_BKGND, NOTFOUND_BKGND, MATHERROR_BKGND
        ]):  # plot props
            lineColor = qt.QColor(data[0])
            lineProps = data[1]
            lineWidth = (lineProps.get('linewidth', 1) + 0.5)
            lineStyle = lineStyles[lineProps.get('linestyle', '-')]

            if lineStyle == qt.Qt.NoPen:
                painter.setPen(qt.QPen(qt.Qt.lightGray))
                painter.drawText(option.rect, qt.Qt.AlignCenter, "hidden")
            else:
                axisY = lineProps.get('yaxis', -1)
                if isinstance(axisY, type("")):
                    axisY = -1 if axisY.startswith("l") else 1


#                line
                linePen = qt.QPen(qt.QBrush(lineColor), lineWidth, lineStyle,
                                  qt.Qt.FlatCap)
                painter.setPen(linePen)
                linePath = qt.QPainterPath()
                if axisY == -1:  # forbid left arrow, comment out to allow it
                    axisY = 0
                dl = lineWidth if axisY == -1 else 0
                dr = lineWidth if axisY == 1 else 0
                linePath.moveTo(rect.left() + 3 + dl,
                                (rect.top() + rect.bottom()) * 0.5)
                linePath.lineTo(rect.right() - 3 - dr,
                                (rect.top() + rect.bottom()) * 0.5)
                painter.drawPath(linePath)

                #                 > or < symbol
                font = painter.font()
                font.setFamily("Arial")
                font.setPointSize(4 + lineWidth)
                painter.setFont(font)

                dh = 2
                rect.setBottom(rect.bottom() - dh)
                if axisY == -1:
                    painter.drawText(rect,
                                     qt.Qt.AlignLeft | qt.Qt.AlignVCenter,
                                     LEFT_SYMBOL)
                elif axisY == 1:
                    painter.drawText(rect,
                                     qt.Qt.AlignRight | qt.Qt.AlignVCenter,
                                     RIGHT_SYMBOL)
                rect.setBottom(rect.bottom() + dh)

            symbol = lineProps.get('symbol', None)
            if symbol in noSymbols:
                symbol = None
            if symbol:
                painter.setRenderHint(qt.QPainter.Antialiasing, True)
                #                symbolFC = lineProps.get(
                #                    'fc', lineProps.get('facecolor', qt.Qt.black))
                #                symbolEC = lineProps.get(
                #                    'ec', lineProps.get('edgecolor', qt.Qt.black))
                symbolFC = lineColor
                symbolEC = lineColor
                symbolSize = (lineProps.get('symbolsize', 2) + 1) * 1.75
                symbolPath = qt.QPainterPath(lineSymbols[symbol])

                scale = symbolSize
                painter.scale(scale, scale)
                symbolOffset = qt.QPointF(
                    (rect.left() + rect.right() - symbolSize) * 0.5 / scale,
                    (rect.top() + rect.bottom() - symbolSize) * 0.5 / scale)
                symbolPath.translate(symbolOffset)
                symbolBrush = qt.QBrush(symbolFC, qt.Qt.SolidPattern)
                # symbolPen = qt.QPen(symbolEC, 1./scale, qt.Qt.SolidLine)
                symbolPen = qt.QPen(symbolEC, 0, qt.Qt.SolidLine)

                painter.setPen(symbolPen)
                painter.setBrush(symbolBrush)
                painter.drawPath(symbolPath)
        elif type(data) is not tuple:
            if isinstance(data, int):
                painter.setPen(qt.QPen(qt.Qt.lightGray))
            else:
                painter.setPen(qt.QPen(qt.Qt.black))
            font = painter.font()
            # font.setFamily("Arial")
            # font.setPointSize(10)
            painter.setFont(font)
            painter.drawText(option.rect, qt.Qt.AlignCenter,
                             "{0}".format(data))
        elif bknd == UNDEFINED_BKGND:
            painter.setPen(qt.QPen(qt.Qt.darkGray))
            font = painter.font()
            painter.setFont(font)
            painter.drawText(option.rect, qt.Qt.AlignCenter, "out")
        elif bknd == MATHERROR_BKGND:
            painter.setPen(qt.QPen(qt.Qt.red))
            font = painter.font()
            painter.setFont(font)
            painter.drawText(option.rect, qt.Qt.AlignCenter, "error")
        elif bknd == NOTFOUND_BKGND:
            painter.setPen(qt.QPen(qt.Qt.red))
            font = painter.font()
            painter.setFont(font)
            painter.drawText(option.rect, qt.Qt.AlignCenter, "not found")
        painter.restore()