Ejemplo n.º 1
0
    def _draw_peak_values(self, painter, labels):
        #mainlog.debug('_draw_peak_values : {}'.format(labels))
        text_pen = QPen()
        text_pen.setCapStyle(Qt.RoundCap)
        text_pen.setColor(Qt.GlobalColor.white) # alpha=255=fully opaque
        text_pen.setWidth(1)
        fm = painter.fontMetrics()

        rects = []

        painter.setPen(text_pen)

        # The sort allow to draw the peak values which are lower first.
        # We do that to visually connect a peak value to its bar in a
        # (hopefully) better way

        for i in sorted( range(len(labels)), key=lambda i:self._item_coordinates(i)[1]):
            x, y_top, y_below = self._item_coordinates(i)

            label = labels[i]

            w = fm.boundingRect(label).width()
            h = fm.boundingRect(label).height()

            r = QRect(self.x_centers[i] - int(w/2), self.y_base-y_top - 5 - h, w, h)

            i = 0
            while i < len(rects):
                old_r = rects[i]
                if r.intersect(old_r):
                    i = 0
                    # Move r atop old_r
                    r.translate(0, -(r.bottom() - old_r.y()) - 2)
                else:
                    i += 1
            rects.append(r)

            self._draw_box_under_text(painter, r.x(), r.y() + h,label)
            painter.drawText( r.x(), r.y() + h,label)
Ejemplo n.º 2
0
 def rotate_clockwise_rect(self):
     r = QRect(0, 0, self.CONTROLS_SIZE, self.CONTROLS_SIZE)
     r.translate(
         QPoint(self.box_rect.width() - self.CONTROLS_SIZE,
                self.box_rect.height() - self.CONTROLS_SIZE))
     return r