summaryrefslogtreecommitdiffstats
path: root/printer.cpp
diff options
context:
space:
mode:
authorGravatar Gehad elrobey <gehadelrobey@gmail.com>2015-07-19 07:12:01 +0200
committerGravatar Lubomir I. Ivanov <neolit123@gmail.com>2015-07-20 15:28:57 +0300
commitcea79b4e0a3780c688319ff7278024b9b69b1946 (patch)
treed30ce54b2ff78a3d53995d97df08a892f5a899ec /printer.cpp
parent1ae1a11c228a245b6befc6cb592d8a1cb4034206 (diff)
downloadsubsurface-cea79b4e0a3780c688319ff7278024b9b69b1946.tar.gz
Printing: transfer profile to QImage if grayscale
Signed-off-by: Gehad elrobey <gehadelrobey@gmail.com> Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Diffstat (limited to 'printer.cpp')
-rw-r--r--printer.cpp24
1 files changed, 23 insertions, 1 deletions
diff --git a/printer.cpp b/printer.cpp
index 7cef1104e..5b1995501 100644
--- a/printer.cpp
+++ b/printer.cpp
@@ -29,7 +29,29 @@ void Printer::putProfileImage(QRect profilePlaceholder, QRect viewPort, QPainter
// use the placeHolder and the viewPort position to calculate the relative position of the dive profile.
QRect pos(x, y, profilePlaceholder.width(), profilePlaceholder.height());
profile->plotDive(dive, true);
- profile->render(painter, pos);
+
+ if (!printOptions->color_selected) {
+ QImage image(pos.width(), pos.height(), QImage::Format_ARGB32);
+ QPainter imgPainter(&image);
+ imgPainter.setRenderHint(QPainter::Antialiasing);
+ imgPainter.setRenderHint(QPainter::SmoothPixmapTransform);
+ profile->render(&imgPainter, QRect(0, 0, pos.width(), pos.height()));
+ imgPainter.end();
+
+ // convert QImage to grayscale before rendering
+ for (int i = 0; i < image.height(); i++) {
+ QRgb *pixel = reinterpret_cast<QRgb *>(image.scanLine(i));
+ QRgb *end = pixel + image.width();
+ for (; pixel != end; pixel++) {
+ int gray_val = qGray(*pixel);
+ *pixel = QColor(gray_val, gray_val, gray_val).rgb();
+ }
+ }
+
+ painter->drawImage(pos, image);
+ } else {
+ profile->render(painter, pos);
+ }
}
void Printer::render(int Pages = 0)