| 
									
										
										
										
											2019-06-07 11:46:02 +02:00
										 |  |  | #include <LibGUI/GAction.h>
 | 
					
						
							| 
									
										
										
										
											2019-02-20 02:39:46 +01:00
										 |  |  | #include <LibGUI/GBoxLayout.h>
 | 
					
						
							|  |  |  | #include <LibGUI/GButton.h>
 | 
					
						
							| 
									
										
										
										
											2019-03-28 17:19:56 +01:00
										 |  |  | #include <LibGUI/GPainter.h>
 | 
					
						
							| 
									
										
										
										
											2019-06-07 11:46:02 +02:00
										 |  |  | #include <LibGUI/GToolBar.h>
 | 
					
						
							| 
									
										
										
										
											2019-02-20 02:39:46 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | GToolBar::GToolBar(GWidget* parent) | 
					
						
							|  |  |  |     : GWidget(parent) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     set_size_policy(SizePolicy::Fill, SizePolicy::Fixed); | 
					
						
							| 
									
										
										
										
											2019-07-20 22:39:24 +02:00
										 |  |  |     set_preferred_size(0, 28); | 
					
						
							| 
									
										
										
										
											2019-02-20 02:39:46 +01:00
										 |  |  |     set_layout(make<GBoxLayout>(Orientation::Horizontal)); | 
					
						
							| 
									
										
										
										
											2019-02-20 11:56:28 +01:00
										 |  |  |     layout()->set_spacing(0); | 
					
						
							| 
									
										
										
										
											2019-03-27 20:48:23 +01:00
										 |  |  |     layout()->set_margins({ 2, 2, 2, 2 }); | 
					
						
							| 
									
										
										
										
											2019-02-20 02:39:46 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | GToolBar::~GToolBar() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-11 15:55:54 +02:00
										 |  |  | void GToolBar::add_action(GAction& action) | 
					
						
							| 
									
										
										
										
											2019-02-20 02:39:46 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     auto item = make<Item>(); | 
					
						
							|  |  |  |     item->type = Item::Action; | 
					
						
							| 
									
										
										
										
											2019-07-11 15:55:54 +02:00
										 |  |  |     item->action = action; | 
					
						
							| 
									
										
										
										
											2019-02-20 02:39:46 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     auto* button = new GButton(this); | 
					
						
							| 
									
										
										
										
											2019-04-12 02:53:27 +02:00
										 |  |  |     button->set_action(*item->action); | 
					
						
							| 
									
										
										
										
											2019-04-08 18:58:44 +02:00
										 |  |  |     button->set_tooltip(item->action->text()); | 
					
						
							| 
									
										
										
										
											2019-02-20 02:39:46 +01:00
										 |  |  |     if (item->action->icon()) | 
					
						
							|  |  |  |         button->set_icon(item->action->icon()); | 
					
						
							|  |  |  |     else | 
					
						
							| 
									
										
										
										
											2019-05-24 16:32:20 +02:00
										 |  |  |         button->set_text(item->action->text()); | 
					
						
							| 
									
										
										
										
											2019-07-11 15:55:54 +02:00
										 |  |  |     button->on_click = [&action](const GButton&) { | 
					
						
							|  |  |  |         action.activate(); | 
					
						
							| 
									
										
										
										
											2019-02-20 02:39:46 +01:00
										 |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-28 17:32:38 +01:00
										 |  |  |     button->set_button_style(ButtonStyle::CoolBar); | 
					
						
							| 
									
										
										
										
											2019-02-20 02:39:46 +01:00
										 |  |  |     button->set_size_policy(SizePolicy::Fixed, SizePolicy::Fixed); | 
					
						
							| 
									
										
										
										
											2019-03-15 23:24:40 +01:00
										 |  |  |     ASSERT(button->size_policy(Orientation::Horizontal) == SizePolicy::Fixed); | 
					
						
							|  |  |  |     ASSERT(button->size_policy(Orientation::Vertical) == SizePolicy::Fixed); | 
					
						
							| 
									
										
										
										
											2019-07-20 22:39:24 +02:00
										 |  |  |     button->set_preferred_size(24, 24); | 
					
						
							| 
									
										
										
										
											2019-02-20 02:39:46 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     m_items.append(move(item)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-07 23:01:36 +01:00
										 |  |  | class SeparatorWidget final : public GWidget { | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  |     SeparatorWidget(GWidget* parent) | 
					
						
							|  |  |  |         : GWidget(parent) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         set_size_policy(SizePolicy::Fixed, SizePolicy::Fixed); | 
					
						
							|  |  |  |         set_background_color(Color::White); | 
					
						
							| 
									
										
										
										
											2019-07-20 22:39:24 +02:00
										 |  |  |         set_preferred_size(8, 22); | 
					
						
							| 
									
										
										
										
											2019-03-07 23:01:36 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-06-07 11:46:02 +02:00
										 |  |  |     virtual ~SeparatorWidget() override {} | 
					
						
							| 
									
										
										
										
											2019-03-07 23:01:36 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     virtual void paint_event(GPaintEvent& event) override | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2019-03-28 17:19:56 +01:00
										 |  |  |         GPainter painter(*this); | 
					
						
							| 
									
										
										
										
											2019-03-29 15:01:54 +01:00
										 |  |  |         painter.add_clip_rect(event.rect()); | 
					
						
							| 
									
										
										
										
											2019-03-07 23:01:36 +01:00
										 |  |  |         painter.translate(rect().center().x() - 1, 0); | 
					
						
							| 
									
										
										
										
											2019-03-27 20:48:23 +01:00
										 |  |  |         painter.draw_line({ 0, 0 }, { 0, rect().bottom() }, Color::MidGray); | 
					
						
							| 
									
										
										
										
											2019-03-07 23:01:36 +01:00
										 |  |  |         painter.draw_line({ 1, 0 }, { 1, rect().bottom() }, Color::White); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-03-15 23:24:40 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							|  |  |  |     virtual const char* class_name() const override { return "SeparatorWidget"; } | 
					
						
							| 
									
										
										
										
											2019-03-07 23:01:36 +01:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-20 02:39:46 +01:00
										 |  |  | void GToolBar::add_separator() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto item = make<Item>(); | 
					
						
							|  |  |  |     item->type = Item::Separator; | 
					
						
							| 
									
										
										
										
											2019-03-07 23:01:36 +01:00
										 |  |  |     new SeparatorWidget(this); | 
					
						
							| 
									
										
										
										
											2019-02-20 02:39:46 +01:00
										 |  |  |     m_items.append(move(item)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void GToolBar::paint_event(GPaintEvent& event) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-03-28 17:19:56 +01:00
										 |  |  |     GPainter painter(*this); | 
					
						
							| 
									
										
										
										
											2019-03-29 15:01:54 +01:00
										 |  |  |     painter.add_clip_rect(event.rect()); | 
					
						
							| 
									
										
										
										
											2019-05-10 22:58:52 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (m_has_frame) | 
					
						
							|  |  |  |         StylePainter::paint_surface(painter, rect(), x() != 0, y() != 0); | 
					
						
							|  |  |  |     else | 
					
						
							| 
									
										
										
										
											2019-06-30 09:23:16 +02:00
										 |  |  |         painter.fill_rect(event.rect(), Color::WarmGray); | 
					
						
							| 
									
										
										
										
											2019-02-20 02:39:46 +01:00
										 |  |  | } |