Exemplo n.º 1
0
    def slotExportBackgroundChanged(self):
        """Button clicked to change background."""

        color = qt4.QColorDialog.getColor(
            utils.extendedColorToQColor(self.exportBackgroundButton.iconcolor),
            self, "Choose color", qt4.QColorDialog.ShowAlphaChannel)
        if color.isValid():
            self.updateExportBackground(utils.extendedColorFromQColor(color))
Exemplo n.º 2
0
    def updateExportBackground(self, colorname):
        """Update color on export background."""
        pixmap = qt4.QPixmap(16, 16)
        col = utils.extendedColorToQColor(colorname)
        pixmap.fill(col)

        # update button (storing color in button itself - what fun!)
        self.exportBackgroundButton.setIcon(qt4.QIcon(pixmap))
        self.exportBackgroundButton.iconcolor = colorname
Exemplo n.º 3
0
    def updateExportBackground(self, colorname):
        """Update color on export background."""
        pixmap = qt4.QPixmap(16, 16)
        col = utils.extendedColorToQColor(colorname)
        pixmap.fill(col)

        # update button (storing color in button itself - what fun!)
        self.exportBackgroundButton.setIcon(qt4.QIcon(pixmap))
        self.exportBackgroundButton.iconcolor = colorname
Exemplo n.º 4
0
    def slotExportBackgroundChanged(self):
        """Button clicked to change background."""

        color = qt4.QColorDialog.getColor(
            utils.extendedColorToQColor(self.exportBackgroundButton.iconcolor),
            self,
            "Choose color",
            qt4.QColorDialog.ShowAlphaChannel )
        if color.isValid():
            self.updateExportBackground( utils.extendedColorFromQColor(color) )
Exemplo n.º 5
0
    def exportBitmap(self, format):
        """Export to a bitmap format."""

        # get size for bitmap's dpi
        dpi = self.bitmapdpi
        size = self.doc.pageSize(self.pagenumber, dpi=(dpi,dpi))

        # create real output image
        backqcolor = utils.extendedColorToQColor(self.backcolor)
        if format == '.png':
            # transparent output
            image = qt4.QImage(size[0], size[1],
                               qt4.QImage.Format_ARGB32_Premultiplied)
        else:
            # non transparent output
            image = qt4.QImage(size[0], size[1],
                               qt4.QImage.Format_RGB32)
            backqcolor.setAlpha(255)

        image.setDotsPerMeterX(dpi*m_inch)
        image.setDotsPerMeterY(dpi*m_inch)
        if backqcolor.alpha() == 0:
            image.fill(qt4.qRgba(0,0,0,0))
        else:
            image.fill(backqcolor.rgb())

        # paint to the image
        painter = painthelper.DirectPainter(image)
        painter.setRenderHint(qt4.QPainter.Antialiasing, self.antialias)
        painter.setRenderHint(qt4.QPainter.TextAntialiasing, self.antialias)
        self.renderPage(size, (dpi,dpi), painter)

        # write image to disk
        writer = qt4.QImageWriter()
        # format below takes extension without dot
        writer.setFormat(qt4.QByteArray(format[1:]))
        writer.setFileName(self.filename)

        if format == 'png':
            # min quality for png as it makes no difference to output
            # and makes file size smaller
            writer.setQuality(0)
        else:
            writer.setQuality(self.quality)

        writer.write(image)
Exemplo n.º 6
0
    def exportBitmap(self, format):
        """Export to a bitmap format."""

        # get size for bitmap's dpi
        dpi = self.bitmapdpi
        size = self.doc.pageSize(self.pagenumber, dpi=(dpi, dpi))

        # create real output image
        backqcolor = utils.extendedColorToQColor(self.backcolor)
        if format == '.png':
            # transparent output
            image = qt4.QImage(size[0], size[1],
                               qt4.QImage.Format_ARGB32_Premultiplied)
        else:
            # non transparent output
            image = qt4.QImage(size[0], size[1], qt4.QImage.Format_RGB32)
            backqcolor.setAlpha(255)

        image.setDotsPerMeterX(dpi * m_inch)
        image.setDotsPerMeterY(dpi * m_inch)
        if backqcolor.alpha() == 0:
            image.fill(qt4.qRgba(0, 0, 0, 0))
        else:
            image.fill(backqcolor.rgb())

        # paint to the image
        painter = qt4.QPainter(image)
        painter.setRenderHint(qt4.QPainter.Antialiasing, self.antialias)
        painter.setRenderHint(qt4.QPainter.TextAntialiasing, self.antialias)
        self.renderPage(size, (dpi, dpi), painter)

        # write image to disk
        writer = qt4.QImageWriter()
        # format below takes extension without dot
        writer.setFormat(qt4.QByteArray(format[1:]))
        writer.setFileName(self.filename)

        if format == 'png':
            # min quality for png as it makes no difference to output
            # and makes file size smaller
            writer.setQuality(0)
        else:
            writer.setQuality(self.quality)

        writer.write(image)