Ejemplo n.º 1
0
    def paintEvent(self, event):
        '''
        @param: event QPaintEvent
        '''
        super().paintEvent(event)

        # Show loading progress
        if gVar.appSettings.showLoadingProgress and self._progressVisible:
            option = QStyleOptionFrame()
            self.initStyleOption(option)

            lm, tm, rm, bm = self.getTextMargins()

            contentsRect = self.style().subElementRect(
                QStyle.SE_LineEditContents, option, self)
            contentsRect.adjust(lm, tm, -rm, -bm)

            bg = QColor(self._progressColor)
            if not bg.isValid() or bg.alpha() == 0:
                pal = self.palette()
                bg = Colors.mid(pal.color(QPalette.Base),
                                pal.color(QPalette.Text),
                                self._progressStyle > 0 and 4 or 8, 1)

            p = QPainter(self)
            p.setBrush(QBrush(bg))

            # We are painting over text, make sure the text stays visible
            p.setOpacity(0.5)

            outlinePen = QPen(bg.darker(110), 0.8)
            p.setPen(outlinePen)

            if self._progressStyle == self._ProgressFilled:
                bar = contentsRect.adjusted(0, 1, 0, -1)
                bar.setWidth(int(bar.width() * self._loadProgress / 100))
                roundness = bar.height() / 4.0
                p.drawRoundedRect(bar, roundness, roundness)
            elif self._progressStyle == self._ProgressBottom:
                outlinePen.setWidthF(0.3)
                outlinePen.setColor(outlinePen.color().darker(130))
                p.setPen(outlinePen)
                bar = QRect(contentsRect.x(),
                            contentsRect.bottom() - 3,
                            contentsRect.width() * self._loadProgress / 100.0,
                            3)
                p.drawRoundedRect(bar, 1, 1)
            elif self._progressStyle == self._ProgressTop:
                outlinePen.setWidthF(0.3)
                outlinePen.setColor(outlinePen.color().darker(130))
                p.setPen(outlinePen)
                bar = QRect(contentsRect.x(),
                            contentsRect.top() + 1,
                            contentsRect.width() * self._loadProgress / 100.0,
                            3)
                p.drawRoundedRect(bar, 1, 1)