Exemplo n.º 1
0
 def paint_emblems(self, painter, rect, emblems):
     gutter = self.emblem_size + self.MARGIN
     grect = QRect(rect)
     gpos = self.gutter_position
     if gpos is self.TOP:
         grect.setBottom(grect.top() + gutter)
         rect.setTop(rect.top() + gutter)
     elif gpos is self.BOTTOM:
         grect.setTop(grect.bottom() - gutter + self.MARGIN)
         rect.setBottom(rect.bottom() - gutter)
     elif gpos is self.LEFT:
         grect.setRight(grect.left() + gutter)
         rect.setLeft(rect.left() + gutter)
     else:
         grect.setLeft(grect.right() - gutter + self.MARGIN)
         rect.setRight(rect.right() - gutter)
     horizontal = gpos in (self.TOP, self.BOTTOM)
     painter.save()
     painter.setClipRect(grect)
     try:
         for i, emblem in enumerate(emblems):
             delta = 0 if i == 0 else self.emblem_size + self.MARGIN
             grect.moveLeft(grect.left() + delta) if horizontal else grect.moveTop(grect.top() + delta)
             rect = QRect(grect)
             rect.setWidth(int(emblem.width() / emblem.devicePixelRatio())), rect.setHeight(int(emblem.height() / emblem.devicePixelRatio()))
             painter.drawPixmap(rect, emblem)
     finally:
         painter.restore()
Exemplo n.º 2
0
 def paint_emblems(self, painter, rect, emblems):
     gutter = self.emblem_size + self.MARGIN
     grect = QRect(rect)
     gpos = self.gutter_position
     if gpos is self.TOP:
         grect.setBottom(grect.top() + gutter)
         rect.setTop(rect.top() + gutter)
     elif gpos is self.BOTTOM:
         grect.setTop(grect.bottom() - gutter + self.MARGIN)
         rect.setBottom(rect.bottom() - gutter)
     elif gpos is self.LEFT:
         grect.setRight(grect.left() + gutter)
         rect.setLeft(rect.left() + gutter)
     else:
         grect.setLeft(grect.right() - gutter + self.MARGIN)
         rect.setRight(rect.right() - gutter)
     horizontal = gpos in (self.TOP, self.BOTTOM)
     painter.save()
     painter.setClipRect(grect)
     try:
         for i, emblem in enumerate(emblems):
             delta = 0 if i == 0 else self.emblem_size + self.MARGIN
             grect.moveLeft(grect.left() + delta) if horizontal else grect.moveTop(grect.top() + delta)
             rect = QRect(grect)
             rect.setWidth(int(emblem.width() / emblem.devicePixelRatio())), rect.setHeight(int(emblem.height() / emblem.devicePixelRatio()))
             painter.drawPixmap(rect, emblem)
     finally:
         painter.restore()
Exemplo n.º 3
0
    def on_printAction3_triggered(self):
        printer = QPrinter()

        image = QPixmap()
        image.load("0.png")

        font = QFont()
        font.setBold(True)
        font.setPixelSize(50)

        textsize = QSize()
        # textsize.setHeight()
        pen = QPen()
        pen.setColor(Qt.black)

        pagesize = QSizeF()

        print(image.width())
        print(image.height())

        pagesize.setWidth(60)
        pagesize.setHeight(40)

        printer.setPaperSize(pagesize, QPrinter.Millimeter)

        print(printer.pageSize())
        printDialog = QPrintDialog(printer, self)
        printDialog.setWindowTitle("打印二维码")
        if printDialog.exec_() == QDialog.Accepted:
            painter = QPainter(printer)

            painter.setPen(pen)
            painter.setFont(font)

            painter.begin(printer)

            picsize = image.size()
            size = QSize()
            # size.setHeight(picsize.height())
            # size.setWidth(picsize.width())

            # size.setWidth(60)
            # size.setHeight(40)
            #
            #
            #
            # image = image.scaled(size, Qt.KeepAspectRatio)

            rectdest = QRect()
            rectdest.setX(25)
            rectdest.setY(0)
            rectdest.setWidth(175)
            rectdest.setHeight(150)

            print(image.rect())
            # rectsrc = QRect()
            # image.rect()
            # rectsrc.setX(0)
            # rectsrc.setY(0)
            # rectsrc.setX(image.width())
            # rectsrc.setY(image.height())

            painter.drawPixmap(rectdest, image, image.rect())

            # rect.setX(10 + picsize.width()/10)
            # rect.setY(12 + picsize.height()/2.5)
            # painter.drawText(50, 120, "10001491274")

            # preview = QPrintPreviewDialog()
            # preview.paintRequested(printer)
            # preview.exec()

            painter.end()
Exemplo n.º 4
0
    def paintEvent(self, event):
        '''
        @param event QPaintEvent
        '''
        p = QPainter(self)
        p.setRenderHint(QPainter.Antialiasing)

        size = 16
        pixmapSize = round(size *
                           self.data().animationPixmap.devicePixelRatioF())

        # Center the pixmap in rect
        r = QRect(self.rect())
        r.setX((r.width() - size) / 2)
        r.setY((r.height() - size) / 2)
        r.setWidth(size)
        r.setHeight(size)

        if self._animationRunning:
            p.drawPixmap(
                r,
                self.data().animationPixmap,
                QRect(self._currentFrame * pixmapSize, 0, pixmapSize,
                      pixmapSize))
        elif self._audioIconDisplayed and not self._tab.isPinned():
            self._audioIconRect = QRect(r)
            p.drawPixmap(
                r,
                self._tab.isMuted() and self.data().audioMutedPixmap
                or self.data().audioPlayingPixmap)
        elif not self._sitePixmap.isNull():
            p.drawPixmap(r, self._sitePixmap)
        elif self._tab and self._tab.isPinned():
            p.drawPixmap(r, IconProvider.emptyWebIcon().pixmap(size))

        # Draw audio icon on top of site icon for pinned tabs
        if not self._animationRunning and self._audioIconDisplayed and self._tab.isPinned(
        ):
            s = size - 4
            r0 = QRect(self.width() - 4, 0, s, s)
            self._audioIconRect = r0
            c = self.palette().color(QPalette.Window)
            c.setAlpha(180)
            p.setPen(c)
            p.setBrush(c)
            p.drawEllipse(r)
            p.drawPixmap(
                r,
                self._tab.isMuted() and self.data().audioMutedPixmap
                or self.data().audioPlayingPixmap)

        # Draw background activity indicator
        if self._tab and self._tab.isPinned() and self._tab.webView(
        ).backgroundActivity():
            s = 5
            # Background
            r1 = QRect(self.width() - s - 2,
                       self.height() - s - 2, s + 2, s + 2)
            c1 = self.palette().color(QPalette.Window)
            c1.setAlpha(180)
            p.setPen(Qt.transparent)
            p.setBrush(c1)
            p.drawEllipse(r1)
            # Forground
            r2 = QRect(self.width() - s - 1, self.height() - s - 1, s, s)
            c2 = self.palette().color(QPalette.Text)
            p.setPen(Qt.transparent)
            p.setBrush(c2)
            p.drawEllipse(r2)
Exemplo n.º 5
0
    def drawIconWithShadow(self,
                           icon,
                           rect,
                           painter,
                           iconMode,
                           radius=3,
                           color=QColor(0, 0, 0, 130),
                           offset=QPoint(1, -2)):
        '''
        @brief: Draw a cached pixmap with shadow
        @param: icon QIcon
        @param: rect QRect
        @param: painter QPainter
        @param: iconMode QIcon.Mode
        @param: radius int
        @param: color QColor
        @param: offset QPoint
        '''
        cache = QPixmap()
        pixmapName = 'icon %s %s %s' % (icon.cacheKey(), iconMode,
                                        rect.height())

        cache = QPixmapCache.find(pixmapName)
        if not cache:
            px = icon.pixmap(rect.size(), iconMode)
            px.setDevicePixelRatio(gVar.app.devicePixelRatio())
            cache = QPixmap(px.size() + QSize(radius * 2, radius * 2))
            cache.setDevicePixelRatio(px.devicePixelRatioF())
            cache.fill(Qt.transparent)

            cachePainter = QPainter(cache)

            # Draw shadow
            tmp = QImage(px.size() + QSize(radius * 2, radius * 2 + 1),
                         QImage.Format_ARGB32_Premultiplied)
            tmp.setDevicePixelRatio(px.devicePixelRatioF())
            tmp.fill(Qt.transparent)

            tmpPainter = QPainter(tmp)

            tmpPainter.setCompositionMode(QPainter.CompositionMode_Source)
            tmpPainter.drawPixmap(QPoint(radius, radius), px)
            tmpPainter.end()

            # blur the alpha channel
            blurred = QImage(tmp.size(), QImage.Format_ARGB32_Premultiplied)
            blurred.fill(Qt.transparent)
            blurPainter = QPainter(blurred)
            # TODO:
            #qt_blurImage(blurPainter, tmp, radius, False, True)
            blurPainter.end()

            tmp = blurred

            # blacken the image...
            tmpPainter.begin(tmp)
            tmpPainter.setCompositionMode(QPainter.CompositionMode_SourceIn)
            tmpPainter.fillRect(tmp.rect(), color)
            tmpPainter.end()

            tmpPainter.begin(tmp)
            tmpPainter.setCompositionMode(QPainter.CompositionMode_SourceIn)
            tmpPainter.fillRect(tmp.rect(), color)
            tmpPainter.end()

            # draw the blurred drop shadow...
            cachePainter.drawImage(
                QRect(0, 0,
                      cache.rect().width() / cache.devicePixelRatioF(),
                      cache.rect().height() / cache.devicePixelRatioF()), tmp)
            # Draw the actual pixmap...
            cachePainter.drawPixmap(QPoint(radius, radius) + offset, px)
            if self.usePixmapCache():
                QPixmapCache.insert(pixmapName, cache)

            sip.delete(cachePainter)
            sip.delete(tmpPainter)
            sip.delete(blurPainter)

        targetRect = QRect(cache.rect())
        targetRect.setWidth(cache.rect().width() / cache.devicePixelRatioF())
        targetRect.setHeight(cache.rect().height() / cache.devicePixelRatioF())
        targetRect.moveCenter(rect.center())
        painter.drawPixmap(targetRect.topLeft() - offset, cache)