Esempio 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)
Esempio n. 2
0
 def color(self, val):
     val = unicode_type(val or '')
     col = QColor(val)
     orig = self._color
     if col.isValid():
         self._color = val
         self.setText(val)
         p = QPixmap(self.iconSize())
         p.fill(col)
         self.setIcon(QIcon(p))
     else:
         self._color = None
         self.setText(self.choose_text)
         self.setIcon(QIcon())
     if orig != col:
         self.color_changed.emit(self._color)
Esempio n. 3
0
 def fset(self, val):
     val = unicode(val or '')
     col = QColor(val)
     orig = self._color
     if col.isValid():
         self._color = val
         self.setText(val)
         p = QPixmap(self.iconSize())
         p.fill(col)
         self.setIcon(QIcon(p))
     else:
         self._color = None
         self.setText(self.choose_text)
         self.setIcon(QIcon())
     if orig != col:
         self.color_changed.emit(self._color)
Esempio n. 4
0
    def setBaseColor(self, newColor):
        '''
        @brief: Sets the base color and makes sure all top level widgets are updated
        @note: We try to ensure that the actual color used are within
            reasonable bounds while generating the actual baseColor
            from the import user request.
        @param: color QColor
        '''
        self._requestedBaseColor = newColor

        color = QColor()
        color.setHsv(newColor.hue(),
                     newColor.saturation() * 0.7, 64 + newColor.value() / 3)

        if color.isValid() and color != self._baseColor:
            self._baseColor = color
            for widget in QApplication.topLevelWidgets():
                widget.update()