Added helper class for tempered opacity in QPainter.
This commit is contained in:
		
							parent
							
								
									eac439713b
								
							
						
					
					
						commit
						18ea4136b7
					
				
					 1 changed files with 27 additions and 0 deletions
				
			
		
							
								
								
									
										27
									
								
								ui/painter.h
									
										
									
									
									
								
							
							
						
						
									
										27
									
								
								ui/painter.h
									
										
									
									
									
								
							|  | @ -135,3 +135,30 @@ private: | |||
| 	QPainter::RenderHints _hints; | ||||
| 
 | ||||
| }; | ||||
| 
 | ||||
| class ScopedPainterOpacity { | ||||
| public: | ||||
| 	ScopedPainterOpacity(QPainter &p, float64 nowOpacity) | ||||
| 	: _painter(p) | ||||
| 	, _wasOpacity(p.opacity()) { | ||||
| 		if (_wasOpacity != nowOpacity) { | ||||
| 			_painter.setOpacity(nowOpacity); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	ScopedPainterOpacity( | ||||
| 		const ScopedPainterOpacity &other) = delete; | ||||
| 	ScopedPainterOpacity &operator=( | ||||
| 		const ScopedPainterOpacity &other) = delete; | ||||
| 
 | ||||
| 	~ScopedPainterOpacity() { | ||||
| 		if (_painter.isActive()) { | ||||
| 			_painter.setOpacity(_wasOpacity); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| private: | ||||
| 	QPainter &_painter; | ||||
| 	const float64 _wasOpacity; | ||||
| 
 | ||||
| }; | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 23rd
						23rd