mirror of
				https://github.com/subsurface/subsurface.git
				synced 2025-02-19 22:16:15 +00:00 
			
		
		
		
	Printing: transfer profile to QImage if grayscale
Signed-off-by: Gehad elrobey <gehadelrobey@gmail.com> Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
This commit is contained in:
		
							parent
							
								
									1ae1a11c22
								
							
						
					
					
						commit
						cea79b4e0a
					
				
					 1 changed files with 23 additions and 1 deletions
				
			
		
							
								
								
									
										24
									
								
								printer.cpp
									
										
									
									
									
								
							
							
						
						
									
										24
									
								
								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) | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue