Exemple #1
0
def overlay_pixmap(pixmap, over_pixmap, overlay_color, align=Qt.AlignCenter):
    """
    Overlays one pixmap over the other
    :param pixmap:
    :param over_pixmap:
    :param overlay_color:
    :param align:
    :return:
    """

    if isinstance(overlay_color, str):
        overlay_color = color.Color.from_string(overlay_color)

    if overlay_color is not None:
        over_pixmap = colorize_pixmap(over_pixmap, overlay_color)

    painter = QPainter(pixmap)
    painter.setCompositionMode(QPainter.CompositionMode_SourceOver)

    x = 0
    y = 0
    if align is Qt.AlignCenter:
        x = pixmap.width() / 2 - over_pixmap.width() / 2
        y = pixmap.height() / 2 - over_pixmap.height() / 2
    elif align is None:
        x = 0
        y = 0

    painter.drawPixmap(x, y, over_pixmap.width(), over_pixmap.height(), over_pixmap)
    painter.end()
Exemple #2
0
    def set_color(self, new_color, size=None):
        """
        Sets icon color
        :param new_color: QColor, new color for the icon
        :param size: QSize, size of the icon
        """

        if isinstance(new_color, str):
            new_color = color.Color.from_string(new_color)
        elif isinstance(new_color, (list, tuple)):
            new_color = color.Color(*new_color)

        if self.isNull():
            return

        icon = self
        size = size or icon.availableSizes()[0]
        pixmap = icon.pixmap(size)

        painter = QPainter(pixmap)
        painter.setCompositionMode(QPainter.CompositionMode_SourceIn)
        painter.setBrush(new_color)
        painter.setPen(new_color)
        painter.drawRect(pixmap.rect())
        painter.end()

        icon = Icon(pixmap)
        self.swap(icon)
Exemple #3
0
def tint_pixmap(pixmap, tint_color=(255, 255, 255, 100), composition_mode=QPainter.CompositionMode_Plus):
    """
    Composite one pixmap on top of another
    :param pixmap:
    :param tint_color:
    :param composition_mode:
    :return:
    """

    tint_color = QColor(*tint_color)
    over_pixmap = QPixmap(pixmap.width(), pixmap.height())
    over_pixmap.fill(tint_color)
    over_pixmap.setMask(pixmap.mask())
    painter = QPainter(pixmap)
    painter.setCompositionMode(composition_mode)
    painter.drawPixmap(0, 0, over_pixmap.width(), over_pixmap.height(), over_pixmap)
    painter.end()
Exemple #4
0
    def set_color(self, new_color):
        """
        Sets pixmap's color
        :param new_color: variant (str || QColor), color to apply to the pixmap
        """

        if isinstance(new_color, str):
            new_color = color.Color.from_string(new_color)

        if not self.isNull():
            painter = QPainter(self)
            painter.setCompositionMode(QPainter.CompositionMode_SourceIn)
            painter.setBrush(new_color)
            painter.setPen(new_color)
            painter.drawRect(self.rect())
            painter.end()

        self._color = new_color
 def cdMapper(self,*args):
     global cdR, cdG, cdB
     
     temp2 = QPixmap(cd_pix2)
     mask = QPixmap(cd_pix2_alpha)
     
     mult = 255
     R = cdR * mult
     G = cdG *mult
     B = cdB * mult
     colour = QColor(R,G,B)
     #print("R:" + str(cdR) + " G:" + str(cdG) + " B:" + str(cdB))
     
     #Paint Lines
     painter2 = QPainter(temp2)
     painter2.setCompositionMode(painter2.CompositionMode_Overlay)
     painter2.fillRect(temp2.rect(), colour)
     painter2.end()
      
     #Update Image
     self.main_widget.lbl_LGTC_PRV.setPixmap(temp2)
Exemple #6
0
    def paintEvent(self, event: QPaintEvent) -> None:
        p = QPainter(self)
        self.m_normalMap.render(p, event.rect())
        p.setPen(Qt.black)
        p.drawText(
            self.rect(),
            Qt.AlignBottom | Qt.TextWordWrap,
            "Map data CCBYSA 2009 OpenStreetMap.org contributors",
        )
        p.end()

        if self.zoomed:
            dim = min(self.width(), self.height())
            magnifierSize = min(MAX_MAGNIFIER, dim * 2 / 3)
            radius = magnifierSize / 2
            ring = radius - 15
            box = QSize(magnifierSize, magnifierSize)

            if self.maskPixmap.size() != box:
                self.maskPixmap = QPixmap(box)
                self.maskPixmap.fill(Qt.transparent)

                g = QRadialGradient()
                g.setCenter(radius, radius)
                g.setFocalPoint(radius, radius)
                g.setRadius(radius)
                g.setColorAt(1.0, QColor(255, 255, 255, 0))
                g.setColorAt(0.5, QColor(128, 128, 128, 255))

                mask = QPainter(self.maskPixmap)
                mask.setRenderHint(QPainter.Antialiasing)
                mask.setCompositionMode(QPainter.CompositionMode_Source)
                mask.setBrush(g)
                mask.setPen(Qt.NoPen)
                mask.drawRect(self.maskPixmap.rect())
                mask.setBrush(QColor(Qt.transparent))
                mask.drawEllipse(g.center(), ring, ring)
                mask.end()

            center = self.dragPos - QPoint(0, radius)
            center = center + QPoint(0, radius / 2)
            corner = center - QPoint(radius, radius)

            xy = center * 2 - QPoint(radius, radius)

            # only set the dimension to the magnified portion
            if self.zoomPixmap.size() != box:
                zoomPixmap = QPixmap(box)
                zoomPixmap.fill(Qt.lightGray)

            if True:
                p = QPainter(zoomPixmap)
                p.translate(-xy)
                self.m_largeMap.render(p, QRect(xy, box))
                p.end()

            clipPath = QPainterPath()
            clipPath.addEllipse(center, ring, ring)

            p = QPainter(self)
            p.setRenderHint(QPainter.Antialiasing)
            p.setClipPath(clipPath)
            p.drawPixmap(corner, zoomPixmap)
            p.setClipping(False)
            p.drawPixmap(corner, self.maskPixmap)
            p.setPen(Qt.gray)
            p.drawPath(clipPath)
        if self.invert:
            p = QPainter(self)
            p.setCompositionMode(QPainter.CompositionMode_Difference)
            p.fillRect(event.rect(), Qt.white)
            p.end()