Example #1
0
    def paintEvent(self, evt):
        """
        Protected method handling a paint event.
        
        @param evt reference to the paint event (QPaintEvent)
        """
        if self.__privateMode:
            backgroundColor = QColor(220, 220, 220)  # light gray
            foregroundColor = Qt.black
        else:
            backgroundColor = QApplication.palette().color(QPalette.Base)
            foregroundColor = QApplication.palette().color(QPalette.Text)

        if self.__browser is not None:
            p = self.palette()
            progress = self.__browser.progress()
            if progress == 0 or progress == 100:
                if self.__browser.url().scheme() == "https":
                    if QSslCertificate is not None:
                        if self.__browser.page().hasValidSslInfo():
                            backgroundColor = Preferences.getHelp(
                                "SaveUrlColor")
                    else:
                        backgroundColor = Preferences.getHelp("SaveUrlColor")
                p.setBrush(QPalette.Base, backgroundColor)
                p.setBrush(QPalette.Text, foregroundColor)
            else:
                if self.__browser.url().scheme() == "https":
                    if QSslCertificate is not None:
                        if self.__browser.page().hasValidSslInfo():
                            backgroundColor = Preferences.getHelp(
                                "SaveUrlColor")
                    else:
                        backgroundColor = Preferences.getHelp("SaveUrlColor")
                highlight = QApplication.palette().color(QPalette.Highlight)
                r = (highlight.red() + 2 * backgroundColor.red()) // 3
                g = (highlight.green() + 2 * backgroundColor.green()) // 3
                b = (highlight.blue() + 2 * backgroundColor.blue()) // 3

                loadingColor = QColor(r, g, b)
                if abs(loadingColor.lightness() -
                       backgroundColor.lightness()) < 20:
                    # special handling for special color schemes (e.g Gaia)
                    r = (2 * highlight.red() + backgroundColor.red()) // 3
                    g = (2 * highlight.green() + backgroundColor.green()) // 3
                    b = (2 * highlight.blue() + backgroundColor.blue()) // 3
                    loadingColor = QColor(r, g, b)

                gradient = QLinearGradient(QPointF(0, 0),
                                           QPointF(self.width(), 0))
                gradient.setColorAt(0, loadingColor)
                gradient.setColorAt(progress / 100.0 - 0.000001, loadingColor)
                gradient.setColorAt(progress / 100.0, backgroundColor)
                p.setBrush(QPalette.Base, gradient)

            self.setPalette(p)

        E5LineEdit.paintEvent(self, evt)
Example #2
0
 def paintEvent(self, evt):
     """
     Protected method handling a paint event.
     
     @param evt reference to the paint event (QPaintEvent)
     """
     if self.__privateMode:
         backgroundColor = QColor(220, 220, 220)     # light gray
         foregroundColor = Qt.black
     else:
         backgroundColor = QApplication.palette().color(QPalette.Base)
         foregroundColor = QApplication.palette().color(QPalette.Text)
     
     if self.__browser is not None:
         p = self.palette()
         progress = self.__browser.progress()
         if progress == 0 or progress == 100:
             if self.__browser.url().scheme() == "https":
                 if QSslCertificate is not None:
                     if self.__browser.page().hasValidSslInfo():
                         backgroundColor = Preferences.getHelp(
                             "SaveUrlColor")
                 else:
                     backgroundColor = Preferences.getHelp("SaveUrlColor")
             p.setBrush(QPalette.Base, backgroundColor)
             p.setBrush(QPalette.Text, foregroundColor)
         else:
             if self.__browser.url().scheme() == "https":
                 if QSslCertificate is not None:
                     if self.__browser.page().hasValidSslInfo():
                         backgroundColor = Preferences.getHelp(
                             "SaveUrlColor")
                 else:
                     backgroundColor = Preferences.getHelp("SaveUrlColor")
             highlight = QApplication.palette().color(QPalette.Highlight)
             r = (highlight.red() + 2 * backgroundColor.red()) // 3
             g = (highlight.green() + 2 * backgroundColor.green()) // 3
             b = (highlight.blue() + 2 * backgroundColor.blue()) // 3
             
             loadingColor = QColor(r, g, b)
             if abs(loadingColor.lightness() -
                     backgroundColor.lightness()) < 20:
                 # special handling for special color schemes (e.g Gaia)
                 r = (2 * highlight.red() + backgroundColor.red()) // 3
                 g = (2 * highlight.green() + backgroundColor.green()) // 3
                 b = (2 * highlight.blue() + backgroundColor.blue()) // 3
                 loadingColor = QColor(r, g, b)
             
             gradient = QLinearGradient(
                 QPointF(0, 0), QPointF(self.width(), 0))
             gradient.setColorAt(0, loadingColor)
             gradient.setColorAt(progress / 100.0 - 0.000001, loadingColor)
             gradient.setColorAt(progress / 100.0, backgroundColor)
             p.setBrush(QPalette.Base, gradient)
         
         self.setPalette(p)
     
     E5LineEdit.paintEvent(self, evt)
Example #3
0
    def __init__(self, colour: QColor) -> None:
        self.colour = colour
        self.brush = QBrush(colour)

        dark_colour = QColor(colour.red() // 2,
                             colour.green() // 2,
                             colour.blue() // 2)
        self.pen = QPen(dark_colour)

        if colour.lightness() > 128:
            self.text = _DARK_TEXT
        else:
            self.text = _LIGHT_TEXT
Example #4
0
def adjustSaturation(image: QImage, value) -> QImage:
    width, height = image.width(), image.height()
    newImage = QImage(width, height, QImage.Format_RGBA8888)
    for h in range(height):
        for w in range(width):
            pixel = QColor(image.pixel(h, w)).toHsl()
            H = pixel.hue()
            S = pixel.saturation() + value
            L = pixel.lightness()
            S = bound(0, 255, S)
            pixel.setHsl(H, S, L)
            newImage.setPixel(
                h, w,
                qRgba(pixel.red(), pixel.green(), pixel.blue(), pixel.alpha()))
    return newImage
Example #5
0
    def rgb_changed(self, *_args):
        if self.changing:
            return

        r, g, b = self.spin_r.value(), self.spin_g.value(), self.spin_b.value()
        rgb = QColor(r, g, b)
        h, s, l = rgb.hslHue(), rgb.hslSaturation(), rgb.lightness()

        self.changing = True

        if h != -1: # Qt returns -1 if the color is achromatic (i.e. grey).
            self.spin_h.setValue(h)
        self.spin_s.setValue(s)
        self.spin_l.setValue(l)
        self.changing = False

        self.rgb_led.set_rgb_value(r, g, b)
        self.label_color.setStyleSheet('QLabel {{ background: #{:02x}{:02x}{:02x} }}'.format(r, g, b))
Example #6
0
    def rgb_changed(self, *_args):
        if self.changing:
            return

        r, g, b = self.spin_r.value(), self.spin_g.value(), self.spin_b.value()
        rgb = QColor(r, g, b)
        h, s, l = rgb.hslHue(), rgb.hslSaturation(), rgb.lightness()

        self.changing = True

        if h != -1:  # Qt returns -1 if the color is achromatic (i.e. grey).
            self.spin_h.setValue(h)
        self.spin_s.setValue(s)
        self.spin_l.setValue(l)
        self.changing = False

        self.rgb_led.set_rgb_value(r, g, b)
        self.label_color.setStyleSheet(
            'QLabel {{ background: #{:02x}{:02x}{:02x} }}'.format(r, g, b))