| 
									
										
										
										
											2019-04-10 05:52:15 +02:00
										 |  |  | #include <LibGUI/GGroupBox.h>
 | 
					
						
							|  |  |  | #include <LibGUI/GPainter.h>
 | 
					
						
							|  |  |  | #include <SharedGraphics/StylePainter.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-11 20:16:34 +02:00
										 |  |  | GGroupBox::GGroupBox(GWidget* parent) | 
					
						
							|  |  |  |     : GGroupBox({}, parent) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-02 14:58:02 +02:00
										 |  |  | GGroupBox::GGroupBox(const StringView& title, GWidget* parent) | 
					
						
							| 
									
										
										
										
											2019-04-10 05:52:15 +02:00
										 |  |  |     : GWidget(parent) | 
					
						
							| 
									
										
										
										
											2019-05-08 14:32:46 +02:00
										 |  |  |     , m_title(title) | 
					
						
							| 
									
										
										
										
											2019-04-10 05:52:15 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     set_fill_with_background_color(true); | 
					
						
							| 
									
										
										
										
											2019-06-30 09:23:16 +02:00
										 |  |  |     set_background_color(Color::WarmGray); | 
					
						
							| 
									
										
										
										
											2019-04-10 05:52:15 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | GGroupBox::~GGroupBox() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void GGroupBox::paint_event(GPaintEvent& event) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     GPainter painter(*this); | 
					
						
							|  |  |  |     painter.add_clip_rect(event.rect()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     Rect frame_rect { | 
					
						
							|  |  |  |         0, font().glyph_height() / 2, | 
					
						
							|  |  |  |         width(), height() - font().glyph_height() / 2 | 
					
						
							|  |  |  |     }; | 
					
						
							| 
									
										
										
										
											2019-04-11 14:27:31 +02:00
										 |  |  |     StylePainter::paint_frame(painter, frame_rect, FrameShape::Box, FrameShadow::Sunken, 2); | 
					
						
							| 
									
										
										
										
											2019-04-10 05:52:15 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-08 14:32:46 +02:00
										 |  |  |     Rect text_rect { 4, 0, font().width(m_title) + 6, font().glyph_height() }; | 
					
						
							| 
									
										
										
										
											2019-04-10 05:52:15 +02:00
										 |  |  |     painter.fill_rect(text_rect, background_color()); | 
					
						
							| 
									
										
										
										
											2019-05-08 14:32:46 +02:00
										 |  |  |     painter.draw_text(text_rect, m_title, TextAlignment::Center, foreground_color()); | 
					
						
							| 
									
										
										
										
											2019-04-10 05:52:15 +02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2019-04-19 01:40:25 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-02 14:58:02 +02:00
										 |  |  | void GGroupBox::set_title(const StringView& title) | 
					
						
							| 
									
										
										
										
											2019-04-19 01:40:25 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-05-08 14:32:46 +02:00
										 |  |  |     if (m_title == title) | 
					
						
							| 
									
										
										
										
											2019-04-19 01:40:25 +02:00
										 |  |  |         return; | 
					
						
							| 
									
										
										
										
											2019-05-08 14:32:46 +02:00
										 |  |  |     m_title = title; | 
					
						
							| 
									
										
										
										
											2019-04-19 01:40:25 +02:00
										 |  |  |     update(); | 
					
						
							|  |  |  | } |