commit 7d83056ab798836dcc18de7fd0922288f40cc85e Author: ion_vasilief Date: Tue Jan 12 12:27:02 2010 +0000 Fixed bug #016656: No transparency for exported .png files. diff --git a/qtiplot/src/plot2D/Graph.cpp b/qtiplot/src/plot2D/Graph.cpp index 846392b..c5938f1 100755 --- a/qtiplot/src/plot2D/Graph.cpp +++ b/qtiplot/src/plot2D/Graph.cpp @@ -1266,11 +1266,14 @@ void Graph::copyImage() #endif } -QPixmap Graph::graphPixmap(const QSize& size, double scaleFontsFactor) +QPixmap Graph::graphPixmap(const QSize& size, double scaleFontsFactor, bool transparent) { if (!size.isValid()){ QPixmap pixmap(boundingRect().size()); - pixmap.fill(Qt::white); + if (transparent) + pixmap.fill(Qt::transparent); + else + pixmap.fill(); QPainter p(&pixmap); print(&p, rect()); p.end(); @@ -1292,7 +1295,10 @@ QPixmap Graph::graphPixmap(const QSize& size, double scaleFontsFactor) scaleFonts(scaleFontsFactor); QPixmap pixmap(size); - pixmap.fill(Qt::white); + if (transparent) + pixmap.fill(Qt::transparent); + else + pixmap.fill(); QPainter p(&pixmap); print(&p, r); p.end(); @@ -1346,28 +1352,8 @@ void Graph::exportImage(const QString& fileName, int quality, bool transparent, if (customSize.isValid()) size = customPrintSize(customSize, unit, dpi); - QPixmap pic = graphPixmap(size, fontsFactor); + QPixmap pic = graphPixmap(size, fontsFactor, transparent); QImage image = pic.toImage(); - - if (transparent){ - QBitmap mask(size); - mask.fill(Qt::color1); - QPainter p(&mask); - p.setPen(Qt::color0); - - QRgb backgroundPixel = QColor(Qt::white).rgb (); - for (int y = 0; y < image.height(); y++){ - for (int x = 0; x < image.width(); x++){ - QRgb rgb = image.pixel(x, y); - if (rgb == backgroundPixel) // we want the frame transparent - p.drawPoint(x, y); - } - } - p.end(); - pic.setMask(mask); - image = pic.toImage(); - } - int dpm = (int)ceil(100.0/2.54*dpi); image.setDotsPerMeterX(dpm); image.setDotsPerMeterY(dpm); diff --git a/qtiplot/src/plot2D/Graph.h b/qtiplot/src/plot2D/Graph.h index 7dd10fa..9646232 100755 --- a/qtiplot/src/plot2D/Graph.h +++ b/qtiplot/src/plot2D/Graph.h @@ -313,7 +313,7 @@ class Graph: public QwtPlot void printCropmarks(bool on){d_print_cropmarks = on;}; void copyImage(); - QPixmap graphPixmap(const QSize& size = QSize(), double scaleFontsFactor = 1.0); + QPixmap graphPixmap(const QSize& size = QSize(), double scaleFontsFactor = 1.0, bool transparent = false); //! Provided for convenience in scripts void exportToFile(const QString& fileName); void exportSVG(const QString& fname, const QSizeF& customSize = QSizeF(), int unit = FrameWidget::Pixel, double fontsFactor = 1.0); diff --git a/qtiplot/src/plot2D/MultiLayer.cpp b/qtiplot/src/plot2D/MultiLayer.cpp index 4e3dc4a..e0f3111 100755 --- a/qtiplot/src/plot2D/MultiLayer.cpp +++ b/qtiplot/src/plot2D/MultiLayer.cpp @@ -679,11 +679,14 @@ void MultiLayer::setRows(int r) d_rows = r; } -QPixmap MultiLayer::canvasPixmap(const QSize& size, double scaleFontsFactor) +QPixmap MultiLayer::canvasPixmap(const QSize& size, double scaleFontsFactor, bool transparent) { if (!size.isValid()){ QPixmap pic(d_canvas->size()); - pic.fill(); + if (transparent) + pic.fill(Qt::transparent); + else + pic.fill(); QPainter p(&pic); QObjectList lst = d_canvas->children();//! this list is sorted according to the stack order foreach (QObject *o, lst){ @@ -702,7 +705,10 @@ QPixmap MultiLayer::canvasPixmap(const QSize& size, double scaleFontsFactor) scaleFontsFactor = scaleFactorY; QPixmap pic(size); - pic.fill(); + if (transparent) + pic.fill(Qt::transparent); + else + pic.fill(); QPainter p(&pic); QObjectList lst = d_canvas->children(); foreach (QObject *o, lst){ @@ -769,28 +775,8 @@ void MultiLayer::exportImage(const QString& fileName, int quality, bool transpar if (customSize.isValid()) size = Graph::customPrintSize(customSize, unit, dpi); - QPixmap pic = canvasPixmap(size, fontsFactor); + QPixmap pic = canvasPixmap(size, fontsFactor, transparent); QImage image = pic.toImage(); - - if (transparent){ - QBitmap mask(size); - mask.fill(Qt::color1); - QPainter p(&mask); - p.setPen(Qt::color0); - - QRgb backgroundPixel = QColor(Qt::white).rgb (); - for (int y = 0; y < image.height(); y++){ - for (int x = 0; x < image.width(); x++){ - QRgb rgb = image.pixel(x, y); - if (rgb == backgroundPixel) // we want the frame transparent - p.drawPoint(x, y); - } - } - p.end(); - pic.setMask(mask); - image = pic.toImage(); - } - int dpm = (int)ceil(100.0/2.54*dpi); image.setDotsPerMeterX(dpm); image.setDotsPerMeterY(dpm); diff --git a/qtiplot/src/plot2D/MultiLayer.h b/qtiplot/src/plot2D/MultiLayer.h index d677403..47569a4 100755 --- a/qtiplot/src/plot2D/MultiLayer.h +++ b/qtiplot/src/plot2D/MultiLayer.h @@ -157,7 +157,7 @@ public slots: //! \name Print and Export //@{ - QPixmap canvasPixmap(const QSize& size = QSize(), double scaleFontsFactor = 1.0); + QPixmap canvasPixmap(const QSize& size = QSize(), double scaleFontsFactor = 1.0, bool transparent = false); void exportToFile(const QString& fileName); void exportImage(QTextDocument *document, int quality = 100, bool transparent = false, int dpi = 0, const QSizeF& customSize = QSizeF (), int unit = FrameWidget::Pixel, double fontsFactor = 1.0);