From cea79b4e0a3780c688319ff7278024b9b69b1946 Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Sun, 19 Jul 2015 07:12:01 +0200 Subject: [PATCH] Printing: transfer profile to QImage if grayscale Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- printer.cpp | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) 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(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)