예제 #1
0
    def _draw_indicator(self, event, qp):

        cx, cy, w, r = self._get_geometry(event)

        pen = qp.pen()
        pen.setWidth(3)
        pen.setColor(Qt.black)
        qp.setPen(pen)
        qp.setBrush(Qt.black)

        ro = r - 10
        cx, cy = r + 5, r + 5

        qp.translate(cx, cy)
        qp.rotate(self.indicator)

        path = QPainterPath()
        path.moveTo(-2, 0)
        path.lineTo(0, -ro)
        path.lineTo(2, 0)
        qp.drawPath(path)

        cr = 10
        cr2 = cr / 2.0

        qp.drawEllipse(-cr2, -cr2, cr, cr)
예제 #2
0
    def _draw_indicator(self, event, qp):

        cx, cy, w, r = self._get_geometry(event)

        pen = qp.pen()
        pen.setWidth(3)
        pen.setColor(Qt.black)
        qp.setPen(pen)
        qp.setBrush(Qt.black)

        ro = r - 10
        cx, cy = r + 5, r + 5

        qp.translate(cx, cy)
        qp.rotate(self.indicator)

        path = QPainterPath()
        path.moveTo(-2, 0)
        path.lineTo(0, -ro)
        path.lineTo(2, 0)
        qp.drawPath(path)

        cr = 10
        cr2 = cr / 2.0

        qp.drawEllipse(-cr2, -cr2, cr, cr)
예제 #3
0
    def update_position(self):

        n = len(self.control_points) - 1

        x_0 = self.control_points[0].pos().x()
        x_1 = self.control_points[-1].pos().x()

        def p(x):
            result = 0
            for i in range(0, n + 1):
                y_i = self.control_points[i].pos().y()
                result += binom(n, i) * ((x_1 - x) / (x_1 - x_0)) ** (n - i) * ((x - x_0) / (x_1 - x_0)) ** i * y_i
            return result
        
        path = QPainterPath()

        xs = linspace(0.02*SCENE_SIZE, 0.98*SCENE_SIZE, num=n*100 + 1)

        path.moveTo(QPointF(xs[0], p(xs[0])))

        for x in xs[1:]:
            path.lineTo(QPointF(x, p(x)))

        self.setPath(path)
예제 #4
0
    def paintEvent(self, event):
        qp = QPainter()
        qp.begin(self)

        qp.setRenderHint(QPainter.Antialiasing)
        qp.setBrush(self.color)
        qp.setPen(self.color)

        rect = event.rect()
        x = rect.x()
        w = rect.width()
        lineheight = 16
        print('-------------------')
        print('lefts', self.lefts)
        print('rights', self.rights)
        print('-------------------')
        ly = self._left_y + 5
        ry = self._right_y + 5
        rs=self.rights[:]

        # offset=1
        for i, l in enumerate(self.lefts):
            path = QPainterPath()
            sl, el = l[0], l[-1]
            try:
                r=rs[i]
                sr, er = r[0], r[-1]
                rs.pop(i)
                # offset+=1
            except IndexError:
                sr, er = l[-1], l[-1]-1

            y = ly + lineheight * sl
            y2 = ry + lineheight * sr

            path.moveTo(x, y)
            path.lineTo(x, y + lineheight * (el - sl + 1))
            path.lineTo(x + w, y2 + lineheight * (er - sr + 1))
            path.lineTo(x + w, y2)
            qp.drawPath(path)

        for i, r in enumerate(rs):
            path = QPainterPath()
            sr, er = r[0], r[-1]
            # try:
            l=self.lefts[i]
            sl, el = r[-1], r[-1]-1
            # except IndexError:
            #     sl, el = l[-1]+2, l[-1]+1
                # print sl, el

            y = ly + lineheight * (sl)
            y2 = ry + lineheight * (sr)

            path.moveTo(x, y)
            path.lineTo(x, y + lineheight * (el - sl + 1))
            path.lineTo(x + w, y2 + lineheight * (er - sr + 1))
            path.lineTo(x + w, y2)
            qp.drawPath(path)

        qp.end()
 def shape(self):
     path = QPainterPath()
     path.addRoundedRect(self.bounding_rectangle, 5, 5)
     return path
예제 #6
0
    def paintEvent(self, event):
        qp = QPainter()
        qp.begin(self)

        qp.setRenderHint(QPainter.Antialiasing)
        qp.setBrush(self.color)
        qp.setPen(self.color)

        rect = event.rect()
        x = rect.x()
        w = rect.width()
        lineheight = 16
        print('-------------------')
        print('lefts', self.lefts)
        print('rights', self.rights)
        print('-------------------')
        ly = self._left_y + 5
        ry = self._right_y + 5
        rs=self.rights[:]

        # offset=1
        for i, l in enumerate(self.lefts):
            path = QPainterPath()
            sl, el = l[0], l[-1]
            try:
                r=rs[i]
                sr, er = r[0], r[-1]
                rs.pop(i)
                # offset+=1
            except IndexError:
                sr, er = l[-1], l[-1]-1

            y = ly + lineheight * sl
            y2 = ry + lineheight * sr

            path.moveTo(x, y)
            path.lineTo(x, y + lineheight * (el - sl + 1))
            path.lineTo(x + w, y2 + lineheight * (er - sr + 1))
            path.lineTo(x + w, y2)
            qp.drawPath(path)

        for i, r in enumerate(rs):
            path = QPainterPath()
            sr, er = r[0], r[-1]
            # try:
            l=self.lefts[i]
            sl, el = r[-1], r[-1]-1
            # except IndexError:
            #     sl, el = l[-1]+2, l[-1]+1
                # print sl, el

            y = ly + lineheight * (sl)
            y2 = ry + lineheight * (sr)

            path.moveTo(x, y)
            path.lineTo(x, y + lineheight * (el - sl + 1))
            path.lineTo(x + w, y2 + lineheight * (er - sr + 1))
            path.lineTo(x + w, y2)
            qp.drawPath(path)

        qp.end()