Exemplo n.º 1
0
 def drawPlotGrid(cls, axeSize, gradient=None):
     """
     Rerturns a QGraphicsPathItem initialized with
     a square grid.
     @param axeSize:
     @type axeSize:
     @param gradient:
     @type gradient
     @return:
     @rtype: QGraphicsPathItem
     """
     lineWidth = 1
     item = QGraphicsPathItem()
     if gradient is None:
         item.setPen(QPen(Qt.darkGray, lineWidth, Qt.DashLine))
     else:
         item.setPen(QPen(gradient, lineWidth, Qt.DashLine))
     qppath = QPainterPath()
     qppath.moveTo(QPoint(0, 0))
     qppath.lineTo(QPoint(axeSize, 0))
     qppath.lineTo(QPoint(axeSize, -axeSize))
     qppath.lineTo(QPoint(0, -axeSize))
     qppath.closeSubpath()
     qppath.lineTo(QPoint(axeSize, -axeSize))
     # draw grid
     for i in range(1, 5):
         a = (axeSize * i) / 4
         qppath.moveTo(a, -axeSize)
         qppath.lineTo(a, 0)
         qppath.moveTo(0, -a)
         qppath.lineTo(axeSize, -a)
     item.setPath(qppath)
     return item
Exemplo n.º 2
0
    def _make_connecting_path(self, guide_path):
        """Returns a 'thick' path connecting source and destination, by following the given 'guide' path.

        Args:
            guide_path (QPainterPath)

        Returns:
            QPainterPath
        """
        points, angles = self._points_and_angles_from_path(guide_path)
        outgoing_points = []
        incoming_points = []
        for point, angle in zip(points, angles):
            off = self._radius_from_point_and_angle(point, angle)
            outgoing_points.append(point + off)
            incoming_points.insert(0, point - off)
        p0 = guide_path.pointAtPercent(0)
        a0 = guide_path.angleAtPercent(0)
        off0 = self._radius_from_point_and_angle(p0, a0)
        curve_path = QPainterPath(p0 + off0)
        self._follow_points(curve_path, outgoing_points)
        curve_path.lineTo(incoming_points[0])
        self._follow_points(curve_path, incoming_points)
        curve_path.lineTo(p0 - off0)
        curve_path.closeSubpath()
        curve_path.setFillRule(Qt.WindingFill)
        return curve_path.simplified()
Exemplo n.º 3
0
    def draw_NI_minimalistic(painter, c, w, h, bounding_rect):
        """
        :param painter: painter from paint event
        :param c: color
        :param w: width
        :param h: height
        :param bounding_rect: NodeInstance's bounding rect
        """

        path = QPainterPath()
        path.moveTo(-w / 2, 0)

        path.cubicTo(-w / 2, -h / 2, -w / 2, -h / 2, 0, -h / 2)
        path.cubicTo(+w / 2, -h / 2, +w / 2, -h / 2, +w / 2, 0)
        path.cubicTo(+w / 2, +h / 2, +w / 2, +h / 2, 0, +h / 2)
        path.cubicTo(-w / 2, +h / 2, -w / 2, +h / 2, -w / 2, 0)
        path.closeSubpath()

        body_gradient = QLinearGradient(bounding_rect.bottomLeft(),
                                        bounding_rect.topRight())
        body_gradient.setColorAt(0, QColor(c.red(), c.green(), c.blue(), 150))
        body_gradient.setColorAt(1, QColor(c.red(), c.green(), c.blue(), 80))

        painter.setBrush(body_gradient)
        painter.setPen(QPen(QColor(30, 43, 48)))

        painter.drawPath(path)
Exemplo n.º 4
0
    def draw_tron_minimalistic(self,
                               painter,
                               background_color=QColor('#36383B')):
        path = QPainterPath()
        path.moveTo(-self.width / 2, 0)

        corner_size = 10
        path.lineTo(-self.width / 2 + corner_size / 2,
                    -self.height / 2 + corner_size / 2)
        path.lineTo(0, -self.height / 2)
        path.lineTo(+self.width / 2 - corner_size / 2,
                    -self.height / 2 + corner_size / 2)
        path.lineTo(+self.width / 2, 0)
        path.lineTo(+self.width / 2 - corner_size / 2,
                    +self.height / 2 - corner_size / 2)
        path.lineTo(0, +self.height / 2)
        path.lineTo(-self.width / 2 + corner_size / 2,
                    +self.height / 2 - corner_size / 2)
        path.closeSubpath()

        painter.setBrush(background_color)
        pen = QPen(self.parent_node.color)
        pen.setWidth(2)
        painter.setPen(pen)

        painter.drawPath(path)
Exemplo n.º 5
0
    def draw_NI_minimalistic(painter,
                             c,
                             w,
                             h,
                             background_color=QColor('#36383B')):
        """
        :param painter: painter from paint event
        :param c_s: corner size/corner radius
        :param c: color
        :param w: width
        :param h: height
        :param background_color: (default) background color
        """

        c_s = 10

        path = QPainterPath()
        path.moveTo(-w / 2, 0)

        path.lineTo(-w / 2 + c_s / 2, -h / 2 + c_s / 2)
        path.lineTo(0, -h / 2)
        path.lineTo(+w / 2 - c_s / 2, -h / 2 + c_s / 2)
        path.lineTo(+w / 2, 0)
        path.lineTo(+w / 2 - c_s / 2, +h / 2 - c_s / 2)
        path.lineTo(0, +h / 2)
        path.lineTo(-w / 2 + c_s / 2, +h / 2 - c_s / 2)
        path.closeSubpath()

        painter.setBrush(background_color)
        pen = QPen(c)
        pen.setWidth(2)
        painter.setPen(pen)

        painter.drawPath(path)
Exemplo n.º 6
0
    def draw_dark_minimalistic(self, painter):
        path = QPainterPath()
        path.moveTo(-self.width / 2, 0)

        path.cubicTo(-self.width / 2, -self.height / 2,
                     -self.width / 2, -self.height / 2,
                     0, -self.height / 2)
        path.cubicTo(+self.width / 2, -self.height / 2,
                     +self.width / 2, -self.height / 2,
                     +self.width / 2, 0)
        path.cubicTo(+self.width / 2, +self.height / 2,
                     +self.width / 2, +self.height / 2,
                     0, +self.height / 2)
        path.cubicTo(-self.width / 2, +self.height / 2,
                     -self.width / 2, +self.height / 2,
                     -self.width / 2, 0)
        path.closeSubpath()

        c = self.parent_node.color
        body_gradient = QLinearGradient(self.boundingRect().bottomLeft(),
                                        self.boundingRect().topRight())
        body_gradient.setColorAt(0, QColor(c.red(), c.green(), c.blue(), 150))
        body_gradient.setColorAt(1, QColor(c.red(), c.green(), c.blue(), 80))

        painter.setBrush(body_gradient)
        painter.setPen(QPen(QColor(30, 43, 48)))

        painter.drawPath(path)
Exemplo n.º 7
0
    def paint(self, painter, *args):
        super().paint(painter, *args)

        kind = self.desc.kind
        painter.setPen(QPen(Qt.black, 2))
        path = QPainterPath()
        r = self.rect()

        if kind == 'and':
            path.moveTo(r.topLeft())
            path.lineTo(r.center().x(), r.top())
            path.quadTo(r.topRight(), QPoint(r.right(), r.height() / 2))
            path.quadTo(r.bottomRight(), QPoint(r.width() / 2, r.bottom()))
            path.lineTo(r.bottomLeft())
            path.closeSubpath()
        elif kind == 'or':
            path.moveTo(r.topLeft())
            path.lineTo(r.width() / 4, r.top())
            path.quadTo(QPoint(r.width() / 4 * 3, r.top()),
                        QPoint(r.right(),
                               r.height() / 2))
            path.quadTo(QPoint(r.width() / 4 * 3, r.bottom()),
                        QPoint(r.width() / 4, r.bottom()))
            path.lineTo(r.bottomLeft())
            path.quadTo(r.center(), r.topLeft())

        painter.drawPath(path)
Exemplo n.º 8
0
def _generate_path(coord):
    path = QPainterPath()
    path.moveTo(*coord[0])
    path.lineTo(*coord[1])
    path.lineTo(*coord[2])
    path.lineTo(*coord[3])
    path.closeSubpath()
    return path
Exemplo n.º 9
0
 def get_extended_body_path_TRON_DESIGN(self, corner_size):
     path = QPainterPath()
     path.moveTo(+self.width/2, -self.height/2+corner_size)
     path.lineTo(+self.width/2-corner_size, -self.height/2)
     path.lineTo(-self.width/2+corner_size, -self.height/2)
     path.lineTo(-self.width/2, -self.height/2+corner_size)
     path.lineTo(-self.width/2, +self.height/2-corner_size)
     path.lineTo(-self.width/2+corner_size, +self.height/2)
     path.lineTo(+self.width/2-corner_size, +self.height/2)
     path.lineTo(+self.width/2, +self.height/2-corner_size)
     path.closeSubpath()
     return path
Exemplo n.º 10
0
    def paint(self, painter):
        painter.setPen(QPen(Qt.black, 2))
        painter.setBrush(Qt.white)

        path = QPainterPath()
        s = self.SIZE
        path.moveTo(QPoint())
        path.lineTo(QPoint(s.width() - 5, s.height() / 2))
        path.lineTo(QPoint(0, s.height()))
        path.closeSubpath()
        painter.drawPath(path)

        painter.drawEllipse(QPoint(s.width() - 2, s.height() / 2), 3, 3)
Exemplo n.º 11
0
 def get_extended_header_path_TRON_DESIGN(self, corner_size):
     header_height = 35 * (self.parent_node.title.count('\n')+1)
     header_bottom = -self.height/2+header_height
     path = QPainterPath()
     path.moveTo(+self.width/2, -self.height/2+corner_size)
     path.lineTo(+self.width/2-corner_size, -self.height/2)
     path.lineTo(-self.width/2+corner_size, -self.height/2)
     path.lineTo(-self.width/2, -self.height/2+corner_size)
     path.lineTo(-self.width/2, header_bottom-corner_size)
     path.lineTo(-self.width/2+corner_size, header_bottom)
     path.lineTo(+self.width/2-corner_size, header_bottom)
     path.lineTo(+self.width/2, header_bottom-corner_size)
     path.closeSubpath()
     return path
Exemplo n.º 12
0
    def paint(self, painter, *args):
        super().paint(painter, *args)

        painter.setPen(QPen(Qt.black, 2))
        painter.setBrush(Qt.white)

        path = QPainterPath()
        r = self.rect()
        path.moveTo(r.topLeft())
        path.lineTo(r.topRight() + QPointF(-5, r.height() / 2))
        path.lineTo(r.bottomLeft())
        path.closeSubpath()
        painter.drawPath(path)

        painter.drawEllipse(QPointF(r.right() - 5, r.height() / 2), 5, 5)
Exemplo n.º 13
0
    def get_extended_body_path_TRON_DESIGN(self, c_s, w, h):
        """
        :param c_s: corner size/corner radius
        :param w: width
        :param h: height
        """

        path = QPainterPath()
        path.moveTo(+w / 2, -h / 2 + c_s)
        path.lineTo(+w / 2 - c_s, -h / 2)
        path.lineTo(-w / 2 + c_s, -h / 2)
        path.lineTo(-w / 2, -h / 2 + c_s)
        path.lineTo(-w / 2, +h / 2 - c_s)
        path.lineTo(-w / 2 + c_s, +h / 2)
        path.lineTo(+w / 2 - c_s, +h / 2)
        path.lineTo(+w / 2, +h / 2 - c_s)
        path.closeSubpath()
        return path
Exemplo n.º 14
0
    def get_extended_body_path(c_s, w, h):
        """
        Very similar to 'extended tron'
        :param c_s: corner size/corner radius
        :param w: width
        :param h: height
        """

        path = QPainterPath()
        path.moveTo(+w / 2, -h / 2 + c_s)
        path.lineTo(+w / 2 - c_s, -h / 2)
        path.lineTo(-w / 2 + c_s, -h / 2)
        path.lineTo(-w / 2, -h / 2 + c_s)
        path.lineTo(-w / 2, +h / 2 - c_s)
        path.lineTo(-w / 2 + c_s, +h / 2)
        path.lineTo(+w / 2 - c_s, +h / 2)
        path.lineTo(+w / 2, +h / 2 - c_s)
        path.closeSubpath()
        return path
Exemplo n.º 15
0
    def get_extended_header_path_TRON_DESIGN(self, c_s, w, h):
        """
        :param c_s: corner size/corner radius
        :param w: width
        :param h: height
        """

        # header_height = 35 * (self.ni.parent_node.title.count('\n') + 1)
        header_height = self.get_header_rect(w, h).height()
        header_bottom = -h / 2 + header_height
        path = QPainterPath()
        path.moveTo(+w / 2, -h / 2 + c_s)
        path.lineTo(+w / 2 - c_s, -h / 2)
        path.lineTo(-w / 2 + c_s, -h / 2)
        path.lineTo(-w / 2, -h / 2 + c_s)
        path.lineTo(-w / 2, header_bottom - c_s)
        path.lineTo(-w / 2 + c_s, header_bottom)
        path.lineTo(+w / 2 - c_s, header_bottom)
        path.lineTo(+w / 2, header_bottom - c_s)
        path.closeSubpath()
        return path
Exemplo n.º 16
0
 def drawChannelHistogram(painter, hist, bin_edges, color):
     # Draw histogram for a single channel.
     # param painter: QPainter
     # param hist: histogram to draw
     # smooth the histogram (first and last bins excepted) for a better visualization of clipping.
     # hist = np.concatenate(([hist[0]], SavitzkyGolayFilter.filter(hist[1:-1]), [hist[-1]]))
     # To emphasize significant values we clip the first bin to max height of the others
     M = max(hist[1: ])  # max(hist)  # max(hist[1:-1])
     imgH = size.height()
     # drawing  trapezia instead of rectangles to quickly "smooth" the histogram
     # the rightmost trapezium is not drawn
     poly = QPolygonF()
     poly.append(QPointF(range[0], imgH))  # bottom left point
     for i, y in enumerate(hist):
         try:
             h = imgH * y / M
             if np.isnan(h):
                 raise ValueError
         except (ValueError, ArithmeticError, FloatingPointError, ZeroDivisionError):
             # don't draw the histogram for this channel if M is too small
             return
         poly.append(QPointF((bin_edges[i] - range[0]) * scale, max(imgH - h, 0)))
         # clipping indicators
         if i == 0 or i == len(hist)-1:
             left = bin_edges[0 if i == 0 else -1] * scale
             left = left - (20 if i > 0 else 0)  # shift the indicator at right
             percent = hist[i] * (bin_edges[i+1]-bin_edges[i])
             if percent > clipping_threshold:
                 # set the color of the indicator according to percent value
                 nonlocal gPercent
                 gPercent = min(gPercent, np.clip((0.05 - percent) / 0.03, 0, 1))
                 painter.fillRect(left, 0, 10, 10, QColor(255, 255*gPercent, 0))
     # draw the filled polygon
     poly.append(QPointF(poly.constLast().x(), imgH))  # bottom right point
     path = QPainterPath()
     path.addPolygon(poly)
     path.closeSubpath()
     painter.setPen(Qt.NoPen)
     painter.fillPath(path, QBrush(color))
Exemplo n.º 17
0
    def _make_arrow_path(self, guide_path):
        """Returns an arrow path for the link's tip.

        Args:
            guide_path (QPainterPath): A narrow path connecting source and destination,
                used to determine the arrow orientation.

        Returns:
            QPainterPath
        """
        angle = self._get_joint_angle(guide_path)
        arrow_p0 = self.dst_center
        d1 = QPointF(sin(angle + self.arrow_angle), cos(angle + self.arrow_angle))
        d2 = QPointF(sin(angle + (pi - self.arrow_angle)), cos(angle + (pi - self.arrow_angle)))
        arrow_diag = self.magic_number / sin(self.arrow_angle)
        arrow_p1 = arrow_p0 - d1 * arrow_diag
        arrow_p2 = arrow_p0 - d2 * arrow_diag
        arrow_path = QPainterPath(arrow_p1)
        arrow_path.lineTo(arrow_p0)
        arrow_path.lineTo(arrow_p2)
        arrow_path.closeSubpath()
        return arrow_path
Exemplo n.º 18
0
    def get_extended_header_path(w, h, title_rect):
        """
        :param w: width
        :param h: height
        :param title_rect: NI's title label's bounding rect
        """
        c_s = 10

        # header_height = 35 * (NIPainter_DarkTron.ni.parent_node.title.count('\n') + 1)
        header_height = NIPainter_DarkTron.get_header_rect(
            w, h, title_rect).height()
        header_bottom = -h / 2 + header_height
        path = QPainterPath()
        path.moveTo(+w / 2, -h / 2 + c_s)
        path.lineTo(+w / 2 - c_s, -h / 2)
        path.lineTo(-w / 2 + c_s, -h / 2)
        path.lineTo(-w / 2, -h / 2 + c_s)
        path.lineTo(-w / 2, header_bottom - c_s)
        path.lineTo(-w / 2 + c_s, header_bottom)
        path.lineTo(+w / 2 - c_s, header_bottom)
        path.lineTo(+w / 2, header_bottom - c_s)
        path.closeSubpath()
        return path
Exemplo n.º 19
0
    series1.append(10, 2)

    series2.append(1, 5)
    series2.append(4, 6)
    series2.append(6, 3)
    series2.append(9, 5)

    starPath = QPainterPath()

    starPath.moveTo(28, 15)

    for i in range(5):
        starPath.lineTo(14 + 14 * math.cos(0.8 * i * math.pi),
                        15 + 14 * math.sin(0.8 * i * math.pi))

    starPath.closeSubpath()

    star = QImage(30, 30, QImage.Format_ARGB32)
    star.fill(Qt.transparent)
    painter = QPainter(star)
    painter.setRenderHint(QPainter.Antialiasing)
    painter.setPen(QColor.fromRgb(0xf6, 0xa6, 0x25))
    painter.setBrush(painter.pen().color())
    painter.drawPath(starPath)

    series2.setBrush(star)
    series2.setPen(QColor(Qt.transparent))

    chartView = QtCharts.QChartView(chart)

    chartView.setRenderHint(QPainter.Antialiasing)
Exemplo n.º 20
0
class wheel(QWidget):
    currentColorChanged = Signal(QColor)

    def __init__(self, parent=None):
        super(wheel, self).__init__(parent)
        self.setFixedSize(256, 256)

        # start, end angles for value arc
        self.s_ang, self.e_ang = 135, 225

        # offset angle and direction for color wheel
        self.o_ang, self.rot_d = 45, -1  # 1 for clock-wise, -1 for widdershins

        # other initializations
        self.pos = QPointF(-100, -100)
        self.vIdCen = QPointF(-100, -100)
        self.vIdAng = radians(self.s_ang)
        self.chPt = self.pos
        self.hue = self.sat = self.value = 255

        self.setup()
        self.pos = self.cWhBox.center()

        self._namedColorList = []
        self._namedColorPts = []
        self._showNames = False

        self.setMouseTracking(True)
        self.installEventFilter(self)

        self._startedTimer = False


##    def timerSpinner(self):
##        "won't this be fun"
##        self.o_ang -= 1; self.o_ang %= 360
##        stable = False
##
##        colWhl = QConicalGradient(self.cen, self.o_ang)
##        whl_cols = [Qt.red, Qt.magenta,
##                    Qt.blue, Qt.cyan, Qt.green,
##                    Qt.yellow, Qt.red]
##        for i, c in enumerate(whl_cols[::self.rot_d]):
##            colWhl.setColorAt(i / 6.0, c)
##
##        if stable:  # crosshairs stay on color
##            t = radians(self.hue + self.o_ang * -self.rot_d) * -self.rot_d
##            r = self.sat / 255.0 * self.cW_rad
##            x, y = r * cos(t) + self.cen.x(), r * -sin(t) + self.cen.y()
##            self.chPt = QPointF(x, y)
##        else:  # crosshairs stay on point
##            t = atan2(self.cen.y() - self.pos.y(), self.pos.x() - self.cen.x())
##            h = (int(degrees(t)) - self.o_ang) * -self.rot_d
##            self.hue = (h if h > 0 else h + 360) % 360
##            col = QColor(); col.setHsv(self.hue, self.sat, self.value)
##            self.currentColorChanged.emit(col)
##
##        self.cWhlBrush1 = QBrush(colWhl)
##        self.update()

    def resizeEvent(self, event):
        self.setup()  # re-construct the sizes
        self.setNamedColors(self._namedColorList)

    def getColor(self):
        col = QColor()
        col.setHsv(self.hue, self.sat, self.value)
        return col

    def setNamedColors(self, colorList):
        "sets list [(name, #html)] of named colors"
        self._namedColorList = colorList
        lst = []
        r2 = (self.vAoBox.width() + self.vAiBox.width()) / 4.0
        for i in self._namedColorList:
            h, s, v, a = QColor(i[1]).getHsv()

            t = radians(h + self.o_ang * -self.rot_d) * -self.rot_d
            r = s / 255.0 * self.cW_rad
            x, y = r * cos(t) + self.cen.x(), r * -sin(t) + self.cen.y()
            lst.append(QPointF(x, y))

            #t2 = ((v / 255.0) * self.ang_w + radians(self.e_ang) + 2 * pi) % (2 * pi)
            #x, y = r2 * cos(t2) + self.cen.x(), r2 * -sin(t2) + self.cen.y()
            #lst.append(QPointF(x, y))
        self._namedColorPts = lst

    def showNamedColors(self, flag=False):
        "show/hide location of named colors on color wheel"
        self._showNames = flag
        self.update()

    def setColor(self, color):  # saturation -> radius
        h, s, v, a = color.getHsv()  # hue -> angle
        self.hue, self.sat, self.value = h, s, v  # value -> side bar thingy

        t = radians(h + self.o_ang * -self.rot_d) * -self.rot_d
        r = s / 255.0 * self.cW_rad
        x, y = r * cos(t) + self.cen.x(), r * -sin(t) + self.cen.y()
        self.chPt = QPointF(x, y)  # hue, saturation

        self.vIdAng = t2 = (v / 255.0) * self.ang_w + radians(self.e_ang)
        self.vIdAng = t2 = t2 if t2 > 0 else t2 + 2 * pi
        r2 = self.vAoBox.width() / 2.0

        x, y = r2 * cos(t2) + self.cen.x(), r2 * -sin(t2) + self.cen.y()
        self.vIdCen, self.vIdAng = QPointF(x, y), t2  # value
        self.vIdBox.moveCenter(self.vIdCen)
        self.update()

    def eventFilter(self, source, event):
        if (event.type() == QEvent.MouseButtonPress
                or (event.type() == QEvent.MouseMove
                    and event.buttons() == Qt.LeftButton)):
            self.pos = pos = event.pos()

            t = atan2(self.cen.y() - pos.y(), pos.x() - self.cen.x())
            if self.colWhlPath.contains(pos):  # in the color wheel
                self.chPt = pos

                #if not self._startedTimer:
                #    self.timer = QTimer()
                #    self.timer.timeout.connect(self.timerSpinner)
                #    self.timer.start(30.303)
                #    self._startedTimer = True

                # hue -> mouse angle (same as t here)
                h = (int(degrees(t)) - self.o_ang) * -self.rot_d
                self.hue = (h if h > 0 else h + 360) % 360

                # saturation -> mouse radius (clipped to wheel radius)
                m_rad = sqrt((self.pos.x() - self.cen.x())**2 +
                             (self.pos.y() - self.cen.y())**2)
                self.sat = int(255 * min(m_rad / self.cW_rad, 1))

            if self.vInArcPath.contains(pos):  # in the value selection arc
                self.vIdAng = t if t > 0 else t + 2 * pi
                r2 = self.vAoBox.width() / 2.0

                x, y = r2 * cos(t) + self.cen.x(), r2 * -sin(t) + self.cen.y()
                self.vIdCen = QPointF(x, y)
                self.vIdBox.moveCenter(self.vIdCen)
                self.value = int(255 *
                                 (t - radians(self.e_ang)) / self.ang_w) % 256

            self.update()
            col = QColor()
            col.setHsv(self.hue, self.sat, self.value)
            self.currentColorChanged.emit(col)
        return QWidget.eventFilter(self, source, event)

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

        #painter.setBrush(QBrush(Qt.black, Qt.NoBrush))
        #painter.drawRect(self.winBox)  # border

        # value selector indicator
        painter.setBrush(QBrush(Qt.black, Qt.SolidPattern))
        painter.drawPie(self.vIdBox, 16 * (degrees(self.vIdAng) - 22.5), 720)

        # value selector arc
        painter.setClipPath(self.vArcPath)
        painter.setPen(Qt.NoPen)
        arc = QConicalGradient(self.cen, self.e_ang)
        color = QColor()
        color.setHsv(self.hue, self.sat, 255)
        arc.setColorAt(1 - (self.e_ang - self.s_ang) / 360.0, color)
        arc.setColorAt(1, Qt.black)
        arc.setColorAt(0, Qt.black)
        painter.setBrush(arc)
        painter.drawPath(self.vArcPath)
        painter.setClipPath(self.vArcPath, Qt.NoClip)

        # color wheel
        painter.setPen(Qt.NoPen)
        painter.setBrush(self.cWhlBrush1)
        painter.drawEllipse(self.cWhBox)
        painter.setBrush(self.cWhlBrush2)
        painter.drawEllipse(self.cWhBox)

        # crosshairs
        painter.setClipPath(self.colWhlPath)
        painter.setBrush(QBrush(Qt.black, Qt.SolidPattern))
        chVert = QRectF(0, 0, 2, 20)
        chHort = QRectF(0, 0, 20, 2)
        chVert.moveCenter(self.chPt)
        chHort.moveCenter(self.chPt)
        painter.drawRect(chVert)
        painter.drawRect(chHort)

        # named color locations
        if self._showNames:
            painter.setClipPath(self.vArcPath, Qt.NoClip)
            painter.setPen(Qt.SolidLine)
            try:
                painter.drawPoints(*self._namedColorPts)  # PyQt
            except:
                painter.drawPoints(self._namedColorPts)  # PySide

    def setup(self):
        "sets bounds on value arc and color wheel"
        # bounding boxes
        self.winBox = QRectF(self.rect())
        self.vIoBox = QRectF()  # value indicator arc outer
        self.vIdBox = QRectF()  # value indicator box
        self.vAoBox = QRectF()  # value arc outer
        self.vAiBox = QRectF()  # value arc inner
        self.cWhBox = QRectF()  # color wheel

        self.vIdBox.setSize(QSizeF(15, 15))
        self.vIoBox.setSize(self.winBox.size())
        self.vAoBox.setSize(self.winBox.size() - self.vIdBox.size() / 2.0)
        self.vAiBox.setSize(self.vAoBox.size() - QSizeF(20, 20))
        self.cWhBox.setSize(self.vAiBox.size() - QSizeF(20, 20))

        # center - shifted to the right slightly
        x = self.winBox.width() - (self.vIdBox.width() +
                                   self.vAiBox.width()) / 2.0
        self.cen = QPointF(x, self.winBox.height() / 2.0)

        # positions and initial settings
        self.vAoBox.moveCenter(self.cen)
        self.vAiBox.moveCenter(self.cen)
        self.cWhBox.moveCenter(self.cen)
        self.vIdBox.moveCenter(self.vIdCen)

        self.cW_rad = self.cWhBox.width() / 2.0
        self.ang_w = radians(self.s_ang) - radians(self.e_ang)

        # gradients
        colWhl = QConicalGradient(self.cen, self.o_ang)
        whl_cols = [
            Qt.red, Qt.magenta, Qt.blue, Qt.cyan, Qt.green, Qt.yellow, Qt.red
        ]
        for i, c in enumerate(whl_cols[::self.rot_d]):
            colWhl.setColorAt(i / 6.0, c)

        rad = min(self.cWhBox.width() / 2.0, self.cWhBox.height() / 2.0)
        cWhlFade = QRadialGradient(self.cen, rad, self.cen)
        cWhlFade.setColorAt(0, Qt.white)
        cWhlFade.setColorAt(1, QColor(255, 255, 255, 0))

        self.cWhlBrush1 = QBrush(colWhl)
        self.cWhlBrush2 = QBrush(cWhlFade)

        # painter paths (arcs, wheel)
        rad = self.vAoBox.width() / 2.0
        x, y = rad * cos(radians(self.s_ang)), -rad * sin(radians(self.s_ang))
        x += self.cen.x()
        y += self.cen.y()

        self.vArcPath = QPainterPath(QPointF(x, y))  # value arc (for color)
        self.vArcPath.arcTo(self.vAoBox, self.s_ang, self.e_ang - self.s_ang)
        self.vArcPath.arcTo(self.vAiBox, self.e_ang, self.s_ang - self.e_ang)
        self.vArcPath.closeSubpath()

        self.vInArcPath = QPainterPath(QPointF(x, y))  # value arc (for mouse)
        self.vInArcPath.arcTo(self.vIoBox, self.s_ang, self.e_ang - self.s_ang)
        self.vInArcPath.arcTo(self.vAiBox, self.e_ang, self.s_ang - self.e_ang)
        self.vInArcPath.closeSubpath()

        self.colWhlPath = QPainterPath()
        self.colWhlPath.addEllipse(self.cWhBox)
Exemplo n.º 21
0
    def paint(self, painter, option, widget=None):

        painter.setRenderHint(QPainter.Antialiasing)
        brush = QBrush(QColor(100, 100, 100, 150))  # QBrush(QColor('#3B9CD9'))
        painter.setBrush(brush)
        std_pen = QPen(
            QColor(30, 43, 48)
        )  # QColor(30, 43, 48)  # used for header title and minimal std dark border
        std_pen.setWidthF(1.5)
        # painter.setPen(std_pen)

        if self.parent_node.design_style == 'extended':

            if GlobalStorage.storage['design style'] == 'dark std':
                c = self.parent_node.color

                # main rect
                body_gradient = QRadialGradient(
                    self.boundingRect().topLeft(),
                    self.flow.pythagoras(self.height, self.width))
                body_gradient.setColorAt(
                    0,
                    QColor(c.red() / 10 + 100,
                           c.green() / 10 + 100,
                           c.blue() / 10 + 100, 200))
                body_gradient.setColorAt(
                    1,
                    QColor(c.red() / 10 + 100,
                           c.green() / 10 + 100,
                           c.blue() / 10 + 100, 0))

                painter.setBrush(body_gradient)
                painter.setPen(Qt.NoPen)
                painter.drawRoundedRect(self.boundingRect(), 12, 12)

                header_gradient = QLinearGradient(
                    self.get_header_rect().topRight(),
                    self.get_header_rect().bottomLeft())
                header_gradient.setColorAt(
                    0, QColor(c.red(), c.green(), c.blue(), 255))
                header_gradient.setColorAt(
                    1, QColor(c.red(), c.green(), c.blue(), 0))
                painter.setBrush(header_gradient)
                painter.setPen(Qt.NoPen)
                painter.drawRoundedRect(self.get_header_rect(), 12, 12)

            elif GlobalStorage.storage['design style'] == 'dark tron':
                # main rect
                c = QColor('#212224')
                painter.setBrush(c)
                pen = QPen(self.parent_node.color)
                pen.setWidth(2)
                painter.setPen(pen)
                body_path = self.get_extended_body_path_TRON_DESIGN(10)
                painter.drawPath(body_path)
                # painter.drawRoundedRect(self.boundingRect(), 12, 12)

                c = self.parent_node.color
                header_gradient = QLinearGradient(
                    self.get_header_rect().topRight(),
                    self.get_header_rect().bottomLeft())
                header_gradient.setColorAt(
                    0, QColor(c.red(), c.green(), c.blue(), 255))
                header_gradient.setColorAt(
                    0.5, QColor(c.red(), c.green(), c.blue(), 100))
                header_gradient.setColorAt(
                    1, QColor(c.red(), c.green(), c.blue(), 0))
                painter.setBrush(header_gradient)
                header_path = self.get_extended_header_path_TRON_DESIGN(10)
                painter.drawPath(header_path)

            painter.setFont(self.display_name_font)
            painter.setPen(std_pen)

            painter.drawText(self.get_title_rect(),
                             Qt.AlignVCenter | Qt.AlignLeft,
                             self.parent_node.title)
            painter.setBrush(Qt.NoBrush)
            painter.setPen(QPen(Qt.white, 1))
            # painter.drawRect(self.get_header_rect())
        elif self.parent_node.design_style == 'minimalistic':
            path = QPainterPath()
            path.moveTo(-self.width / 2, 0)
            if GlobalStorage.storage['design style'] == 'dark std':
                path.cubicTo(-self.width / 2, -self.height / 2,
                             -self.width / 2, -self.height / 2, 0,
                             -self.height / 2)
                path.cubicTo(+self.width / 2, -self.height / 2,
                             +self.width / 2, -self.height / 2,
                             +self.width / 2, 0)
                path.cubicTo(+self.width / 2, +self.height / 2,
                             +self.width / 2, +self.height / 2, 0,
                             +self.height / 2)
                path.cubicTo(-self.width / 2, +self.height / 2,
                             -self.width / 2, +self.height / 2,
                             -self.width / 2, 0)
                path.closeSubpath()

                c = self.parent_node.color
                body_gradient = QLinearGradient(
                    self.boundingRect().bottomLeft(),
                    self.boundingRect().topRight())
                # 2*self.flow.pythagoras(self.height, self.width))
                body_gradient.setColorAt(
                    0, QColor(c.red(), c.green(), c.blue(), 150))
                body_gradient.setColorAt(
                    1, QColor(c.red(), c.green(), c.blue(), 80))

                painter.setBrush(body_gradient)
                painter.setPen(std_pen)

            elif GlobalStorage.storage['design style'] == 'dark tron':
                corner_size = 10
                path.lineTo(-self.width / 2 + corner_size / 2,
                            -self.height / 2 + corner_size / 2)
                path.lineTo(0, -self.height / 2)
                path.lineTo(+self.width / 2 - corner_size / 2,
                            -self.height / 2 + corner_size / 2)
                path.lineTo(+self.width / 2, 0)
                path.lineTo(+self.width / 2 - corner_size / 2,
                            +self.height / 2 - corner_size / 2)
                path.lineTo(0, +self.height / 2)
                path.lineTo(-self.width / 2 + corner_size / 2,
                            +self.height / 2 - corner_size / 2)
                path.closeSubpath()

                c = QColor('#36383B')
                painter.setBrush(c)
                pen = QPen(self.parent_node.color)
                pen.setWidth(2)
                painter.setPen(pen)

            painter.drawPath(path)

            painter.setFont(self.display_name_font)
            painter.drawText(self.boundingRect(), Qt.AlignCenter,
                             self.parent_node.title)