mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 16:40:04 +00:00 
			
		
		
		
	Add q_color_modulate for modulating the color of QIcons
This commit is contained in:
		
							parent
							
								
									c73698619d
								
							
						
					
					
						commit
						daa5bd24dc
					
				
					 3 changed files with 80 additions and 0 deletions
				
			
		
							
								
								
									
										56
									
								
								scwx-qt/source/scwx/qt/util/q_color_modulate.cpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										56
									
								
								scwx-qt/source/scwx/qt/util/q_color_modulate.cpp
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,56 @@ | |||
| #include <scwx/qt/util/q_color_modulate.hpp> | ||||
| 
 | ||||
| #include <QColor> | ||||
| #include <QImage> | ||||
| #include <QIcon> | ||||
| #include <QPixmap> | ||||
| #include <QSize> | ||||
| 
 | ||||
| namespace scwx | ||||
| { | ||||
| namespace qt | ||||
| { | ||||
| namespace util | ||||
| { | ||||
| 
 | ||||
| void modulateColors_(QImage& image, const QColor& color) | ||||
| { | ||||
|    for (int y = 0; y < image.height(); ++y) | ||||
|    { | ||||
|       QRgb* line = reinterpret_cast<QRgb*>(image.scanLine(y)); | ||||
|       for (int x = 0; x < image.width(); ++x) | ||||
|       { | ||||
|          QRgb& rgb   = line[x]; | ||||
|          int   red   = qRed(rgb) * color.redF(); | ||||
|          int   green = qGreen(rgb) * color.greenF(); | ||||
|          int   blue  = qBlue(rgb) * color.blueF(); | ||||
|          int   alpha = qAlpha(rgb) * color.alphaF(); | ||||
| 
 | ||||
|          rgb = qRgba(red, green, blue, alpha); | ||||
|       } | ||||
|    } | ||||
| } | ||||
| 
 | ||||
| QImage modulateColors(const QImage& image, const QColor& color) | ||||
| { | ||||
|    QImage copy = image.copy(); | ||||
|    modulateColors_(copy, color); | ||||
|    return copy; | ||||
| } | ||||
| 
 | ||||
| QPixmap modulateColors(const QPixmap& pixmap, const QColor& color) | ||||
| { | ||||
|    QImage image = pixmap.toImage(); | ||||
|    modulateColors_(image, color); | ||||
|    return QPixmap::fromImage(image); | ||||
| } | ||||
| 
 | ||||
| QIcon modulateColors(const QIcon& icon, const QSize& size, const QColor& color) | ||||
| { | ||||
|    QPixmap pixmap = modulateColors(icon.pixmap(size), color); | ||||
|    return QIcon(pixmap); | ||||
| } | ||||
| 
 | ||||
| } // namespace util
 | ||||
| } // namespace qt
 | ||||
| } // namespace scwx
 | ||||
							
								
								
									
										22
									
								
								scwx-qt/source/scwx/qt/util/q_color_modulate.hpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								scwx-qt/source/scwx/qt/util/q_color_modulate.hpp
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,22 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <QColor> | ||||
| #include <QImage> | ||||
| #include <QIcon> | ||||
| #include <QPixmap> | ||||
| #include <QSize> | ||||
| 
 | ||||
| namespace scwx | ||||
| { | ||||
| namespace qt | ||||
| { | ||||
| namespace util | ||||
| { | ||||
| 
 | ||||
| QImage  modulateColors(const QImage& image, const QColor& color); | ||||
| QPixmap modulateColors(const QPixmap& pixmap, const QColor& color); | ||||
| QIcon modulateColors(const QIcon& icon, const QSize& size, const QColor& color); | ||||
| 
 | ||||
| } // namespace util
 | ||||
| } // namespace qt
 | ||||
| } // namespace scwx
 | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 AdenKoperczak
						AdenKoperczak