Exemple #1
0
    def updateLineGradient(self):
        pos_top = self.boundingRect().top()
        pos_bot = self.boundingRect().bottom()
        if self.item2.scenePos().y() >= self.item1.scenePos().y():
            pos1 = 0
            pos2 = 1
        else:
            pos1 = 1
            pos2 = 0

        port_type1 = self.item1.getPortType()
        port_type2 = self.item2.getPortType()
        port_gradient = QLinearGradient(0, pos_top, 0, pos_bot)

        #if port_type1 == PORT_TYPE_AUDIO_JACK:
        #port_gradient.setColorAt(pos1, canvas.theme.line_audio_jack_sel if self.m_lineSelected else canvas.theme.line_audio_jack)
        #elif port_type1 == PORT_TYPE_MIDI_JACK:
        #port_gradient.setColorAt(pos1, canvas.theme.line_midi_jack_sel if self.m_lineSelected else canvas.theme.line_midi_jack)
        #elif port_type1 == PORT_TYPE_MIDI_ALSA:
        #port_gradient.setColorAt(pos1, canvas.theme.line_midi_alsa_sel if self.m_lineSelected else canvas.theme.line_midi_alsa)
        #elif port_type1 == PORT_TYPE_PARAMETER:
        #port_gradient.setColorAt(pos1, canvas.theme.line_parameter_sel if self.m_lineSelected else canvas.theme.line_parameter)

        #if port_type2 == PORT_TYPE_AUDIO_JACK:
        #port_gradient.setColorAt(pos2, canvas.theme.line_audio_jack_sel if self.m_lineSelected else canvas.theme.line_audio_jack)
        #elif port_type2 == PORT_TYPE_MIDI_JACK:
        #port_gradient.setColorAt(pos2, canvas.theme.line_midi_jack_sel if self.m_lineSelected else canvas.theme.line_midi_jack)
        #elif port_type2 == PORT_TYPE_MIDI_ALSA:
        #port_gradient.setColorAt(pos2, canvas.theme.line_midi_alsa_sel if self.m_lineSelected else canvas.theme.line_midi_alsa)
        #elif port_type2 == PORT_TYPE_PARAMETER:
        #port_gradient.setColorAt(pos2, canvas.theme.line_parameter_sel if self.m_lineSelected else canvas.theme.line_parameter)

        base_color = canvas.theme.line_audio_jack
        if self.m_lineSelected:
            base_color = canvas.theme.line_audio_jack_sel

        if port_type1 == PORT_TYPE_MIDI_JACK:
            base_color = canvas.theme.port_midi_jack_bg
            if self.m_lineSelected:
                base_color = canvas.theme.port_midi_jack_bg_sel

        if self.m_is_semi_hidden:
            base_color = QColor(
                int(base_color.red() * canvas.semi_hide_opacity + 0.5),
                int(base_color.green() * canvas.semi_hide_opacity + 0.5),
                int(base_color.blue() * canvas.semi_hide_opacity + 0.5))

        if self.m_ready_to_disc:
            port_gradient.setColorAt(pos1, QColor(34, 34, 34))
            port_gradient.setColorAt(pos2, QColor(34, 34, 34))
            self.setPen(QPen(port_gradient, 2, Qt.DotLine))
        else:
            port_gradient.setColorAt(0, base_color.lighter(130))
            port_gradient.setColorAt(0.5, base_color.darker(130))
            port_gradient.setColorAt(1, base_color.lighter(130))

        self.setPen(QPen(port_gradient, 1.750001, Qt.SolidLine, Qt.FlatCap))
Exemple #2
0
    def highlightCurrentLine(self):
        extraSelections = []
        if not self.isReadOnly():
            selection = QTextEdit.ExtraSelection()

            lineColor = QColor()
            lineColor.setNamedColor('#102020')
            lineColor.lighter(500)
            selection.format.setBackground(lineColor)

            selection.format.setProperty(QTextFormat.FullWidthSelection, True)
            selection.cursor = self.textCursor()
            selection.cursor.clearSelection()
            extraSelections.append(selection)
        self.setExtraSelections(extraSelections)
Exemple #3
0
    def drawSquare(self, painter, x, y, shape):
        colorTable = {
            0: 0xcccccc,
            2: 0xfccff0,
            4: 0xCC6666,
            8: 0x66CC66,
            16: 0x06eC66,
            32: 0xCCCC66,
            64: 0xCC66CC,
            128: 0x66CCCC,
            256: 0xDAAA00,
            512: 0x00CC66,
            1024: 0x0000CC,
            2048: 0x66CCCC,
        }
        color = QColor(colorTable[shape])

        # 画出格子
        painter.fillRect(x + 5, y + 5, self.squareWidth() - 10,
                         self.squareHeight() - 10, color)

        # 画数字,0不用画
        if shape != 0:
            painter.setPen(color.lighter())
            painter.setFont(QFont('Decorative', 20))
            painter.drawText(x + 5, y-5,
                             self.squareHeight(), self.squareWidth(), Qt.AlignCenter, str(shape))
Exemple #4
0
    def addBreakdownSeries(self, series, color):
        # Add breakdown series as a slice to center pie.
        slice = self.mainSeries.append(series.name(), series.sum())

        # Customize the slice.
        slice.setBrush(color)
        slice.setLabelVisible()
        slice.setLabelColor(Qt.white)
        slice.setLabelPosition(QPieSlice.LabelInsideHorizontal)

        # Position and customize the breakdown series.
        series.setPieSize(0.8)
        series.setHoleSize(0.7)
        series.setLabelsVisible()

        color = QColor(color)

        for slice in series.slices():
            color = color.lighter(115)
            slice.setBrush(color)
            slice.setLabelFont(QFont("Arial", 8))

        # Add the series to the chart.
        self.addSeries(series)

        # Recalculate breakdown donut segments.
        self.recalculateAngles()
Exemple #5
0
 def labelLines(self, img: Optional[QPixmap], toSrc: bool):
     if not img or not self.lines:
         return None
     painter = QPainter()
     painter.begin(img)
     painter.setRenderHint(QPainter.Antialiasing, True)
     pen = QPen()
     pen.setCapStyle(Qt.RoundCap)
     font = QFont('Consolas')
     if toSrc:
         pen.setWidthF(config.lineWidth * self.ratioToSrc)
         font.setPointSizeF(config.fontSize * self.ratioToSrc)
     else:
         pen.setWidthF(config.lineWidth)
         font.setPointSizeF(config.fontSize)
     painter.setFont(font)
     for (indexA, indexB), color in self.lines.items():
         isHighlight = indexA in self.highlightPoints and indexB in self.highlightPoints \
             and (self.mode == LabelMode.AngleMode or self.mode == LabelMode.VerticalMode)
         pen.setColor(QColor.lighter(color) if isHighlight else color)
         painter.setPen(pen)
         A = self.points[indexA][0]
         B = self.points[indexB][0]
         srcA = self.getSrcPoint(A)
         srcB = self.getSrcPoint(B)
         labelPoint: QPointF
         if toSrc:
             painter.drawLine(srcA, srcB)
             labelPoint = static.getMidpoint(srcA, srcB)
         else:
             painter.drawLine(A, B)
             labelPoint = static.getMidpoint(A, B)
         painter.drawText(static.getDistanceShift(A, B, labelPoint), str(round(static.getDistance(srcA, srcB), 2)))
     painter.end()
Exemple #6
0
    def draw_storey(self, painter, x, y, storey_state):
        color_table = [Qt.black, Qt.yellow, Qt.blue]
        color = QColor(color_table[storey_state])

        painter.fillRect(x + 1, y + 1,
                         self.square_width() - 2,
                         self.square_height() - 2, color)

        painter.setPen(color.lighter())
        painter.drawLine(x, y + self.square_height() - 1, x, y)
        painter.drawLine(x, y, x + self.square_width() - 1, y)

        painter.setPen(color.darker())
        painter.drawLine(x + 1, y + self.square_height() - 1,
                         x + self.square_width() - 1,
                         y + self.square_height() - 1)
        painter.drawLine(x + self.square_width() - 1,
                         y + self.square_height() - 1,
                         x + self.square_width() - 1, y + 1)

        if storey_state != StoreyState.EMPTY:
            if not self.current_state.is_open:
                painter.setBrush(QBrush(Qt.DiagCrossPattern))
                painter.drawRect(x + 1, y + 1,
                                 self.square_width() - 2,
                                 self.square_height() - 2)

            if self.current_state.weight > 0:
                painter.setPen(Qt.red)
                painter.drawText(
                    QRect(x + 1, y + 1,
                          self.square_width() - 2,
                          self.square_height() - 2), Qt.AlignCenter,
                    str(self.current_state.weight))
Exemple #7
0
    def draw_square(self, left, top, sq_type):
        """ отрисовка квадратика """

        w = left * self.scale_width()
        h = top * self.scale_height()

        painter = QPainter(self)

        if sq_type == config.FIELD_TYPE_NONE:
            painter.fillRect(w, h, self.scale_width(), self.scale_height(), QColor(config.Colors[sq_type]))
            return
        elif sq_type == config.FIELD_TYPE_BODY:
            color = QColor(self.body_gradient[self.engine.body_index(top, left)].get_hex())
        else:
            color = QColor(config.Colors[sq_type])

        painter.fillRect(w + 1, h + 1, self.scale_width() - 2, self.scale_height() - 2, color)

        painter.setPen(color.lighter())
        painter.drawLine(w, h + self.scale_height() - 1, w, h)
        painter.drawLine(w, h, w + self.scale_width() - 1, h)

        painter.setPen(color.darker(150))
        painter.drawLine(w + 1, h + self.scale_height() - 1, w + self.scale_width() - 1, h + self.scale_height() - 1)
        painter.drawLine(w + self.scale_width() - 1, h + self.scale_height() - 1, w + self.scale_width() - 1, h + 1)
Exemple #8
0
    def draw(self, painter, x, y, shape):

        painter.drawRect(self.game_top_left[0], self.game_top_left[1],
                         self.game_width, self.game_height)
        painter.drawRect(self.score_top_left[0], self.score_top_left[1],
                         self.score_width, self.score_height)
        painter.drawRect(self.predict_top_left[0], self.predict_top_left[1],
                         self.predict_width, self.predict_height)
        # for i in range(self.square_height_num):
        #     for j in range(self.square_width_num):
        #         painter.drawRect(self.game_top_left[0] + j * self.square_width, self.game_top_left[1] + i * self.square_height,self.square_width,self.square_height)
        # 加个网格看得清

        colorTable = [
            0x000000, 0xCC6666, 0x66CC66, 0x6666CC, 0xCCCC66, 0xCC66CC,
            0x66CCCC, 0xDAAA00
        ]

        color = QColor(colorTable[shape])
        painter.fillRect(x + 1, y + 1, self.square_width - 2,
                         self.square_height - 2, color)
        painter.setPen(color.lighter())
        painter.drawLine(x, y + self.square_height - 1, x, y)
        painter.drawLine(x, y, x + self.square_width - 1, y)

        painter.setPen(color.darker())
        painter.drawLine(x + 1, y + self.square_height - 1,
                         x + self.square_width - 1, y + self.square_height - 1)
        painter.drawLine(x + self.square_width - 1, y + self.square_height - 1,
                         x + self.square_width - 1, y + 1)
Exemple #9
0
    def drawSquare(self, painter, x, y, shape):
        """绘制方块图形"""

        colorTable = [
            0x000000, 0xCC6666, 0x66CC66, 0x6666CC, 0xCCCC66, 0xCC66CC,
            0x66CCCC, 0xDAAA00
        ]

        color = QColor(colorTable[shape])

        painter.fillRect(x + 1, y + 1,
                         self.squareWidth() - 2,
                         self.squareHeight() - 2, color)

        painter.setPen(color.lighter())

        painter.drawLine(x, y + self.squareHeight() - 1, x, y)

        painter.drawLine(x, y, x + self.squareWidth() - 1, y)

        painter.setPen(color.darker())

        painter.drawLine(x + 1, y + self.squareHeight() - 1,
                         x + self.squareWidth() - 1,
                         y + self.squareHeight() - 1)

        painter.drawLine(x + self.squareWidth() - 1,
                         y + self.squareHeight() - 1,
                         x + self.squareWidth() - 1, y + 1)
Exemple #10
0
 def labelPoints(self, img: Optional[QPixmap], toSrc: bool):
     if not img or not self.points:
         return None
     painter = QPainter()
     painter.begin(img)
     painter.setRenderHint(QPainter.Antialiasing, True)
     pen = QPen()
     pen.setCapStyle(Qt.RoundCap)
     font = QFont('Consolas')
     if toSrc:
         pen.setWidthF(config.pointWidth * self.ratioToSrc)
         font.setPointSizeF(config.fontSize * self.ratioToSrc)
     else:
         pen.setWidthF(config.pointWidth)
         font.setPointSizeF(config.fontSize)
     painter.setFont(font)
     for index, (point, color) in self.points.items():
         labelPoint: QPointF
         if toSrc:
             pen.setColor(color)
             labelPoint = self.getSrcPoint(point)
         else:
             pen.setColor(
                 color if index != self.highlightMoveIndex and index not in self.highlightPoints
                 else QColor.lighter(color)
             )
             labelPoint = point
         painter.setPen(pen)
         painter.drawPoint(labelPoint)
         painter.drawText(static.getIndexShift(labelPoint), str(index))
     painter.end()
Exemple #11
0
    def drawSquare(self, painter, x, y, shape):

        colorTable = [
            0x000000, 0xCC6666, 0x66CC66, 0x6666CC, 0xCCCC66, 0xCC66CC,
            0x66CCCC, 0xDAAA00
        ]

        color = QColor(colorTable[shape])
        painter.fillRect(x + 1, y + 1,
                         self.squareWidth() - 2,
                         self.squareHeight() - 2, color)

        painter.setPen(color.lighter())
        painter.drawLine(x, y + self.squareHeight() - 1, x, y)
        painter.drawLine(x, y, x + self.squareWidth() - 1, y)
        painter.drawLine(x + 1, y + self.squareHeight() - 1,
                         x + self.squareWidth() - 1,
                         y + self.squareHeight() - 1)
        painter.drawLine(x + self.squareWidth() - 1,
                         y + self.squareHeight() - 1,
                         x + self.squareWidth() - 1, y + 1)

        pen = QPen(Qt.black, 5, Qt.SolidLine)
        painter.setPen(pen)
        painter.drawLine(0, 0, 0, 720)
        painter.drawLine(0, 720, 720, 720)
        painter.drawLine(720, 720, 720, 0)
        painter.drawLine(720, 0, 0, 0)
    def paint(self, painter, option, index):
        hasValue = True
        if (self.m_editorPrivate):
            property = self.m_editorPrivate.indexToProperty(index)
            if (property):
                hasValue = property.hasValue()

        opt = QStyleOptionViewItem(option)
        if ((self.m_editorPrivate and index.column() == 0) or not hasValue):
            property = self.m_editorPrivate.indexToProperty(index)
            if (property and property.isModified()):
                opt.font.setBold(True)
                opt.fontMetrics = QFontMetrics(opt.font)

        c = QColor()
        if (not hasValue
                and self.m_editorPrivate.markPropertiesWithoutValue()):
            c = opt.palette.color(QPalette.Dark)
            opt.palette.setColor(QPalette.Text,
                                 opt.palette.color(QPalette.BrightText))
        else:
            c = self.m_editorPrivate.calculatedBackgroundColor(
                self.m_editorPrivate.indexToBrowserItem(index))
            if (c.isValid()
                    and (opt.features & QStyleOptionViewItem.Alternate)):
                c = c.lighter(112)

        if (c.isValid()):
            painter.fillRect(option.rect, c)
        opt.state &= ~QStyle.State_HasFocus

        if (index.column() == 1):
            item = self.m_editorPrivate.indexToItem(index)
            if (self.m_editedItem and (self.m_editedItem == item)):
                self.m_disablePainting = True

        super(QtPropertyEditorDelegate, self).paint(painter, opt, index)
        if (option.type):
            self.m_disablePainting = False

        opt.palette.setCurrentColorGroup(QPalette.Active)
        color = QApplication.style().styleHint(QStyle.SH_Table_GridLineColor,
                                               opt)
        painter.save()
        painter.setPen(QPen(color))
        if (not self.m_editorPrivate
                or (not self.m_editorPrivate.lastColumn(index.column())
                    and hasValue)):
            if option.direction == Qt.LeftToRight:
                right = option.rect.right()
            else:
                right = option.rect.left()
            painter.drawLine(right, option.rect.y(), right,
                             option.rect.bottom())

        painter.restore()
Exemple #13
0
 def draw_square(painter, x, y, val, s):
     if val != 0:
         color = QColor(Drawing.color_table[val])
         painter.fillRect(x+1, y+1, s-2, s-2, color)
         painter.setPen(color.lighter())
         painter.drawLine(x, y + s - 1, x, y)
         painter.drawLine(x, y, x + s - 1, y)
         painter.setPen(color.darker())
         painter.drawLine(x + 1, y + s - 1, x + s - 1, y + s - 1)
         painter.drawLine(x + s - 1, y + s - 1, x + s - 1, y + 1)
    def drawRect(self, qp):
        # 创建红色,宽度为4像素的画笔
        pen = QPen()
        pen.setWidth(4)
        pen.setColor(Qt.red)
        pen.setStyle(Qt.SolidLine)
        pen.setCapStyle(Qt.FlatCap)
        pen.setJoinStyle(Qt.BevelJoin)
        qp.setPen(pen)

        qp.setRenderHint(QPainter.Antialiasing)
        qp.setRenderHint(QPainter.TextAntialiasing)
        brush = QBrush()
        qc = QColor()
        qc.lighter()
        brush.setColor(qc.lighter(1))
        brush.setStyle(Qt.SolidPattern)
        qp.setBrush(brush)
        qp.drawRect(*self.rect)
Exemple #15
0
 def drawLine(self, painter, x, y):
     w = self.size
     h = self.size
     x = x * self.size + self.offset
     y = y * self.size + self.offset
     color = QColor(self.color)
     painter.setPen(color.lighter())
     painter.drawLine(x, y + h, x, y)
     painter.drawLine(x, y, x + w, y)
     painter.drawLine(x, y + h, x + w, y + h)
     painter.drawLine(x + w, y + h, x + w, y)
Exemple #16
0
    def drawPawn(self, painter, x, y, colorIndex, isKing=False):
        colorTable = [0xC1442E, 0xF6CD37]

        color = QColor(colorTable[colorIndex])
        painter.setBrush(color)
        painter.drawEllipse(x, y, self.squareWidth(), self.squareHeight())
        painter.setBrush(Qt.green)
        if isKing == True:
            painter.setPen(color.lighter())
            painter.drawEllipse(x, y,
                                self.squareWidth() / 2,
                                self.squareHeight() / 2)
Exemple #17
0
def drawCell(painter, x, y, shape, grid_size):
	colors = [0x000000, 0xCC6666, 0x66CC66, 0x6666CC, 0xCCCC66, 0xCC66CC, 0x66CCCC, 0xDAAA00]
	if shape == 0:
		return
	color = QColor(colors[shape])
	painter.fillRect(x+1, y+1, grid_size-2, grid_size-2, color)
	painter.setPen(color.lighter())
	painter.drawLine(x, y+grid_size-1, x, y)
	painter.drawLine(x, y, x+grid_size-1, y)
	painter.setPen(color.darker())
	painter.drawLine(x+1, y+grid_size-1, x+grid_size-1, y+grid_size-1)
	painter.drawLine(x+grid_size-1, y+grid_size-1, x+grid_size-1, y+1)
Exemple #18
0
    def draw_cube(self, qp, x, y, color):
        color = QColor(color)

        width = self.board_cube_width()
        height = self.board_cube_height()
        x *= width
        y *= height

        qp.fillRect(x + 1, y + 1, width - 2, height - 2, color)

        qp.setPen(color.lighter())
        qp.setPen(color.darker())
Exemple #19
0
    def draw_item(self, qp, x, y, m, n):
        # x 10, y 10, z 25, w: 25

        color = QColor(0xCCCC66)
        qp.fillRect(x + 1, y + 1, m - 2, n - 2, color)

        qp.setPen(color.lighter())
        qp.drawLine(x, y + n - 1, x, y)
        qp.drawLine(x, y, x + m - 1, y)

        qp.setPen(color.darker())
        qp.drawLine(x + 1, y + n - 1, x + m - 1, y + n - 1)
        qp.drawLine(x + n - 1, y + n - 1, x + m - 1, y + 1)
Exemple #20
0
 def drawLine(self, painter):
     if self.border == None:
         return
     w = self.size * 4
     h = self.size * 4
     x = self.offsetX + self.size * self.pointX
     y = self.offsetY + self.size * self.pointY
     color = QColor(self.border)
     painter.setPen(color.lighter())
     painter.drawLine(x, y, x + w, y)
     painter.drawLine(x, y + h, x, y)
     painter.drawLine(x, y + h, x + w, y + h)
     painter.drawLine(x + w, y + h, x + w, y)
Exemple #21
0
def getColorObj(hex_string, alpha=None, lighter=None):
    """Checks internal cache for specified color. If not in the cache, add it.

    Args:
        hex_string (str): hexadecimal color code in the form: #RRGGBB
        alpha (int): 0–255
        lighter (int): see `QColor.lighter <http://doc.qt.io/qt-5/qcolor.html#lighter>`_.

    Returns:
        color (QColor)
    """
    global color_cache
    if alpha is not None:
        hex_string = '#%0.2x%s' % (alpha, hex_string[1:])
    key = (hex_string, lighter)
    color = color_cache.get(key)
    if color is None:
        color = QColor(hex_string)
        if lighter is not None:
            color.lighter(lighter)
        color_cache[key] = color
    return color
Exemple #22
0
def getColorObj(hex_string, alpha=None, lighter=None):
    """Checks internal cache for specified color. If not in the cache, add it.

    Args:
        hex_string (str): hexadecimal color code in the form: #RRGGBB
        alpha (int): 0–255
        lighter (int): see `QColor.lighter <http://doc.qt.io/qt-5/qcolor.html#lighter>`_.

    Returns:
        color (QColor)
    """
    global color_cache
    if alpha is not None:
        hex_string = '#%0.2x%s' % (alpha, hex_string[1:])
    key = (hex_string, lighter)
    color = color_cache.get(key)
    if color is None:
        color = QColor(hex_string)
        if lighter is not None:
            color.lighter(lighter)
        color_cache[key] = color
    return color
    def draw_square(self, x, y, size, color):
        width, height = size
        color = QColor(color)

        painter = self.painter
        painter.fillRect(x + 1, y + 1, width - 2, height - 2, color)

        painter.setPen(color.lighter())
        painter.drawLine(x, y + height - 1, x, y)
        painter.drawLine(x, y, x + width - 1, y)

        painter.setPen(color.darker())
        painter.drawLine(x + 1, y + height - 1, x + width - 1, y + height - 1)
        painter.drawLine(x + width - 1, y + height - 1, x + width - 1, y + 1)
Exemple #24
0
    def brush(self, option: QStyleOptionToolButton):
        over = option.state & QStyle.State_MouseOver
        pressed = option.state & QStyle.State_Sunken

        g1 = QColor(219, 217, 215)
        g2 = QColor(205, 202, 199)
        g3 = QColor(187, 183, 180)

        if pressed:
            g1 = g1.darker(120)
            g2 = g2.darker(120)
            g3 = g3.darker(120)
        elif over:
            g1 = g1.lighter(110)
            g2 = g2.lighter(110)
            g3 = g3.lighter(110)

        gradient = QLinearGradient(0, 0, 0, self.height())
        gradient.setColorAt(0.0, g1)
        gradient.setColorAt(0.40, g2)
        gradient.setColorAt(1.0, g3)

        return QBrush(gradient)
Exemple #25
0
    def draw_square(painter, x, y, size, color):
        """draws a square of a shape"""
        color = QColor(color)
        painter.fillRect(x + 1, y + 1, size[1] - 2,
                         size[0] - 2, color)

        painter.setPen(color.lighter())
        painter.drawLine(x, y + size[0] - 1, x, y)
        painter.drawLine(x, y, x + size[1] - 1, y)

        painter.setPen(color.darker())
        painter.drawLine(x + 1, y + size[0] - 1,
                         x + size[1] - 1, y + size[0] - 1)
        painter.drawLine(x + size[1] - 1,
                         y + size[0] - 1, x + size[1] - 1, y + 1)
Exemple #26
0
    def drawBlock(self, painter, x, y, c):
        w = self.size
        h = self.size
        x = self.size * x + self.offset
        y = self.size * y + self.offset
        color = QColor(c)
        painter.fillRect(x + 1, y + 1, w - 2, h - 2, color)

        painter.setPen(color.lighter())
        painter.drawLine(x, y + h - 1, x, y)
        painter.drawLine(x, y, x + w - 1, y)

        painter.setPen(color.darker())
        painter.drawLine(x + 1, y + h - 1, x + w - 1, y + h - 1)
        painter.drawLine(x + w - 1, y + h - 1, x + w - 1, y + 1)
Exemple #27
0
def format(color, style='', darker=100, lighter=100):
    """Return a QTextCharFormat with the given attributes.
    """
    _color = QColor(color)
    _color = _color.darker(darker)
    _color = _color.lighter(lighter)

    _format = QTextCharFormat()
    _format.setForeground(_color)
    if 'bold' in style:
        _format.setFontWeight(QFont.Bold)
    if 'italic' in style:
        _format.setFontItalic(True)

    return _format
    def paint(self, painter, option, index):
        hasValue = True
        if (self.m_editorPrivate):
            property = self.m_editorPrivate.indexToProperty(index)
            if (property):
                hasValue = property.hasValue()

        opt = QStyleOptionViewItem(option)
        if ((self.m_editorPrivate and index.column() == 0) or not hasValue):
            property = self.m_editorPrivate.indexToProperty(index)
            if (property and property.isModified()):
                opt.font.setBold(True)
                opt.fontMetrics = QFontMetrics(opt.font)

        c = QColor()
        if (not hasValue and self.m_editorPrivate.markPropertiesWithoutValue()):
            c = opt.palette.color(QPalette.Dark)
            opt.palette.setColor(QPalette.Text, opt.palette.color(QPalette.BrightText))
        else:
            c = self.m_editorPrivate.calculatedBackgroundColor(self.m_editorPrivate.indexToBrowserItem(index))
            if (c.isValid() and (opt.features & QStyleOptionViewItem.Alternate)):
                c = c.lighter(112)

        if (c.isValid()):
            painter.fillRect(option.rect, c)
        opt.state &= ~QStyle.State_HasFocus

        if (index.column() == 1):
            item = self.m_editorPrivate.indexToItem(index)
            if (self.m_editedItem and (self.m_editedItem == item)):
                self.m_disablePainting = True

        super(QtPropertyEditorDelegate, self).paint(painter, opt, index)
        if (option.type):
            self.m_disablePainting = False

        opt.palette.setCurrentColorGroup(QPalette.Active)
        color = QApplication.style().styleHint(QStyle.SH_Table_GridLineColor, opt)
        painter.save()
        painter.setPen(QPen(color))
        if (not self.m_editorPrivate or (not self.m_editorPrivate.lastColumn(index.column()) and hasValue)):
            if option.direction == Qt.LeftToRight:
                right = option.rect.right()
            else:
                right = option.rect.left()
            painter.drawLine(right, option.rect.y(), right, option.rect.bottom())

        painter.restore()
Exemple #29
0
    def painter_square(self, qp, x, y, width, height, shape_type):
        # 根据长宽和起始地点画框
        x *= self.every_square_per_width()
        y *= self.every_square_per_height()
        width *= self.every_square_per_width()
        height *= self.every_square_per_height()

        color = QColor(ShapeType.Shape_Colors[shape_type])
        qp.fillRect(x + 1, y + 1, width - 1, height - 2, color)

        qp.setPen(color.lighter())
        qp.drawLine(x, y, x + width - 1, y)
        qp.drawLine(x, y, x, y + height - 1)
        qp.setPen(color.darker())
        qp.drawLine(x + width - 1, y + 1, x + width - 1, y + height - 1)
        qp.drawLine(x + 1, y + height - 1, x + width - 1, y + height - 1)
Exemple #30
0
def drawSquare(painter, x, y, val, s):
    colorTable = [0x000000, 0xCC6666, 0x66CC66, 0x6666CC,
                  0xCCCC66, 0xCC66CC, 0x66CCCC, 0xDAAA00, 0xFFFFFF]
    if val == 0:
        return
        
    color = QColor(colorTable[val])
    painter.fillRect(x + 1, y + 1, s - 2, s - 2, color)

    painter.setPen(color.lighter())
    painter.drawLine(x, y + s - 1, x, y)
    painter.drawLine(x, y, x + s - 1, y)

    painter.setPen(color.darker())
    painter.drawLine(x + 1, y + s - 1, x + s - 1, y + s - 1)
    painter.drawLine(x + s - 1, y + s - 1, x + s - 1, y + 1)
Exemple #31
0
class NodeUIScene(QGraphicsScene):
    def __init__(self, parent=None):
        QGraphicsScene.__init__(self, parent)

        self._backgroundColor = QColor(50, 55, 60)
        self._gridPen = QPen(self._backgroundColor.lighter(120))
        self._gridPen.setWidth(1)
        self._zoom = 1.0

        self.setItemIndexMethod(
            QGraphicsScene.NoIndex)  # fixes bug with scene.removeItem()
        self.setBackgroundBrush(self._backgroundColor)
        self.setStickyFocus(True)

    def zoom(self):
        return self._zoom

    def setZoom(self, zoom):
        self._zoom = zoom

    def helpEvent(self, event):
        QGraphicsScene.helpEvent(self, event)

    def mouseReleaseEvent(self, event):
        QGraphicsScene.mouseReleaseEvent(self, event)

    def drawBackground(self, painter, rect):
        if not isinstance(painter, QPainter):
            return

        QGraphicsScene.drawBackground(self, painter, rect)
        painter.setPen(self._gridPen)

        grid_size = 50

        left = int(rect.left()) - (int(rect.left()) % grid_size)
        top = int(rect.top()) - (int(rect.top()) % grid_size)

        x = left
        while x < rect.right():
            painter.drawLine(x, rect.top(), x, rect.bottom())
            x += grid_size

        y = top
        while y < rect.bottom():
            painter.drawLine(rect.left(), y, rect.right(), y)
            y += grid_size
Exemple #32
0
    def _refresh_colors(self):
        """
        Refresh elements in the node
        """
        # color around ellipse
        outline_color = QColor('grey')
        outline_style = Qt.SolidLine
        outline_width = 1
        if self.status_wallet:
            outline_width = 2
        if not self.status_member:
            outline_color = QColor('red')

        if self.status_sentry:
            outline_color = QColor('black')
            outline_width = 3

        self.setPen(QPen(outline_color, outline_width, outline_style))

        if self.highlighted:
            text_color = QColor('grey')
        else:
            text_color = QColor('black')

        if self.status_wallet == NodeStatus.HIGHLIGHTED:
            text_color = QColor('grey')

        if self.text_item:
            self.text_item.setBrush(QBrush(text_color))

        # create gradient inside the ellipse
        gradient = QRadialGradient(
            QPointF(0,
                    self.boundingRect().height() / 4),
            self.boundingRect().width())
        color = QColor()
        color.setHsv(120 - 60 / self.steps_max * self.steps,
                     180 + 50 / self.steps_max * self.steps,
                     60 + 170 / self.steps_max * self.steps)
        if self.highlighted:
            color = color.darker(200)
        color = color.lighter(
            math.fabs(math.sin(self.loading_counter / 100 * math.pi) * 100) +
            100)
        gradient.setColorAt(0, color)
        gradient.setColorAt(1, color.darker(150))
        self.setBrush(QBrush(gradient))
Exemple #33
0
def drawSquare(painter, x, y, val, s):
    colorTable = [0x000000, 0xCC6666, 0x66CC66, 0x6666CC,
                  0xCCCC66, 0xCC66CC, 0x66CCCC, 0xDAAA00]

    if val == 0:
        return

    color = QColor(colorTable[val])
    painter.fillRect(x + 1, y + 1, s - 2, s - 2, color)

    painter.setPen(color.lighter())
    painter.drawLine(x, y + s - 1, x, y)
    painter.drawLine(x, y, x + s - 1, y)

    painter.setPen(color.darker())
    painter.drawLine(x + 1, y + s - 1, x + s - 1, y + s - 1)
    painter.drawLine(x + s - 1, y + s - 1, x + s - 1, y + 1)
Exemple #34
0
    def drawSquare(self, painter, x, y, shape):
        colorTable = [0x000000, 0xCC6666, 0x66CC66, 0x6666CC,
                      0xCCCC66, 0xCC66CC, 0x66CCCC, 0xDAAA00]

        color = QColor(colorTable[shape])
        painter.fillRect(x + 1, y + 1, self.squareWidth() - 2,
                self.squareHeight() - 2, color)

        painter.setPen(color.lighter())
        painter.drawLine(x, y + self.squareHeight() - 1, x, y)
        painter.drawLine(x, y, x + self.squareWidth() - 1, y)

        painter.setPen(color.darker())
        painter.drawLine(x + 1, y + self.squareHeight() - 1,
                x + self.squareWidth() - 1, y + self.squareHeight() - 1)
        painter.drawLine(x + self.squareWidth() - 1,
                y + self.squareHeight() - 1, x + self.squareWidth() - 1, y + 1)
Exemple #35
0
 def updateColor(self, item):
     pixmap = QPixmap(16, 16)
     color = QColor()
     if item:
         color = item.backgroundColor()
     if not color.isValid():
         color = self.palette().base().color()
     painter = QPainter(pixmap)
     painter.fillRect(0, 0, 16, 16, color)
     lighter = color.lighter()
     painter.setPen(lighter)
     # light frame
     painter.drawPolyline(QPoint(0, 15), QPoint(0, 0), QPoint(15, 0))
     painter.setPen(color.darker())
     # dark frame
     painter.drawPolyline(QPoint(1, 15), QPoint(15, 15), QPoint(15, 1))
     painter.end()
     self.colorAction.setIcon(QIcon(pixmap))
Exemple #36
0
    def make_labels(self, target):
        """ Create labels for the web nodes in 'source'; if not defined,
        find all visible anchor nodes first

        TODO pass a color? for 'title' tags

        NAV11 DOM01

        """

        if target == "links":
            source = self.__find_visible(navigables=True)
            self.attr.clear('find_titles')
        elif target == "titles":
            source = self.__find_visible(navigables=False)
            self.attr.insert('find_titles')

        self.map_tags = dict(zip(ALL_TAGS, source))

        for tag, node in self.map_tags.items():
            label = QLabel(tag, parent=self)
            self.__labels.append(label)

            palette = QToolTip.palette()

            color = QColor(Qt.yellow)

            color = color.lighter(160)
            color.setAlpha(196)
            palette.setColor(QPalette.Window, color)

            label.setPalette(palette)
            label.setAutoFillBackground(True)
            label.setFrameStyle(QFrame.Box | QFrame.Plain)

            point = QPoint(
                node.geometry().left(),
                node.geometry().center().y())
            point -= self.page().mainFrame().scrollPosition()
            label.move(point)
            label.show()
            label.move(label.x(), label.y() + label.height() // 4)
Exemple #37
0
    def __init__(self, parent=None):
        super(NotifyLabel, self).__init__(parent)

        print("NOTIFYLABEL", self, parent)

        palette = QToolTip.palette()
        color = QColor(Qt.blue)
        color = color.lighter(170)
        color.setAlpha(128)
        palette.setColor(QPalette.Window, color)

        self.setPalette(palette)
        self.setAutoFillBackground(True)
        self.setFrameStyle(QFrame.Box | QFrame.Plain)

        self.setFont(QFont(None, 20, QFont.Bold))

        self.hide()

        self.content = deque(maxlen=4)
Exemple #38
0
    def _refresh_colors(self):
        """
        Refresh elements in the node
        """
        # color around ellipse
        outline_color = QColor('black')
        outline_style = Qt.SolidLine
        outline_width = 1
        if self.status_wallet:
            outline_color = QColor('grey')
            outline_width = 2
        if not self.status_member:
            outline_color = QColor('red')
            outline_style = Qt.SolidLine
        self.setPen(QPen(outline_color, outline_width, outline_style))

        if self.highlighted:
            text_color = QColor('grey')
        else:
            text_color = QColor('black')

        if self.status_wallet == NodeStatus.HIGHLIGHTED:
            text_color = QColor('grey')
        self.text_item.setBrush(QBrush(text_color))

        # create gradient inside the ellipse
        gradient = QRadialGradient(QPointF(0, self.boundingRect().height() / 4), self.boundingRect().width())
        color = QColor()
        color.setHsv(120 - 60 / self.steps_max * self.steps,
                     180 + 50 / self.steps_max * self.steps,
                     60 + 170 / self.steps_max * self.steps)
        if self.highlighted:
            color = color.darker(200)
        color = color.lighter(math.fabs(math.sin(self.loading_counter / 100 * math.pi) * 100) + 100)
        gradient.setColorAt(0, color)
        gradient.setColorAt(1, color.darker(150))
        self.setBrush(QBrush(gradient))
Exemple #39
0
    def mouseMoveEvent(self, event):
        """When normal selection, update power spectrum with current selection.
        Otherwise, show the range of the new marker.
        """
        if not self.scene:
            return

        if self.idx_sel in self.scene.items():
            self.scene.removeItem(self.idx_sel)
            self.idx_sel = None

        chk_marker = self.parent.notes.action['new_bookmark'].isChecked()
        chk_event = self.parent.notes.action['new_event'].isChecked()

        if chk_marker or chk_event:
            xy_scene = self.mapToScene(event.pos())
            y_distance = self.parent.value('y_distance')
            pos = QRectF(self.sel_xy[0],
                         0,
                         xy_scene.x() - self.sel_xy[0],
                         len(self.idx_label) * y_distance)
            item = QGraphicsRectItem(pos.normalized())
            item.setPen(NoPen)

            if chk_marker:
                color = QColor(self.parent.value('annot_bookmark_color'))

            elif chk_event:
                eventtype = self.parent.notes.idx_eventtype.currentText()
                color = convert_name_to_color(eventtype)

            item.setBrush(QBrush(color.lighter(115)))
            item.setZValue(-10)
            self.scene.addItem(item)
            self.idx_sel = item
            return

        xy_scene = self.mapToScene(event.pos())
        pos = QRectF(self.sel_xy[0], self.sel_xy[1],
                     xy_scene.x() - self.sel_xy[0],
                     xy_scene.y() - self.sel_xy[1])
        self.idx_sel = QGraphicsRectItem(pos.normalized())
        self.idx_sel.setPen(QPen(QColor(LINE_COLOR), LINE_WIDTH))
        self.scene.addItem(self.idx_sel)

        if self.idx_info in self.scene.items():
            self.scene.removeItem(self.idx_info)

        duration = '{0:0.2f}s'.format(abs(xy_scene.x() - self.sel_xy[0]))

        # get y-size, based on scaling too
        y = abs(xy_scene.y() - self.sel_xy[1])
        scale = self.parent.value('y_scale') * self.chan_scale[self.sel_chan]
        height = '{0:0.3f}uV'.format(y / scale)

        item = TextItem_with_BG()
        item.setText(duration + ' ' + height)
        item.setPos(self.sel_xy[0], self.sel_xy[1])
        self.scene.addItem(item)
        self.idx_info = item

        trial = 0
        time = self.parent.traces.data.axis['time'][trial]
        beg_win = min((self.sel_xy[0], xy_scene.x()))
        end_win = max((self.sel_xy[0], xy_scene.x()))
        time_of_interest = time[(time >= beg_win) & (time < end_win)]
        if len(time_of_interest) > MINIMUM_N_SAMPLES:
            data = self.parent.traces.data(trial=trial,
                                           chan=self.chan[self.sel_chan],
                                           time=time_of_interest)
            n_data = len(data)
            n_pad = (power(2, ceil(log2(n_data))) - n_data) / 2
            data = pad(data, (int(ceil(n_pad)), int(floor(n_pad))), 'constant')

            self.parent.spectrum.display(data)
Exemple #40
0
class PixmapDial(QDial):
    # enum CustomPaintMode
    CUSTOM_PAINT_MODE_NULL        = 0 # default (NOTE: only this mode has label gradient)
    CUSTOM_PAINT_MODE_CARLA_WET   = 1 # color blue-green gradient (reserved #3)
    CUSTOM_PAINT_MODE_CARLA_VOL   = 2 # color blue (reserved #3)
    CUSTOM_PAINT_MODE_CARLA_L     = 3 # color yellow (reserved #4)
    CUSTOM_PAINT_MODE_CARLA_R     = 4 # color yellow (reserved #4)
    CUSTOM_PAINT_MODE_CARLA_PAN   = 5 # color yellow (reserved #3)
    CUSTOM_PAINT_MODE_COLOR       = 6 # color, selectable (reserved #3)
    CUSTOM_PAINT_MODE_ZITA        = 7 # custom zita knob (reserved #6)
    CUSTOM_PAINT_MODE_NO_GRADIENT = 8 # skip label gradient

    # enum Orientation
    HORIZONTAL = 0
    VERTICAL   = 1

    HOVER_MIN = 0
    HOVER_MAX = 9

    MODE_DEFAULT = 0
    MODE_LINEAR = 1

    # signals
    realValueChanged = pyqtSignal(float)

    def __init__(self, parent, index=0):
        QDial.__init__(self, parent)

        self.fDialMode = self.MODE_LINEAR

        self.fMinimum   = 0.0
        self.fMaximum   = 1.0
        self.fRealValue = 0.0
        self.fPrecision = 10000
        self.fIsInteger = False

        self.fIsHovered = False
        self.fIsPressed = False
        self.fHoverStep = self.HOVER_MIN

        self.fLastDragPos = None
        self.fLastDragValue = 0.0

        self.fIndex     = index
        self.fPixmap    = QPixmap(":/bitmaps/dial_01d.png")
        self.fPixmapNum = "01"

        if self.fPixmap.width() > self.fPixmap.height():
            self.fPixmapOrientation = self.HORIZONTAL
        else:
            self.fPixmapOrientation = self.VERTICAL

        self.fLabel     = ""
        self.fLabelPos  = QPointF(0.0, 0.0)
        self.fLabelFont = QFont(self.font())
        self.fLabelFont.setPixelSize(8)
        self.fLabelWidth  = 0
        self.fLabelHeight = 0

        if self.palette().window().color().lightness() > 100:
            # Light background
            c = self.palette().dark().color()
            self.fLabelGradientColor1 = c
            self.fLabelGradientColor2 = QColor(c.red(), c.green(), c.blue(), 0)
            self.fLabelGradientColorT = [self.palette().buttonText().color(), self.palette().mid().color()]
        else:
            # Dark background
            self.fLabelGradientColor1 = QColor(0, 0, 0, 255)
            self.fLabelGradientColor2 = QColor(0, 0, 0, 0)
            self.fLabelGradientColorT = [Qt.white, Qt.darkGray]

        self.fLabelGradient = QLinearGradient(0, 0, 0, 1)
        self.fLabelGradient.setColorAt(0.0, self.fLabelGradientColor1)
        self.fLabelGradient.setColorAt(0.6, self.fLabelGradientColor1)
        self.fLabelGradient.setColorAt(1.0, self.fLabelGradientColor2)

        self.fLabelGradientRect = QRectF(0.0, 0.0, 0.0, 0.0)

        self.fCustomPaintMode  = self.CUSTOM_PAINT_MODE_NULL
        self.fCustomPaintColor = QColor(0xff, 0xff, 0xff)

        self.updateSizes()

        # Fake internal value, custom precision
        QDial.setMinimum(self, 0)
        QDial.setMaximum(self, self.fPrecision)
        QDial.setValue(self, 0)

        self.valueChanged.connect(self.slot_valueChanged)

    def getIndex(self):
        return self.fIndex

    def getBaseSize(self):
        return self.fPixmapBaseSize

    def forceWhiteLabelGradientText(self):
        self.fLabelGradientColor1 = QColor(0, 0, 0, 255)
        self.fLabelGradientColor2 = QColor(0, 0, 0, 0)
        self.fLabelGradientColorT = [Qt.white, Qt.darkGray]

    def setLabelColor(self, enabled, disabled):
        self.fLabelGradientColor1 = QColor(0, 0, 0, 255)
        self.fLabelGradientColor2 = QColor(0, 0, 0, 0)
        self.fLabelGradientColorT = [enabled, disabled]

    def updateSizes(self):
        self.fPixmapWidth  = self.fPixmap.width()
        self.fPixmapHeight = self.fPixmap.height()

        if self.fPixmapWidth < 1:
            self.fPixmapWidth = 1

        if self.fPixmapHeight < 1:
            self.fPixmapHeight = 1

        if self.fPixmapOrientation == self.HORIZONTAL:
            self.fPixmapBaseSize    = self.fPixmapHeight
            self.fPixmapLayersCount = self.fPixmapWidth / self.fPixmapHeight
        else:
            self.fPixmapBaseSize    = self.fPixmapWidth
            self.fPixmapLayersCount = self.fPixmapHeight / self.fPixmapWidth

        self.setMinimumSize(self.fPixmapBaseSize, self.fPixmapBaseSize + self.fLabelHeight + 5)
        self.setMaximumSize(self.fPixmapBaseSize, self.fPixmapBaseSize + self.fLabelHeight + 5)

        if not self.fLabel:
            self.fLabelHeight = 0
            self.fLabelWidth  = 0
            return

        self.fLabelWidth  = QFontMetrics(self.fLabelFont).width(self.fLabel)
        self.fLabelHeight = QFontMetrics(self.fLabelFont).height()

        self.fLabelPos.setX(float(self.fPixmapBaseSize)/2.0 - float(self.fLabelWidth)/2.0)

        if self.fPixmapNum in ("01", "02", "07", "08", "09", "10"):
            self.fLabelPos.setY(self.fPixmapBaseSize + self.fLabelHeight)
        elif self.fPixmapNum in ("11",):
            self.fLabelPos.setY(self.fPixmapBaseSize + self.fLabelHeight*2/3)
        else:
            self.fLabelPos.setY(self.fPixmapBaseSize + self.fLabelHeight/2)

        self.fLabelGradient.setStart(0, float(self.fPixmapBaseSize)/2.0)
        self.fLabelGradient.setFinalStop(0, self.fPixmapBaseSize + self.fLabelHeight + 5)

        self.fLabelGradientRect = QRectF(float(self.fPixmapBaseSize)/8.0, float(self.fPixmapBaseSize)/2.0, float(self.fPixmapBaseSize*3)/4.0, self.fPixmapBaseSize+self.fLabelHeight+5)

    def setCustomPaintMode(self, paintMode):
        if self.fCustomPaintMode == paintMode:
            return

        self.fCustomPaintMode = paintMode
        self.update()

    def setCustomPaintColor(self, color):
        if self.fCustomPaintColor == color:
            return

        self.fCustomPaintColor = color
        self.update()

    def setLabel(self, label):
        if self.fLabel == label:
            return

        self.fLabel = label
        self.updateSizes()
        self.update()

    def setIndex(self, index):
        self.fIndex = index

    def setPixmap(self, pixmapId):
        self.fPixmapNum = "%02i" % pixmapId
        self.fPixmap.load(":/bitmaps/dial_%s%s.png" % (self.fPixmapNum, "" if self.isEnabled() else "d"))

        if self.fPixmap.width() > self.fPixmap.height():
            self.fPixmapOrientation = self.HORIZONTAL
        else:
            self.fPixmapOrientation = self.VERTICAL

        # special pixmaps
        if self.fCustomPaintMode == self.CUSTOM_PAINT_MODE_NULL:
            # reserved for carla-wet, carla-vol, carla-pan and color
            if self.fPixmapNum == "03":
                self.fCustomPaintMode = self.CUSTOM_PAINT_MODE_COLOR

            # reserved for carla-L and carla-R
            elif self.fPixmapNum == "04":
                self.fCustomPaintMode = self.CUSTOM_PAINT_MODE_CARLA_L

            # reserved for zita
            elif self.fPixmapNum == "06":
                self.fCustomPaintMode = self.CUSTOM_PAINT_MODE_ZITA

        self.updateSizes()
        self.update()

    def setPrecision(self, value, isInteger):
        self.fPrecision = value
        self.fIsInteger = isInteger
        QDial.setMaximum(self, value)

    def setMinimum(self, value):
        self.fMinimum = value

    def setMaximum(self, value):
        self.fMaximum = value

    def setValue(self, value, emitSignal=False):
        if self.fRealValue == value:
            return

        if value <= self.fMinimum:
            qtValue = 0
            self.fRealValue = self.fMinimum

        elif value >= self.fMaximum:
            qtValue = self.fPrecision
            self.fRealValue = self.fMaximum

        else:
            qtValue = round(float(value - self.fMinimum) / float(self.fMaximum - self.fMinimum) * self.fPrecision)
            self.fRealValue = value

        # Block change signal, we'll handle it ourselves
        self.blockSignals(True)
        QDial.setValue(self, qtValue)
        self.blockSignals(False)

        if emitSignal:
            self.realValueChanged.emit(self.fRealValue)

    @pyqtSlot(int)
    def slot_valueChanged(self, value):
        self.fRealValue = float(value)/self.fPrecision * (self.fMaximum - self.fMinimum) + self.fMinimum
        self.realValueChanged.emit(self.fRealValue)

    @pyqtSlot()
    def slot_updatePixmap(self):
        self.setPixmap(int(self.fPixmapNum))

    def minimumSizeHint(self):
        return QSize(self.fPixmapBaseSize, self.fPixmapBaseSize)

    def sizeHint(self):
        return QSize(self.fPixmapBaseSize, self.fPixmapBaseSize)

    def changeEvent(self, event):
        QDial.changeEvent(self, event)

        # Force pixmap update if enabled state changes
        if event.type() == QEvent.EnabledChange:
            self.setPixmap(int(self.fPixmapNum))

    def enterEvent(self, event):
        self.fIsHovered = True
        if self.fHoverStep == self.HOVER_MIN:
            self.fHoverStep = self.HOVER_MIN + 1
        QDial.enterEvent(self, event)

    def leaveEvent(self, event):
        self.fIsHovered = False
        if self.fHoverStep == self.HOVER_MAX:
            self.fHoverStep = self.HOVER_MAX - 1
        QDial.leaveEvent(self, event)

    def mousePressEvent(self, event):
        if self.fDialMode == self.MODE_DEFAULT:
            return QDial.mousePressEvent(self, event)

        if event.button() == Qt.LeftButton:
            self.fIsPressed = True
            self.fLastDragPos = event.pos()
            self.fLastDragValue = self.fRealValue

    def mouseMoveEvent(self, event):
        if self.fDialMode == self.MODE_DEFAULT:
            return QDial.mouseMoveEvent(self, event)

        if not self.fIsPressed:
            return

        range = (self.fMaximum - self.fMinimum) / 4.0
        pos   = event.pos()
        dx    = range * float(pos.x() - self.fLastDragPos.x()) / self.width()
        dy    = range * float(pos.y() - self.fLastDragPos.y()) / self.height()
        value = self.fLastDragValue + dx - dy

        if value < self.fMinimum:
            value = self.fMinimum
        elif value > self.fMaximum:
            value = self.fMaximum
        elif self.fIsInteger:
            value = float(round(value))

        self.setValue(value, True)

    def mouseReleaseEvent(self, event):
        if self.fDialMode == self.MODE_DEFAULT:
            return QDial.mouseReleaseEvent(self, event)

        if self.fIsPressed:
            self.fIsPressed = False

    def paintEvent(self, event):
        painter = QPainter(self)
        event.accept()

        painter.save()
        painter.setRenderHint(QPainter.Antialiasing, True)

        if self.fLabel:
            if self.fCustomPaintMode == self.CUSTOM_PAINT_MODE_NULL:
                painter.setPen(self.fLabelGradientColor2)
                painter.setBrush(self.fLabelGradient)
                painter.drawRect(self.fLabelGradientRect)

            painter.setFont(self.fLabelFont)
            painter.setPen(self.fLabelGradientColorT[0 if self.isEnabled() else 1])
            painter.drawText(self.fLabelPos, self.fLabel)

        if self.isEnabled():
            normValue = float(self.fRealValue - self.fMinimum) / float(self.fMaximum - self.fMinimum)
            target    = QRectF(0.0, 0.0, self.fPixmapBaseSize, self.fPixmapBaseSize)

            curLayer = int((self.fPixmapLayersCount - 1) * normValue)

            if self.fPixmapOrientation == self.HORIZONTAL:
                xpos = self.fPixmapBaseSize * curLayer
                ypos = 0.0
            else:
                xpos = 0.0
                ypos = self.fPixmapBaseSize * curLayer

            source = QRectF(xpos, ypos, self.fPixmapBaseSize, self.fPixmapBaseSize)
            painter.drawPixmap(target, self.fPixmap, source)

            # Custom knobs (Dry/Wet and Volume)
            if self.fCustomPaintMode in (self.CUSTOM_PAINT_MODE_CARLA_WET, self.CUSTOM_PAINT_MODE_CARLA_VOL):
                # knob color
                colorGreen = QColor(0x5D, 0xE7, 0x3D).lighter(100 + self.fHoverStep*6)
                colorBlue  = QColor(0x3E, 0xB8, 0xBE).lighter(100 + self.fHoverStep*6)

                # draw small circle
                ballRect = QRectF(8.0, 8.0, 15.0, 15.0)
                ballPath = QPainterPath()
                ballPath.addEllipse(ballRect)
                #painter.drawRect(ballRect)
                tmpValue  = (0.375 + 0.75*normValue)
                ballValue = tmpValue - floor(tmpValue)
                ballPoint = ballPath.pointAtPercent(ballValue)

                # draw arc
                startAngle = 216*16
                spanAngle  = -252*16*normValue

                if self.fCustomPaintMode == self.CUSTOM_PAINT_MODE_CARLA_WET:
                    painter.setBrush(colorBlue)
                    painter.setPen(QPen(colorBlue, 0))
                    painter.drawEllipse(QRectF(ballPoint.x(), ballPoint.y(), 2.2, 2.2))

                    gradient = QConicalGradient(15.5, 15.5, -45)
                    gradient.setColorAt(0.0,   colorBlue)
                    gradient.setColorAt(0.125, colorBlue)
                    gradient.setColorAt(0.625, colorGreen)
                    gradient.setColorAt(0.75,  colorGreen)
                    gradient.setColorAt(0.76,  colorGreen)
                    gradient.setColorAt(1.0,   colorGreen)
                    painter.setBrush(gradient)
                    painter.setPen(QPen(gradient, 3))

                else:
                    painter.setBrush(colorBlue)
                    painter.setPen(QPen(colorBlue, 0))
                    painter.drawEllipse(QRectF(ballPoint.x(), ballPoint.y(), 2.2, 2.2))

                    painter.setBrush(colorBlue)
                    painter.setPen(QPen(colorBlue, 3))

                painter.drawArc(4.0, 4.0, 26.0, 26.0, startAngle, spanAngle)

            # Custom knobs (L and R)
            elif self.fCustomPaintMode in (self.CUSTOM_PAINT_MODE_CARLA_L, self.CUSTOM_PAINT_MODE_CARLA_R):
                # knob color
                color = QColor(0xAD, 0xD5, 0x48).lighter(100 + self.fHoverStep*6)

                # draw small circle
                ballRect = QRectF(7.0, 8.0, 11.0, 12.0)
                ballPath = QPainterPath()
                ballPath.addEllipse(ballRect)
                #painter.drawRect(ballRect)
                tmpValue  = (0.375 + 0.75*normValue)
                ballValue = tmpValue - floor(tmpValue)
                ballPoint = ballPath.pointAtPercent(ballValue)

                painter.setBrush(color)
                painter.setPen(QPen(color, 0))
                painter.drawEllipse(QRectF(ballPoint.x(), ballPoint.y(), 2.0, 2.0))

                # draw arc
                if self.fCustomPaintMode == self.CUSTOM_PAINT_MODE_CARLA_L:
                    startAngle = 216*16
                    spanAngle  = -252.0*16*normValue
                else:
                    startAngle = 324.0*16
                    spanAngle  = 252.0*16*(1.0-normValue)

                painter.setPen(QPen(color, 2))
                painter.drawArc(3.5, 4.5, 22.0, 22.0, startAngle, spanAngle)

            # Custom knobs (Color)
            elif self.fCustomPaintMode == self.CUSTOM_PAINT_MODE_COLOR:
                # knob color
                color = self.fCustomPaintColor.lighter(100 + self.fHoverStep*6)

                # draw small circle
                ballRect = QRectF(8.0, 8.0, 15.0, 15.0)
                ballPath = QPainterPath()
                ballPath.addEllipse(ballRect)
                tmpValue  = (0.375 + 0.75*normValue)
                ballValue = tmpValue - floor(tmpValue)
                ballPoint = ballPath.pointAtPercent(ballValue)

                # draw arc
                startAngle = 216*16
                spanAngle  = -252*16*normValue

                painter.setBrush(color)
                painter.setPen(QPen(color, 0))
                painter.drawEllipse(QRectF(ballPoint.x(), ballPoint.y(), 2.2, 2.2))

                painter.setBrush(color)
                painter.setPen(QPen(color, 3))
                painter.drawArc(4.0, 4.0, 26.0, 26.0, startAngle, spanAngle)

            # Custom knobs (Zita)
            elif self.fCustomPaintMode == self.CUSTOM_PAINT_MODE_ZITA:
                a = normValue * pi * 1.5 - 2.35
                r = 10.0
                x = 10.5
                y = 10.5
                x += r * sin(a)
                y -= r * cos(a)
                painter.setBrush(Qt.black)
                painter.setPen(QPen(Qt.black, 2))
                painter.drawLine(QPointF(11.0, 11.0), QPointF(x, y))

            # Custom knobs
            else:
                painter.restore()
                return

            if self.HOVER_MIN < self.fHoverStep < self.HOVER_MAX:
                self.fHoverStep += 1 if self.fIsHovered else -1
                QTimer.singleShot(20, self.update)

        else: # isEnabled()
            target = QRectF(0.0, 0.0, self.fPixmapBaseSize, self.fPixmapBaseSize)
            painter.drawPixmap(target, self.fPixmap, target)

        painter.restore()

    def resizeEvent(self, event):
        QDial.resizeEvent(self, event)
        self.updateSizes()
Exemple #41
0
class NGL_SeekBar(NGL_Base):
    """NGL_SeekBar(NGL_Base)
    Provides a embedded NGL library widget.
    """

    # order for NGL library page struct pointers order
    ngl_order = 4

    def __init__(self, parent=None):
        super(NGL_SeekBar, self).__init__(parent)

        self._max = 100
        self._min = 0
        self._level = 50
        self._orientation = Qt.Horizontal
        self._show_progress = True
        self._slider_size = QSize(8,8)
        self._slider_color = QColor(Qt.blue)

        self._eventsEnabled = True

        self.setGeometry(50, 50, 150, 15)
        self.setStyleSheet('color: rgb(64, 128, 64);')
        self.update()

    def paintEvent(self, event):
        p = QPainter()

        color = QStyleParser.getColor(self.styleSheet(), 'color: rgb')
        rect = self.geometry()

        # calc and draw respect orientation
        fullscale = self._max - self._min
        slider_size = self._slider_size

        p.begin(self)

        # calc slider respect orientation
        if self._orientation == Qt.Horizontal:
            posX = self._level * (rect.width() / fullscale)
            posY = rect.height() / 2

        else:
            posX = rect.width() / 2
            posY = rect.height() - ((self._level * rect.height()) / fullscale)

        # calc coordinates respect orientation
        rect_0, rect_1, color_0, color_1 = self._calcCoordinates(posX, posY, slider_size)

        # draw seekbar
        p.fillRect(rect_0, color_0)
        p.setPen(color_0)
        p.drawRect(rect_0)

        p.fillRect(rect_1, color_1)
        p.setPen(color_1)
        p.drawRect(rect_1)

        # draw slider
        for i in range(min(slider_size.width(), slider_size.height())):
            p.setPen(self._slider_color.lighter(100 + (i * 10)))
            p.drawRect(posX - (slider_size.width() - i) // 2,
                       posY - (slider_size.height() - i) // 2,
                       slider_size.width() - i,
                       slider_size.height() - i)

        p.end()

    def _calcCoordinates(self, posX, posY, slider_size):

        rect = self.geometry()
        color = QStyleParser.getColor(self.styleSheet(), 'color: rgb')
        color_0 = color.lighter(125)
        color_1 = color.lighter(125)

        if self._orientation == Qt.Horizontal:
            x0 = 0
            y0 = (rect.height() // 2) - 2
            w0 = (posX - slider_size.width() // 2) - 1
            h0 = 4

            x1 = (posX + slider_size.width() // 2) + 1
            y1 = y0
            w1 = rect.width() - x1
            h1 = 4

            if self._show_progress:
                color_0 = color.lighter(175)

        else:
            x0 = (rect.width() // 2) - 2
            y0 = 0
            w0 = 4
            h0 = (posY - slider_size.height() // 2) - 1

            x1 = x0
            y1 = (posY + slider_size.height() // 2) + 1
            w1 = 4
            h1 = rect.height() - y1

            if self._show_progress:
                color_1 = color.lighter(175)


        rect0 = QRect(x0, y0, w0, h0)
        rect1 = QRect(x1, y1, w1, h1)

        return (rect0, rect1, color_0, color_1)

    # Provide getter and setter methods for the property
    @pyqtProperty(int)
    def level(self):
        return self._level

    @level.setter
    def level(self, level):
        self._level = level
        self.update()

    # Provide getter and setter methods for the property.
    @pyqtProperty(int)
    def maximum(self):
        return self._max

    @maximum.setter
    def maximum(self, max):
        self._max = max
        self.update()

    # Provide getter and setter methods for the property.
    @pyqtProperty(int)
    def minimum(self):
        return self._min

    @minimum.setter
    def minimum(self, min):
        self._min = min
        self.update()

    # Provide getter and setter methods for the property.
    @pyqtProperty(Qt.Orientation)
    def orientation(self):
        return self._orientation

    @orientation.setter
    def orientation(self, _orientation):
        self._orientation = _orientation
        self.update()

    # Provide getter and setter methods for the property.
    @pyqtProperty(bool)
    def show_progress(self):
        return self._show_progress

    @show_progress.setter
    def show_progress(self, state):
        self._show_progress = state
        self.update()

    # Provide getter and setter methods for the property.
    @pyqtProperty(QSize)
    def slidersize(self):
        return self._slider_size

    @slidersize.setter
    def slidersize(self, size):

        if self.orientation == Qt.Horizontal:
            _size = QSize( size.width(), min( self.size().height(), size.height() ) )
        else:
            _size = QSize( min( self.size().width(), size.width() ), size.height() )

        self._slider_size = _size
        self.update()

    # Provide getter and setter methods for the property.
    @pyqtProperty(QColor)
    def slidercolor(self):
        return self._slider_color

    @slidercolor.setter
    def slidercolor(self, newcolor):
        self._slider_color = newcolor
        self.update()


    def doNGLCode(self, **kwargs):

        import pkg_resources

        res_path = pkg_resources.resource_filename('ngl_utils', 'templates/seekbar.ntp')
        with open(res_path, 'rt') as f:
            template = f.read()

        # convert coordinates
        g = self._ngl_geometry()

        # orientation
        ori = {1: 'NGL_Horizontal', 2: 'NGL_Vertical'}

        # slider
        if self.orientation == Qt.Horizontal:
            slider_size = self._slider_size.width()
        else:
            slider_size = self._slider_size.height()

        return template.format(
            pageName = self._ngl_parent_obj_name(),
            itemName = self.objectName(),
            x0 = g.x(),
            y0 = g.y(),
            x1 = g.x() + g.width() - 1,
            y1 = g.y() + g.height() - 1,
            slider_size = slider_size,
            old_posX = '(uint16_t)(65535)',
            old_posY = '(uint16_t)(65535)',
            VertHoriz = ori[self.orientation],
            Level_MIN = self.minimum,
            Level_MAX = self.maximum,
            Level = self.level,
            ShowProgress = self._show_progress,
            Color = self._ngl_color('color: rgb'),
            SliderColor = hex(NGL_Colors.fromQColor(self._slider_color)),
            p_event = self.clickEventName)

    @staticmethod
    def ngl_draw(**kwargs):
        s = 'NGL_GUI_DrawSeekBar({objects}[{index}]);'

        return s.format(
            objects = kwargs['name'],
            index = kwargs['index'])
Exemple #42
0
    def data(self, index, role):
        row = index.row()
        col = index.column()

        if not index.isValid():
            return QVariant()

        source_data = self.transfers_data[row][col]
        txhash_data = self.transfers_data[row][HistoryTableModel.columns_types.index('txhash')]
        state_data = self.transfers_data[row][HistoryTableModel.columns_types.index('state')]
        block_data = self.transfers_data[row][HistoryTableModel.columns_types.index('block_number')]

        if state_data == Transaction.VALIDATED and block_data:
            current_confirmations = self.blockchain_processor.current_buid(self.app.currency).number - block_data
        else:
            current_confirmations = 0

        if role == Qt.DisplayRole:
            if col == HistoryTableModel.columns_types.index('pubkey'):
                return "<p>" + source_data.replace('\n', "<br>") + "</p>"
            if col == HistoryTableModel.columns_types.index('date'):
                if txhash_data == STOPLINE_HASH:
                    return ""
                else:
                    ts = self.blockchain_processor.adjusted_ts(self.connection.currency, source_data)
                    return QLocale.toString(
                        QLocale(),
                        QDateTime.fromTime_t(ts).date(),
                        QLocale.dateFormat(QLocale(), QLocale.ShortFormat)
                    ) + " BAT"
            if col == HistoryTableModel.columns_types.index('amount'):
                if txhash_data == STOPLINE_HASH:
                    return ""
                else:
                    amount = self.app.current_ref.instance(source_data, self.connection.currency,
                                                           self.app, block_data).diff_localized(False, False)
                    return amount

            return source_data

        if role == Qt.FontRole:
            font = QFont()
            if txhash_data == STOPLINE_HASH:
                font.setItalic(True)
            else:
                if state_data == Transaction.AWAITING or \
                        (state_data == Transaction.VALIDATED and current_confirmations < MAX_CONFIRMATIONS):
                    font.setItalic(True)
                elif state_data == Transaction.REFUSED:
                    font.setItalic(True)
                elif state_data == Transaction.TO_SEND:
                    font.setBold(True)
                else:
                    font.setItalic(False)
            return font

        if role == Qt.ForegroundRole:
            color = None
            if state_data == Transaction.REFUSED:
                color = QColor(Qt.darkGray)
            elif state_data == Transaction.TO_SEND:
                color = QColor(Qt.blue)
            if col == HistoryTableModel.columns_types.index('amount'):
                if source_data < 0:
                    color = QColor(Qt.darkRed)
                elif state_data == HistoryTableModel.DIVIDEND:
                    color = QColor(Qt.darkBlue)
            if state_data == Transaction.AWAITING or \
                    (state_data == Transaction.VALIDATED and current_confirmations == 0):
                color = QColor("#ffb000")
            if color:
                if self.app.parameters.dark_theme:
                    return color.lighter(300)
                else:
                    return color

        if role == Qt.TextAlignmentRole:
            if HistoryTableModel.columns_types.index('amount'):
                return Qt.AlignRight | Qt.AlignVCenter
            if col == HistoryTableModel.columns_types.index('date'):
                return Qt.AlignCenter

        if role == Qt.ToolTipRole:
            if col == HistoryTableModel.columns_types.index('date'):
                ts = self.blockchain_processor.adjusted_ts(self.connection.currency, source_data)
                return QDateTime.fromTime_t(ts).toString(Qt.SystemLocaleLongDate)

            if state_data == Transaction.VALIDATED or state_data == Transaction.AWAITING:
                if current_confirmations >= MAX_CONFIRMATIONS:
                    return None
                elif self.app.parameters.expert_mode:
                    return self.tr("{0} / {1} confirmations").format(current_confirmations, MAX_CONFIRMATIONS)
                else:
                    confirmation = current_confirmations / MAX_CONFIRMATIONS * 100
                    confirmation = 100 if confirmation > 100 else confirmation
                    return self.tr("Confirming... {0} %").format(QLocale().toString(float(confirmation), 'f', 0))
Exemple #43
0
 def lighter(self, color: QColor) -> QColor:
     return color.lighter(110)